Data Algorithms
Data Algorithms
4. Which of the following searching algorithm is used with exponential sort after finding the
appropriate range?
a) Jump search
b) Fibonacci Search
c) Linear search
d) Binary search
5. Which of the following searching algorithm is fastest when the input array is not sorted but has
uniformly distributed values?
a) linear search
b) jump search
c) interpolation search
d) binary search
6. What is the time complexity of Z algorithm for pattern searching (m = length of text, n = length
of pattern)?
a) O(n)
b) O(m)
c) O(n + m)
d) O(m * n)
7. In which of the cases uniform binary search fails compared to binary search?
a) Complexity of code
b) Many searches will be performed on several arrays of the same length
c) Many searches will be performed on the same array
d) A table lookup is generally faster than an addition and a shift
1
d) Jump search
10. Which of the following step is taken after finding an element having value greater than the
element being searched?
a) binary search takes place in the forward direction
b) binary search takes place in a backward direction
c) linear search takes place in the forward direction
d) linear search takes place in the backward direction
12. In which of the following case jump search will be preferred over exponential search?
a) when the given array is very small in size
b) when the given array is very large in size
c) jumping backwards takes significantly more time than jumping forward
d) jumping forward takes significantly more time than jumping backwards
Is there any difference in the speed of execution between linear serach(recursive) vs linear
search(lterative)?
a) Both execute at same speed
b) Linear search(recursive) is faster
c) Linear search(Iterative) is faster
d) Cant be said
Is the space consumed by the linear search(recursive) and linear search(iterative) same?
a) No, recursive algorithm consumes more space
b) No, recursive algorithm consumes less space
c) Yes
d) Nothing can be said
2
Can linear search recursive algorithm and binary search recursive algorithm be performed on an
unordered list?
a) Binary search can’t be used
b) Linear search can’t be used
c) Both cannot be used
d) Both can be used
What is the recurrence relation for the linear search recursive algorithm?
a) T(n-2)+c
b) 2T(n-1)+c
c) T(n-1)+c
d) T(n+1)+c
In which of the cases uniform binary search fails compared to binary search? ANS(Complexity of
code)
3
c) Can be used for large arrays which do not fit in the CPU cache or in the RAM
d) It can be applied efficiently on unsorted arrays
Which of the following searching algorithm is used with exponential sort after finding the
appropriate range?
a) Linear search
b) Binary search
c) Jump search
d) Fibonacci Search
. In which of the following case jump search will be preferred over exponential search?
a) jumping backwards takes significantly more time than jumping forward
1. Which of the following is the most desirable condition for interpolation search?
a) array should be sorted
b) array should not be sorted but the values should be uniformly distributed
c) array should have a less than 64 elements
d) array should be sorted and the values should be uniformly distributed
4
c) array is sorted but the values are not uniformly distributed
d) array is not sorted
4. In which of the following case jump search performs better than interpolation search?
a) When array has uniformly distributed values but is not sorted
b) when array is sorted and has uniform distribution of values
c) when array is sorted but the values increases exponentially
d) when array is not sorted
5. What is the time complexity of interpolation search when the input array has uniformly
distributed values and is sorted?
a) O(n)
b) O(log log n)
c) O(n log n)
d) O(log n)
7. What is the time complexity of exponential search when the input array is sorted but the values
are not uniformly distributed?
a) O(n1/2)
b) O(log log n)
c) O(n)
d) O(log n)
8. Which of the following searching algorithm is fastest when the input array is sorted and has
uniformly distributed values?
a) jump search
b) exponential search
c) binary search
d) interpolation search
9. Which of the following searching algorithm is fastest when the input array is sorted but has non
uniformly distributed values?
a) jump search
b) linear search
c) binary search
d) interpolation search
10. Which of the following searching algorithm is fastest when the input array is not sorted but
has uniformly distributed values?
a) jump search
b) linear search
c) binary search
d) interpolation search
5
11. Interpolation search is an in place algorithm.
a) true
b) false
12. Interpolation search has a better time complexity than exponential search for any given array.
a) True
b) False
13. What is the formula used for calculating the position in interpolation search?
(x = element being searched, A[] = input array, low and high are the leftmost and rightmost index
of A[] respectively)
a) ((x – A[low]) * (high – low)) / (A[high] – A[low])
b) high + ((x – A[low]) * (high – low)) / (A[high] – A[low])
c) low + ((x – A[low]) * (high – low)) / (A[high] – A[low])
d) x + ((x – A[low]) * (high – low)) / (A[high] – A[low])
14. What are the updated values of high and low in the array if the element being searched is
greater than the value at calculated index in interpolation search? (pos = current position)
a) low = pos + 1, high remains unchanged
b) high = pos – 1, low remains unchanged
c) low = low +1, high = high – 1
d) low = pos +1, high = pos – 1
15. What are the updated values of high and low in the array if the element being searched is
lower than the value at calculated index in interpolation search? (pos = current position)
a) low = pos + 1, high remains unchanged
b) high = pos – 1, low remains unchanged
c) low = low +1, high = high – 1
d) low = pos +1, high = pos – 1
Which of the following sorting algorithms is the fastest for sorting small arrays?
a) Quick sort
b) Shell sort
c) Insertion sort
d) Heap sort.
6
b) merge sort
c) heap sort
d) quick sort
9. In heap sort, after deleting the last minimum element, the array will contain elements in?
a) increasing sorting order
b) tree preorder
c) tree inorder
d) decreasing sorting order
12. Which of the following sorting algorithm uses the method of insertion?
a) selection sort
b) quick sort
c) bubble sort
7
d) cycle sort
4. Any algorithm that sorts by exchanging adjacent elements require O(N 2) on average.
a) True
b) False
6. What is the running time of an insertion sort algorithm if the input is pre-sorted?
a) O(N2)
b) O(N log N)
c) O(N)
d) O(M log N)
7. What will be the number of passes to sort the elements using insertion sort?
14, 12,16, 6, 3, 10
a) 6
b) 5
c) 7
d) 1
8. For the following question, how will the array elements look like after second pass?
34, 8, 64, 51, 32, 21
8
a) 8, 21, 32, 34, 51, 64
b) 8, 32, 34, 51, 64, 21
c) 8, 34, 51, 64, 32, 21
d) 8, 34, 64, 51, 32, 21
10. In C, what are the basic loops required to perform an insertion sort?
a) do- while
b) if else
c) for and while
d) for and if
11. Binary search can be used in an insertion sort algorithm to reduce the number of comparisons.
a) True
b) False
12. Which of the following options contain the correct feature of an insertion sort algorithm?
a) anti-adaptive
b) dependable
c) stable, not in-place
d) stable, adaptive
13. Which of the following sorting algorithms is the fastest for sorting small arrays?
a) Quick sort
b) Insertion sort
c) Shell sort
d) Heap sort
14. For the best case input, the running time of an insertion sort algorithm is?
a) Linear
b) Binary
c) Quadratic
d) Depends on the input
15. Which of the following examples represent the worst case input for an insertion sort?
a) array in sorted order
b) array sorted in reverse order
c) normal unsorted array
d) large array
9
2. Which of the following sorting algorithm is best suited if the elements are already sorted?
a) Heap Sort
b) Quick Sort
c) Insertion Sort
d) Merge Sort
3. The worst case time complexity of insertion sort is O(n2). What will be the worst case time
complexity of insertion sort if the correct position for inserting element is calculated using binary
search?
a) O(nlogn)
b) O(n2)
c) O(n)
d) O(logn)
. Which of the following is good for sorting arrays having less than 100 elements?
a) Quick Sort
b) Selection Sort
c) Merge Sort
d) Insertion Sort
10
d) It is faster than any other sorting technique
8. The given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and selection sort
respectively are __________
a) 5 and 4
b) 4 and 5
c) 2 and 4
d) 2 and 5
9. The given array is arr = {1,2,3,4,5}. (bubble sort is implemented with a flag variable)The number
of iterations in selection sort and bubble sort respectively are __________
a) 5 and 4
b) 1 and 4
c) 0 and 4
d) 4 and 1
11
. Which of the following is not an advantage of optimised bubble sort over other sorting
techniques in case of sorted elements?
a) It is faster
b) Consumes less memory
c) Detects whether the input is already sorted
d) Consumes less time
. What is the best case efficiency of bubble sort in the improvised version?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
12
b) partitioning
c) selection
d) exchanging.
7. What will be the best case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
9. Choose the incorrect statement about merge sort from the following?
a) it is a comparison based sort
b) it is an adaptive algorithm
c) it is not an in place algorithm
d) it is stable algorithm
12. Which of the following stable sorting algorithm takes the least time when applied to an almost
sorted array?
a) Quick sort
b) Insertion sort
c) Selection sort
d) Merge sort
14. Which of the following sorting algorithm makes use of merge sort?
a) tim sort
b) intro sort
c) bogo sort
d) quick sort
13
1. Which of the following sorting algorithms is the fastest?
a) Merge sort
b) Quick sort
c) Insertion sort
d) Shell sort
4. Which of the following methods is the most effective for picking the pivot element?
a) first element
b) last element
c) median-of-three partitioning
d) random element
5. Find the pivot element from the given input using median-of-three partitioning method.
8, 1, 4, 9, 6, 3, 5, 2, 7, 0.
a) 8
b) 7
c) 9
d) 6
8. Which of the following sorting algorithms is used along with quick sort to sort the sub arrays?
a) Merge sort
b) Shell sort
c) Insertion sort
d) Bubble sort
14
a) one
b) two
c) three
d) four
The best case behaviour occurs for quick sort is, if partition splits the array of size n into
__________
a) n/2 : (n/2) – 1
b) n/2 : n/3
c) n/4 : 3n/2
d) n/4 : 3n/4
6. Consider the Quick sort algorithm in which the partitioning procedure splits elements into two
sub-arrays and each sub-array contains at least one-fourth of the elements. Let T(n) be the
number of comparisons required to sort array of n elements. Then T(n)<=?
a) T(n) <= 2 T(n/4) + cn
b) T(n) <= T(n/4) + T(3n/4) + cn
c) T(n) <= 2 T(3n/4) + cn
d) T(n) <= T(n/3) + T(3n/4) + cn
A machine needs a minimum of 200 sec to sort 1000 elements by Quick sort. The minimum time
needed to sort 200 elements will be approximately __________
15
a) 60.2 sec
b) 45.54 sec
c) 31.11 sec
d) 20 sec
9. Which one of the following sorting algorithm is best suited to sort an array of 1 million
elements?
a) Bubble sort
b) Insertion sort
c) Merge sort
d) Quick sort
16
c) adaptive sorting algorithm
d) can be implemented as a stable sort
10. How many elements can be sorted in O(logn) time using Heap sort?
a) O(1)
b) O(n/2)
c) O(logn/log(logn))
d) O(logn)
In binary tree sort, we first construct the BST and then we perform _______ traversal to get the
sorted order.
a) inorder
b) postorder
17
c) preorder
d) level order
3. What is the worst case time complexity of the binary tree sort?
a) O(n)
b) O(nlogn)
c) O(n2)
d) O(logn)
5. What is the best case time complexity of the binary tree sort?
a) O(n)
b) O(nlogn)
c) O(n2)
d) O(logn)
8. Which of the following sorting algorithms can be considered as improvement to the binary tree
sort?
a) Heap sort
b) Quick sort
c) Selection sort
d) Insertion sort
3. Which of the following non-comparison sort can also be considered as a comparison based sort?
a) counting sort
18
b) MSD radix sot
c) bucket sort
d) pigeonhole sort
5. Which of the following don’t affect the time complexity of bucket sort?
a) algorithm implemented for sorting individual buckets
b) number of buckets used
c) distribution of input
d) input values
8. What is the worst case time complexity of bucket sort (k = number of buckets)?
a) O(n + k)
b) O(n.k)
c) O(n2)
d) O(n log n)
.
9. What is the best time complexity of bucket sort (k= number of buckets)?
a) O(n + k)
b) O(n.k)
c) O(n2)
d) O(n log n)
19
12. What is the worst space complexity of bucket sort (k = number of buckets)?
a) O(n + k)
b) O(n.k)
c) O(n2)
d) O(n log n)
4. What is the basic formula applied in Rabin Karp Algorithm to get the computation time as
Theta(m)?
a) Halving rule
b) Horner’s rule
c) Summation lemma
d) Cancellation lemma
13. If the expected number of valid shifts is small and modulus is larger than the length of pattern
what is the matching time of Rabin Karp Algorithm?
a) Theta(m)
b) Big-Oh(n+m)
c) Theta(n-m)
d) Big-Oh(n)
20
d) Dynamic Programming
.
15. Who created the Rabin Karp Algorithm?
a) Joseph Rabin and Michael Karp
b) Michael Rabin and Joseph Karp
c) Richard Karp and Michael Rabin
d) Michael Karp and Richard Rabin
2. Which of the following algorithms formed the basis for the Quick search algorithm?
a) Boyer-Moore’s algorithm
b) Parallel string matching algorithm
c) Binary Search algorithm
d) Linear Search algorithm
21
3. The Data structure used in standard implementation of Breadth First Search is?
a) Stack
b) Queue
c) Linked List
d) Tree
5. A person wants to visit some places. He starts from a vertex and then wants to visit every vertex
till it finishes from one vertex, backtracks and then explore other vertex from same vertex. What
algorithm he should use?
a) Depth First Search
b) Breadth First Search
c) Trim’s algorithm
d) Kruskal’s Algorithm
8. Regarding implementation of Depth First Search using stacks, what is the maximum distance
between two nodes present in the stack? (considering each edge length 1)
a) Can be anything
b) 0
c) At most 1
d) Insufficient Information
.
9. In Depth First Search, how many times a node is visited?
a) Once
b) Twice
c) Equivalent to number of indegree of the node
d) Thrice
22
2. Which of the following traversal in a binary tree is similar to depth first traversal?
a) level order
b) post order
c) pre order
d) in order
3. What will be the result of depth first traversal in the following tree?
a) 4 2 5 1 3
b) 1 2 4 5 3
c) 4 5 2 3 1
d) 1 2 3 4 5
4. Which of the following is a possible result of depth first traversal of the given graph(consider 1
to be source element)?
a) 1 2 3 4 5
b) 1 2 3 1 4 5
c) 1 4 5 3 2
d) 1 4 5 1 2 3
6. What will be the time complexity of the iterative depth first traversal code(V=no. of vertices
E=no.of edges)?
a) O(V+E)
b) O(V)
c) O(E)
d) O(V*E)
. What is the space complexity of standard DFS(V: no. of vertices E: no. of edges)?
a) O(V+E)
b) O(V)
c) O(E)
d) O(V*E)
10. Choose the incorrect statement about DFS and BFS from the following?
a) BFS is equivalent to level order traversal in trees
b) DFS is equivalent to post order traversal in trees
c) DFS and BFS code has the same time complexity
23
d) BFS is implemented using queue
Breadth First Search is equivalent to which of the traversal in the Binary Trees?
a) Pre-order Traversal
b) Post-order Traversal
c) Level-order Traversal
d) In-order Traversal
2. Time Complexity of Breadth First Search is? (V – number of vertices, E – number of edges)
a) O(V + E)
b) O(V)
c) O(E)
d) O(V*E)
3. The Data structure used in standard implementation of Breadth First Search is?
a) Stack
b) Queue
c) Linked List
d) Tree
5. A person wants to visit some places. He starts from a vertex and then wants to visit every place
connected to this vertex and so on. What algorithm he should use?
a) Depth First Search
b) Breadth First Search
c) Trim’s algorithm
d) Kruskal’s algorithm
8. Regarding implementation of Breadth First Search using queues, what is the maximum distance
between two nodes present in the queue? (considering each edge length 1)
a) Can be anything
b) 0
c) At most 1
24
d) Insufficient Information
2. Who described this Best First Search algorithm using heuristic evaluation rule?
a) Judea Pearl
b) Max Bezzel
c) Franz Nauck
d) Alan Turing
3. Which type of best first search algorithm was used to predict the closeness of the end of path
and its solution?
a) Greedy BFS
b) Divide and Conquer
c) Heuristic BFS
d) Combinatorial
6. Which algorithm is used to find the least cost path from source node to destination node?
a) A* BFS
b) C* BFS
c) D* BFS
d) B* BFS
25
b) A*
c) B*
d) Both A* and B*
2. Which of the following is not a branch and bound strategy to generate branches?
a) LIFO branch and bound
b) FIFO branch and bound
c) Lowest cost branch and bound
d) Highest cost branch and bound
3. Which data structure is used for implementing a LIFO branch and bound strategy?
a) stack
b) queue
c) array
d) linked list
4. Which data structure is used for implementing a FIFO branch and bound strategy?
a) stack
b) queue
c) array
d) linked list
5. Which data structure is most suitable for implementing best first branch and bound strategy?
a) stack
b) queue
c) priority queue
d) linked list
6. Which of the following branch and bound strategy leads to breadth first search?
a) LIFO branch and bound
b) FIFO branch and bound
c) Lowest cost branch and bound
d) Highest cost branch and bound
26
7. Which of the following branch and bound strategy leads to depth first search?
a) LIFO branch and bound
b) FIFO branch and bound
c) Lowest cost branch and bound
d) Highest cost branch and bound
8. Both FIFO branch and bound strategy and backtracking leads to depth first search.
a) true
b) false
9. Both LIFO branch and bound strategy and backtracking leads to depth first search.
a) true
b) false
11. Which of the following can traverse the state space tree only in DFS manner?
a) branch and bound
b) dynamic programming
c) greedy algorithm
d) backtracking
3. Consider a complete graph G with 4 vertices. The graph G has ____ spanning trees.
a) 15
b) 8
c) 16
d) 13
4. The travelling salesman problem can be solved using _________
a) A spanning tree
b) A minimum spanning tree
c) Bellman – Ford algorithm
d) DFS traversal
5. Consider the graph M with 3 vertices. Its adjacency matrix is shown below. Which of the following
is true?
27
a) Graph M has no minimum spanning tree
b) Graph M has a unique minimum spanning trees of cost 2
c) Graph M has 3 distinct minimum spanning trees, each of cost 2
d) Graph M has 3 spanning trees of different costs
6. Consider a undirected graph G with vertices { A, B, C, D, E}. In graph G, every edge has distinct
weight. Edge CD is edge with minimum weight and edge AB is edge with maximum weight. Then,
which of the following is false?
a) Every minimum spanning tree of G must contain CD
b) If AB is in a minimum spanning tree, then its removal must disconnect G
c) No minimum spanning tree contains AB
d) G has a unique minimum spanning tree
7. If all the weights of the graph are positive, then the minimum spanning tree of the graph is a
minimum cost subgraph.
a) True
b) False
8. Consider the graph shown below. Which of the following are the edges in the MST of the given
graph?
a) (a-c)(c-d)(d-b)(d-b)
b) (c-a)(a-d)(d-b)(d-e)
c) (a-d)(d-c)(d-b)(d-e)
d) (c-a)(a-d)(d-c)(d-b)(d-e)
28
9. Which of the following is not the algorithm to find the minimum spanning tree of the given
graph?
a) Boruvka’s algorithm
b) Prim’s algorithm
c) Kruskal’s algorithm
d) Bellman–Ford algorithm
What is the weight of the minimum spanning tree using the Kruskal’s algorithm?
a) 24
b) 23
29
c) 15
d) 19
5. Consider the following graph. Using Kruskal’s algorithm, which edge will be selected first?
a) GF
b) DE
c) BE
d) BG
6. Which of the following edges form minimum spanning tree on the graph using kruskals
algorithm?
30
a) (B-E)(G-E)(E-F)(D-F)
b) (B-E)(G-E)(E-F)(B-G)(D-F)
c) (B-E)(G-E)(E-F)(D-E)
d) (B-E)(G-E)(E-F)(D-F)(D-G)
9. Kruskal’s algorithm is best suited for the dense graphs than the prim’s algorithm.
a) True
b) False
10. Consider the following statements.
S1. Kruskal’s algorithm might produce a non-minimal spanning tree.
S2. Kruskal’s algorithm can efficiently implemented using the disjoint-set data structure.
a) S1 is true but S2 is false
b) Both S1 and S2 are false
c) Both S1 and S2 are true
31
d) S2 is true but S1 is false
What is the weight of the minimum spanning tree using the Prim’s algorithm,starting from vertex a?
a) 23
b) 28
c) 27
d) 11
edge from the vertex in MST to vertex not in MST. From, figure shown below weight of MST = 27.
3. Worst case is the worst case time complexity of Prim’s algorithm if adjacency matrix is used?
a) O(log V)
b) O(V2)
c) O(E2)
d) O(V log E)
32
b) False
6. Kruskal’s algorithm is best suited for the sparse graphs than the prim’s algorithm.
a) True
b) False
Which of the following edges form the MST of the given graph using Prim’a algorithm, starting from
vertex 4.
a) (4-3)(5-3)(2-3)(1-2)
b) (4-3)(3-5)(5-1)(1-2)
c) (4-3)(3-5)(5-2)(1-5)
d) (4-3)(3-2)(2-1)(1-5)
Explanation: The MST for the given graph using Prim’s algorithm starting from vertex 4 is,
9. Prim’s algorithm can be efficiently implemented using _____ for graphs with greater density.
a) d-ary heap
b) linear search
c) fibonacci heap
33
d) binary search
2. What is the running time of an unweighted shortest path algorithm whose augmenting path is
the path with the least number of edges?
a) O(|E||V|)
b) O(|E|)
c) O(|E| log |V|)
d) O(|E|2|V|)
34
9. Chan’s algorithm is used for computing _________
a) Shortest path between two points
b) Area of a polygon
c) Convex hull
d) Closest distance between two points
2. Which of the following is the most commonly used data structure for implementing Dijkstra’s
Algorithm?
a) Max priority queue
b) Stack
c) Circular queue
d) Min priority queue
7. How many times the insert and extract min operations are invoked per vertex?
a) 1
b) 2
c) 3
d) 0
8. The maximum number of times the decrease key operation performed in Dijkstra’s algorithm
will be equal to ___________
a) Total number of vertices
b) Total number of edges
c) Number of vertices – 1
d) Number of edges – 1
35
9. What is running time of Dijkstra’s algorithm using Binary min- heap method?
a) O(V)
b) O(VlogV)
c) O(E)
d) O(ElogV)
10. The running time of Bellmann Ford algorithm is lower than that of Dijkstra’s Algorithm.
a) True
b) False
11. Dijkstra’s Algorithm run on a weighted, directed graph G={V,E} with non-negative weight
function w and source s, terminates with d[u]=delta(s,u) for all vertices u in V.
a) True
b) False
1. The Bellmann Ford algorithm returns _______ value.
a) Boolean
b) Integer
c) String
d) Double
3. Bellmann Ford algorithm is used to indicate whether the graph has negative weight cycles or
not.
a) True
b) False
4. How many solution/solutions are available for a graph having negative weight cycle?
a) One solution
b) Two solutions
c) No solution
d) Infinite solutions
6. How many times the for loop in the Bellmann Ford Algorithm gets executed?
a) V times
b) V-1
c) E
d) E-1
36
9. What is the basic principle behind Bellmann Ford Algorithm?
a) Interpolation
b) Extrapolation
c) Regression
d) Relaxation
12. Consider the following graph. What is the minimum cost to travel from node A to node C?
a) 5
b) 2
c) 1
d) 3
View Answer
Answer: b
Explanation: The minimum cost to travel from node A to node C is 2.
A-D, cost=1
D-B, cost=-2
B-C, cost=3
Hence the total cost is 2.
13. In the given graph, identify the path that has minimum cost to travel from node a to node f.
a) a-b-c-f
b) a-d-e-f
37
c) a-d-b-c-f
d) a-d-b-c-e-f
View Answer
Answer: d
Explanation: The minimum cost taken by the path a-d-b-c-e-f is 4.
a-d, cost=2
d-b, cost=-2
b-c, cost=1
c-e, cost= 2
e-f, cost=1
Hence the total cost is 4.
14. Bellmann Ford Algorithm is an example for ____________
a) Dynamic Programming
b) Greedy Algorithms
c) Linear Programming
d) Branch and Bound
38
d) Transitive closure
8. Who proposed the modern formulation of Floyd-Warshall Algorithm as three nested loops?
a) Robert Floyd
b) Stephen Warshall
c) Bernard Roy
d) Peter Ingerman
10. What happens when the value of k is 0 in the Floyd Warshall Algorithm?
a) 1 intermediate vertex
b) 0 intermediate vertex
c) N intermediate vertices
d) N-1 intermediate vertices
11. Using logical operator’s instead arithmetic operators saves time and space.
a) True
b) False
12. The time taken to compute the transitive closure of a graph is Theta(n 2).
a) True
b) False
13. In the given graph, what is the minimum cost to travel from vertex 1 to vertex 3?
a) 3
b) 2
c) 10
d) -3
View Answer
Answer: d
Explanation: The minimum cost required to travel from node 1 to node 5 is -3.
39
1-5, cost is -4
5-4, cost is 6
4-3, cost is -5
Hence total cost is -4 + 6 + -5 = -3.
14. In the given graph, how many intermediate vertices are required to travel from node a to node
e at a minimum cost?
a) 2
b) 0
c) 1
d) 3
1. What is the objective of tower of hanoi puzzle?
a) To move all disks to some other rod by following rules
b) To divide the disks equally among the three rods by following rules
c) To move all disks to some other rod in random order
d) To divide the disks equally among three rods in random order
3. The time complexity of the solution tower of hanoi problem using recursion is _________
a) O(n2)
b) O(2n)
c) O(n log n)
d) O(n)
4. Recurrence equation formed for the tower of hanoi problem is given by _________
a) T(n) = 2T(n-1)+n
b) T(n) = 2T(n/2)+c
c) T(n) = 2T(n-1)+c
d) T(n) = 2T(n/2)+n
5. Minimum number of moves required to solve a tower of hanoi problem with n disks is
__________
a) 2n
b) 2n-1
c) n2
40
d) n2-1
10. Minimum time required to solve tower of hanoi puzzle with 4 disks assuming one move takes 2
seconds, will be __________
a) 15 seconds
b) 30 seconds
c) 16 seconds
d) 32 seconds
41
d) There is no such condition
2. Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you
choose the largest denomination coin which is not greater than the remaining sum. For which of
the following sums, will the algorithm produce an optimal answer?
a) 100
b) 10
c) 6
d) 14
6. Which of the following algorithms is the best approach for solving Huffman codes?
a) greedy algorithm
b) exhaustive search
c) divide and conquer algorithm
d) brute force algorithm
7. Fractional knapsack problem is solved most efficiently by which of the following algorithm?
a) Backtracking
b) Greedy algorithm
c) Dynamic programming
d) Divide and conquer
42
d) It can accept cycles in the MST
2. Fractional knapsack problem is solved most efficiently by which of the following algorithm?
a) Divide and conquer
b) Dynamic programming
c) Greedy algorithm
d) Backtracking
4. Which of the following statement about 0/1 knapsack and fractional knapsack problem is
correct?
a) In 0/1 knapsack problem items are divisible and in fractional knapsack items are indivisible
b) Both are the same
c) 0/1 knapsack is solved using a greedy algorithm and fractional knapsack is solved using dynamic
programming
d) In 0/1 knapsack problem items are indivisible and in fractional knapsack items are divisible
8. The result of the fractional knapsack is greater than or equal to 0/1 knapsack.
a) True
b) False
43
b) Adding items into knapsack
c) Sorting
d) Looping through sorted items
10. Given items as {value,weight} pairs {{60,20},{50,25},{20,5}}. The capacity of knapsack=40. Find
the maximum value output assuming items to be divisible and nondivisible respectively.
a) 100, 80
b) 110, 70
c) 130, 110
d) 110, 80
Which of the following approach should be used to find the solution of the activity selection
problem?
a) Greedy approach
b) Divide and conquer
c) Brute-force approach
d) Dynamic programming
. Which of the following algorithms is the best approach for solving Huffman codes?
a) exhaustive search
b) greedy algorithm
c) brute force algorithm
d) divide and conquer algorithm
2. How many printable characters does the ASCII character set consists of?
a) 120
b) 128
c) 100
d) 98
.
3. Which bit is reserved as a parity bit in an ASCII set?
a) first
b) seventh
c) eighth
d) tenth
4. How many bits are needed for standard encoding if the size of the character set is X?
a) log X
b) X+1
c) 2X
d) X2
5. The code length does not depend on the frequency of occurrence of characters.
a) true
b) false
44
d) right sub trees
3. If a problem can be broken into subproblems which are reused several times, the problem
possesses ____________ property.
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy
5. When dynamic programming is applied to a problem, it takes far less time as compared to other
methods that don’t take advantage of overlapping subproblems.
a) True
b) False
6. A greedy algorithm can be used to solve all the dynamic programming problems.
a) True
b) False
7. In dynamic programming, the technique of storing the previously calculated values is called
___________
a) Saving value property
b) Storing value property
c) Memoization
d) Mapping
45
d) Increases both, the time complexity and the space complexity
10. Which of the following problems should be solved using dynamic programming?
a) Mergesort
b) Binary search
c) Longest common subsequence
d) Quicksort
46