1 / 15

Sort and Tree

Sort and Tree. 2014 Spring CS32 Discussion Jungseock Joo. Selection Sort. - From wikipedia.com. Bubble Sort. Merge Sort. Quicksort. Time Complexity. Divide-and-conquer : O(n log 2 n) Otherwise, O(n 2 ). When use what?. In practice std::sort();

eryk
Download Presentation

Sort and Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sort and Tree 2014 Spring CS32 Discussion JungseockJoo

  2. Selection Sort - From wikipedia.com

  3. Bubble Sort

  4. Merge Sort

  5. Quicksort

  6. Time Complexity • Divide-and-conquer : O(n log2n) • Otherwise, O(n2)

  7. When use what? • In practice • std::sort(); • If n is small, you may choose simpler ones. • Considerations • Worst-case performance? • Already sorted? Partially-already sorted? Reversed order? • # of comparisons vs. # of swap/shift

  8. Binary Search Tree • Find 7?

  9. Binary Search Tree • Find 7? – O(log n) Depth of tree ~ log n If balanced.

  10. Binary Search Tree • But, O(n) in unbalanced BSTs • Depth >> log n Depth of tree ~ n If unbalanced.

  11. Code example

  12. Sum of items?

  13. Tree Traversal

More Related