Exam Result of Algorithms Topic Test - 3 (Greedy Algorithms)
Exam Result of Algorithms Topic Test - 3 (Greedy Algorithms)
Total Question in 15 Total Answered Question 0 Left Question 15 Left Question 25.00
Test in Test Marks
testseries.ravindrababuravula.com/crm/Results/printresult/166956 1/28
3/13/2021 Download PDF
P) Hu man coding
R) Prim’s algorithm
S) Kruskal’s algorithm
T) Dijkstra’s algorithm
5 Given undirected graph G=(V,E) to nd the A-C, C-G, C-E, 1.00 - Easy
correct sequence order for minimum cost E-F, B-D, B-G,
spanning tree(MST) using kruskal’s E-H
algorithms.
testseries.ravindrababuravula.com/crm/Results/printresult/166956 2/28
3/13/2021 Download PDF
6 The most appropriate matching for the P:4, Q:4, R:1, 2.00 - Easy
following pairs S:3, T:1, U:2,
V:2, W:5, X:6,
Y:2, Z:1, A:7
Y: DFS
testseries.ravindrababuravula.com/crm/Results/printresult/166956 3/28
3/13/2021 Download PDF
SOLUTIONSADDA
testseries.ravindrababuravula.com/crm/Results/printresult/166956 4/28
3/13/2021 Download PDF
testseries.ravindrababuravula.com/crm/Results/printresult/166956 5/28
3/13/2021 Download PDF
testseries.ravindrababuravula.com/crm/Results/printresult/166956 6/28
3/13/2021 Download PDF
15 Which of the following statement(s) is/are Both (i) and 2.00 - Easy
TRUE? (ii)
Question: 1
Suppose we have 6 sorted lists and each of sizes 5, 10, 15, 20, 25, 30 respectively, which need to be merged into
a combined sorted list, but we can merge only two at a time. Find the total record movements of optimal merge
pattern.
Max Marks : 1.00 Marks Scored : Time Taken : 15 Sec
testseries.ravindrababuravula.com/crm/Results/printresult/166956 7/28
3/13/2021 Download PDF
Solution :
30, 25, 20, 15, 10, 5
=(2*30)+(4*10)+(4*5)+(3*15)+(2*20)+(2*25)
=255
testseries.ravindrababuravula.com/crm/Results/printresult/166956 8/28
3/13/2021 Download PDF
Question: 2
Which of the following algorithm is not using greedy technique?
P) Hu man coding
R) Prim’s algorithm
S) Kruskal’s algorithm
T) Dijkstra’s algorithm
1.
U and V
2.
S,T and U
3.
only V
4.
P,Q and R
Solution :
Bellman ford and oyd warshall algorithm is follows Dynamic Programming(DP) technique. Even though
bellman ford algorithm uses for Single Source Shortest Path(SSSP) problem it follows DP technique. We know
that Floyd warshall algorithm uses DP technique for solving All Pair Shortest Path(APSP) problem.
Question: 3
The following Knapsack bag. The Knapsack bag maximum Capacity is 30. Find out the maximum pro t for
Greedy Knapsack___?
testseries.ravindrababuravula.com/crm/Results/printresult/166956 9/28
3/13/2021 Download PDF
Solution :
We sort the objects based on pro t/Weight Ratio in descending order and place it accordingly in the knapsack.
The objects are in sorted order according to their pro ts are: R,V,T,Q,S,P
Question: 4
What is the time complexity of Dijkstra’s algorithm if it is implemented using AVL Tree instead of Priority Queue
over a graph G=(V,E)?
1.
O(VlogE)
2.
O(VE)
3.
O(V2)
4.
O((V+E)logV)
Solution :
Using AVL Trees, both Decrease key and Extract-min operation can implemented in O(log V) time, So over all time
complexity is O((V+E)logV)
testseries.ravindrababuravula.com/crm/Results/printresult/166956 10/28
3/13/2021 Download PDF
Question: 5
Given undirected graph G=(V,E) to nd the correct sequence order for minimum cost spanning tree(MST) using
kruskal’s algorithms.
1.
2.
3.
4.
testseries.ravindrababuravula.com/crm/Results/printresult/166956 11/28
3/13/2021 Download PDF
Solution :
To nd kruskal’s algorithm, First we have to sort all edge weights and based on the least weights we are forming
spanning tree.
Note: If same edge weights we can take any order. So that we can get number of spanning trees for single MST.
Question: 6
The most appropriate matching for the following pairs
Y: DFS
testseries.ravindrababuravula.com/crm/Results/printresult/166956 12/28
3/13/2021 Download PDF
1.
P:4, Q:4, R:1, S:3, T:1, U:2, V:3, W:6, X:5, Y:3, Z:7, A:7
2.
P:4, Q:4, R:1, S:3, T:1, U:2, V:2, W:5, X:6, Y:2, Z:1, A:7
3.
P:4, Q:3, R:1, S:3, T:1, U:2, V:2, W:5, X:6, Y:2, Z:7, A:1
4.
P:4, Q:6, R:1, S:3, T:1, U:2, V:3, W:6, X:5, Y:2, Z:2, A:1
Solution :
P: Prim’s Algorithm→ O(ElogV)
U: BFS → O(V+E)
Y: DFS → O(V+E)
Question: 7
Anand having total 24 chocolates of the following brands. 12 Cadbury, 8 Ferrero Rocher, 2 Ghirardelli, 1
Hershey's and 1 Toblerone. Seshu picks a chocolate randomly from a total, and messages to Shiva its color using
string of 0’s and 1’s. Seshu replaces the chocolates in the total, and repeats this experiment, many times. What is
the minimum expected length of the message Seshu has to convey to Shiva per experiment [Note:Use 2
numbers after fraction part ] ?
testseries.ravindrababuravula.com/crm/Results/printresult/166956 13/28
3/13/2021 Download PDF
Solution :
Using static Hu man compression you can encode the more common chocolates in fewer bits than the rare
chocolates, that being the case on can expect that common chocolates will usually be chosen.
Eg:
Cadbury: 1
Ferrero Rocher: 01
Ghirardelli: 001
Hershey's: 0001
Toblerone: 0000
12 blue = (1*12=12)
8 red = (2*8=16)
2 white = (3*2=6)
1 yellow = (4*1=4)
1 orange = (4*1=4)
= 21/12
= 1.75
Question: 8
Ravindrababu Ravula and Anand started new website. The website contains all computer science(CS) questions
and detailed explanations given by expert faculties. Till the date they given explanations for GATE, ISRO, DRDO,
UGC-NET, KVS, AAI, NIELIT and PHD entrance exams conducted by di erent universities. If students are sending
questions papers to our team, we will give explanations within 15 days and will be upload to our website. The
website name contains di erent characters.
SOLUTIONSADDA
Website name of 26 characters over X is encoded using Hu man coding. Then the expected length of the
encoded website name in bits is____
Solution :
testseries.ravindrababuravula.com/crm/Results/printresult/166956 15/28
3/13/2021 Download PDF
= (4 + 6 + 6 + 6 + 3 + 4 + 4 + 4 + 4)
= 41
→ 41 for 13 characters
Question: 9
Suppose we have Single Source Shortest Path on the following Adjacency list with vertex 0 as the source.
Find out total cost for reaching source node to all other vertices for which the shortest path distances are
nalized(Note: No need to calculate In nity cost vertices) ____
Solution :
Step-1: Convert adjacency list into undirected graph
testseries.ravindrababuravula.com/crm/Results/printresult/166956 16/28
3/13/2021 Download PDF
= 29
testseries.ravindrababuravula.com/crm/Results/printresult/166956 17/28
3/13/2021 Download PDF
Question: 10
Suppose we have 8 tasks to execute. The execution of each task takes 1 unit of time. The following table contains,
each task Ti has pro t Pi and deadline di. if task Ti is completed before dith unit of time then we can earn pro t
Pi.
1.
T1 and T4
2.
Only T8
3.
T1 and T8
4.
T4 and T8
Solution :
testseries.ravindrababuravula.com/crm/Results/printresult/166956 18/28
3/13/2021 Download PDF
Question: 11
Consider the following graph
Find a spanning tree with minimal total weight containing the edges {e, i} and {g, k} in the given weighted graph.
1.
30
2.
29
3.
28
4.
27
testseries.ravindrababuravula.com/crm/Results/printresult/166956 19/28
3/13/2021 Download PDF
Solution :
The minimum spanning tree of graph {e, i} and {g, k}
Total weight = 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 3 + 4
= 29
Question: 12
Use Hu man coding to encode the following symbols with the frequencies listed A : 0.08, B : 0.10, C : 0.12, D :
0.15, E : 0.20, F : 0.35. What is the average number of bits used to encode a character?
1.
3.45
2.
1.45
3.
2.75
4.
2.45
Solution :
testseries.ravindrababuravula.com/crm/Results/printresult/166956 20/28
3/13/2021 Download PDF
testseries.ravindrababuravula.com/crm/Results/printresult/166956 21/28
3/13/2021 Download PDF
= 2.45
Question: 13
Given a graph, nd total number of strongly connected components
testseries.ravindrababuravula.com/crm/Results/printresult/166956 22/28
3/13/2021 Download PDF
Solution :
A directed graph is strongly connected if there is a path between all pairs of vertices. A strongly connected
component (SCC) of a directed graph is a maximal strongly connected subgraph.
2. We can nd strongly connected components using kosaraju algorithm and Trojan’s algorithm
Kosaraju’s algorithm:
1) Create an empty stack ‘S’ and do DFS traversal of a graph. In DFS traversal, after calling recursive DFS for
adjacent vertices of a vertex, push the vertex to stack.
3) One by one pop a vertex from S while S is not empty. Let the popped vertex be ‘v’. Take v as source and do DFS
(call DFSUtil(v)). The DFS starting from v prints strongly connected component of v.
Tarjan Algorithm:
3. If we can nd head of such subtrees, we can print/store all the nodes in that subtree (including head) and that
will be one SCC.
4. There is no back edge from one SCC to another (There can be cross edges, but cross edges will not be used
while processing the graph).
testseries.ravindrababuravula.com/crm/Results/printresult/166956 23/28
3/13/2021 Download PDF
Question: 14
Given a graph, nd the correct topological sequence using indegree elimination method
1.
0-3-1-5-6-7-2-4
2.
0-1-3-6-7-2-4-5
3.
0-4-3-1-2-5-6-7
4.
0-1-2-3-4-6-7-5
testseries.ravindrababuravula.com/crm/Results/printresult/166956 24/28
3/13/2021 Download PDF
Solution :
Here, we have to take the sequence when indegree becomes ‘0’.
Step-1:
Question: 15
Which of the following statement(s) is/are TRUE?
(i). Suppose that Dijkstra’s algorithm is run using a priority queue data structure for which insert and decrease
key operations take O(log log V) time, extract-min operation take O(√V) time then the running time of Dijkstra’s
algorithm on a directed weighted graph G = (V, E) containing non-negative edges will be O(V √V + Elog log V)
(ii). If a topological sort exists for the vertices in a directed graph, then a DFS on the graph will produce no back
edges.
1.
Only (ii)
2.
3.
Only (i)
4.
testseries.ravindrababuravula.com/crm/Results/printresult/166956 25/28
3/13/2021 Download PDF
Solution :
(i). There are V extract-min operations, and E decrease key operations for the Dijkstra’s algorithm using priority
queue. So, time complexity is O(V √V + Elog log V)
(ii). Both parts of the statement hold if and only if the graph is acyclic.
testseries.ravindrababuravula.com/crm/Results/printresult/166956 26/28
3/13/2021 Download PDF
testseries.ravindrababuravula.com/crm/Results/printresult/166956 27/28
3/13/2021 Download PDF
testseries.ravindrababuravula.com/crm/Results/printresult/166956 28/28