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?
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Hm. Do you know what the merge sort method for computing the intersection is?
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?
The only weird thing about this is that merge sort implies there's an ordering to these students.
Not the answer you are looking for? Search for more explanations.
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.
But that may be a worst case so average may be n + n log(n)
There is an interesting article here on this topic: http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergen.htm
"This yields a running time of mergesort of at most 1.5n log(n) steps."
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)?
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.