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

37

Explanation

Explain heap sort algorithim.




Heap sort is used to sort binary heap data structure.
Steps:
1. Build max heap.
2. The largest item is stored at the root of the heap. Replace it with the last item of the heap followed by reducing the size of heap by 1.
3. Finally, heapify the root of the tree.
4. Repeat step 2 and step 3 while size of heap is greater than 1.

Heapify: heapify is the process of converting a binary tree into a Heap data structure.
It is the operation in which we reorder the tree based on the heap property.

Question

38

Explanation

Write a c program to check a number is palindrom or not.

#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
return 0;
}

Question

39

Explanation

Write c program to check two string are anagrams or not.

#include <stdio.h>
int check_anagram(char [], char []);

int main()
{
char string1[10000], string2[10000];

printf("Enter two strings\n");
gets(string1);
gets(string2);

if (check_anagram(string1, string2))
printf("The strings are anagrams.\n");
else
printf("The strings aren't anagrams.\n");

return 0;
}

int check_anagram(char a[], char b[])
{
int first[26] = {0}, second[26] = {0}, c=0;

while (a[c] != '\0') {
first[a[c]-'a']++;
c++;
}

c = 0;

while (b[c] != '\0') {
second[b[c]-'a']++;
c++;
}

for (c = 0; c < 26; c++)
if (first[c] != second[c])
return 0;

return 1;
}

Question

40

Explanation

What will be the time complexity of A()?

int A(int n)
{
int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count += 1;
return count;
}

For a input integer n, the innermost statement of A() is executed following times. n + n/2 + n/4 + ... 1 So time complexity T(n) can be written as T(n) = O(n + n/2 + n/4 + ... 1) = O(n) The value of count is also n + n/2 + n/4 + .. + 1

bottom of page