This preview shows pages 1–10. Sign up to view the full content.
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 DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 141ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiICS141: Discrete Mathematics for Computer Science IDepartment of Information and Computer SciencesUniversity of HawaiiStephen Y. Itoga142ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiLecture 14Chapter 3. The Fundamentals3.3 Complexity of Algorithms3.4 The Integers and Division143ICS 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 slides were done by Prof. Baek144ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiReview: ComplexityAlgorithmic complexity = costof computation.Focus on timecomplexity for our course.Although space & energy are also important.Characterize complexity as a function of input size: Worstcase, bestcase, or averagecase.Use ordersofgrowth notation to concisely summarize the growth properties of complexity functions.145ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiAnalysis of Sorting AlgorithmsCheck out Example 5and Example 6for worstcase time complexity of bubble sort and insertion sort algorithms in terms of the number of comparisons made.146ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiBubble Sort Analysisprocedurebubble sort (a1, a2, …, an: real numbers with n≥2)fori := 1ton – 1forj := 1ton – iifajaj+1theninterchange ajand aj+1{a1, a2, …, anis in increasing order}Worstcase complexity in terms of the number of comparisons: Θ(n2)147ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiInsertion Sortprocedureinsertion sort (a1, a2, …, an: real numbers with n≥2)forj :=2tonbegini:= 1whileajaii:= i+ 1m := ajfork := toj – i – 1ajk:= ajk1ai:= mend{a1, a2, …, anare sorted in increasing order}Worstcase complexity in terms of the number of comparisons: Θ(n2)148ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiCommon Terminology for the Complexity of Algorithms149ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiComputer Time ExamplesAssume time = 1 ns (109second) per operation, problem size = nbits, and #ops is a function of n, as shown.#ops(n) n=10 n=106 log2n3.3 ns 19.9 ns n10 ns 1 ms nlog2n 33 ns 19.9 ms n2 100 ns 16 m 40 s 2n1.024 μs 10301,004.5n! 3.63 ms Ouch!...
View
Full
Document
This note was uploaded on 09/12/2008 for the course ICS 141 taught by Professor Idk during the Fall '08 term at Hawaii.
 Fall '08
 IDK

Click to edit the document details