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

101. Which one the following in place sorting algorithms needs the minimum number of swaps?

  • Option : C
  • Explanation :
    Minimum no of swap for selection sort is O when array is already sorted and maximum swap is Q(n).
Cancel reply
Cancel reply

102. If we use Radix Sort to sort n integers in the range (nk/12, nk], for some k > 0 which is independent of n, the time taken would be

  • Option : C
  • Explanation :
    Time complexity of radix sort is = O(nd)
    Where n = keys, d = maximum digit in keys.
    = d = log (nk)
    O(nd) = O(n * k logn)
    = k × O (nlogn)
    = O(nlogn)
Cancel reply
Cancel reply

103. The number of elements that can be stored in Θ(log n) time using heap sort is

  • Option : C
  • Explanation :
    Let the number of element is “K”, they can be sorted in Θ(k log k) time.
    We try the options in decreasing order of complexity since, we need a tight band i.e. Θ

    So if K ∈ Θ(log n) time required for loop sort is.
    Θ(k log k) i.e.
    Θ(log n x log log n), But this is not in Θ(log n)
Cancel reply
Cancel reply

104. Let P be a quicksort program to sort numbers in ascending order. Let t1 and t2 be the time taken by the program for the inputs [1 2 3 4] and [5 4 3 2 1], respectively. Which of the following holds?

  • Option : A
  • Explanation :
    It input is in either ascending order or in descending order both are worst case of quick sort Algorithms.
Cancel reply
Cancel reply