0% found this document useful (0 votes)
2 views

Data Algorithms

The document consists of a series of questions and answers related to various searching and sorting algorithms, including their complexities, advantages, and applications. It covers algorithms such as binary search, linear search, jump search, interpolation search, and sorting techniques like insertion sort and merge sort. The document serves as a quiz or study guide for understanding key concepts in algorithm design and analysis.

Uploaded by

yicoc86443
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Algorithms

The document consists of a series of questions and answers related to various searching and sorting algorithms, including their complexities, advantages, and applications. It covers algorithms such as binary search, linear search, jump search, interpolation search, and sorting techniques like insertion sort and merge sort. The document serves as a quiz or study guide for understanding key concepts in algorithm design and analysis.

Uploaded by

yicoc86443
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Data Algorithms

1. Which of the following searching algorithm is fastest?


a) binary search
b) linear search
c) jump search
d) all are equally fast

2. Where is linear searching used?


a) Used all the time
b) When the list has only a few elements
c) When performing a single search in an unordered list
d) When the list has only a few elements and When performing a single search in an unordered list

3. How can Jump Search be improved?


a) Step size should be other than sqrt(n)
b) Cannot be improved
c) Begin from the kth item, where k is the step size
d) Start searching from the end

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

8. Interpolation search is a variation of?


a) Exponential search
b) Linear search
c) Binary search

1
d) Jump search

9. Which of the following is not an application of binary search?


a) To search in unordered list
b) Debugging
c) Union of intervals
d) To find the lower/upper bound in an ordered sequence

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

11. Which of the following is not an advantage of Fibonacci Search?


a) When the element being searched for has a non-uniform access storage
b) It can be applied efficiently on unsorted arrays
c) Can be used for large arrays which do not fit in the CPU cache or in the RAM
d) Can be used in magnetic tapes

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

Where is linear searching used?


a) When the list has only a few elements
b) When performing a single search in an unordered list
c) Used all the time
d) When the list has only a few elements and When performing a single search in an unordered list

Which of the following is a disadvantage of linear search?


a) Requires more space
b) Greater time complexities compared to other searching algorithms
c) Not easy to understand
d) Not easy to implement

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

What is the advantage of recursive approach than an iterative approach?


a) Consumes less memory
b) Less code and easy to implement
c) Consumes more memory
d) More code has to be written

Which of the following is not an application of binary search?


a) To find the lower/upper bound in an ordered sequence
b) Union of intervals
c) Debugging
d) To search in unordered list

In which of the cases uniform binary search fails compared to binary search? ANS(Complexity of
code)

Which of the following false about Jump Search?


a) Jump Search is better than Linear Search
b) Useful when jumping back is more costly than jumping forward
c) Jump Search is worse than Binary Search
d) Jump search starts from the index 0 even though specified index is k

Which algorithmic technique does Fibonacci search use?


a) Brute force
b) Divide and Conquer
c) Greedy Technique
d) Backtracking

Choose the recursive formula for the Fibonacci series.(n>=1)


a) F(n) = F(n+1) + F(n+2)
b) F(n) = F(n) + F(n+1)
c) F(n) = F(n-1) + F(n-2)
d) F(n) = F(n-1) – F(n-2)

What is the time complexity of Fibonacci Search? a) O(logn)

Which of the following is not an advantage of Fibonacci Search?


a) When the element being searched for has a non uniform access storage
b) Can be used in magnetic tapes

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

What is the time complexity of Jump Search?


a) O(logn)
b) O(n)
c) O(sqrt(n))
d) O(nlogn)

Exponential search algorithm requires which of the following condition to be true?


a) array should be sorted

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

Exponential search has ____________


a) neither an exponential space complexity nor exponential time complexity

What is the time complexity of exponential sort?


a) O(n)
b) O(2n)
c) O(n log n)
d) O(log n)

. In which of the following case jump search will be preferred over exponential search?
a) jumping backwards takes significantly more time than jumping forward

Which of the following is not an alternate name of exponential search?


a) Logarithmic search
b) Doubling search
c) Galloping search
d) Struzik search

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

2. Interpolation search is a variation of?


a) Linear search
b) Binary search
c) Jump search
d) Exponential search

3. Interpolation search performs better than binary search when?


a) array has uniformly distributed values but is not sorted
b) array is sorted and has uniform distribution of values

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)

