Data Structures and Algorithms - Performance Analysis of Algorithms and Recurrences

Avatto > > UGC NET COMPUTER SCIENCE > > PRACTICE QUESTIONS > > Data Structures and Algorithms > > Performance Analysis of Algorithms and Recurrences

111. Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n(≥ 2) numbers? In the recurrence equations given in the options below, c is a constant.

  • Option : B
  • Explanation :
    The recurrence equation is
    T(n) = T(n – 1) + T(1) + cn
    In quick sort, worst case divide the list into two list with 1 and (n – 1) elements each time.
Cancel reply
Cancel reply

112. Suppose you are provided with the following function declaration in the C programming language.
int partition (int a[ ], int n);
The function treats the first element of a[ ] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part. The following partially given function in the C programming language is used to find the kth smallest element in an array a[ ] of size n using the partition function. We assume k < n.

  • Option : A
  • Explanation :
    When we put (a, left–End, K) and (a+ left – end + 1, n– left – end –1, k– left–end –1)at the place of fill in the blank algorithm work for partition.
Cancel reply
Cancel reply

114. Merge sort uses

  • Option : A
  • Explanation :
    If we take example, 40, 30, 10, 12, 85, 48, 9, 16
    Next step : 30, 40, 10, 12, 35, 48, 9, 16
    Next step : 10, 12, 30, 40, 9, 16, 35, 48
Cancel reply
Cancel reply

115. What would be the worst case time complexity of the insertion sort algorithm, if the inputs are restricted to permutations of l...n with at most n inversions?

  • Option : D
  • Explanation :
    If array of size n with n inversion then complexity of insertion sort is Q (n)
    Let us take an example.
    (6 1 2 3 5 6 4)
    total no. of comparision require to sort above array is 2 (n–1) = 2* 5 = 10
    so complexity is Q (n).
Cancel reply
Cancel reply