Asignment 2
Asignment 2
Q4. Write Dijkstra's algorithm and apply the same to find single source problem for the 6
following graph taking vertex ‘a’ as source?
Q5. Explain how sum of subsets problem can be solved using the concept of 6
backtracking.
For Slow Learner (Assignment 2 Theory based)
Q6 – Define principle of optimality.
Q7 – What are greedy algorithms? Explain their characteristics?
Q8 – Explain Dijkstra’s algorithm to solve single source shortest path problem with suitable
example.
Q9 – Find optimal solution to the fractional knapsack instances n=7 and knapsack capacity
M=15 where profits and weights are as follows (p1, p2, … p7) = (10, 5, 15, 7, 6, 18, 3) & (w1,
w2, … w7) = (2, 3, 5, 7, 1, 4, 1) respectively.
Q10 Describe Huffman’s algorithm with an example for generation for prefix code.
Q11 What is an optimization problem? How greedy method are can be used to solve the
optimization problem?
Q12 (i) State Bellman ford algorithm using suitable graph find the shortest path.
(ii) Consider following instance for simple knapsack problem. Find the solution using
greedy method.
N = 8 P = {11, 21, 31, 33, 43, 53, 55, 65} W = {1, 11, 21, 23, 33, 43, 45, 55} M = 110
Q13. Given a weighted directed graph G = (V, E) with source s and weight function W: E ->
R, then write an algorithm to solve a single source path problem whose complexity is O(VE).
Apply the same on the following graph.
Q14. Explain and write an algorithm for greedy method of algorithm design. Given 10
activities along with their start and finish time as
S = {A1, A2, A3, A4, A5, A6, A7, A8, A9, A10}
Start time = {1, 2, 3, 4, 7, 8, 9, 9, 11, 12}
Finish time = {3, 5, 4, 7, 10, 9, 11, 13, 12, 14}
Compute a schedule where the largest numbers of activities take place.
For advance Learner (Practical Based)
Q1. Given the array points (balloons are represented as a 2D integer array points where points[i]
= [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and
xend), return the minimum number of arrows that must be shot to burst all balloons.
Q2. You are given an integer array nums. You are initially positioned at the array's first index,
and each element in the array represents your maximum jump length at that position. Return
true if you can reach the last index, or false otherwise.
Q3. Given an array of strings words, return the smallest string that contains each string in words
as a substring. If there are multiple valid strings of the smallest length, return any of them.
Q4. Given two integer arrays gas and cost, return the starting gas station's index if you can
travel around the circuit once in the clockwise direction, otherwise return -1.
Q5. Given a set of n activities with their start and finish times, we need to select the maximum
number of non-conflicting activities that can be performed by a single person, given that the
person can handle only one activity at a time.
Q6. Write a python code to solve the several problems (Coin change, Knapsack, Huffman
coding, and activity selection) using Greedy Approach.