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

29

Explanation

How will the array elements look like after second pass in insertion sort? 34, 8, 64, 51, 32, 21


First pass: i=1 (8,34,64,51,32,21)
Second Pass:i=2 (8, 34, 64, 51, 32, 21) no change because 64 is greater than 8 and 34

Question

30

Explanation

Write fundamental steps to solve an algorithm.


An algorithm is a sequence of unambiguous instructions for solving problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. Algorithmic steps are
1. Understand the problem
2. Decision making
3. Design an algorithm
4. Proving correctness of an algorithm
5. Analyze the algorithm
6. Coding and implementation of an algorithm

Question

31

Explanation

Implement bubble-sort.

for(int j=arr.length-1; j>=0; j--)
{
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}

Question

32

Explanation

How do you implement a selection sort algorithm?

int min;
for(int j=0; j<arr.length-1; j++)
{
min = j;
for(int k=j+1; k<=arr.length-1; k++)
{
if(arr[k] < arr[min])
min = k;
}
int temp = arr[min];
arr[min] = arr[j];
arr[j] = temp;
}

bottom of page