lec10 - 6.006 Introduction to AlgorithmsLecture 10 Prof...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.006- Introduction to AlgorithmsLecture 10 Prof. Piotr Indyk Quiz Rules •Do not open this quiz booklet until directed to do so. Read all the instructions on this page •When the quiz begins, write your name on every page of this quiz booklet. •You have 120 minutes to earn 120 points. Do not spend too much time on any one problem. Read them all through first, and attack them in the order that allows you to make the most progress. •This quiz booklet contains X pages, including this one. Two extra sheets of scratch paper are attached. Please detach them before turning in your quiz at the end of the exam period. •This quiz is closed book. You may use one 8 1 ′′×11′′or A4 crib sheets (both sides). No calculators or programmable devices are permitted. No cell phones or other communications devices are permitted. •Write your solutions in the space provided. If you need more space, write on the back of the sheet containing the problem. Pages may be separated for grading. •Do not waste time and paper re-deriving facts that we have studied. It is sufficient to cite known results. •Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the clarity with which you express it. Be neat. *At participating locations only. Do not use while sleeping. Read label before using. Details inside.Harmful if swallowed. Menu: sorting ctd. •Show that Θ(nlg n)is the best possible running time for a sorting algorithm. •Design an algorithm that sorts in Θ(n)time. •??? •Hint: maybe the models are different ? Comparison sort All the sorting algorithms we have seen so far are comparison sorts: only use comparisons to determine the relative order of elements. •E.g., insertion sort, merge sort, heapsort. The best running time that we’ve seen for comparison sorting is O(nlgn). Is O(nlgn)the best we can do via comparisons? Decision treescan help us answer this question. Decision-tree 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 A recipe for sorting nnumbers 〈a1, a2, …, an〉≥≤- Branching direction depends on outcome of comparisons. - Nodes are suggested comparisons: i:jmeans compareaitoaj, for i, j ∈{1, 2,…, n}. ≥≤≥≤≥≤≥≤- Leaves are labeled with permutations corresponding to the outcome of the sorting. Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i:jfor i, j ∈{1, 2,…, n}. •The left subtree shows subsequent comparisons if ai≤aj. •The right subtree shows subsequent comparisons if ai≥aj. 9 ≥4 Sort 〈a1, a2, a3〉= 〈9, 4, 6 〉:1:2 Decision-tree example 1:2 2:3 123 1:3 132 312 1:3 213 2:3 231 321 Each internal node is labeled i:jfor i, j ∈{1, 2,…, n}....
View Full Document

Page1 / 64

lec10 - 6.006 Introduction to AlgorithmsLecture 10 Prof...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online