1 / 14

Sorting Algorithm

Sorting Algorithm. Zhen Jiang West Chester University zjiang@wcupa.edu. Outline. Introduction to sorting Selection sorting Bubble sorting Insertion sorting Shell sorting Heap sorting Merge sorting Quick sorting. For instance, 100 print jobs, # of pages is random

palers
Download Presentation

Sorting Algorithm

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. Sorting Algorithm Zhen Jiang West Chester University zjiang@wcupa.edu

  2. Outline • Introduction to sorting • Selection sorting • Bubble sorting • Insertion sorting • Shell sorting • Heap sorting • Merge sorting • Quick sorting

  3. For instance, • 100 print jobs, # of pages is random • Three queues (1-9, 10-49, and 50-100 pages) • 3 printers (each prints out 1 page per second) • Pick a job from queue 1 first • If none, pick a job from queue 2, and then 3. • Each job arrived at the beginning and be cashed into the queue according to its length (page #). Its waiting time is counted from the beginning until when it is served by a printer. • Develop a program to simulate this process and print out the total waiting time of all jobs.

  4. For example 3, 2, 4, 5, 4, 2, 4. • Waiting 0, 0, 0, 2, 3, 4, 6. Total = 15 seconds.

  5. Smallest first of 3, 2, 4, 5, 4, 2, 4? • Waiting 0, 0, 2, 6, 2, 0, 3. Total = 13 seconds. • Sorting is needed!

  6. Selection sort • https://www.youtube.com/watch?v=cqh8nQwuKNE • See SelectionSort.java in project materials • Due to the unchecked call to compareTo, there is warning message in the compiling. Please ignore it.

  7. Bubble sort • https://www.youtube.com/watch?v=F13_wsHDIG4 • See SelectionSort.java in project materials

  8. Insertion sort, p272 • https://www.youtube.com/watch?v=lCDZ0IprFw4 • https://www.youtube.com/watch?v=eTvQIbB-AuE • See InsertionSort.java in project materials

  9. Shell Sort, p274 • https://www.youtube.com/watch?v=ddeLSDsYVp8 • See ShellSort.java in the project materials

  10. Heap sorting, p278 • https://www.youtube.com/watch?v=LbB357_RwlY • Sorting_out

  11. Mergesort, p282 • https://www.youtube.com/watch?v=iMT7gTPpaqw • https://www.youtube.com/watch?v=qdv3i6X0PiQ • See MergeSort.java in the project materials

  12. Quicksort, p288 • https://www.youtube.com/watch?v=B4URnLNITgw • https://www.youtube.com/watch?v=ZHVk2blR45Q&t=13s • See QuickSort.java in the project materials

  13. Summary • What is the target to select in selection sort? • What is that bubble in the bubble sort? • What is to insert and where to insert in the insertion sort? • Why the shell sort is better than the insertion sort? • When the heap sort can perform over than quick and merge sorts? • Why merge sort has a performance of O(n2)? • Why quick sort is the quickest and how to ensure this?

  14. Reference answer • The i^th min/max value in i^th iteration • The larger value, may be replaced in the middle of process by an even larger value • Current value in sort and its location in the sorted values. • The data preparation in a bipartite graph, which has a less cost than the following insertion sort in the 2nd phase • When the partial sorting results are needed, e.g., top 3 • Total log n levels + n new location at each level • The use of pivot

More Related