1.
A Stack follows the principle of
Correct Answer
A. LIFO
Explanation
A stack follows the principle of LIFO (Last In, First Out), which means that the last element added to the stack will be the first one to be removed. This is similar to a stack of plates, where the last plate placed on top is the first one to be taken off. In a stack data structure, elements are added and removed from one end only, called the top. When a new element is added, it is pushed onto the top of the stack, and when an element is removed, it is popped off from the top.
2.
Which one is the Application of Stack
Correct Answer
E. All of the Above
Explanation
All of the given options are applications of a stack.
- Polished notations, such as infix, postfix, and prefix, can be evaluated using stacks to store operators and operands.
- Storing return addresses of function calls is a common use of a stack in computer programming. When a function is called, the address of the instruction following the function call is stored on the stack, allowing the program to return to that point after the function execution is complete.
- Reversing a string can be done using a stack by pushing each character onto the stack and then popping them off in reverse order.
- Recursion, which is a programming technique where a function calls itself, often relies on a stack to keep track of the function calls and their return addresses.
Therefore, all of the given options are valid applications of a stack.
3.
Find the value of the postfix expression :- ABCD ^*- (IF A = 150, B=10, C=2 D=3)
Correct Answer
A. 70
Explanation
The given postfix expression is "ABCD ^*-". In this expression, "^" represents exponentiation, "*" represents multiplication, and "-" represents subtraction. The values of A, B, C, and D are given as A=150, B=10, C=2, and D=3.
First, the exponentiation operation is performed, which is A^B = 150^10 = 1500000000000000000000.
Then, the multiplication operation is performed, which is (1500000000000000000000) * C = 1500000000000000000000 * 2 = 3000000000000000000000.
Finally, the subtraction operation is performed, which is (3000000000000000000000) - D = 3000000000000000000000 - 3 = 2999999999999999999997.
Therefore, the value of the postfix expression is 2999999999999999999997, which is not one of the given answer choices. Hence, the correct answer cannot be determined from the given options.
4.
What is the advantage of linear search
Correct Answer
D. Does not needs a sorted array
Explanation
The advantage of linear search is that it does not require the array to be sorted. This means that it can be used on unsorted data, making it more flexible and versatile compared to other search algorithms that require a sorted array. Linear search sequentially checks each element in the array until a match is found, which allows it to work efficiently regardless of the order of the elements.
5.
What is the disadvantage of a binary search
Correct Answer
C. Needs a sorted array
Explanation
The disadvantage of a binary search is that it requires the array to be sorted. This means that if the array is not already sorted, it would need to be sorted first before performing the binary search. This extra step of sorting the array can be time-consuming and may require additional resources.
6.
Two main measures for the efficiency of an algorithm are
Correct Answer
C. Time and space
Explanation
The efficiency of an algorithm is typically measured by considering the amount of time it takes to execute and the amount of space it requires. Time refers to the execution time of the algorithm, which measures how long it takes for the algorithm to complete its task. Space refers to the memory space required by the algorithm, which measures how much memory the algorithm needs to store its data and variables. Therefore, the correct answer is "Time and space" as these two measures are commonly used to evaluate the efficiency of an algorithm.
7.
Which of the following case does not exist in complexity theory
Correct Answer
D. Null case
Explanation
The null case does not exist in complexity theory because it refers to a scenario where there are no inputs or operations to be analyzed. Complexity theory focuses on analyzing the performance of algorithms and the relationship between input size and computational resources required. In the null case, there is no input or operation to analyze, making it irrelevant in the context of complexity theory.
8.
The Average case occur in linear search algorithm
Correct Answer
A. When Item is somewhere in the middle of the array
Explanation
In linear search algorithm, the average case occurs when the item being searched for is somewhere in the middle of the array. This means that on average, the algorithm will need to iterate through half of the array elements before finding the desired item. The time complexity for the average case in linear search is O(n/2), which simplifies to O(n).
9.
Write the prefix notation of A + B * C / D
Correct Answer
C. +/*BCDA
Explanation
The given expression is "A + B * C / D". The prefix notation of this expression is "+ / * B C D A". In prefix notation, the operator is placed before its operands. Therefore, the correct answer is "+ / * B C D A".
10.
What is the correct sequence of data structures used in BFS and DFS?
Correct Answer
C. Queue,stack
Explanation
BFS (Breadth-First Search) and DFS (Depth-First Search) are graph traversal algorithms. In BFS, we explore all the vertices at the same level before moving to the next level. This can be efficiently implemented using a queue data structure, where we enqueue the vertices as we visit them. On the other hand, DFS explores a path until it reaches a dead end before backtracking. This can be implemented using a stack data structure, where we push the vertices onto the stack as we visit them. Therefore, the correct sequence of data structures used in BFS and DFS is queue, stack.