Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Sections 1.1 – 1.4 pages 1-40. Homework  Read Section 1.4 (recap of data structures)  pages 26-37  Answer the following questions: page 38,

Similar presentations


Presentation on theme: "Chapter 1 Sections 1.1 – 1.4 pages 1-40. Homework  Read Section 1.4 (recap of data structures)  pages 26-37  Answer the following questions: page 38,"— Presentation transcript:

1 Chapter 1 Sections 1.1 – 1.4 pages 1-40

2 Homework  Read Section 1.4 (recap of data structures)  pages 26-37  Answer the following questions: page 38, questions 1a, 1b, 2a, 2b, & 10page 38, questions 1a, 1b, 2a, 2b, & 10 Also, what exactly is a dictionary (not Webster's)Also, what exactly is a dictionary (not Webster's) Due Wed 1/28 (in class)Due Wed 1/28 (in class)

3 Agenda  WTF?  Euclid’s algorithm  What is an algorithm  What is algorithm analysis all about  Problem types

4 Algorithm design & analysis process Understand the Problem Pick an algorithm design technique Pick data structures, etc. Design an algorithmAnalyze the algorithmProve correctnessCode the algorithm WTF?

5 Euclid’s Algorithm  while n != 0 do r  m mod n m  n n  r return m  Isn’t it a cool algorithm?  Its very efficient, no?  How many divisions must it do, as a function of m or n?

6 Euclid’s Algorithm  Best case: m mod n equal zero  Worst case? Prime numbers maybe?Prime numbers maybe? How do you get it to do a lot of divisions?How do you get it to do a lot of divisions?

7 Try This  Two prime numbers 29 and 7  Then try 13 and 8.  How can you cause the worst case?

8 Euclid’s Algorithm  Answer: Two consecutive Fibonacci numbers.  In the worst case it will require about L divisions where L is the total number of digits in both n and m.where L is the total number of digits in both n and m.  Proving this is not fun.  Lets not do it, OK?

9 Euclid’s Algorithm  If I have two 10 digit numbers, Euclid’s algorithm will take (at most) about 20 divisions.  Whereas, consecutive integer checking could take 9,999,999,999 X 2 divisions.  How does Euclid’s algorithm gain such an advantage?

10 Euclid’s Algorithm  r  m mod n  If r is not equal to zero then all the numbers between m and r are NOT gcd’s of m and n.  Its all about understanding the properties of the problem. What is the definition of a gcd?What is the definition of a gcd? What is the definition of mod?What is the definition of mod? The two are related.The two are related.

11 An Algorithm  A sequence of unambiguous instructions for solving a problem,  i.e., for obtaining a required output for any legitimate input  in a finite amount of time.

12 History Lesson  Muhammad ibn Musa al-Khwarizmi Famous mathematician from Bagdad 800 A.DFamous mathematician from Bagdad 800 A.D  He wrote Al-jabr wa'l muqabala (from which our modern word "algebra" comes)  The English word "algorithm" derives from the Latin form of al-Khwarizmi's name

13 Stupid, irrelevant, personal anecdote  As an undergraduate, I had Indian Professor who was an expert on algorithms and pronounced the word  A – grow – rid – em’s  Lets practice saying the word so we don’t sound like idiots.

14 Notion of algorithm “computer” problem algorithm inputoutput

15 Example of computational problem: sorting  Statement of problem: Input: A sequence of n numbers Input: A sequence of n numbers Output: A reordering of the input sequence so that a ´ i ≤ a ´ j whenever i so that a ´ i ≤ a ´ j whenever i < j  Instance: The sequence  Instance: The sequence  Algorithms: Selection sortSelection sort Insertion sortInsertion sort Merge sortMerge sort (many others)(many others)

16 Example  Input: array a[1],…,a[n]  Output: array a sorted in non-decreasing order  Algorithm: for i=1 to n for i=1 to n swap a[i] with smallest of a[i],…a[n] swap a[i] with smallest of a[i],…a[n]

17 Algorithm design strategies  Brute force  Divide and conquer  Decrease and conquer  Transform and conquer  Greedy approach  Dynamic programming  Backtracking and Branch and bound  Space and time tradeoffs

18 Analysis of Algorithms  How good is the algorithm? CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace efficiency  Does there exist a better algorithm? Lower boundsLower bounds OptimalityOptimality

