This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 121ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiICS141: Discrete Mathematics for Computer Science IDepartment of Information and Computer SciencesUniversity of HawaiiStephen Y. Itoga122ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiLecture 12Chapter 3. The Fundamentals3.1 Algorithms3.2 The Growth of Functions123ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiSome material in these slides were taken/adapted from the slides made by Prof. Michael P. Frank and Prof. Jonathan L. Gross which are provided through the publisher of “Discrete Mathematics and Its Applications” written by Kenneth H. Rosen.Some material was done by Prof. Baek124ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiSorting AlgorithmsSorting is a common operation in many applications.E.g.spreadsheets and databasesIt is also widely used as a subroutine in other dataprocessing algorithms.Two sorting algorithms shown in textbook:Bubble sortInsertion sortHowever, these are notvery efficient, and you shouldnot use them on large data sets!We’ll see some more efficient algorithms later in the course.125ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiBubble SortSmaller elements “float” up to the top of the list, like bubbles in a container of liquid, and the larger elements “sink” to the bottom.126ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiBubble Sort Algorithmprocedurebubble sort (a1, a2, …, an: real numbers with n≥2)fori := 1ton – 1forj := 1ton – iifajaj+1theninterchange ajand aj+1{a1, a2, …, anis in increasing order}Example 4: Use the bubble sort to put 3, 2, 4, 1, 5 into increasing order. (See previous slide)127ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiInsertion Sort AlgorithmEnglish description of algorithm:For each item in the input list,“Insert” it into the correct place in the sorted output list generated so far. Like so:Use linear or binary search to find the location where the new item should be inserted....
View
Full Document
 Fall '08
 IDK
 Insertion Sort, Big O notation, University of Hawaii

Click to edit the document details