6. What is the auxiliary space requirement of interpolation search?


a) O(n)
b) O(2n)
c) O(1)
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.

2. What is the advantage of selection sort over other sorting techniques?


a) It is faster than any other sorting technique
b) It is scalable
c) It works best for inputs which are already sorted
d) It requires no additional storage space

3. Which of the following method is used for sorting in merge sort?


a) partitioning
b) merging
c) exchanging
d) selection

4. Which of the following sorting algorithm does not use recursion?


a) bottom up merge sort

6
b) merge sort
c) heap sort
d) quick sort

5. Merge sort uses which of the following method to implement sorting?


a) selection
b) exchanging
c) merging
d) partitioning
.
6. Which of the following sorting algorithms is the fastest?
a) Merge sort
b) Shell sort
c) Insertion sort
d) Quick sort

7. Shell sort algorithm is an example of?


a) Bottom-up sorting
b) In-place sorting
c) Internal sorting
d) External sorting

8. Quick sort uses which of the following method to implement sorting?


a) partitioning
b) selection
c) exchanging
d) merging

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

10. Which of the following sorting algorithm is used by C++ internally?


a) quicksort
b) merge sort
c) introsort
d) heap sort

11. Which of the following sorting algorithm is stable?


a) Introsort
b) Tim sort
c) Heap sort
d) Quick sort

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

13. Which of the following pair of sorting algorithms are stable?


a) gnome sort and merge sort
b) heap sort and merge sort
c) gnome sort and quick sort
d) merge sort and selection sort

How many passes does an insertion sort algorithm consist of?


a) N
b) N-1
c) N+1
d) N2

2. Which of the following algorithm implementations is similar to that of an insertion sort?


a) Binary heap
b) Quick sort
c) Merge sort
d) Radix sort

3. What is the average case running time of an insertion sort algorithm?


a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)

4. Any algorithm that sorts by exchanging adjacent elements require O(N 2) on average.
a) True
b) False

5. What is the average number of inversions in an array of N distinct numbers?


a) N(N-1)/4
b) N(N+1)/2
c) N(N-1)/2
d) N(N-1)/3

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

9. Which of the following real time examples is based on insertion sort?


a) arranging a pack of playing cards
b) database scenarios and distributes scenarios
c) arranging books on a library shelf
d) real-time systems

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

1. Which of the following is correct with regard to insertion sort?


a) insertion sort is stable and it sorts In-place
b) insertion sort is unstable and it sorts In-place
c) insertion sort is stable and it does not sort In-place
d) insertion sort is unstable and it does not sort In-place

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)

4. Insertion sort is an example of an incremental algorithm.


a) True
b) False

. 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

Which of the following is not an exchange sort?


a) Bubble Sort
b) Quick Sort
c) Partition-exchange Sort
d) Insertion Sort

. What is an in-place sorting algorithm?


a) It needs O(1) or O(logn) memory to create auxiliary locations
b) The input is already sorted and in-place
c) It requires additional storage
d) It requires additional space
2. In the following scenarios, when will you use selection sort?
a) The input is already sorted
b) A large file has to be sorted
c) Large values need to be sorted with small keys
d) Small values need to be sorted with large keys

3. What is the worst case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

What is the advantage of selection sort over other sorting techniques?


a) It requires no additional storage space
b) It is scalable
c) It works best for inputs which are already sorted

10
d) It is faster than any other sorting technique

6. What is the average case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

7. What is the disadvantage of selection sort?


a) It requires auxiliary memory
b) It is not scalable
c) It can be used for small keys
d) It takes linear time to sort the elements

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

10. What is the best case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

1. What is an external sorting algorithm?


a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
.
2. What is an internal sorting algorithm?
a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’

3. What is the worst case complexity of bubble sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

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)

Which of the following sorting algorithm does not use recursion?


a) quick sort
b) merge sort
c) heap sort
d) bottom up merge sort

1. Merge sort uses which of the following technique to implement sorting?


a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming

2. What is the average case time complexity of merge sort?


a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)

3. What is the auxiliary space complexity of merge sort?


a) O(1)
b) O(log n)
c) O(n)
d) O(n log n

4. Merge sort can be implemented using O(1) auxiliary space.


a) true
b) false

5. What is the worst case time complexity of merge sort?


a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)

6. Which of the following method is used for sorting in merge sort?


