






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Approach to solving a problem May combine several approaches
Iterative ⇒ execute action in loop Recursive ⇒ reapply action to subproblem(s)
Satisfying ⇒ find any satisfactory solution Optimization ⇒ find best solutions (vs. cost metric)
Some Algorithm Strategies
Recursive Algorithm
Backtracking Algorithm – Example
Start at beginning of maze If at exit, return true Else for each step from current location Recursively find path Return with first successful step Return false if all steps fail
Backtracking Algorithm – Example
If all countries have been colored return success Else for each color c of four colors and country n If country n is not adjacent to a country that has been colored c Color country n with color c Recursively color country n+ If successful, return success Return failure
Divide and Conquer
Divide and Conquer – Examples
Partition array into two parts around pivot Recursively quicksort each part of array Concatenate solutions
Partition array into two parts Recursively mergesort each half Merge two sorted arrays into single sorted array
Dynamic Programming – Example
If n is 0 or 1, return 1 Else solve fibonacci(n-1) and fibonacci(n-2) Look up value if previously computed Else recursively compute Find their sum and store Return result
Since solving fibonacci(n-2) is just looking up value
Dynamic Programming – Example
Djikstra’s Shortest Path Algorithm
{ S } = ∅
while ( not all nodes in { S } )
Greedy Algorithm
At each step of algorithm Choose best local solution
Greedy Algorithm – Example
Kruskal’s Minimal Spanning Tree Algorithm
Branch and Bound Algorithm
Track best current solution found Eliminate partial solutions that can not improve upon best current solution Reduces amount of backtracking
Branch and Bound – Example
Find possible paths using recursive backtracking Track cost of best current solution found Stop searching path if cost > best current solution Return lowest cost path
Heuristic Algorithm
Generate and evaluate possible solutions Using “rule of thumb” Stop if satisfactory solution is found
Heuristic Algorithm – Example
Find possible paths using recursive backtracking Search 2 lowest cost edges at each node first Calculate cost of each path Return lowest cost path from first 100 solutions