AlgorithmStrategies

# AlgorithmStrategies - CMSC 132 Object-Oriented Programming...

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

1 CMSC 132: Object-Oriented Programming II Algorithm Strategies Department of Computer Science University of Maryland, College Park

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

View Full Document
2 Course Evaluations The CourseEvalUM system will be open for student participation Tuesday, Dec 1, through Sunday, Dec 13. Please as soon as possible complete the evaluations for this course. We consider them extremely important. WHERE TO GO TO COMPLETE THE EVALUATION https://www.courseevalum.umd.edu/portal
3 General Concepts Algorithm strategy Approach to solving a problem May combine several approaches Algorithm structure Iterative execute action in loop Recursive reapply action to subproblem(s) Problem type

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

View Full Document
4 Problem Type Satisfying Find any satisfactory solution Example → Find path from A to F Optimization Find best solution (vs. cost metric) Example → Find shortest path from A to E A C E D 3 8 5 1 7 2 B 6 4 F
5 Some Algorithm Strategies Recursive algorithms Backtracking algorithms Divide and conquer algorithms Dynamic programming algorithms Greedy algorithms Brute force algorithms Branch and bound algorithms Heuristic algorithms

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

View Full Document
6 Recursive Algorithm Based on reapplying algorithm to subproblem Approach 1. Solves base case(s) directly 2. Recurs with a simpler subproblem 3. May need to combine solution(s) to subproblems
7 Backtracking Algorithm Based on depth-first recursive search Approach 1. Tests whether solution has been found 2. If found solution, return it 3. Else for each choice that can be made a) Make that choice b) Recur c) If recursion returns a solution, return it 4. If no choices remain, return failure Tree of alternatives → search tree

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

View Full Document
8 Backtracking Algorithm – Reachability Find path in graph from A to F 1. Start with currentNode = A 2. If currentNode has edge to F, return path 3. Else select neighbor node X for currentNode Recursively find path from X to F If path found, return path Else repeat for different X Return false if no path from any neighbor X
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 29

AlgorithmStrategies - CMSC 132 Object-Oriented Programming...

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

View Full Document
Ask a homework question - tutors are online