AlgorithmStrategies

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

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

View Full Document Right Arrow Icon
1 CMSC 132: Object-Oriented Programming II Algorithm Strategies Department of Computer Science University of Maryland, College Park
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online