divide and conquer

divide and conquer - Overview Data structures and...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Overview Data structures and associated operations Data structures Associated operations Linked list insert, delete, makenull Stacks push, pop Queues remove from head, insert from tail rees sert delete traverse Trees insert, delete, traverse Graphs traverse, shortest path, trong components, etc. so g c o p o e s , e c . • Data structures and associated operations are “ ools” for building programs Data Structures and Algorithms II tools for building programs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Overview (cont.) lgorithm design Algorithm design A sequence of operations which are clearly defined (no ambiguity as to what to do next) effective (component operations done in finite time) terminate g t i E.g. Sorting Data structures: an array of length n Algorithms: comparing & swapping elements (bubble sort, insertion sort, selection sort, quick sort, merge sort, etc.) Programs = Algorithms + Data structures Data Structures and Algorithms II
Background image of page 2
Overview (cont.) General principles ivide d nquer Divide-and-conquer Greedy Dynamic programming Backtracking Branch-and-bound Data Structures and Algorithms II
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Caveats There are a lot more principles for gorithm designs that we do not cover algorithm designs that we do not cover Numerical algorithms h l ith Graph algorithms Geometrical algorithms (e.g., vision, graphics) Probabilistical algorithms Multi-stage, discrete, countably many, unique
Background image of page 4
ivide nd onquer Divide Divide-and and-Conquer Conquer
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Divide-and-Conquer put :n ements stored in an array Input A ( 1:n ): n elements stored in an array Procdure DandC(p,q) if Small(p,q) then return (G(p,q)) else m Divide(p,q) return Combine(DandC(p,m),DandC(m +1,q)) end if end DandC Data Structures and Algorithms II
Background image of page 6
Divide-and-Conquer (cont.) Divide : split a larger problem into sub- roblems of smaller size problems of smaller size Combine : merge the solutions of sub- bl i t th t f l bl problems into that of a larger problem Small : is the problem small enough? G(p,q) : easy solutions to small problems Data Structures and Algorithms II
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Hanoi Towers AB C Three pegs, A has n disks of different sizes stacked with smaller ones on top of bigger ones Move disks one at a time Never place a larger disk on top of a smaller one l l d i k t B Move all disks onto B Trivial problem, the rule of the game dictates divide-and- conquer Data Structures and Algorithms II
Background image of page 8
Hanoi(n, A, B, C) ( , ,,) n: number of disks : starting peg A: starting peg B: end peg : temporary peg C: temporary peg A B C n=1 Data Structures and Algorithms II
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
AB C n=2 1 =3 23 A B C n=3 1 2 3 Data Structures and Algorithms II 4
Background image of page 10
ovement steps of isks will be used in Movement steps of m disks will be used in moving n disks ( n>m ) roblem is decomposable Problem is decomposable Hanoi(n,A,B,C) = Hanoi(n-1,A,C,B) + Hanoi(1,A,B,C) + Hanoi(n-1,C,B,A) Data Structures and Algorithms II
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
AB C
Background image of page 12
H(4,A,B,C) H(3,A,C,B) H(1,A,B,C) H(3,C,B,A) H(2,A,B,C) H(1,A,C,B) H(2,B,C,A) H(2,C,A,B) H(1,C,B,A) H(2,A,B,C) H(1,A,C,B) H(1,A,B,C) H(1,C,B,A) H(1,B,A,C) H(1,B,C,A)
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 81

divide and conquer - Overview Data structures and...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online