a) merging

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)

8. Which of the following is not a variant of merge sort?


a) in-place merge sort
b) bottom up merge sort
c) top down merge sort
d) linear merge sort

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

10. Which of the following is not in place sorting algorithm by default?


a) merge sort
b) quick sort
c) heap sort
d) insertion sort

11. Which of the following is not a stable sorting algorithm?


a) Quick sort
b) Cocktail sort
c) Bubble sort
d) Merge sort

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

13. Merge sort is preferred for arrays over linked lists.


a) true
b) false

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

2. Quick sort follows Divide-and-Conquer strategy.


a) True
b) False

3. What is the worst case time complexity of a quick sort algorithm?


a) O(N)
b) O(N log N)
c) O(N2)
d) O(log N)

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

6. Which is the safest method to choose a pivot element?


a) choosing a random element as pivot
b) choosing the first element as pivot
c) choosing the last element as pivot
d) median-of-three partitioning method

7. What is the average running time of a quick sort algorithm?


a) O(N2)
b) O(N)
c) O(N log N)
d) O(log N)

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

9. Quick sort uses join operation rather than merge operation.


a) true
b) false

14
a) one
b) two
c) three
d) four

11. Which is the worst method of choosing a pivot element?


a) first element as pivot
b) last element as pivot
c) median-of-three partitioning
d) random element as pivot
.
12. Which among the following is the best cut-off range to perform insertion sort within a quick
sort?
a) N=0-5
b) N=5-20
c) N=20-30
d) N>30

. Quick Sort is a __________


a) greedy algorithm
b) divide and conquer algorithm
c) dynamic programming algorithm
d) backtracking algorithm

2. What is the worst case time complexity of the Quick sort?


a) O(nlogn)
b) O(n)
c) O(n3)
d) O(n2)

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

5. Quick sort is a stable sorting algorithm.


a) True
b) False

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

10. Quick sort is a space-optimised version of ____


a) Bubble sort
b) Selection sort
c) Insertion sort
d) Binary tree sort

. Quick Sort can be categorized into which of the following?


a) Brute Force technique
b) Divide and conquer
c) Greedy algorithm
d) Dynamic programming

What is the worst case complexity of QuickSort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

4. What is a randomized QuickSort?


a) The leftmost element is chosen as the pivot
b) The rightmost element is chosen as the pivot
c) Any element in the array is chosen as the pivot
d) A random number is generated which is used as the pivot

. What is the best case complexity of QuickSort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

What is the average case complexity of QuickSort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

10. Which of the following is not true about QuickSort?


a) in-place algorithm
b) pivot position can be changed

16
c) adaptive sorting algorithm
d) can be implemented as a stable sort

Heap sort is an implementation of ____________ using a descending priority queue.


a) insertion sort
b) selection sort
c) bubble sort
d) merge sort

2. Which one of the following is false?


a) Heap sort is an in-place algorithm
b) Heap sort has O(nlogn) average case time complexity
c) Heap sort is stable sort
d) Heap sort is a comparison-based sorting algorithm

The descending heap property is ___________


a) A[Parent(i)] = A[i]
b) A[Parent(i)] <= A[i]
c) A[Parent(i)] >= A[i]
d) A[Parent(i)] > 2 * A[i]

5. What is its wort case time complexity of Heap sort?


a) O(nlogn)
b) O(n2logn)
c) O(n2)
d) O(n3)
In average case Heap sort is as efficient as the Quick sort.
a) True
b) False

. Which one of the following is a variation of Heap sort?


a) Comb sort
b) Smooth sort
c) Binary tree sort
d) Shell sort
9. Introsort algorithm is combination of _____________
a) Quick sort and Heap sort
b) Quick sort and Shell sort
c) Heap sort and Merge sort
d) Heap sort and insertion 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)

6. Binary tree sort is an in-place sorting algorithm.


a) True
b) False

7. Which of the following is false?


a) Binary tree sort and quick sort have same running time
b) Binary tree sort used BST as work area
c) As the number of elements to sort gets larger, binary tree sort gets more and more efficient
d) Both quick sort and binary tree are in place sorting algorithms

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

9. Consider the following statements related to the binary tree sort.


