and elementary data structures linear sorting algorithms
play

and Elementary Data Structures Linear Sorting Algorithms - PowerPoint PPT Presentation

. . Januray 25th, 2011 Biostatistics 615/815 - Lecture 6 Hyun Min Kang Januray 25th, 2011 Hyun Min Kang and Elementary Data Structures Linear Sorting Algorithms Biostatistics 615/815 Lecture 6: . . . . . . . Summary Array Radix


  1. . . Januray 25th, 2011 Biostatistics 615/815 - Lecture 6 Hyun Min Kang Januray 25th, 2011 Hyun Min Kang and Elementary Data Structures Linear Sorting Algorithms Biostatistics 615/815 Lecture 6: . . . . . . . Summary Array Radix sort Introduction . . . . . . . . . . 1 / 32 . . . . . . . . . . . . . . . . . . . . . . . . .

  2. . . Homework #2 will be announced in the next lecture . 815 projects . . . . . . . . 5-6 team pairs in total Team assignment will be made during this week Each team should set up a meeting with the instructor to kick-start the project Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . . . . . . . . . . . . Introduction Radix sort Array Summary Announcements . A good and bad news . . . . 2 / 32 . . . . . . . . . . . . . . . . . . . . . . . . .

  3. . . . . 815 projects . . . . . . . . 5-6 team pairs in total Team assignment will be made during this week Each team should set up a meeting with the instructor to kick-start the project Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . . . . . . . . . . . . Introduction Radix sort Array Summary Announcements . A good and bad news . . . 2 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . • Homework #2 will be announced in the next lecture

  4. . . . . . 815 projects . . . . . . . . the project Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . Array . . . . . . . . . . Introduction . Radix sort Summary Announcements . A good and bad news . . 2 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . • Homework #2 will be announced in the next lecture • 5-6 team pairs in total • Team assignment will be made during this week • Each team should set up a meeting with the instructor to kick-start

  5. . . . . Insertion sort is loop invariant . . . . . . . . Time complexity of Insertion sort . . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . Algorithm description . . . . . . . . . . Introduction Radix sort Array Summary Recap on sorting algorithms : Insertion sort . 3 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 For each j ∈ [2 · · · n ] , iterate element at indices j − 1 , j − 2 , · · · 1 . 2 If A [ i ] > A [ j ] , swap A [ i ] and A [ j ] 3 If A [ i ] < = A [ j ] , increase j and go to step 1 At the start of each iteration, A [1 · · · j − 1] is loop invariant iff: • A [1 · · · j − 1] consist of elements originally in A [1 · · · j − 1] . • A [1 · · · j − 1] is in sorted order. • Worst and average case time-complexity is Θ( n 2 )

  6. . . . Data : array A and indices p and r Mergesort ( A , p , q ); Merge ( A , p , q , r ); end . Time complexity of Mergesort . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . Summary . . . . . . . . . . Introduction Radix sort Array . 4 / 32 Recap on sorting algorithms : Mergesort . Algorithm Mergesort . . . . . . . . . . . . . . . . . . . . . . . . . . . . Result : A [ p .. r ] is sorted if p < r then q = ⌊ ( p + r )/2 ⌋ ; Mergesort ( A , q + 1 , r ); • Worst and average case time-complexity is Θ( n log n )

  7. . . . Data : array A and indices p and r q = Partition ( A , p , r ); end . Time complexity of Quicksort . . . . . . . . Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . Summary . . . . . . . . . . Introduction Radix sort . Array Recap on sorting algorithms : Quicksort Algorithm Quicksort . . . . 5 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . Result : A [ p .. r ] is sorted if p < r then Quicksort ( A , p , q − 1 ); Quicksort ( A , q + 1 , r ); • Average case time-complexity is Θ( n log n ) • Worst case time-complexity is Θ( n 2 ) , but practically faster than other Θ( n log n ) algorithms.

  8. . . Januray 25th, 2011 Biostatistics 615/815 - Lecture 6 Hyun Min Kang How Partition algorithm works Summary Array Radix sort Introduction . . . . . . . . . . 6 / 32 . . . . . . . . . . . . . . . . . . . . . . . . .

  9. . . Januray 25th, 2011 Biostatistics 615/815 - Lecture 6 Hyun Min Kang . . . . . . . . Running example with 100,000 elements (in UNIX or MacOS) . Performance of sorting algorithms in practice . . . . . . . . . Summary . 7 / 32 Introduction Radix sort Array . . . . . . . . . . . . . . . . . . . . . . . . . user@host: ˜ /> time cat src/sample.input.txt | src/stdSort > /dev/null real 0m0.430s user 0m0.281s sys 0m0.130s user@host: ˜ /> time cat src/sample.input.txt | src/insertionSort > /dev/null real 1m8.795s user 1m8.181s sys 0m0.206s user@host: ˜ /> time cat src/sample.input.txt | src/mergeSort > /dev/null real 0m0.898s user 0m0.755s sys 0m0.131s user@host: ˜ /> time cat src/sample.input.txt | src/quickSort > /dev/null real 0m0.427s user 0m0.285s sys 0m0.129s

  10. . a sequence. . . . . . . . Any comparison sort algorithm can be represented as a binary decision tree, where each node represents a comparison. Each path from the root to leaf represents possible series of comparisons to sort Each leaf of the decision tree represents one of n possible An informal proof permutations of input sequences We have n l h , where l is the number of leaf nodes, and h is the height of the tree, equivalent to the # of comparisons. Then it implies h log n n log n Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . . . the worst case . . . . . . . . . . Introduction Radix sort Array Summary Lower bounds for comparison sorting . CLRS Theorem 8.1 . . . . . . . . 8 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . Any comparison-based sort algorithm requires Ω( n log n ) comparisons in

  11. . a sequence. . . . . . . . . decision tree, where each node represents a comparison. Each path from the root to leaf represents possible series of comparisons to sort Each leaf of the decision tree represents one of n possible . permutations of input sequences We have n l h , where l is the number of leaf nodes, and h is the height of the tree, equivalent to the # of comparisons. Then it implies h log n n log n Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 An informal proof . the worst case . . . . . . . . . . . Introduction Radix sort Array Summary Lower bounds for comparison sorting CLRS Theorem 8.1 . . . . . . . . 8 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . Any comparison-based sort algorithm requires Ω( n log n ) comparisons in • Any comparison sort algorithm can be represented as a binary

  12. . a sequence. . . . . . . . . decision tree, where each node represents a comparison. Each path from the root to leaf represents possible series of comparisons to sort permutations of input sequences . We have n l h , where l is the number of leaf nodes, and h is the height of the tree, equivalent to the # of comparisons. Then it implies h log n n log n Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 An informal proof . the worst case . . . . . . . . . . . Introduction Radix sort Array Lower bounds for comparison sorting Summary CLRS Theorem 8.1 . . . . . . . . 8 / 32 . . . . . . . . . . . . . . . . . . . . . . . . . Any comparison-based sort algorithm requires Ω( n log n ) comparisons in • Any comparison sort algorithm can be represented as a binary • Each leaf of the decision tree represents one of n ! possible

  13. . decision tree, where each node represents a comparison. Each path An informal proof . . . . . . . . from the root to leaf represents possible series of comparisons to sort . a sequence. permutations of input sequences the height of the tree, equivalent to the # of comparisons. Then it implies h log n n log n Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . the worst case . Summary . . . . . . . . . . Introduction Radix sort Array 8 / 32 Lower bounds for comparison sorting . . . CLRS Theorem 8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Any comparison-based sort algorithm requires Ω( n log n ) comparisons in • Any comparison sort algorithm can be represented as a binary • Each leaf of the decision tree represents one of n ! possible • We have n ! ≤ l ≤ 2 h , where l is the number of leaf nodes, and h is

  14. . . the worst case . An informal proof . . . . . . . . decision tree, where each node represents a comparison. Each path from the root to leaf represents possible series of comparisons to sort a sequence. permutations of input sequences the height of the tree, equivalent to the # of comparisons. Hyun Min Kang Biostatistics 615/815 - Lecture 6 Januray 25th, 2011 . 8 / 32 . . . Introduction Radix sort . . Array . Summary Lower bounds for comparison sorting . CLRS Theorem 8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Any comparison-based sort algorithm requires Ω( n log n ) comparisons in • Any comparison sort algorithm can be represented as a binary • Each leaf of the decision tree represents one of n ! possible • We have n ! ≤ l ≤ 2 h , where l is the number of leaf nodes, and h is • Then it implies h ≥ log ( n !) = Θ( n log n )

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend