QuestionBank2024
QuestionBank2024
3. Create
12.3.1 a trieBrute
consisting
Force of the following words: bear, bell, bid, bull, buy, belly, buyer,
sell, stock, stop. Delete the word bell and show the resultant trie.
The brute-force algorithmic design pattern is a powerful technique for algorithm
4. Whatdesign
is the when
cost of wesearching
have something wewwish
a string in a to search
trie? for or when we wish to opti-
Explain.
mize some function. In applying this technique in a general situation we typically
5. Drawenumerate
the suffixall tree for theconfigurations
possible string abcabaca$.
of the inputs involved and pick the best of all
these enumerated configurations.
6. Given a text string Tthis
In applying of length n and
technique a pattern
to design the string P of length
brute-force patternm, we are algo-
matching required to
find therithm,
startingwe derive what is probably the first algorithm that we might think ofPfor
index of the rst occurrence of P in T or an indication that the is not in
T. Consider
solvingthethefollowing algorithm
pattern matching to solve thesimply
problem—we problem:
test all the possible placements
of P relative to T . This algorithm, shown in Code Fragment 12.3, is quite simple.
What is the running time of the algorithm? Specify your answer in terms of m and n.
7. Suppose we're looking for pattern P = "nano" in text T = “banananobano". Show complete
working of the BruteForceMatch algorithm algorithm on the the given problem instance. Mention
! the number of comparisons done by in the process. !
ffi
fi
8. Suppose we're looking for pattern P = "nano" in text T = “banananobano". Show
complete working of the Knuth-Morris-Pratt algorithm algorithm on the the given problem
instance. Mention the number of comparisons done by in the process.
9. Draw standard trie for the following set of words: arid, area, eerie, err, red, read, road,
roast, logged, loggerhead, loggia, logging
10. Draw compressed trie for the following set of words: arid, area, eerie, err, red, read,
road, roast, logged, loggerhead, loggia, logging,
1. Insert the following keys one by one in the following B-tree of order ve:
58, 78, 40, 42, 99, 64
Show the status of the tree after each insertion.
2. A memory block can store maximum 4 values and minimum 2 values in ascending
order and give way to 5 more such blocks for creating hierarchical data storage. However,
the top block of this hierarchical data storage is allowed to have minimum 1 value.
Considering these restrictions, store the following elements in a way such that the search
time is logarithmic. Show the data structure after each insertion.
<50,17,76,9,23,54,14,19,72,12,67,100,11,25,7,8,52,53,51>
Then, delete values “8” and “23” one by one. Show the data structure after each
deletion.
Show the contents of the tree after each insertion. Mention the total number of times that
a split happens during these insertions
ffi
fi
4. Insert the following keys in an intially empty B-tree of order:
Show the contents of the tree after each insertion. Mention the total number of times that
a split happens during these insertions
Unit 5: More on Graphs ( Bellman Ford Algorithm, Union Find Data Structures
application Kruskal’s algorithm)
2. What would be the time complexity if one memoized the recursive computation of nth
Fibonacci number.
3. An undirected graph having 5 nodes (A,B,C, D and E) is given below in the form of a weighted
matrix :
A B C D E
A 0 12 9 3 7
B. 12 0 2 0 5
C. 9 2 0 4 0
D. 3 0 4 0 6
E. 7 5 0 6 0
4. Given an undirected graph G = (V,E), where V = {a, b, c, d, e, f, g, h, i, j, k} and the set of edges
E = {(d,i), (f,k), (g,i), (b,g), (a,h), (i,j), (d,k), (b,j), (d,f), (g,j), (a,e)}. Find connected components in
the given graph. List the vertices in each connected component. (Hint: use Union-Find data
structure)
5. Would you use BFS to find the shortest path between two nodes in a weighted graph with
arbitrary edge weights? If yes, justify your answer. If no, then give a counterexample.
6. Can we use DFS algorithm to find the shortest-path distance from the source to a reachable
vertex in an unweighted graph? If yes, justify, if no give a counter example.
7. Both Dijkstra's and BFS algorithm are used to nd shortest path in a graph, can they be used
interchangeably? Explain brie y.
8. Can a graph in which the edge weights are not necessarily distinct have more than one MSTs? If
yes, give an example. If no, justify.
9. Given a graph G with weights, weights are allowed to be negative, we are required to find
shortest path from a vertex s to a vertex t in the graph. Write a dynamic programming algorithm to
solve the problem. Give an example to show that the Dijkstra’s algorithm fails to find shortest path
for such a graph.
10. The number of sub problems in the DP solution provided by the Bellman-Ford algorithm of the
shortest path problem is ———-?
11. Use the Kruskal’s algorithm to find an MST in the following graph.
12. Using the Bellman Ford algorithm, determine the shortest paths from A to all other nodes in
the following graph. What is the length of the shortest path from A to C?
13. Using the Bellman Ford algorithm, determine the shortest paths from all other nodes to H in
the following graph. What is the length of the shortest path from A to H?
fl
fi
2 Handout 14: Lecture Notes on Skip Lists
– Cost:
– Minimized when
3 linked lists:
Unit 6: Randomization ( Randomized Quicksort, Randomized Select, Skip lists ):
linked lists:
1. What is the bene t of randomization in quicksort algorithm ?
linked
2. Consider the lists: skip-list:
following
14 79
14 50 79 110
14 34 50 66 79 96 110 125
First step: 5
Second step: 2
Third step: 2
Forth step: 3
Fifth step: 2
fi
without boxed numbers—specifically, the four edges of capacity 3—have 2
no flow being sent on them.)
s
(a)
What is the value of this flow? Is this a maximum (s,t) flow in this
graph? 4
In which of the recursive steps the partition was nearly balanced? v
(b) Find a minimum s-t cut in the flow network pictured in Figure 7.26,
and also say what its capacity is.
Figure 7.25 Wh
Unit 7: Network Flows ( Ford Fulkerson algorithm for the max ow problem ) imum capacity
3. Figure 7.27 shows a flow network on which an s-t flow has been computed. this flow netwo
1. Following gure
The shows
capacitya ofow network
each on which
edge appears asan s-t ow
a label nexthas
to been computed.
the edge, and theThe
capacity of each edgein
numbers appears as a the
boxes give labelamount
next toofthe edge,
flow sentand
on the numbers
each in boxes
edge. (Edges
give the amount of ow
without sent
boxed on eachhave
numbers edge.
no (Edges without
flow being sent boxed numbers have no
on them.)
ow being sent on them.)
(a) What is the value of this flow? Is this a maximum (s,t) flow in this
graph?
(a) What is the value of this ow? Is this a maximum (s,t) ow in this graph?
5 5
10 5
3 3
8 8 10 8 8 8
s t
3 3
5
5
5 10
d
Figure 7.26 What is the value of the depicted flow? Is it a maximum flow? What is the
minimum cut?
2. Following gure shows a ow network on which an s-t ow has been computed. The
capacity of each edge appears as a label next to the edge, and the numbers in boxes
give the amount of ow sent on each edge. (Edges without boxed numbers have no ow
being sent on them.)
(a) What is the value of this ow? Is this a maximum (s,t) ow in this graph?
a
6 5
10 2 5
1
1
3 6 5
s b c t
3 5 5
1 3 3
1 10
1
d
Figure 7.27 What is the value of the depicted flow? Is it a maximum flow? What is the
minimum cut?
(b) Find a minimum s-t cut in the flow network pictured in Figure 7.27,
and also say what its capacity is.
! Capacities
Let G be an arbitrary flow network, with a source s, a sink t, and a positive
integer capacity ce on every edge e; and let (A, B) be a mimimum s-t cut with
respect to these capacities {ce : e ∈ E}. Now suppose we add 1 to every capacity;
then (A, B) is still a minimum s-t cut with respect to these new capacities
{1 + ce : e ∈ E}.