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

91. Suppose P, Q, R, S, T are sorted sequences having lengths 20,24,30,35,50 respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is __________.

  • Option : A
  • Explanation :
    20, 24, 30, 35, 50
    Step 1 : We take

    Comparisons = (20 + 24 – 1) Max = 43
    Step 2 :

    Total comparison = 43 + (65 – 44) = 64
    Step 3 :

    Total comparison = 64 + 19 = 83
    Step 4 :

    Total comparison = 93 + 65 = 158
    = 158 + 93 + 64 + 43 = 358
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


92. Give the correct matching for the following pairs:

List-IList-II
A.O(logn)P.Selection
B.O(n)Q.Insertion sort
C.O(n log n)R.Binary search
D.O(n2)S.Merge sort
Codes:
(a) A – R B – P C – Q D – S
(b) A – R B – P C – S D – Q
(c) A – P B – R C – S D – Q
(d) A – P B – S C – R D – Q

  • Option : D
  • Explanation :
    Selection sort = O (n2)
    Insertion sort = O (n2) or (O(n) in best case)
    Binary Search = O (logn)
    Merge Sort = O (n logn)
    None of the options is true
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


93. Suppose we want to arrange the n numbers stored in an array such that all negative values occur before all positive ones. Minimum number of exchanges required in the worst case is

  • Option : D
  • Explanation :
    When we have ‘n’ numbers stored in an array, we have to swap all positive number with negative number so in worst case positive numbers will be n/2,
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


94. If T1 = O(1), give the correct matching for the following pairs:

  • Option : D
  • Explanation :
    T(n) = T(n–1)+n ⇒ O(n2)
    T(n) = T(n/2) + n ⇒ O(n)
    T(n) = T(n/2) + n logn ⇒ O(n logn)
    T(n) = T(n–1) + logn ⇒ O(log2n)
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


95. If all permutations are equally likely, what is the expected number of inversions in a randomly chosen permutation of 1...n?

  • Option : B
  • Explanation :
    There are n(n-1)/2 pairs. So average inversions are
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *