1.
An Array is what kind of data structure.
Correct Answer
A. Linear
Explanation
An array is a linear data structure because it stores elements in a contiguous memory location. Each element in the array can be accessed using its index value, which represents its position in the array. The elements are stored in a sequential manner, allowing for efficient traversal and access. Therefore, the correct answer is "Linear."
2.
While inserting an item in an array of integers which loop is right, where pos is the pos at which insertion is to be made(assume array starts from 1 and N is the max no. of items in the array.)
Correct Answer
D. For(i=N; i>=pos;i--) { A[i+1] = A[i] }
Explanation
The correct answer is "for(i=N; i>=pos;i--) { A[i+1] = A[i] }". This loop starts from the last element of the array and moves towards the position where the insertion is to be made. It shifts each element one position to the right, creating space for the new element to be inserted at the desired position.
3.
To delete an item from an array which loop is correct, where p is the position of deletion( assume array starts from 1 and N is the max no. of items in the array.)
Correct Answer
B. For(i=pos;i
Explanation
The correct loop to delete an item from an array at position p is "for(i=pos;i
4.
What is the contents of the array after the execution of the following program :-int a[] = {10,30, 20, 10, 30, 40};for(i=1;i<=6;i++) { for(j=i+1 ; j<= 6; j++) { if(a[i] == a[j]) { a[j] = 0; }}
Correct Answer
D. 10,30, 20, 0, 0, 40
Explanation
The program iterates through the array and checks for duplicate elements. If a duplicate element is found, it sets the value of that element to 0. In this case, the initial array is {10, 30, 20, 10, 30, 40}. After executing the program, the duplicate elements 10 and 30 are replaced with 0. Therefore, the resulting array is {10, 30, 20, 0, 0, 40}.
5.
A Stack follows the principle of
Correct Answer
A. LIFO
Explanation
A stack follows the principle of LIFO, which stands for "Last In, First Out." This means that the last element added to the stack will be the first one to be removed. It is similar to a stack of plates, where you can only remove the topmost plate. In a stack data structure, items are added and removed from the same end, known as the top of the stack. This principle allows for efficient insertion and deletion operations, making it useful in various applications like function calls, expression evaluation, and backtracking algorithms.
6.
With every push in the stack the top
Correct Answer
B. Increments by one
Explanation
In a stack, the "top" refers to the position of the most recently added element. When a new element is pushed onto the stack, it becomes the new top element, causing the top position to increment by one. Therefore, the correct answer is "increments by one".
7.
Identify the UnderFlow condition for a Stack
Correct Answer
A. If( top < 1)
Explanation
The correct answer is "if( top < 1)". This condition checks if the top of the stack is less than 1, which indicates that the stack is empty or underflowing. In a stack, the top represents the index of the last element, so if it is less than 1, it means there are no elements in the stack.
8.
Identify the OverFlow condition for a Queue
Correct Answer
A. If(REAR > N)
Explanation
The correct answer is "if(REAR > N)". This condition checks if the rear of the queue is greater than the maximum size of the queue (N). If this condition is true, it indicates that the queue has reached its maximum capacity and cannot accept any more elements. This is known as an overflow condition in a queue.
9.
To Delete an item from a Queue identify the correct set of statements :-
Correct Answer
B. Item = Q[FRONT];
FRONT++;
Explanation
The correct set of statements to delete an item from a Queue is "item = Q[FRONT]; FRONT++;" This is because in a Queue, the element that has been in the queue for the longest time is always at the front. So, to delete an item, we need to first assign the value of the item at the front of the queue to the variable "item" and then increment the value of the "FRONT" pointer to move it to the next element in the queue.
10.
To Insert an item from a stack identify the correct set of statements :-
Correct Answer
A.
top++;
S[top] = Item;
Explanation
The correct set of statements to insert an item from a stack is "top++; S[top] = Item;". This set of statements first increments the top pointer to create space for the new item in the stack, and then assigns the item to the position pointed by the top pointer in the stack array.
11.
Which Data structure is best suited for the UNDO operation in Windows
Correct Answer
A. Stack
Explanation
The UNDO operation in Windows requires a data structure that follows the Last-In-First-Out (LIFO) principle, where the most recently performed action is undone first. A stack is the best-suited data structure for this purpose as it allows elements to be added and removed from only one end, the top. When an action needs to be undone, it can be easily popped off the stack, reversing the order of operations. Therefore, a stack is the most appropriate data structure for implementing the UNDO operation in Windows.
12.
Which data structure is best suited to print the documents in the printer
Correct Answer
B. Queues
Explanation
Queues are the best suited data structure for printing documents in a printer because they follow the First-In-First-Out (FIFO) principle. When multiple documents are sent to the printer, the documents are printed in the order they were received, just like how people stand in a queue and are served in the same order. This ensures that the documents are printed in a fair and orderly manner, without any document being skipped or delayed. Stacks, on the other hand, follow the Last-In-First-Out (LIFO) principle, which is not suitable for printing documents in the desired order. Arrays can be used, but queues provide a more efficient and logical approach for this specific task.
13.
Which one is the Application of Stack
Correct Answer
E. All of the Above
Explanation
The application of a stack includes all of the above options. Polished notations, such as postfix or prefix notations, can be evaluated using a stack. Storing return addresses of function calls is another common use of a stack in programming languages. Reversing a string can be achieved by pushing each character onto a stack and then popping them off in reverse order. Recursion, which involves calling a function within itself, can also be implemented using a stack to keep track of function calls. Therefore, all of the given options are valid applications of a stack.
14.
Write the postfix notation of A + B * C / D
Correct Answer
C. ABC*D/+
Explanation
The given expression is A + B * C / D. In postfix notation, the operators are placed after their operands. To convert the expression to postfix, we start by placing A and B as operands. Then, we encounter the multiplication operator * and place it after B. Next, we encounter the division operator / and place it after C. Finally, we encounter the addition operator + and place it after the previous two operands and operator. Hence, the postfix notation of A + B * C / D is ABC*D/+.
15.
Write the prefix notation of A + B * C / D
Correct Answer
C. +/*BCDA
Explanation
The given prefix notation is "+/*BCDA". This notation represents the expression A + (B * (C / D)). In prefix notation, the operator comes before the operands. Here, the "+" operator is applied to the result of the "*" operator, which in turn is applied to the result of the "/" operator. The operands A, B, C, and D represent variables or values.
16.
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 "ABCD ^*- " can be evaluated as follows:
1. The symbol "^" represents the exponentiation operation. So, "C ^ D" means C raised to the power of D, which is equal to 2^3 = 8.
2. The symbol "*" represents the multiplication operation. So, "A * B" means A multiplied by B, which is equal to 150 * 10 = 1500.
3. The symbol "-" represents the subtraction operation. So, "A - B" means A minus B, which is equal to 1500 - 8 = 1492.
Therefore, the value of the postfix expression is 1492.
17.
Find the postfix expression of the following :- A OR B AND !C
Correct Answer
C. ABC! AND OR
Explanation
The postfix expression of "A OR B AND !C" is "ABC! AND OR". In postfix notation, the operators are placed after their operands. Here, the expression "!C" is evaluated first because of the "!" operator. Then, "B AND !C" is evaluated because of the "AND" operator. Finally, "A OR (B AND !C)" is evaluated because of the "OR" operator.
18.
What is the advantage of a linear search?
Correct Answer
D. Does not needs a sorted array
Explanation
The advantage of a linear search is that it does not require the array to be sorted. This means that the elements can be in any order and the linear search will still be able to find the desired element. This makes it a flexible and versatile search algorithm that can be used in various scenarios.
19.
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 a sorted array. This means that before performing the search, the array must be sorted, which can be time-consuming and may require additional space. If the array is not already sorted, it would need to be sorted first, which adds an extra step and potentially increases the overall time complexity of the search algorithm.
20.
If the search item lies in the upper half in case of binary search which is the correct set of statements.
Correct Answer
D. Bot = mid - 1;
Explanation
In binary search, the search item lies in the upper half when the value at the middle index is less than the search item. In this case, the correct set of statements is "bot = mid - 1;". This statement updates the lower bound of the search range to be one less than the middle index, effectively narrowing down the search range to the upper half.