1.9 Heuristics Flashcards

1
Q

What is a heuristic?

A

A technique that willingly accepts a non-optimal or less accurate solution to improve execution speed.

Heuristics are often used in algorithms when optimal solutions require excessive computational resources.

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

What is the goal in the knapsack problem?

A

To put items in the knapsack such that the weight ≤ 30 pounds and the value is maximized.

Each item has a specific weight and value associated with it.

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

What is the maximum weight limit for the knapsack in the given example?

A

30 pounds.

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

What is an example of a combination of items that can fit in the knapsack worth $142?

A

One 20 pound item and one 8 pound item.

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

What combination of items provides the best value in the knapsack example?

A

5 6-pound items.

This combination is worth $151, which is greater than the other options.

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

True or False: The optimal solution for the knapsack problem can exceed the weight limit.

A

False.

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

What does the term ‘0-1 knapsack problem’ refer to?

A

A knapsack problem where at most 1 of each item can be taken.

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

What is the main characteristic of a heuristic algorithm?

A

It quickly determines a near-optimal or approximate solution.

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

What is the purpose of the Knapsack01 function?

A

To sort the item list by value and fill the knapsack with the most valuable items that fit within the weight limit.

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

What is the result of the Knapsack01 function in the given example?

A

$95.

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

What is a limitation of the heuristic algorithm demonstrated in the Knapsack01 function?

A

It sacrifices optimality for efficiency and simplicity.

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

Fill in the blank: A self-adjusting heuristic modifies a _______ based on its use.

A

data structure.

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

What happens when a frequently searched item is moved to the front of a list?

A

It lowers the total number of comparisons needed for future searches.

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

What does the move-to-front self-adjusting heuristic do?

A

Moves a list item to the front when that item is searched for.

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

True or False: A heuristic algorithm typically does not sacrifice accuracy.

A

False.

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

Which item combination is better than the result from Knapsack01, worth $102?

A

The 12-pound and 8-pound items together.

17
Q

What is the sorting order for the item list in the Knapsack01 function?

A

Descending by value.

18
Q

Under what condition will the Knapsack01 function not include the most valuable item?

A

If the weight of the most valuable item is greater than the knapsack’s limit.

19
Q

What is the effect of frequent searches for already-searched-for keys?

A

Lowers the total number of comparisons

This is due to the move-to-front heuristic, which optimizes search efficiency by moving frequently accessed elements closer to the start of the list.

20
Q

How many items does a linear search for 42 compare against when it is at the end of a list with 8 items?

A

8 items

A linear search checks each item sequentially until it finds the target.

21
Q

What does the move-to-front heuristic do after a search for a key?

A

Moves the key to the front of the list

This technique reduces future search times for that key by placing it at the beginning.

22
Q

After moving 42 to the front of the list, how many comparisons are needed for a subsequent search for 42?

A

1 comparison

This is the most efficient scenario for searching after the key has been moved to the front.

23
Q

How many items does a search for 64 compare against when it is at the end of the list?

A

8 items

Similar to the search for 42, a linear search for 64 at the end of the list requires checking all items.

24
Q

What happens to 64 after a search for it?

A

Moves to the front of the list

This adjustment follows the move-to-front heuristic principle.

25
Q

Which scenario results in faster searches?

A

Back-to-back searches for the same key

This is because the key will be found at the front of the list after the first search.

26
Q

In the first search for 81, how many list items are compared?

A

4 items

The items compared are 56, 11, 92, and 81 before finding the search key.

27
Q

In the second search for 81, how many list items are compared?

A

1 item

Since 81 is now at the front of the list, it is found immediately.

28
Q

Fill in the blank: A move-to-front heuristic is used on a list that starts as _______.

A

(56, 11, 92, 81, 68, 44)

This is an example list used to illustrate the heuristic’s effect.