I. Element can be added gradually as they become available
II. It needs extra memory space
a) Statement I is true but Statement II is false
b) Both Statement I and Statement II are false
c) Both Statement I and Statement II are true
d) Statement II is true but Statement I is false
. How many comparisons will be made to sort the array arr={1, 5, 3, 8, 2} using bucket sort?
a) 5
b) 7
c) 9
d) 0
2. What is the alternate name of bucket sort?
a) group sort
b) radix sort
c) bin sort
d) uniform 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

4. Which of the following is not true about bucket sort?


a) It is a non comparison based integer sort
b) It is a distribution sort
c) It can also be considered as comparison based sort
d) It is in place sorting algorithm

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

6. Bucket sort is most efficient in the case when __________


a) the input is non uniformly distributed
b) the input is uniformly distributed
c) the input is randomly distributed
d) the input range is large

7. Bucket sort is a generalization of which of the following sort?


a) LSD radix sort
b) Pigeonhole sort
c) Counting sort
d) MSD radix sort

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)

10. Which of the following is not necessarily a stable sorting algorithm?


a) bucket sort
b) counting sort
c) merge sort
d) pigeonhole sort

11. Bucket sort is an in place sorting algorithm.


a) True
b) False

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)

. What is a Rabin and Karp Algorithm?


a) String Matching Algorithm
b) Shortest Path Algorithm
c) Minimum spanning tree Algorithm
d) Approximation Algorithm

2. What is the pre-processing time of Rabin and Karp Algorithm?


a) Theta(m2)
b) Theta(mlogn)
c) Theta(m)
d) Big-Oh(n)

3. Rabin Karp Algorithm makes use of elementary number theoretic notions.


a) True
b) False

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

5. What is the worst case running time of Rabin Karp Algorithm?


a) Theta(n)
b) Theta(n-m)
c) Theta((n-m+1)m)
d) Theta(nlogm)

6. Rabin- Karp algorithm can be used for discovering plagiarism in a sentence.


a) True
b) False

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)

14. What is the basic principle in Rabin Karp algorithm?


a) Hashing
b) Sorting
c) Augmenting

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

Which of the following is the fastest algorithm in string matching field?


a) Boyer-Moore’s algorithm
b) String matching algorithm
c) Quick search algorithm
d) Linear search algorithm

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

3. What is the time complexity of the Quick search algorithm?


a) O(n)
b) O(log n)
c) O(m+n)
d) O(mn)

4. What character shift tables does quick search algorithm use?


a) good-character shift tables
b) bad-character shift tables
c) next-character shift tables
d) both good and bad character shift tables

5. What is the space complexity of quick search algorithm?


a) O(n)
b) O(log n)
c) O(m+n)
d) O(mn)

Depth First Search (DFS) Multiple Choice Questions and Answers


Depth 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 DFS is? (V – number of vertices, E – number of edges)


a) O(V + E)
b) O(V)
c) O(E)
d) O(V*E)

21
3. The Data structure used in standard implementation of Breadth First Search is?
a) Stack
b) Queue
c) Linked List
d) Tree

4. The Depth First Search traversal of a graph will result into?


a) Linked List
b) Tree
c) Graph with back edges
d) Array

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

6. Which of the following is not an application of Depth First Search?


a) For generating topological sort of a graph
b) For generating Strongly Connected Components of a directed graph
c) Detecting cycles in the graph
d) Peer to Peer Networks

7. When the Depth First Search of a graph is unique?


a) When the graph is a Binary Tree
b) When the graph is a Linked List
c) When the graph is a n-ary Tree
d) When the graph is a ternary Tree

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

1. Which of the following data structure is used to implement DFS?


a) linked list
b) tree
c) stack
d) queue

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)

9. Which of the following data structure is used to implement BFS?


a) linked list
b) tree
c) stack
d) queue

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

4. The Breadth First Search traversal of a graph will result into?


a) Linked List
b) Tree
c) Graph with back edges
d) Arrays

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

6. Which of the following is not an application of Breadth First Search?


a) Finding shortest path between two nodes
b) Finding bipartiteness of a graph
c) GPS navigation system
d) Path Finding

7. When the Breadth First Search of a graph is unique?


a) When the graph is a Binary Tree
b) When the graph is a Linked List
c) When the graph is a n-ary Tree
d) When the graph is a Ternary Tree

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

9. In BFS, how many times a node is visited?


a) Once
b) Twice
c) Equivalent to number of indegree of the node
d) Thrice

