Download presentation
Presentation is loading. Please wait.
1
Preliminaries (Sections 2.1 & 2.2)
2
SimpleSearch Algorithm
Suppose that we are given an array A[1…N+1] with N elements and an element e. We need to return the position in A where e is located or N+1 if e is not in A. i 1 While (A [i] e and i < N+1) i i +1 Return i
3
Complexity: Worst-Case vs Best-Case
Let k = # operations in one cycle of SimpleSearch (assume that operations take the same amount of time) t(Best case): t(Worst case):
4
Complexity: Average Case
(t(Best Case) + … + t(Worst Case)) / (# cases) We are making an strong assumption here, which? That each case will occur with the same probability! Can you think of situations were this does not occur? Array of people with traffic violations. Ordered by highest number of traffic violations
5
O-Notation Definition. A function t(n) is in O(g(n)) if there is a constant c and a number n0 such that: t(n) ≤ cg(n), for all n ≥ n0 Alternative: t(n) is in O(g(n)) if lim(n∞) t(n)/g(n) = k where k is a non-negative real number If t(n) is in O(g(n)) then the order of growth of g(n) is at least as large as t(n)
6
Ω-Notation Definition. A function t(n) is in Ω(g(n)) if there is a constant c and a number n0 such that: t(n) ≥ cg(n), for all n ≥ n0 Alternative: t(n) is in Ω(g(n)) if lim(n∞) t(n)/g(n) = ∞ or lim(n∞) t(n)/g(n) = k where k is a positive real number If t(n) is in Ω(g(n)) then the order of growth of g(n) is at most as large as t(n)
7
Θ-Notation Definition. A function t(n) is in Θ(g(n)) if there are constants c and c’ and a number n0 such that: c’g(n) ≥ t(n) ≥ cg(n), for all n ≥ n0 Alternative: t(n) is in Θ(g(n)) if lim(n∞) t(n)/g(n) = k where k is a positive real number If t(n) is in Θ(g(n)) then the order of growth of g(n) is the same as t(n)
8
Order of Growth List the following functions according to their order of growth (from least to most): n, 2n, n!, n2, n3, ln n, n ln n Note: this is the kind of things you need to know. No calculators are allowed in the tests
9
Homework (Friday) 010: 2.1: 8.b, 8.c 2.2: 2.a, 3.a, 3.d
Look at exercise 7 in Section 2.2 and do what it is asked for the following assertion: 011: 2.1: 3, 8.a, 8.d 2.2: 2.b, 3.b, 7.a t(n) is in Θ(g(n)) then g(n) is in Θ(t(n))
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.