19 Some Well-known Computational Problems  Sorting  Searching  Shortest paths in a graph  Minimum spanning tree  Primality testing  Traveling salesman problem  Knapsack problem  Chess  Towers of Hanoi  Program termination

20 Why do we care?  Sorting  Searching  Shortest paths in a graph  Minimum spanning tree  Primality testing  Traveling salesman problem  Knapsack problem  Chess  Towers of Hanoi  Program termination Variations of the solutions to these problems are used to…  Schedule flights  Route Internet traffic  Make Google work  Prevent the stock-market from crashing  Assemble the human genome  Encrypt data  Save UPS millions of dollars  Track terrorist cell communication on the Internet  Make spell checkers work  help keep you from going through the walls in games like Halo and CounterStrike

21 Basic Issues Related to Algorithms  How to design algorithms  How to express algorithms  Proving correctness  Efficiency Theoretical analysisTheoretical analysis Empirical analysis (experiments)Empirical analysis (experiments)  Optimality

22 What is an algorithm?  Recipe, process, method, technique, procedure, routine,… with following requirements: 1. Finiteness b terminates after a finite number of steps 2. Definiteness b rigorously and unambiguously specified 3. Input b valid inputs are clearly specified 4. Output b can be proved to produce the correct output given a valid input 5. Effectiveness b steps are sufficiently simple and basic

23 Why study algorithms?  Theoretical importance the core of computer sciencethe core of computer science  Practical importance A practitioner’s toolkit of known algorithmsA practitioner’s toolkit of known algorithms Framework for designing and analyzing algorithms for new problemsFramework for designing and analyzing algorithms for new problems

24 Important Types of Problems  Sorting & Searching  String matching & pattern matching  Graph Problems  Combinatorial Problems  Geometric Problems  Numerical Problems

25 Sorting & Searching  Intrinsically related Sorting can make searching easierSorting can make searching easier  sort key – an important attribute used to sort data  stable sort – preserves the relative order of any two equal elements  in place sorting – doesn’t require extra memory  search key – not necessarily unique

26 String matching & pattern matching  Amazingly well-studied  Surprisingly difficult problem for certain variations  Tons of applications: Approximate matching used in spell checkersApproximate matching used in spell checkers Pattern matching used to find genes in DNAPattern matching used to find genes in DNA Or, used to find patterns in the stock marketOr, used to find patterns in the stock market

27 Graph Problems  Graphs can be used to model all sorts of real-world environments, scenarios, and systems. Relationship modeling using graphs is very powerfulRelationship modeling using graphs is very powerful  Representing the real-world as a graph can allow computers to solve all sorts of problems.  Graph related algorithms are being used to detect terrorist cell communication via the Internet.  Hell, the Internet itself is a massive graph.

28 Combinatorial Problems  Certain problems, like optimal scheduling or routing, can be reduced to finding the optimal parameters among the set of all possible parameters  But, the number of different parameter combinations can become very large, too large.  Reducing the combinatorial space of problems is a very important strategy in algorithms

29 Geometric Problems  These problems can be as simple as finding the intersection point of two lines to  Finding the Delaunay Triangulation of the smallest convex polygon containing a given set of points.  These types of problems arise from modeling all sorts of real-world entities.

30 Numerical Problems  Problems involving mathematical objects  solving equations  computing integrals  efficiently evaluating functions  i.e., really boring stuff

31 Data Structures  The assigned reading is all about common data structures used in algorithms  Data structures are just one of many tools that can be used to improve algorithms  Perhaps they are the most important tool  Do the reading and homework  This material should not be new.

32 Homework  Read Section 1.4 (recap of data structures)  pages 26-37  Answer the following questions: page 38, questions 1a, 1b, 2a, 2b, & 10page 38, questions 1a, 1b, 2a, 2b, & 10 Also, what exactly is a dictionary (not Webster's)Also, what exactly is a dictionary (not Webster's) Due Wed 1/28 (in class)Due Wed 1/28 (in class)


Download ppt "Chapter 1 Sections 1.1 – 1.4 pages 1-40. Homework  Read Section 1.4 (recap of data structures)  pages 26-37  Answer the following questions: page 38,"

Similar presentations


Ads by Google