retagged by
1,243 views
1 votes
1 votes

What is the worst case time complexity to count pairs of numbers with difference ‘k’ from an input array of ‘n’ numbers 

  1. O(log n)
  1. O(n log n)
  1. O(n)^2
  1. O(n^2 log n)

The answer given was B but since worst case time is stated shouldn't the answer be C? I mean we can check all possible pairs in the worst case. Correct me if I am wrong? 

retagged by

1 Answer

0 votes
0 votes
you have to always mark worst case TC which will be O(n2)
Answer:

Related questions

0 votes
0 votes
0 answers
1
Deepalitrapti asked Sep 1, 2018
814 views
0 votes
0 votes
0 answers
2
Sajal Mallick asked Nov 27, 2023
171 views
As we have to select maximal set of “non overlapping” activities. So like job scheduling algo of greedy we can solve it. So according to that complexity must be O(n l...
0 votes
0 votes
1 answer
4
Ray Tomlinson asked Aug 9, 2023
424 views
How many times is the comparison $i >= n$ performed in the following program?int i = 200 n = 80; main() { while (i >= n) { i = i - 2 n = n + 1 } }