Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and Algorithms

Similar presentations


Presentation on theme: "Data Structures and Algorithms"— Presentation transcript:

1 Data Structures and Algorithms
Hard Problems PLSD210

2 Polynomial multiplication
Lecture 21 - Key points Polynomial multiplication Coefficient representation: O(n2) Point-value representation: O(n) Conversion (simple): O(n2) FFT does conversion in O(nlogn) FFT Divide and conquer algorithm Split transform into odd and even components

3 Lecture 21 - Key points FFT Divide and conquer algorithm
Evaluate A(x): Use nk, k=0,n-1 to evaluate A(x) Split log2n times, n/2 work in each step O(nlogn) overall Aeven(x) = a0 + a2x + a4x an-2 xn/2-1 Aodd(x) = a1 + a3x + a5x an-1 xn/2-1 A(x) = Aeven(x2) + Aodd(x2) x

4 Lecture 21 - Key points FFT Actual realisations
Iterative - for efficiency log2n “butterfly” stages Coefficients swapped based on bit reversal of index

5 Polynomial or Intractable?
Polynomial time complexity O(nk) time algorithm, k constant Intractable No O(nk) algorithm is known O(nn) or O(n!) or O(kn) time required

6 Similar Problems? Euler’s Problem Hamilton’s Problem
Is there a path through a graph which traverses each edge only once? Hamilton’s Problem Is there a path which visits each vertex only once?

7 The Bridges of Königsberg
Euler’s Problem The Bridges of Königsberg Can I make a tour through the park, crossing each bridge only once?

8 The Bridges of Königsberg
A Sunday Stroll Can I make a tour through the park, crossing each bridge only once? Exhaustive search Start at each point Traverse all possible paths n x (n -1) x (n -2) ...  O(n!) First choices Second choices

9 Eulerian Path An Eulerian Path exists iff
It is possible to go from any vertex to any other by following the edges (graph must be connected) Every vertex must have an even number of edges connected to it - with at most two exceptions (the start and end points) Obviously necessary conditions Sufficiency proof may be found in the literature

10 Transform the Bridges Problem
Nodes = land Edges = bridges No solution! Determined in O(n) time Count degree of each vertex Hamiltonian Path?

11 Hamiltonian Path Although a path may easily found in this case, no known efficient algorithm for finding a Hamiltonian path But if we find a path, we can verify that it is a Hamiltonian path in polynomial - O(|E|) - time Check that each edge in the path is an edge in the graph (use adjacency matrix) Check that each vertex is visited once only - O(n2)

12 Classes P and NP Class P Class NP Problems solvable in polynomial time
eg Euler’s problem Class NP Non-deterministic Polynomial eg Hamilton’s problem

13 Non-deterministic Polynomial
Class NP Non-deterministic Polynomial At each step, guess which step to take next (eg which vertex to check) Have you found a correct solution? Need polynomial time only Nothing from previous steps guides the next step You have to try all possibilities O(n!) algorithms Non-deterministic part You simply guess!

14 Winning the Turing Award*
No proof that any problem  class NP Problems (eg Hamiltonian path) are believed to be in class NP Because no polynomial time algorithm is known Proving that a problem  class NP or finding a class P algorithm Instant fame! *Computing’s equivalent of the Nobel Prize

15 Composite Numbers Determine whether a number n can be written as the product of two other numbers If the divisors can be found, then it’s simple to verify that they are divisors, but no efficient method of finding them is known

16 Assignment Problem You have to assign students to rooms in a college
You are a compatibility map Students are vertices, Compatible students are linked by an edge If rooms hold 2 students, a class P algorithm but if rooms hold 3 students, a class NP problem!

17 Boolean Satisfiability
Find an assignment of values (true or false) to ai so that is true where op are boolean operators: and, or, ... Equivalent to circuit satisfiability problem: Find a set of inputs which produce a true at the output of a circuit composed of logic gates Solution: Try all 2n possible assignments a1 op a2 op a3 ... op an

18 Map Colouring Colour a map using only three colours, so that adjoining countries don’t have the same colour Easily answered for 2 colours: point at which an odd number of countries meet Solvable for 4 colours proof that 4 colours suffice for any map

19 Map Colouring - Equivalent Problems
Graph equivalent Vertices = countries Edges connect countries with common borders Work scheduling Vertices = tasks Edges represent common resources eg linked tasks require some machine 3 colour marking of the vertices allocation of tasks to 3 shifts in a day

20 Reducing Problems Reduction Map Colouring  boolean satisfiability
A solution can be constructed by assignment of true or false to a set of variables: ar = true  A is red ab = true  A is blue ag = true  A is green br = true  B is red

21 Reducing Problems Map colouring solution
If we can find a set of values for ax, bx, ... which make this expression true, we’ve found a map colouring Special class of problems in NP The NP-complete problems All problems in NP are efficiently reducible to them Efficiently = “in polynomial time” ((ar & ~ ab & ~ag ) & (bb & ~ br. ... ) & (cb ...

22 NP-Complete problems Many problems have been shown to be efficiently reducible to boolean satisfiability but an efficient solution to this (and thus any other NP-complete problem!) has eluded many researchers for a long time! It’s believed that class NP  class P Key word!

23 Solving NP-Complete problems
Intractible problems are soluble It’s just a question of patience (or longevity!) Non-deterministic algorithms Alternately Non-deterministic (guessing) step Select the next step randomly No guidelines: any step may be the solution Deterministic step Determine (in polynomial time) whether you have found a solution or not Key word!

24 The Travelling Salesman Problem
A salesman has a number of cities which he must visit, find the minimum cost tour Optimisation problem Can we reduce it to boolean satisfiability? Problem must have a true / false answer Recast as: Does a tour exist with cost less than x? Reduce x until the answer is provably no ... optimal tour This problem may be proved equivalent to finding a Hamiltonian circuit

25 The Travelling Salesman Problem
A salesman has a number of cities which he must visit, find the minimum cost tour Many real world problems map to TSP Drilling circuit boards Inspection tours ... How do we solve it? Heuristics Approximate techniques leading to near-optimal solutions If you find the optimal solution, will you know?

26 Travelling Salesman Heuristics
Start with the Minimum Spanning Tree Optimal tour cost <= 2 MST cost Heuristics Christofides’ algorithm Prune the tour by taking short-cuts Tour must be an Eulerian path Each vertex of even degree Add edges to odd degree vertices Christofides’ algorithm produces a tour <= 1.5 optimal tour cost

27 Travelling Salesman Heuristics
“Banding” Divide the region into bands Number of cities in each band sufficiently small that the TSP problem can be solved by exhaustion (brute-force or try all solutions) Greedy algorithm to join the band solutions

28 Travelling Salesman Heuristics
Genetic algorithms Biological evolution analogy Reasonably effective Trivially parallelisable! Simulated annealing Model: Annealing of solid Solution heads towards local minimum Temperature allows some probability of climbing hills to escape a local minimum

29 Games Search trees can be huge
Chess: ~40 possible choices for each move 10+-move look-ahead needed to win >4010 positions to explore Modern computers just “touching” this capability 150MHz ~104 evaluations/second (EE student programming .. so you can add a factor of 10 if you like  ) Still a rather boring game ... ~1 year/move??

30 Games Board games Assume a “score” can be assigned to a position
Player tries to maximise this score Opponent tries to minimise this score Game proceeds in alternating maximise and minimise steps Minimax algorithm


Download ppt "Data Structures and Algorithms"

Similar presentations


Ads by Google