Quiz 3

[Me] | Nov 21, 2024 min read

Answer 1

Answer 2

Blue edges show updated graph.

Answer 3

Red lines how the paths selected for MST. They are selected by picking n - 1 (n = number of vertices) edges in acceding order of their weights.

Total Weight = 38

Answer 4

Solution isn’t actually possible because Dijkstra’s algorithm doesn’t work with negative weights.

For accurate shortest paths with negative weights, we should use Bellman-Ford algorithm instead. Bellman ford will look something like this.

StepTree Vertex (Distance)Fringe Vertices (Distance, Via)Shortest Path from a
1a(0,)b(1,a), c(2,a), d(2,a), e(∞), f(∞), g(∞)b: a->b (1)
2b(1,a)c(2,a), d(2,a), e(-2,b), f(∞), g(∞)c: a->c (2)
3c(2,a)d(2,a), e(-2,b), f(∞), g(∞)d: a->d (2)
4d(2,a)e(-2,b), f(∞), g(4,d)e: a->b->e (-2)
5e(-2,b)f(0,e), g(-1,e)g: a->b->e->g (-1)
6g(-1,e)f(0,e)f: a->b->e->f (0)
7f(0,e)--

Answer 5

Item1234
Profit per weight10/5 = 240/4 = 1030/6 = 550/3 ~= 16.6

Total Weight (W) = 10

Picking item with most profit/weight in each iteration until we fill the capacity of knapsack.

Pending WeightPicked ItemQtyProfit
104350
72490
33315

Total Profit = 105

comments powered by Disqus