Docsity

Lecture Notes on Algorithms and Data Structures | CSE 331, Study notes of Computer Science

Toggle sidebar
bg1
CSE 331, Summer 2002, Lecture #1
1. Algorithms, Data Structures & Computer Science
(a) Core of computer science; of the youngest of math disciplines
(b) Definitions / Purposes
(c) An algorithm is good, bad, better than, best, or worst – how? In terms of what?
(d) Today: Functions & Rates of Growth (O, Θ, and Ω)
2. Requirement of notation for comparison
3. Definitions:
Let n, c, c1, c2be positive integers
Let all functions be of non-negative range
(a) T(N) = O(f(N)) iff ∃c, ∃n:: ∀N > n,T(N)≤c·f(N)
(b) T(N) = Ω(g(N)) iff ∃c, ∃n:: ∀N > n, T (N)≥c·g(N)
(c) T(N) = Θ(h(N)) iff ∃c1,∃c2,∃n:: ∀N > n, T (N)≤c1·h(N) and T(N)≥
c2·h(N), or
(c) T(N) = Θ(h(N)) iff T(N) = O(h(N)) and T(N) = Ω(h(N))
(d) T(N) = o(p(N)) iff T(N) = O(p(N)) and T(N)6= Θ(p(N))
4. Basic examples
5. Rules:
•If T1(N) = O(f(N)) and T2(N) = O(g(N)),
(a) T1(N) + T2(N) = max(O(f(N), O(g(N)))
(b) T1(N)·T2(N) = O(f(N)·g(N))
•If T(N) is a polynomial of degree x,T(N) = Θ(Nx)
•logk(N) = O(N) for any constant k
6. Examples (Style: The Good, The Bad, and The Just Plain Wrong)
7. Assumed model of computation: standard computer (Turing machine)
8. General rules (statements / control constructs); examples
9. Recursion, recurrence relations
(a) Recurrence relation formation; example: Fibonacci
(b) Solving: three general methods: substitution, iteration, “master”
i. Substitution:
pf2

Partial preview of the text

Download Lecture Notes on Algorithms and Data Structures | CSE 331 and more Study notes Computer Science in PDF only on Docsity!

CSE 331, Summer 2002, Lecture

  1. Algorithms, Data Structures & Computer Science

(a) Core of computer science; of the youngest of math disciplines (b) Definitions / Purposes (c) An algorithm is good, bad, better than, best, or worst – how? In terms of what? (d) Today: Functions & Rates of Growth (O, Θ, and Ω)

  1. Requirement of notation for comparison
  2. Definitions:

Let n, c, c 1 , c 2 be positive integers Let all functions be of non-negative range

(a) T (N) = O(f (N)) iff ∃c, ∃n :: ∀N > n, T (N) ≤ c · f (N) (b) T (N) = Ω(g(N)) iff ∃c, ∃n :: ∀N > n, T (N) ≥ c · g(N) (c) T (N) = Θ(h(N)) iff ∃c 1 , ∃c 2 , ∃n :: ∀N > n, T (N) ≤ c 1 · h(N) and T (N) ≥ c 2 · h(N), or (c) T (N) = Θ(h(N)) iff T (N) = O(h(N)) and T (N) = Ω(h(N)) (d) T (N) = o(p(N)) iff T (N) = O(p(N)) and T (N) 6 = Θ(p(N))

  1. Basic examples
  2. Rules:
    • If T 1 (N) = O(f (N)) and T 2 (N) = O(g(N)), (a) T 1 (N) + T 2 (N) = max(O(f (N), O(g(N))) (b) T 1 (N) · T 2 (N) = O(f (N) · g(N))
    • If T (N) is a polynomial of degree x, T (N) = Θ(N x)
    • logk(N) = O(N) for any constant k
  3. Examples (Style: The Good, The Bad, and The Just Plain Wrong)
  4. Assumed model of computation: standard computer (Turing machine)
  5. General rules (statements / control constructs); examples
  6. Recursion, recurrence relations

(a) Recurrence relation formation; example: Fibonacci (b) Solving: three general methods: substitution, iteration, “master” i. Substitution:

  • Make a(n educated) guess at the bound
  • Substitute your guess
  • Prove the desired bound (via algebraic manipulation ii. Substitution example iii. Iteration:
  • Iteratively expandthe recurrence until a bounding condition on N is reached (e.g., N=1)
  • Algebraically manipulate the iterated expression into a summation orother non-recurring form
  • Solve/bound the resulting expression through normal means iv. Iteration example (with recursion tree) v. Master method:
  • Conveniently solves recurrences of the form: T (N) = aT (N/b)+f (N), a, b ≥ 1 where a and b are constants and f (N) is asymptotically positive
  • This form of recurrence generally describes running times of recursive algorithms which divide a problem into subproblems of size N/b. Appli- cation requires the memorization of three rules: A. If f (N) = O(N logb(a−)) for some constant  > 0, then T (N) = Θ(N logb^ a) B. If f (N) = Θ(N logb^ a) for some constant  > 0, then T (N) = Θ(N logb^ a^ lg N) C. If f (N) = Ω(N logb(a+)) for some constant  > 0, and if a · f (N/b) ≤ cf (N) for some constant c < 1, and all sufficiently large N, then T (N) = Θ(f (N)) vi. Master method basic idea; holes; inapplicability vii. Master method examples; proof (not here) (c) Examples: Fibonacci, Maximum Subsequence Sum, Binary Search, Euclid’s Al- gorithm
  1. Summary; review