Introduction - Introduction to Algorithms - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Introduction to Algorithms which includes Expensive Operations, Sort Edges, Running Time, Upshot, Union, Makeset, Disjoint Set, Disjoint Set Union, Naïve Implementation etc. Key important points are: Introduction, Programming, Introduction to Algorithms, Big White Book, Smaller Green Book, Constant, Proof By Induction, Formula, Inductive Hypothesis, Arbitrary

Typology: Slides

2012/2013

Uploaded on 03/23/2013

dhruv
dhruv 🇮🇳

4.3

(12)

194 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Algorithms
Introduction
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Introduction - Introduction to Algorithms - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Algorithms

Introduction

The Course

  • Purpose: a rigorous introduction to the design

and analysis of algorithms

 Not a lab or programming course  Not a math course, either

  • Textbook: Introduction to Algorithms ,

Cormen, Leiserson, Rivest, Stein

 The “Big White Book”  Second edition: now “Smaller Green Book”  An excellent reference you should own

The Course

  • Grading policy:

 Homework: 30%  Exam 1: 15%  Exam 2: 15%  Final: 35%  Participation: 5%

The Course

  • Prerequisites:

 CS 202 w/ grade of C- or better  CS 216 w/ grade of C- or better  CS 302 recommended but not required o Who has not taken CS 302?

Review: Induction

  • Suppose

 S(k) is true for fixed constant k o Often k = 0  S(n)  S(n+1) for all n >= k

  • Then S(n) is true for all n >= k

Proof By Induction

  • Claim:S(n) is true for all n >= k
  • Basis:

 Show formula is true when n = k

  • Inductive hypothesis:

 Assume formula is true for an arbitrary n

  • Step:

 Show that formula is then true for n+

Induction Example: Geometric Closed Form

  • Prove a 0 + a^1 + … + a n^ = (an+1^ - 1)/(a - 1) for

all a ≠ 1

 Basis: show that a 0 = (a 0+1^ - 1)/(a - 1) a 0 = 1 = (a 1 - 1)/(a - 1)  Inductive hypothesis: o Assume a 0 + a 1 + … + a n^ = (a n+1^ - 1)/(a - 1)  Step (show true for n+1): a 0 + a 1 + … + a n+1^ = a 0 + a 1 + … + a n^ + a n+ = (a n+1^ - 1)/(a - 1) + a n+1^ = (a n+1+1^ - 1)/(a - 1)

Induction

  • We’ve been using weak induction
  • Strong induction also holds  Basis: show S(0)  Hypothesis: assume S(k) holds for arbitrary k <= n  Step: Show S(n+1) follows
  • Another variation:  Basis: show S(0), S(1)  Hypothesis: assume S(n) and S(n+1) are true  Step: show S(n+2) follows

Asymptotic Notation

  • By now you should have an intuitive feel for

asymptotic (big-O) notation:

What does O(n) running time mean? O(n 2 )? O(n lg n)?How does asymptotic running time relate to asymptotic memory usage?

  • Our first task is to define this notation more

formally and completely

Analysis of Algorithms

  • Analysis is performed with respect to a

computational model

  • We will usually use a generic uniprocessor

random-access machine (RAM)

 All memory equally expensive to access  No concurrent operations  All reasonable instructions take unit time o Except, of course, function calls  Constant word size o Unless we are explicitly manipulating bits

Running Time

  • Number of primitive steps that are executed

 Except for time of executing a function call most statements roughly require the same amount of time o y = m * x + b o c = 5 / 9 * (t - 32 ) o z = f(x) + g(y)

  • We can be more exact if need be

Analysis

  • Worst case

 Provides an upper bound on running time  An absolute guarantee

  • Average case

 Provides the expected running time  Very useful, but treat with care: what is “average”? o Random (equally likely) inputs o Real-life inputs