Intro to Computer Algorithms Lecture 1 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Intro to Computer Algorithms Lecture 1

Description:

Euclid's Algorithm. Correctness. How do we know it halts? ... Prove Euclid's algorithm always halts on positive integer inputs m n. Page 18: #5, #9 ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 19
Provided by: pgb8
Category:

less

Transcript and Presenter's Notes

Title: Intro to Computer Algorithms Lecture 1


1
Intro to Computer Algorithms Lecture 1
  • Phillip G. Bradford
  • Computer Science
  • University of Alabama

2
General Lecture Format
  • Some power-point slides
  • Some white-board writing
  • Details are very important
  • Lots of Interaction a good thing

3
Lecture Outline
  • Syllabus
  • Learning
  • Grading
  • Your Expectations
  • My Expectations
  • Material High Level Overview
  • Motivation
  • Foundations, History and Perspective
  • Applications of Algorithms the Future

4
Lecture Outline
  • The book by A. Levitin
  • Design paradigms approach
  • Nice way to think about design analysis
  • Classifications of challenges on how they are
    solved
  • Commonalities are the solutions
  • Lets get started
  • Chapter 1.1 to 1.3

5
My Expectations
  • Exercise gives strength
  • This is an exercise course
  • Excellent Students give excellent results
  • Given a good deal of exercise
  • What are your expectations?
  • Survey

6
Motivation
  • How hard is it to solve Computer Challenges?
  • Deep Questionheavy ramifications
  • Optimization Applications
  • Networks
  • Financial Models, business issues, etc.
  • Real-Time Applications
  • Airplanes, trains, cars
  • Missiles, Sensors, medical applications, etc.

7
Motivation
  • Foundational questions
  • Sorting searching
  • Exhaustive Search
  • Apparent hardness of old and new challenges
  • Cuts across engineering and many other science
    disciplines

8
Algorithms
  • What is an algorithm?
  • Unambiguous list of instructions that solve a
    challenge
  • Gives the right answer on legitimate input
  • What about algorithms that use randomness?
  • Designed with randomness in mind
  • Really, pseudo-random numbers

9
Algorithms what to doPage 10, Figure 1.2
  • Understand the challenge!
  • Design an algorithm
  • Easy sub cases first, perhaps
  • Prove correctness
  • Analyze the algorithm
  • Check improve design if analysis warrants
  • Iterate, iterate,

10
Euclids Algorithm
  • The challenge
  • Greatest-common divisors
  • GCD(12,6) 6
  • GCD(17,16) 1
  • GCD(20,15) 5
  • Euclids method (assume mgtn)
  • GCD(m,0) m
  • GCD(m,n) GCD(n, m mod n)

11
Euclids Algorithm, cont.
  • Book example
  • GCD(60,24) GCD(24,12) GCD(12,0) 12
  • Euclid(m,n)
  • While(n ! 0)
  • r ? m mod n
  • m ? n
  • n ? r
  • Return m

12
Euclids Algorithm
  • Correctness?
  • Halts?
  • Prime-Factor approach
  • How?
  • Which is better??
  • Relative costs?

13
Euclids Algorithm Correctness
  • Assume m gt n
  • What is the mod function?
  • Start m nfloor(m/n) m mod n
  • So, m - nfloor(m/n) m mod n
  • Thus, if pm and p(nfloor(m/n))
  • Then p(m mod n)
  • What about piqj, for both p and q primes and igt0
    and jgt0 integers?

14
Euclids Algorithm Correctness
  • How do we know it halts?
  • Guaranteed a parameter always decreases at each
    iteration
  • Why?
  • Answer in HW

15
Sieve of Eratosthenes
  • Challenge given an integer n, find all primes lt
    n.
  • Example n 18, then output 2,3,5,7,11,13,17
  • Elimination of prime candidates by potential
    factors
  • Claim the largest potential factor
    floor(sqroot(n))

16
Types of Problems
  • Sorting, Searching
  • Stable Sorts
  • String Processing
  • Graph problems
  • Combinatorial problems
  • TSP
  • Geometric Problems
  • Numerical Problems

17
Homework set
  • Due next Thursday
  • Prove Euclids algorithm always halts on positive
    integer inputs mgtn
  • Page 18 5, 9
  • Page 24 1, 4,
  • Some Old HW briefly reviewed on Tuesday
  • Page 17, 1
  • Page 18, 3, 8

18
Lets Have a Great Semester!
  • Good work pays off!
  • Make use of my office hours!
  • Consider me your algorithms coach!
Write a Comment
User Comments (0)
About PowerShow.com