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

56. Consider the following functions:
f(n) = 2n
g(n) = n!
h(n) = nlogn
which of the following statements about the asymptotic behaviour of f(n), g(n), and h(n) is true?

  • Option : D
  • Explanation : f(n) = 2n g(n) = n! ≅ nn h(n) = nlogn for larger value of n g(n) > f(n) > h(n) so we can conclude that f(n) = O(g(n)) or g(n) = Ω(f(n)) and h(n)= Of(n).
Cancel reply
Cancel reply

60. What is the number of swaps required to sort n elements using selection sort, in the worst case?

  • Option : A
  • Explanation :
    If there are n elements, then in worst case, total swaps will be (n-1) in selection sort. So the number of swaps is Θ(n).
    Alternately
    The selection sort is similar to bubble sort except it does not swap elements with every move. The sorting algorithm first finds the smallest element in the list and then puts it in to place in single swap. So n swap required for n elements.
Cancel reply
Cancel reply