






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!







1
2
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)
3
Some Algorithm Strategies
4
Recursive Algorithm
7
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
8
Divide and Conquer
9
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
10
Dynamic Programming Algorithm
13
Dynamic Programming – Example
Djikstra’s Shortest Path Algorithm
S = ∅
while ( not all nodes in S )
14
Greedy Algorithm
At each step of algorithm Choose best local solution
15
Greedy Algorithm – Example
Kruskal’s Minimal Spanning Tree Algorithm
16
Brute Force Algorithm
Generate and evaluate possible solutions until Satisfactory solution is found Best solution is found (if can be determined) All possible solutions found Return best solution Return failure if no satisfactory solution
19
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
20
Heuristic Algorithm
Generate and evaluate possible solutions Using “rule of thumb” Stop if satisfactory solution is found
21
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
22
Summary
Properties of problem Expected problem size Available resources