Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Algorithm Strategies. 2 Introduction zAlgorithms may be grouped into categories or types. zThis is based upon how they go about finding a solution to.

Similar presentations


Presentation on theme: "1 Algorithm Strategies. 2 Introduction zAlgorithms may be grouped into categories or types. zThis is based upon how they go about finding a solution to."— Presentation transcript:

1 1 Algorithm Strategies

2 2 Introduction zAlgorithms may be grouped into categories or types. zThis is based upon how they go about finding a solution to a particular problem. zAs examples, we’ll be using sorting and graph algorithms.

3 3 Introduction II zAt any time, these algorithms should be viewed as representing a STATE of the problem. zA step in the algorithm (or a decision) represents a transition from one state to another. zThus, these algorithms can be thought of as state space searches.

4 4 Brute Force Algorithms zThese examine all possible solutions to a problem, and then pick the best one. zExample: Let’s sort an array of n values by generating all possible orderings of the n elements and selecting the one that is in order. zExample II: Let’s solve the 8-puzzle problem by generating the entire search space and locating a path to the goal.

5 5 Brute Force Discussion zAdvantages: yCan be fairly easy to implement zDisadvantages: yAre usually too time consuming to be practical. zLook at the 8-Puzzle example search space to 4 levels...

6 6 Backtracking zSimilar to Brute Force, except search in a particular order. zPerhaps using a Depth First or Breadth First Search. zExamples: yTesting for Graph Connectivity ySolving the 8-Puzzle problem with a Breadth First Search of the search space.

7 7 Backtracking Discussion zAdvantages yWill stop generating states when a solution is found. yA BFS will find the minimum number of steps to a solution. zDisadvantages yWill still search the entire space in the worst case. yDoesn’t apply well to something like sorting.

8 8 Branch and Bound zAgain, similar to backtracking, except we do not examine all possibilities. zWe eliminate those options that are infeasible or for which a solution has been found which is guaranteed to be better. zExample: The cabbage-goat-wolf problem would not examine any state that would cause the cabbage or goat to be eaten.

9 9 Branch and Bound Discussion zAdvantages: yLikely to be even faster as transitions that would not lead to an optimal solution are not explored. zDisadvantages: yStill could search the whole space in the worst case. zAs a general rule, you always look for ways to bound the search space.

10 10 Greedy Algorithms zFrom each state, the “best” option is chosen. zOnce made a decision is not re-examined. zExamples: yDijkstra’s Algorithm is a greedy algorithm in that it always adds the next vertex of least cost. yA Selection Sort could be viewed as a greedy algorithm as well.

11 11 Greedy Discussion zAdvantages: yDrastically reduces the number of states. zDisadvantages: yHow to define “best”? yRarely produces an optimal solution when “best” must be determined by looking at succeeding states.

12 12 Divide and Conquer zBreak the problem to be solved into sub- problems, which can be solved easier and combined to form the complete solution. zExamples: yMerge Sort breaks a list of values to sort into smaller lists and then combines the list. yA Binary Search is also an example of a divide and conquer strategy.

13 13 Divide and Conquer Discussion zAdvantages: yOften easier to solve smaller problems and put their solutions together, rather than solve entire problem. yConsider brute force sorting of an array of 100 elements versus brute force sorting of 5 elements 20 times and merging the results. zDisadvantages: yNot always possible to break the problem down into discrete steps.

14 14 The End Slide z


Download ppt "1 Algorithm Strategies. 2 Introduction zAlgorithms may be grouped into categories or types. zThis is based upon how they go about finding a solution to."

Similar presentations


Ads by Google