top of page
  • Facebook
  • Twitter
  • Instagram

Top Algorithms Interview Questions

Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important MCQ questions which are asked in most companies such as Infosys, TCS, Wipro, Accenture, etc. The placement handbooks also have detailed explanations for every question ensuring you revise all the questions with detailed answers and explanations.

Question

33

Explanation

What is worst case and best case time complexity of a heap sort algorithm?


The time complexity of heap sort is not affected in any case as it is independent of distribution of data. So its time complexity remains to be O(n log n) in both cases

Question

34

Explanation

What will be the output of the following code snippet?

void A_recursive_function()
{
A_recursive_function();
}
int main()
{
A_recursive_function();
return 0;
}

Every function call is stored in the stack memory. In this case, there is no terminating condition(base case). So, A_recursive_function() will be called continuously till the stack overflows and there is no more space to store the function calls. At this point of time, the program will stop abruptly.

Question

35

Explanation

What will be the output of the following code snippet?

void A_recursive_function(int n)
{
if(n == 0)
return;
printf("%d ",n);
A_recursive_function(n-1);
}
int main()
{
A_recursive_function(10);
return 0;
}

output: 10 9 8 7 6 5 4 3 2 1

Question

36

Explanation

Swap two numbers without using third variable using bitwise opeartor.

public static void main(String args[]){
int x = 30; int y = 60;
System.out.printf("Before swap 'x': %d, 'y': %d %n", x, y);
x = x ^ y;
y = x ^ y;
x = x ^ y;
System.out.printf("After swapping, 'x': %d, 'y': %d %n", x, y); }

bottom of page