Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (s3a):

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?

OpenStudy (shadowfiend):

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

OpenStudy (shadowfiend):

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?

OpenStudy (shadowfiend):

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

OpenStudy (shadowfiend):

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.

OpenStudy (shadowfiend):

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

OpenStudy (asnaseer):

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."

OpenStudy (shadowfiend):

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)?

OpenStudy (asnaseer):

sounds plausible

OpenStudy (mathmate):

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.

OpenStudy (shadowfiend):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!