1 / 27

Interesting Algorithms for Real-World Problems

Explore real-world problems and algorithms that can be used in high school classrooms, covering topics such as graph theory, priority queues, and combinatorics.

tosh
Download Presentation

Interesting Algorithms for Real-World Problems

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. Interesting Algorithms for Real World Problems Peter Andreae, VUW Comp Sci

  2. Abstract • There are lots of interesting algorithms for problems that matter in the real world. Often these algorithms are explained with tiny examples that make the problem seem trivial, the algorithm uninteresting, and the mathematics irrelevant. • With slightly larger and more realistic examples, the problems immediately become challenging, and students can see the power of good algorithms and the importance of the related mathematics. • This workshop will explore several such problems and algorithms, which could be used in high school classrooms.

  3. Topics • Mathematics of algorithms • Looking for a name in a list • Graph theory and Djikstra’s Shortest Path algorithm • Google Directions • Graph Theory, Combinatorics for complexity • Priority Queues and Partially Ordered Trees • For Djikstra’s algorithm, simulation, … • Trees, logarithms and more Combinatorics • The Halting problem • Security for browsing and using apps • Proof by contradiction

  4. Looking for a Name in a List • Is the name “Stevens” in your list? • How did you find it? • Two algorithms: • bottom ← 0, top ← n • while you haven’t found it, and bottom ≤ top • look at the middle value • if target < middle: top ← middle • if target > middle: bot ← middle

  5. Looking for a Name in a List • Analysis: • If the list had 1,000,000 names, how many names would you have to look at? • If the list had n names, how many names would you have to look at?

  6. Where’s the Maths? • Writing down the algorithm – requires precision • Thinking about the general case. • Logarithms • log2 (n) = number of times you have to cut a number in half to get to 1 • log2 (n) steps => If a list needs20 steps, doubling the list only takes 21 steps

  7. Finding the Shortest Path in a Graph • Easy! • Obvious that there is a path • How long would it take a computer to find the shortest path? • Who cares – it’s an easy problem. Start 8 13 4 4 8 5 2 1 4 3 2 7 2 2 End 1

  8. Finding the Shortest Path in a Graph 6 3 Start 8 3 8 4 4 4 5 1 9 8 6 7 2 3 5 2 9 2 5 1 7 9 3 5 3 3 3 4 6 4 4 3 5 4 2 2 7 5 2 3 9 8 7 8 2 6 8 6 5 9 7 7 7 6 6 4 5 6 9 8 7 8 9 5 3 End 2 5 2

  9. How did you do it?

  10. Where’s the Maths? • Graph Theory • There a lots of real world problems that can be abstracted into a network of nodes and links (or graphs of vertices and edges) • Road maps (Google Directions) • Social Networks (Facebook etc) • The internet • … • Mathematics is about abstracting stuff, and then working with the abstractions.

  11. Where’s the Maths? • Algorithms • One part of Graph Theory is coming up with effective algorithms for solving various problems in graphs • Shortest paths • Traveling salesman problem • Finding cliques • Max Flow • Planarity • Good algorithms are hard to find! • Many algorithms are tricky!

  12. Where’s the Maths? • Working out whether an Algorithm is good • Complexity theory • How many steps would the algorithm take if there were n nodes? • Relevant maths for high school? • basic combinatorics • logarithms and exponentials • There’s a large collection of problems for which no-one knows if there is an efficient algorithm or not (everyone believes not) • P = NP ?

  13. Djikstra’s Algorithm • Given a graph (nodes and links) and a start node and a goal node,Find the shortest path from start to goal • Key idea: • Build outwards from the start node, building shortest paths to processed nodes. • Keep a fringe of all the unprocessed neighbours of processed nodes • Always choose the node on the fringe with the next shortest path • Stop when you get to the goal.

  14. Djikstra’s algorithm Start 8 13 A B 4 4 8 5 H E 2 1 4 3 K F 2 7 D 2 2 C J End G 1

  15. Djikstra’s algorithm • make a “fringe” – a list with (start, -, 0) on it • repeat until goal is found: • take best (node, from, length) off list • if node’s length is not set • set node’s length to length • record node’s path as from • for each edge from node to an unmarked neighbour • pathLength = node’s length + edge length • add (neighbour, node, pathlength) to fringe Start 8 13 A B 4 4 8 5 H E 2 1 4 3 K F 2 7 D 2 2 C J End G 1

  16. Djikstra’s algorithm • fringe: • node: • from: • length: Start 8 13 A B 4 4 8 5 H E 2 1 4 3 K F 2 7 D 2 2 C J End G 1

  17. Djikstra’s Algorithm • How fast is it? How many steps? • Assume there are n nodes in the graph • Look for the worst case. • repeat • take best node off the fringe • mark it • add its unmarked neighbours to the fringe How many times do we repeat? How many steps does each line take?

  18. Partially Ordered Trees Dog 14 Fox 3 Keep largest (or smallest) element at the root. Bee 35 Cat 19 Eel 26 Hen 23 Ant 9 Gnu 13 Jay 1 • Binary tree • Children ≤ parent, • Order of children not important

  19. Partially Ordered Tree: add Bee 35 Cat 19 Eel 26 Dog 14 Fox 3 Hen 23 Ant 9 Jay 1 Gnu 13 Kea 24 • Easy to add and remove because the order is not complete. • Add: • insert at bottom rightmost • “push up” to correct position. (swapping)

  20. Partially Ordered Tree: remove Bee 35 Kea 24 Eel 26 Dog 14 Cat 19 Hen 23 Ant 9 Jay 1 Gnu 13 Fox 3 • Easy to add and remove because the order is not complete. • Add: • insert at bottom rightmost • “push up” to correct position. • Remove: • “pull up” largest childand recurse. • But: makes tree unbalanced!

  21. Partially Ordered Tree: remove I Bee 35 Kea 24 Eel 26 Dog 14 Cat 19 Hen 25 Ant 9 Jay 1 Gnu 13 Fox 3 • Easier to add and remove because the order is not complete. • Add: • insert at bottom rightmost • “push up” to correct position. • Remove: • “pull up” largest child of rootand recurse on that subtree. • But: makes tree unbalanced! Alternative: • replace root by bottom rightmost node • “push down” to correct position (swapping) • keeps tree balanced – and complete!

  22. Partially Ordered Tree: Eel 26 Kea 24 Hen 23 Dog 14 Cat 19 Fox 3 Ant 9 Jay 1 Gnu 13 How fast is it to add or remove? If there are n nodes in the tree, how many levels? How many swaps to add or remove? So Djikstra’s algorithm takes n2 x log(n) steps

  23. Halting Problem • Malicious code on web pages, malicious apps: => major security problem. • We would like to automatically detect bad programs. • Can you do it? • Not in general! • Can’t even tell if a piece of code will loop for ever or halt!! • How do we know? • We can prove that no-one could do it (for all cases)!

  24. Halting Problem: Proof by contradiction • Suppose you give me a “DoesItHalt” program: • Given another program and an inputSays whether the program would halt or loop forever when given the input • Perhaps the simplest malicious code detector! DoesItHalt Program “Halts” (or “Loops”) Input

  25. Halting Problem: Proof by contradiction • Suppose you give me a“DoesItHalt” program, • Then I could make the following “Tricky” program: • What does Tricky(Tricky) do? Tricky DoesItHalt Program If “Halts” => loop forever If “Loops” => stop

  26. Summary • There’s lots of interesting mathematics wrapped up in algorithms and algorithmic problems. • If you get students to work on a problem, make sure it’s a big enough example • Little examples are too easy to do using visual search • Discrete mathematics is the the mathematics of the digital age!

More Related