May 20, 20223 min
Updated: Oct 15, 2022
Algorithms determine whether or not a you have understood how the code works. Conceptualising algorithms prior to an interview can not only acquaint you with them, but will also give you confidence in conveying the solution to the interviewee. Follow the blog to master top algorithm placement questions and answers.
Back tracking
Greedy approach
Dynamic programming
Brute force
Answer B
Explanation:
The above problem can be solved by the algorithm i.e. Container loading problem which is a type of greedy approach.
int sum(int A[], int n)
{
int sum = 0, i;
for(i = 0; i< n; i++)
sum = sum + A[i];
return sum;
}
n+8
2n+16
2n+8
n^2
Answer C
Explanation:
'n*2' bytes of memory to store array variable 'a[]'. 2 bytes of memory for integer parameter 'n'
4 bytes of memory for local integer variables 'sum' and 'i‘ (2 bytes each) 2 bytes of memory for return value. That means, totally it requires '2n+8' bytes of memory to complete its execution. Here, the amount of memory depends on the input value of 'n'.
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
O(n^2)
O(n)
O(3n+2)
O(n^3)
Answer B
Explanation:
Frequency Count: 3n+2
Time Complexity is O(n) (Note: Ignore the constants value)
O(n^n)
O(n)
O(nlogn)
O(n^3)
Answer A
Explanation:
For any number of loops present in nested form, the time complexity is n raise to the power of maximum no of nested loops present in a program.
Huffman coding may become lossy in some cases
Huffman Codes may not be optimal lossless codes in some cases
In Huffman coding, no code is prefix of any other code.
All of the above
Answer C
Explanation: Huffman coding is a lossless data compression algorithm. The codes assigned to input character are prefix codes, means the codes are assigned in such a way that the code assigned to one character is not prefix of code assigned to any other character. This is how Huffman Coding makes sure that there is no ambiguity when decoding.
Backtracking
Brute force
Huff man coding
Activity selection
Answer B
Explanation:
Brute force technique guarantees 100 % accurate results. The technique is however avoided as it is not an efficient algorithm
O(n)
O(1)
O(n^2)
O(logn)
Answer A
Explanation:
The worst case scenario can be that the element is present at the end or not present. In both situations we have to iterate through the entire array. If the size of the array in n then we will have N checks, so time complexity is n.
Dijkstra’s algorithm
Multi stage graph
Floyd-War shall algorithm
Knapsack
Answer. B
Explanation:
Multi multi-stage graph is a dynamic algorithm which can be used as a greedy approach does not guarantee an optimal solution.
T(n) = 8T(n/2) + n^2
T(n) = 7T(n/2) + n^2
T(n) = 8T(n/2) + n^3
T(n) = 8T(n) + n2
Answer B
Explanation:
Binary heap
Quick sort
Merge sort
Radix sort
Answer: A
Explanation:
Insertion sort is similar to that of a binary heap algorithm because of the use of temporary variable to swap.
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 with detailed explanations to ensure the best placement preparation.