unit 4 aos 1/2 Flashcards
Class
Class Change making problem
NP-complete (min number of coins)
NP-hard (how many possibilities)
Dynamic (divide and conquer)
Knapsack
runtime
Runtime: O(n*w)
Heuristic solution (guesstimate)
Travelling salesmen
runtime
- randomly guessing and run several times
O(n * c) where c is the time that u run it
Greedy (NN - nearest neighbour):
Travelling salesmen
runtime
- nearest neighbour approach
- pick the closest node all the time that has not been visited
- runtime is O(n^2)
Binary search
Runtime and design type (include best case)
Start from the middle and keep on removing half of it until it is lower or higher until it finds the number.
Best -> O(1)
Worse/Average -> O(log N)
Design type -> decrease and conquer
Merge sort
runtime and design type
Best/Worse/Average -> O(n log n)
* input does the same thing no matter what (input of array)
Design type -> divide and conquer
Quick sort
runtimes & design type & when does best and worse case occur
best: O(N log N)
- pivot middle value for best time
- array is random
average: O(N log N)
Worse: (n^2)
- ascending and descending order for worse time
Design type -> divide and conquer
- acts like decrease and conquer in worse case)
When does Merge sort perform the worse
• input does the same thing no matter what (input of array)
When does quick sort perform the worse
- if the pivot happens to be the smallest or largest element in the list
- list is already sorted
When does the A* Algorithm guarantee the smallest node
- heuristic needs to underestimate the distance for guarantee getting the smallest node
- depending on the way heuristics are implemented.
Runtime for knapsap bruteforce
O(2^n)
Stochastic hill climbing
what it is
The algorithm takes the initial point as the current best candidate solution and generates a new point within the step size distance of the provided point. The generated point is evaluated, and if it is equal or better than the current point, it is taken as the current point
Simulated annealing
Simulated annealing executes the search in the same way as stochastic hill climbing but new points that are not as good as the current point (worse points) are accepted sometimes
- lower the temperature, lower the chance
advantage and limitations of using heuristics as an algorithm in TSP
- Limitation: may not give the most optimal solution
- Advantage: relatively fast compared to brute force
Change making problem “formula”
min(array[coin - i] + 1, array[i])
where: coin is the value coins in the array
i is the iterations looping through the array