Documente Academic
Documente Profesional
Documente Cultură
Q1.Which of the following is/are true about the following sorting algorithms
a)Insertion an element in to min heap or max heap which already contains ‘n’
elements required O(logn)times in worst case.
b)If the array is already sorted or almost sorted in the insertion sort will give best
case of O(n).But quick sort will give worst case of O(n^2).
c)If the array size is very small then insertion sort is preferable but Merge sort is
not.
d)Bubble sort Contain (n-1)passes and every pass contain max n comparisons so it
will have O(n^2) in all Best ,average and worst case.
e)None.
Q2. Suppose we are sorting an array of eight integers using quicksort, and we have
just finished the first partitioning with the array looking like this: 2, 5, 1, 7, 9, 12, 11,
10 Which statement is correct?
d)Neither 7 nor 9.
Q3(a)What are the correct intermediate steps of the following data set when it is
being sorted with the Selection sort? Given:15,20,10,18
a)True
b)False
c)Depends on Elements
d)None of the above
Q4.Which sorting algorithm will take least time when all elements of input array are
identical? Consider typical implementations of sorting algorithms.
a)Insertion Sort
b)Heap Sort
c)Merge Sort
d)Selection Sort
a)Merge sort is based on Divide and conquer method. It takes the list to be
sorted and divide it in half to create two unsorted lists.
Q6.The worst case running times of Insertion sort, Merge sort and Quick sort,
respectively, are:
b)O(n^2),O(n^2),O(nlog n)
d)There is no best case for bubble sort it always take O(n*n) time.
Q8.What are the correct intermediate steps of the following data set when it
is being sorted with the Insertion sort? 15,20,10,18
# include <stdio.h>
int main( )
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0' ;
printf ("%s", s1);
}
a)12
b)120400
c)1204
d)1034
Q9(b) What will be output of the program if characters ‘a’,’b’and ‘c’ enter as input
#include<stdio.h>
int main() {
fun();
void fun() {
char c;
if((c= getchar())!=’\n’)
fun();
printf(“%c”,c);}
97,25,15,42,16,5,7,0,8,66,21,3,12,40.
b)What will be the tree after deletion of root node and insertion of node 56.
First deletion happens then insertion build the min heap after performing
these operations.