1 / 15

Sorting Algorithms

Sorting Algorithms. Discrete Mathematics. Keyang He. Basic Concepts. Algorithm – a specific set of instructions for carrying out a procedure or solving a problem, usually with the requirement that the procedure terminate at some point .

chandler
Télécharger la présentation

Sorting Algorithms

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 Algorithms Discrete Mathematics Keyang He

  2. Basic Concepts • Algorithm – a specific set of instructions for carrying out a procedure or solving a problem, usually with the requirement that the procedure terminate at some point. • Sorting – the rearrangement of numbers in a list into their correct lexicographic order.

  3. Example • 1, 7, 5, 3, 9 • 1, 3, 5, 7, 9 • 13, 25, 63, 73, 12, 2, 6, 90, 111, 242, 14, 12425, 8, 79, 64, 842, 678931, 53332

  4. Bubble Sort • From n = 1, compare an and an+1 • If an > an+1, switch the order of an and an+1 • Continue this process until all an< an+1

  5. Bubble Sort • 1, 7, 5, 3, 9 • 1, 3, 5, 7, 9 • 1, 7, 5, 3, 9 • 1, 3, 5, 7, 9 • 1, 5, 7, 3, 9 • 1, 5, 3, 7, 9 • 1, 5, 3, 7, 9 • 1, 5, 3, 7, 9

  6. Time Complexity Analysis • Input Size – the size of the input • Basic Operation – instruction or group of instructions such that the total work done by the algorithm is roughly proportional to the number of times this instruction or group of instructions is done

  7. Time Complexity Analysis • Time Complexity Analysis – the determination of how many times the basic operation is done for each value of the input size

  8. Big-O Notation • Big-O Notation –describes the limiting behavior of a function when the argument tends towards a particular value or infinity

  9. Big-O Notation

  10. Merge Sort • Invented by John von Neumann in 1945 • Algorithm • Divide the unsorted list into n sublists, each containing 1 element. • Repeatedly merge sublists to produce new sublists until there is only 1 sublist remaining. This will be the sorted list.

  11. Merge Sort

  12. Sorting Algorithms Comparison

  13. Key-comparison Algorithms • It has been shown that no key-comparison algorithm can perform better than O(n log(n)). • A few special case algorithms can sort certain data sets faster than O(n log(n)). These algorithms are not based on comparing the items being sorted and rely on tricks.

  14. Non Key-comparison Algorithms • Example: 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1,….. a) Count the number of 0’s and 1’s Let n = the number of 0’s Let m = the number of 1’s b) The new array will consist of n 0’s followed by m 1’s

  15. References • http://mathworld.wolfram.com/Sorting.html • http://mathworld.wolfram.com/Algorithm.html • http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html

More Related