Week 5 Flashcards

1
Q

What are the 3 fundamental techniques?

A
  • The Greedy Method
  • Divide and Conquer
  • Dynamic Programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the Greedy Method?

A
  • a problem solving strategy used in optimisation problems
  • involves making locally optimal choices at each step in the hope these choices lead to a globally optimal solution
  • so at every decision point, it selects the best available option without considering overall future consquences
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why might we not use a greedy method approach?

A
  • because this doesn’t guarantee the optimal solution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does the greedy method decide what is the best/optimal local decision to make?

A
  • it uses a given criteria to decide what the best choice to make is
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give examples of problems solved by the greedy method

A
  • Fractional knapsack problem
  • interval scheduling
  • task scheduling
  • minimum spanning trees
  • shortest paths (Dijkstra’s algorithm)
  • change making (smallest number of coins)
  • maximum spacing of k-clustering
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the fractional Knapsack Problem?

A

Have a set S of n items, each item has a positive benefit bi and weight wi
- goal is to find the maximum benefit subset that does not exceed total weight W
- we can take arbitrary fraction xi of each item where each fraction is 0 <= xi <= wi
- the sum of all the fractions must be <= max W

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

What is the objective function for solving the fractional knapsack problem?

A
  • the total benefit of items taken is determined by the sum of each item whose fraction xi/wi of it’s benefit to the solution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the general method for solving the FKP?

A
  1. Compute the value index for each item = vi = bi/wi
  2. select items to pack into the knapsack by choosing from highest value index to lowest
  3. once we reach the max weight W, we stop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the greedy element in the greedy method’s solution for the FKP?

A
  • that in each iteration locally we’re choosing the next item to pack and our greedy criteria is to take the item with the highest value index
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What amount do we add to the total benefit after an item is packed?

A
  • We add the value index multiplied by xi (we don’t add bi to the benefit)
  • for example if item 3 has vi = 3/2 and we add item 3’s full wi of 2, we add 3/2 * 2 = 3 to the total benefit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the {0,1} knapsack problem?

A

Similar to the Fractional knapsack problem, however only a whole item’s weight can be packed into the knapsack
- so an item can only get packed or not rather than a fraction of it
- optimal solution isn’t always found with the greedy method
- can be solved by dynamic programming

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

What is interval scheduling?

A
  • have a set T of n tasks and a single machine that can process these tasks
  • goal is to select a subset of tasks to maximise the number of tasks we can schedule
  • the tasks cannot overlap (conflict)
  • ni is the start time and nf is the finish time
  • two tasks are non-conflicting if fi<=fj or fj<=fi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do we use a greedy algorithm to solve the interval scheduling problem?

A
  • we order tasks by completion/finish time, so we put them in order of finishes first to finishes last.
  • we then take the task that finishes first and add it to the schedule, we then remove any task that conflicts with this added task
  • we then repeat doing this until there are no tasks left.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What data structure can we use to implement the solution of a greedy algorithm for both the fractional knapsack problem and the interval scheduling problem

A
  • We can use a heap data structure for the implementation of these problems
  • root holds highest value index in FKP
  • root holds smallest finish time in ISP
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is clustering?

A
  • when we tr to group together a collection of n objects based on the idea of distance
  • we have n objects: O1, O2, …On and a distance function that compares how far a pair of objects are.
  • this distance function has 3 axioms (properties)
    1. d(Oi,Oi) = 0 - distance between identical objects = 0
    2. d(Oi, Oj) > 0 for all i != j - distance between different objects must be positive
    3. d(Oi,Oj) = (Oj, Oi) - distance between a and b is the same as distance between b and a
  • We want to group objects into k (non empty) clusters C1,…Cn where k &laquo_space;n (much less than)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the maximum spacing clustering problem?

A

Given a set of clusters C1, … Ck, where the maximum spacing is defined as the minimum distance between two objects in two different clusters, we want to find a clustering so that the minimum inter cluster distance is as large as possible.

17
Q

What type of problem is the maximum spacing clustering problem?

A
  • it’s an optimisation problem as we’re trying to find the maximum of something - so this can be solved by the Greedy method
18
Q

How do we solve the maximum spacing clustering problem

A
  • build a graph where the objects O1,…On are nodes of the graph
  • the connected components of the graph we build will be clusters, we aim to bring objects that are similar close together into the same cluster, so they don’t end up in different clusters (hence making max spacing small)
  • Take the two closest objects and add an edge between them and repeatedly keep doing this
  • continue considering distances between pairs in increasing orders
  • we don’t put an edge between items in the same cluster
  • adding an edge corresponds to merging two clusters into 1.
19
Q

What are the steps for solving the maximum spacing clustering problem?

A
  1. put all n objects into their own cluster, so we have n clusters to start off with
  2. then calculate the distance between every pair of objects
  3. take the pair of objects with the smallest distance and merge them into one cluster to leave you with n-1 clusters
  4. recalculate the distances between each object (the objects in the same cluster know have a distance of ∞ so they won’t be remerged)
  5. repeat step 3 and 4 until there are k clusters left
  6. calculate the distances between all the pairs of objects in different clusters and find the minimum
  7. return the minimum as this is the maximum spacing clustering distance