A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

s3a

  • 4 years ago

I have no idea how to begin for this: In general, what would be the average running time of the merge sort method for computing the intersection between two lists of n students (assuming n>=32000)? Give your answers as a function of n (e.g. T(n) = 43 n + 5 log(n) milliseconds). Could someone please help?

  • This Question is Closed
  1. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hm. Do you know what the merge sort method for computing the intersection is?

  2. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Presumably you sort both lists and then go through piecewise. Assuming merge sort is considered to be T(n) = n log(n) (the usual running time attributed to merge sort), how many additional runs do you have to do through the lists to check what corresponding items there are?

  3. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The only weird thing about this is that merge sort implies there's an ordering to these students.

  4. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    But I think we're looking at T(n) = 2n + n log(n). Because let's assume the two lists have no items in common, but they alternate which one has an item that is greater than the other. Then you'd have to keep switching between each list to check if there are any correspondences and end up going through each of them once.

  5. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    But that may be a worst case so average may be n + n log(n)

  6. asnaseer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There is an interesting article here on this topic: http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergen.htm which states: "This yields a running time of mergesort of at most 1.5n log(n) steps."

  7. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Cool. The missing piece here is of course computing the intersection. Although now that I think about it, what is the intersection but essentially a last application of the merge step with some slightly different logic? So possibly 1.5n + n log(n)?

  8. asnaseer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    sounds plausible

  9. mathmate
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Students usually have a unique numeric id. I believe that was assumed in the question. I think by intersection the question means finding ALL intersections, so we have 2nlogn for sorting 2 lists each of length n, and 2n for going through them once for at total of 2nlogn+2n.

  10. shadowfiend
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Derp. Two lists, two sorts. Good catch hehe.

  11. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.