1. Is Best First Search a searching algorithm used in graphs.


a) True
b) False

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

4. What is the other name of the greedy best first search?


a) Heuristic Search
b) Pure Heuristic Search
c) Combinatorial Search
d) Divide and Conquer Search

5. Which algorithm is used in graph traversal and path finding?


a) A*
b) C*
c) D*
d) E*

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

7. Which of the following is an example of Best First Search algorithm?


a) A*
b) B*
c) C*
d) Both A* and B*

8. Which of the following is the greedy best first search?


a) Pure Heuristic Search

25
b) A*
c) B*
d) Both A* and B*

9. Which of the following scientists didn’t publish A* algorithm?


a) Peter Hart
b) Nils Nilsson
c) Bertram Raphael
d) Hans Berliner

10. Who published the B* search algorithm?


a) Peter Hart
b) Nils Nilsson
c) Bertram Raphael
d) Hans Berliner

1. Branch and bound is a __________


a) problem solving technique
b) data structure
c) sorting algorithm
d) type of tree

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

10. Choose the correct statement from the following.


a) branch and bound is more efficient than backtracking
b) branch and bound is not suitable where a greedy algorithm is not applicable
c) branch and bound divides a problem into at least 2 new restricted sub problems
d) backtracking divides a problem into at least 2 new restricted sub problems

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

1. Which of the following is false in the case of a spanning tree of a graph G?


a) It is tree that spans G
b) It is a subgraph of the G
c) It includes every vertex of the G
d) It can be either cyclic or acyclic

2. Every graph has only one minimum spanning tree.


a) True
b) False

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

10. Which of the following is false?


a) The spanning trees do not have any cycles
b) MST have n – 1 edges if the graph has n edges
c) Edge e belonging to a cut of the graph if has the weight smaller than any other edge in the same
cut, then the edge e is present in all the MSTs of the graph
d) Removing one edge from the spanning tree will not make the graph disconnected

1. Kruskal’s algorithm is used to ______


a) find minimum spanning tree
b) find single source shortest path
c) find all pair shortest path algorithm
d) traverse the graph

2. Kruskal’s algorithm is a ______


a) divide and conquer algorithm
b) dynamic programming algorithm
c) greedy algorithm
d) approximation algorithm

3. Consider the given graph.

What is the weight of the minimum spanning tree using the Kruskal’s algorithm?
a) 24
b) 23

29
c) 15
d) 19

So, the weight of the MST is 19.


4. What is the time complexity of Kruskal’s algorithm?
a) O(log V)
b) O(E log V)
c) O(E2)
d) O(V log E)

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)

So, the edges in the MST are, (B-E)(G-E)(E-F)(D-F).


7. Which of the following is true?
a) Prim’s algorithm can also be used for disconnected graphs
b) Kruskal’s algorithm can also run on the disconnected graphs
c) Prim’s algorithm is simpler than Kruskal’s algorithm
d) In Kruskal’s sort edges are added to MST in decreasing order of their weights

8. Which of the following is false about the Kruskal’s algorithm?


a) It is a greedy algorithm
b) It constructs MST by selecting edges in increasing order of their weights
c) It can accept cycles in the MST
d) It uses union-find data structure

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

1. Which of the following is true?


a) Prim’s algorithm initialises with a vertex
b) Prim’s algorithm initialises with a edge
c) Prim’s algorithm initialises with a vertex which has smallest edge
d) Prim’s algorithm initialises with a forest

2. Consider the given graph.

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)

4. Prim’s algorithm is a ______


a) Divide and conquer algorithm
b) Greedy algorithm
c) Dynamic Programming
d) Approximation algorithm

5. Prim’s algorithm resembles Dijkstra’s algorithm.


a) True

32
b) False

6. Kruskal’s algorithm is best suited for the sparse graphs than the prim’s algorithm.
a) True
b) False

7. Consider the graph shown below.

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,

So, the MST contains edges (4-3)(3-2)(2-1)(1-5).


8. Prim’s algorithm is also known as __________
a) Dijkstra–Scholten algorithm
b) Borůvka’s algorithm
c) Floyd–Warshall algorithm
d) DJP Algorithm

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

10. Which of the following is false about Prim’s algorithm?


a) It is a greedy algorithm
b) It constructs MST by selecting edges in increasing order of their weights
c) It never accepts cycles in the MST
d) It can be implemented using the Fibonacci heap

