1.

What is the space complexity of pigeonhole sort (k=range of input)?(a) O(n*k)(b) O(n)(c) O(k)(d) O(n+k)I had been asked this question in an internship interview.My enquiry is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (d) O(n+k)

Best explanation: PIGEONHOLE sort algorithm requires two arrays. The FIRST one is REQUIRED to store the input elements so its size is n. The second one is the pigeonhole array and has a size equal to range k. OVERALL space complexity BECOMES O(n+k).



Discussion

No Comment Found

Related InterviewSolutions