unit 4 aos 1/2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Class

Class Change making problem

A

NP-complete (min number of coins)

NP-hard (how many possibilities)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Dynamic (divide and conquer)

Knapsack

runtime

A

Runtime: O(n*w)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Heuristic solution (guesstimate)

Travelling salesmen

runtime

A
  • randomly guessing and run several times
    O(n * c) where c is the time that u run it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Greedy (NN - nearest neighbour):

Travelling salesmen

runtime

A
  • nearest neighbour approach
    • pick the closest node all the time that has not been visited
  • runtime is O(n^2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Binary search
Runtime and design type (include best case)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Merge sort

runtime and design type

A

Best/Worse/Average -> O(n log n)
* input does the same thing no matter what (input of array)

Design type -> divide and conquer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Quick sort

runtimes & design type & when does best and worse case occur

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When does Merge sort perform the worse

A

• input does the same thing no matter what (input of array)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When does quick sort perform the worse

A
  • if the pivot happens to be the smallest or largest element in the list
  • list is already sorted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When does the A* Algorithm guarantee the smallest node

A
  • heuristic needs to underestimate the distance for guarantee getting the smallest node
  • depending on the way heuristics are implemented.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Runtime for knapsap bruteforce

A

O(2^n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Stochastic hill climbing

what it is

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Simulated annealing

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

advantage and limitations of using heuristics as an algorithm in TSP

A
  • Limitation: may not give the most optimal solution
  • Advantage: relatively fast compared to brute force
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Change making problem “formula”

A

min(array[coin - i] + 1, array[i])
where: coin is the value coins in the array
i is the iterations looping through the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly