1 / 32

Chapter 1

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, questions 1a, 1b, 2a, 2b, & 10 Also, what exactly is a dictionary (not Webster's) Due Wed 1/28 (in class). Agenda. WTF? Euclid’s algorithm

Download Presentation

Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 Sections 1.1 – 1.4pages 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, & 10 • Also, what exactly is a dictionary (not Webster's) • 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. Pick an algorithm design technique Pick data structures, etc. Design an algorithm Prove correctness Analyze the algorithm Code the algorithm Algorithm design & analysis process Understand the Problem WTF?

  5. Euclid’s Algorithm • while n != 0 do r  m mod n m  n n  rreturn 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? • 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. • 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 mod? • 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.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 problem algorithm “computer” input output

  15. Example of computational problem: sorting • Statement of problem: • Input: A sequence of n numbers <a1, a2, …, an> • Output: A reordering of the input sequence <a´1, a´2, …, a´n> so that a´i≤ a´j whenever i < j • Instance: The sequence <5, 3, 2, 8, 3> • Algorithms: • Selection sort • Insertion sort • Merge sort • (many others)

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

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

  18. Analysis of Algorithms • How good is the algorithm? • Correctness • Time efficiency • Space efficiency • Does there exist a better algorithm? • Lower bounds • Optimality

  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. 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 Why do we care?

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

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

  23. Why study algorithms? • Theoretical importance • the core of computer science • Practical importance • A practitioner’s toolkit of known algorithms • Framework 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 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 checkers • Pattern matching used to find genes in DNA • Or, 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 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, & 10 • Also, what exactly is a dictionary (not Webster's) • Due Wed 1/28 (in class)

More Related