Question 10146 – Time-Complexity
November 14, 2023Question 9893 – Time-Complexity
November 14, 2023Question 9890 – Time-Complexity
Suppose we want to arrange the n numbers stored in any array such that all negative values occur before all positive ones. Minimum number of exchanges required in the worst case is
Correct Answer: D
Question 6 Explanation:
Minimum no. of exchanges required in worst case will be when 1st half will contain all +ve nos and 2nd half will contain all -ve nos.
Now we will swap 1st no. with nth no. and then 2nd no. with (n-1)th no. and then 3rd no. with (n-2)th and so on. Like this we will have to do n/2 swaps in worst case.
Now we will swap 1st no. with nth no. and then 2nd no. with (n-1)th no. and then 3rd no. with (n-2)th and so on. Like this we will have to do n/2 swaps in worst case.
n – 1
n
n + 1
None of the above
Subscribe
Login
0 Comments