. Which is the correct technique for finding a maximum matching in a graph?


a) BFS traversal
b) DFS traversal
c) Shortest path traversal
d) Heap order traversal

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|)

3. Floyd Warshall Algorithm can be used for finding _____________


a) Transitive closure
b) Minimum spanning tree
c) Topological sort
d) Single source shortest path

4. Bellmann ford algorithm provides solution for ____________ problems.


a) Network flow
b) Single source shortest path
c) All pair shortest path
d) Sorting

6. Dijkstra’s Algorithm is used to solve _____________ problems.


a) Single source shortest path
b) All pair shortest path
c) Sorting
d) Network flow

7. What approach is being followed in Floyd Warshall Algorithm?


a) Linear Programming
b) Backtracking
c) Greedy technique
d) Dynamic Programming

8. Which of the following is not an application of Breadth First Search?


a) Path Finding
b) Finding bipartiteness of a graph
c) GPS navigation system
d) Finding shortest path between two nodes

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

. Dijkstra’s Algorithm is used to solve _____________ problems.


a) All pair shortest path
b) Single source shortest path
c) Network flow
d) Sorting

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

3. What is the time complexity of Dijikstra’s algorithm?


a) O(N)
b) O(N3)
c) O(N2)
d) O(logN)

4. Dijkstra’s Algorithm cannot be applied on ______________


a) Directed and weighted graphs
b) Graphs having negative weight function
c) Unweighted graphs
d) Undirected and unweighted graphs

6. How many priority queue operations are involved in Dijkstra’s Algorithm?


a) 1
b) 3
c) 2
d) 4

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

2. Bellmann ford algorithm provides solution for ____________ problems.


a) All pair shortest path
b) Sorting
c) Network flow
d) Single source shortest path

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

5. What is the running time of Bellmann Ford Algorithm?


a) O(V)
b) O(V2)
c) O(ElogV)
d) O(VE)

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

7. Dijikstra’s Algorithm is more efficient than Bellmann Ford Algorithm.


a) True
b) False

36
9. What is the basic principle behind Bellmann Ford Algorithm?
a) Interpolation
b) Extrapolation
c) Regression
d) Relaxation

10. Bellmann Ford Algorithm can be applied for _____________


a) Undirected and weighted graphs
b) Undirected and unweighted graphs
c) Directed and weighted graphs
d) All directed graphs

11. Bellmann Ford algorithm was first proposed by ________


a) Richard Bellmann
b) Alfonso Shimbe
c) Lester Ford Jr
d) Edward F. Moore

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

15. A graph is said to have a negative weight cycle when?


a) The graph has 1 negative weighted edge
b) The graph has a cycle
c) The total weight of the graph is negative
d) The graph has 1 or more negative weighted edges

Floyd Warshall’s Algorithm is used for solving ____________


a) All pair shortest path problems
b) Single Source shortest path problems
c) Network flow problems
d) Sorting problems

2. Floyd Warshall’s Algorithm can be applied on __________


a) Undirected and unweighted graphs
b) Undirected graphs
c) Directed graphs
d) Acyclic graphs

3. What is the running time of the Floyd Warshall Algorithm?


a) Big-oh(V)
b) Theta(V2)
c) Big-Oh(VE)
d) Theta(V3)

4. What approach is being followed in Floyd Warshall Algorithm?


a) Greedy technique
b) Dynamic Programming
c) Linear Programming
d) Backtracking

5. Floyd Warshall Algorithm can be used for finding _____________


a) Single source shortest path
b) Topological sort
c) Minimum spanning tree

38
d) Transitive closure

6. What procedure is being followed in Floyd Warshall Algorithm?


a) Top down
b) Bottom up
c) Big bang
d) Sandwich

7. Floyd- Warshall algorithm was proposed by ____________


a) Robert Floyd and Stephen Warshall
b) Stephen Floyd and Robert Warshall
c) Bernad Floyd and Robert Warshall
d) Robert Floyd and Bernad Warshall

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

2. Which of the following is NOT a rule of tower of hanoi puzzle?


a) No disk should be placed over a smaller disk
b) Disk can only be moved if it is the uppermost disk of the stack
c) No disk should be placed over a larger disk
d) Only one disk can be moved at a time

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

