0% found this document useful (0 votes)
10 views6 pages

Quiz 2

Uploaded by

Shazia Siddiqui
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)
10 views6 pages

Quiz 2

Uploaded by

Shazia Siddiqui
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/ 6

ENROLLMENT NO*

NAME *

Q1 For linear search, the "best case scenario" (when the algorithm
completes with the fewest number of steps) is when:*
The first item equals the key
The middle item equals the key
The data does not contain the key
The last item equals the key

Q2 The number of swappings needed to sort the numbers 8, 22, 7,


9, 31, 19, 5, 13 in ascending order, using bubble sort is*
10
9
13
14

Q3 As part of the maintenance work, you are entrusted with the


work of rearranging the library books in a shelf in proper order, at
the end of each day. The ideal choice will be*
Bubble sort
Selection sort
Insertion sort
merge sort

Q4 Select the appropriate code that performs selection sort.*


int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=
int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k
int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=<
Option 4

Q5 What is the best case complexity of selection sort?*


O(nlogn)
O(logn)
O(n)
O(n2)

Q6 Which of the following sorting algorithm is of divide-and-


conquer type?*
Bubble sort
Insertion sort
Quick Sort
All of the above
Q7 The running time of the following sorting algorithm depends on
whether the partitioning is balanced or unbalanced*
Insertion sort
Selection sort
Quick sort
merge sort

Q8 Pivot element is used in ___________ sort*


heap sort
merge sort
insertion sort
selection sort

Q9 What is the worst case time complexity of a quick sort


algorithm?*
O(N)
O(N log N)
O(N^2 )
O(log N)

Q10 Choose the correct code for merge sort.*


void merge_sort(int arr[], int left, int right) { if (left > right) { int mid = (right-left)/2; merge_sort(arr,
left, mid); merge_sort(arr, mid+1, right); merge(arr, left, mid, right); //function to merge sorted
arrays } }
void merge_sort(int arr[], int left, int right) { if (left < right) { int mid = left+(right-left)/2;
merge_sort(arr, left, mid); merge_sort(arr, mid+1, right); merge(arr, left, mid, right); //function to
merge sorted arrays } }
void merge_sort(int arr[], int left, int right) { if (left < right) { int mid = left+(right-left)/2; merge(arr,
left, mid, right); //function to merge sorted arrays merge_sort(arr, left, mid); merge_sort(arr, mid+1,
right); } }
Option 4

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


True
False

Q12 Which of the following is not a common application of a hash


table?*
Dictionary
Spell checker
Cache
Binary search tree

Q13 Which of the following is False about the merge sort


algorithm?*
It is a comparison sorting algorithm.
The unsorted array is divided into sub lists, which are, in turn, divided into more sub lists.
The unsorted array is divided into sublists. Each sublist is then sorted recursively by re-applying the
algorithm.
All of the above statements are true.

Q14 An array has indices ranging from x to x+n; the merge sort
would be applied from c to x+n, where c*
Is the remainder of x/2, if x is an odd number
Is the non-integer part of x/2
Is the integer part of x/2
Is an integer chosen arbitrarily, so long that it is smaller than x+n

Q15 Which of the following sorting algorithm is of priority queue


sorting type?*
Bubble sort
Insertion sort
merge sort
selection sort

Q 16 What is the advantage of bubble sort over other sorting


techniques?*
It is faster
Consumes less memory
Detects whether the input is already sorted
All of the mentioned

Q 17 Given a dataset, we would like to sort the first k smallest (k is


much smaller than the size of the dataset) in ascending
order. Which of the following is the best algorithm to sort such
data?*
Insertion sort
Quick sort
selection sort
Bubble sort

Q18 How many passes (or "scans") will there be through a list
being sorted using a selection sort?*
Array_size*2
Array_size+1
Array_size-1
None of the above

Q19 Bubble sorting got its name from a Bubble gum company that
used it for the first time.*
True
False
Q20 Which one of the following is the first step in a selection sort
algorithm?*
The minimum value in the list is found.
The maximum value in the list is found.
Adjacent elements are swapped.
opposite elements are swapped.

Q21 What are the correct intermediate steps of the following data
set when it is being sorted with the bubble sort? 15,20,10,18*
15,10,20,18 -- 15,10,18,20 -- 10,15,18,20
10, 20,15,18 -- 10,15,20,18 -- 10,15,18,20
15,20,10,18 -- 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20
15,18,10,20 -- 10,18,15,20 -- 10,15,18,20 -- 10,15,18,20

Q22 What is the max number of comparisons that can take place
when a bubble sort is implemented? Assume there are n elements in
the array?*
(1/2)(n-1)
(1/2)n(n-1)
Option 3
None of the above
(1/4)n(n-1)

Q23 Which among the following sorting algorithm is the most


optimal one to sort a random linked list?*
merge sort
heap sort
quick sort
insertion sort

Q24 You have to sort a list L consisting of a sorted list followed by


a few ‘random’ elements. Which of the following sorting methods
would be especially suitable for such a task?*
merge sort
insertion sort
heap sort
selection sort

Q25 Binary search algorithm performs efficiently on*


linked list
array
both
none

Q26 A min heap is the tree structure where smallest element is


available at the*
leaf
intermediate parent
root
anywhere

Q27 Consider a situation where the data to be sorted is too big to


fit in memory, so most of it is on disk. Which of the following is the
best algorithm to sort such data?*
Insertion sort
Heap sort
Selection sort
All of the above

Q28 Heap sort is faster than Shell sort.*


True
False

Q29 What would be the worst case time complexity of the


insertion sort algorithm, if the inputs are restricted to permutation
of 1…..n with at most n inversion?

*
θ (n2)
θ (nlogn)
θ (n1.5)
θ (n)

Q30 Which of the following sorting algorithm has the running time
that is least dependent on the initial ordering of the input?*
Insertion sort
Quick sort
Merge sort
Selection sort

Submit

Clear form

You might also like