











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
During the study of discrete mathematics, I found this course very informative and applicable.The main points in these lecture slides are:Algorithms, Finite Set of Precise Instructions, Performing Computation, Maximum Element, Linear Search, Binary Search, Endpoint of Search Interval, Binary Search Running Time, Growth of Functions, Measure Algorithms
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












List does NOT have to be sorted!
procedure linear_search ( x : integer; a 1 , a 2 , …, an : integers) i := 1 while ( i ≤ n and x ≠ ai ) i := i + 1 if i ≤ n then location := i else location := 0
{ location is the subscript of the term that equals x, or it is 0 if x is not found}
It takes 3 steps
It takes 4 steps
It takes 6 steps
It takes log 2 n steps
ch3.
Growth of Functions
The binary search takes log 2 n “steps”
Let’s say the binary search takes the following number of steps on specific CPUs: Intel Pentium IV CPU: 58* log 2 n / Motorola CPU: 84.4(log 2 n + 1)/ Intel Pentium V CPU: 44(log 2 n)/
As n increases, the other terms will drop out
The exponent on n will not
c g(x) is greater than f(x) for sufficiently large x. f(x) grows no faster than g(x), as x gets large.
Need to find k and c to show f(x)∈O(g(x)).
In other words, show that 3 x +7 ≤ c* x^2
For input size n = 1000
O(1) 1
O(log n) ≈
O(n) 103
O(n log n) ≈10^4
O(n 2 ) 106
O(n 3 ) 109
O(n 4 ) 1012
O(n c^ ) 10 3*c^ c is a consant
2 n^ ≈10^301
n! ≈10^2568
Proof) Take c = 1, k=1. Then, x 2 > x log x for all x > 1, since x log x = 0 when x = 1, while x 2 = 1.
Proof) Suppose x^2 is O(x log x). Then ∃ c and k such that c x log x ≥ x 2 for x > k. Note that c>2. Otherwise, cx log x < x 2 for x = 3. Consider x = c 3. Then lhs) cx log x = c 4 log c 3 = 2 c 4 log c rhs) x 2 = c 6. Since c>2, it is clear that c 2 > 2 log c. Therefore, cxlog x<x 2 for x=c 3. (Contradiction)
Efficiency of your algorithm? Given input size,
Time complexity: Time used by your computer to solve the problem We use number of operations… Memory (space) complexity: Memory used by your computer to solve the problem We use number of variables allocated…
Example: Find the maximal element in a set
max = a 1 , i = 2 While (i ≤ n) if (max < a (^) i ) max = a (^) i i++ Time complexity: 2 n - 2 comparison, n-1 addition, n+ assignment (worst case) = 4n - 2 operation = θ(n) Memory complexity: 2 = θ(1)
Other example: Hash Chain