6. Space complexity of recursive solution of tower of hanoi puzzle is ________


a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)

8. Recursive solution of tower of hanoi problem is an example of which of the following


algorithm?
a) Dynamic programming
b) Backtracking
c) Greedy algorithm
d) Divide and conquer

9. Tower of hanoi problem can be solved iteratively.


a) True
b) False

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

1. Recursion is a method in which the solution of a problem depends on ____________


a) Larger instances of different problems
b) Larger instances of the same problem
c) Smaller instances of the same problem
d) Smaller instances of different problems

2. Which of the following problems can’t be solved using recursion?


a) Factorial of a number
b) Nth fibonacci number
c) Length of a string
d) Problems without base case

3. Recursion is similar to which of the following?


a) Switch Case
b) Loop
c) If-else
d) if elif else
View Answer
Answer: b
Explanation: Recursion is similar to a loop.
4. In recursion, the condition for which the function will stop calling itself is ____________
a) Best case
b) Worst case
c) Base case

41
d) There is no such condition

1. The first step in the naïve greedy algorithm is?


a) adding flows with higher values
b) reversing flow if required
c) analysing the zero flow
d) calculating the maximum flow using trial and error

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

3. Choose the correct statement from the following.


a) branch and bound is not suitable where a greedy algorithm is not applicable
b) branch and bound divides a problem into at least 2 new restricted sub problems
c) backtracking divides a problem into at least 2 new restricted sub problems
d) branch and bound is more efficient than backtracking

4. Dijkstra’s Algorithm is the prime example for ___________


a) Dynamic programming
b) Back tracking
c) Branch and bound
d) Greedy algorithm

5. Bellmann Ford Algorithm is an example for ____________


a) Linear Programming
b) Greedy Algorithms
c) Dynamic Programming
d) Branch and Bound

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

8. Which of the following is false about the Kruskal’s algorithm?


a) It constructs MST by selecting edges in increasing order of their weights
b) It is a greedy algorithm
c) It uses union-find data structure

42
d) It can accept cycles in the MST

1. Fractional knapsack problem is also known as __________


a) 0/1 knapsack problem
b) Continuous knapsack problem
c) Divisible knapsack problem
d) Non continuous knapsack problem

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

3. What is the objective of the knapsack problem?


a) To get maximum total value in the knapsack
b) To get minimum total value in the knapsack
c) To get maximum weight in the knapsack
d) To get minimum weight in the knapsack

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

5. Time complexity of fractional knapsack problem is ____________


a) O(n log n)
b) O(n)
c) O(n2)
d) O(nW)

6. Fractional knapsack problem can be solved in time O(n).


a) True
b) False

7. Given items as {value,weight} pairs {{40,20},{30,10},{20,5}}. The capacity of knapsack=20. Find


the maximum value output assuming items to be divisible.
a) 60
b) 80
c) 100
d) 40

8. The result of the fractional knapsack is greater than or equal to 0/1 knapsack.
a) True
b) False

9. The main time taking step in fractional knapsack problem is ___________


a) Breaking items into fraction

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

6. In Huffman coding, data in a tree always occur?


a) roots
b) leaves
c) left sub trees

44
d) right sub trees

. Which of the following is/are property/properties of a dynamic programming problem?


a) Optimal substructure
b) Overlapping subproblems
c) Greedy approach
d) Both optimal substructure and overlapping subproblems
.
2. If an optimal solution can be created for a problem by constructing optimal solutions for its
subproblems, the problem possesses ____________ property.
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy

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

4. If a problem can be solved by combining optimal solutions to non-overlapping problems, the


strategy is called _____________
a) Dynamic programming
b) Greedy
c) Divide and conquer
d) Recursion

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

8. When a top-down approach of dynamic programming is applied to a problem, it usually


_____________
a) Decreases both, the time complexity and the space complexity
b) Decreases the time complexity and increases the space complexity
c) Increases the time complexity and decreases the space complexity

45
d) Increases both, the time complexity and the space complexity

9. Which of the following problems is NOT solved using dynamic programming?


a) 0/1 knapsack problem
b) Matrix chain multiplication problem
c) Edit distance problem
d) Fractional knapsack problem

10. Which of the following problems should be solved using dynamic programming?
a) Mergesort
b) Binary search
c) Longest common subsequence
d) Quicksort

46

You might also like