divide and conquer

# divide and conquer - Overview Data structures and...

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

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

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

View Full Document
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
Overview (cont.) General principles ivide d nquer Divide-and-conquer Greedy Dynamic programming Backtracking Branch-and-bound Data Structures and Algorithms II

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

View Full Document
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
ivide nd onquer Divide Divide-and and-Conquer Conquer

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
AB C n=2 1 =3 23 A B C n=3 1 2 3 Data Structures and Algorithms II 4
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

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

View Full Document
AB C
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)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/19/2012 for the course ENGR 361 taught by Professor Drexel during the Spring '12 term at Bloomsburg.

### 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
Ask a homework question - tutors are online