Midterm 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

17. The prefix form of an infix expression p + q - r * t is? a) + pq - *rt b) - +pqr * t c) - +pq * rt d) - + * pqrt

Answer: - +pq * rt Show your work Explanation: Applying the prefix expression evaluation.

11. What data structure would you mostly likely see in a non-recursive implementation of a recursive algorithm? a) Linked List b) Stack c) Queue d) Tree

Answer: Stack

34. What is the term for inserting into a full queue known as? a) overflow b) underflow c) null pointer exception d) all of the mentioned

Answer: overflow Explanation: Just as stack, inserting into a full queue is termed overflow.

32. Which of the following is not the type of queue? a) Ordinary queue b) Single ended queue c) Circular queue d) Priority queue

Answer: Single ended queue Explanation: Queue always has two ends.

39. What does 'stack underflow' refer to? a) accessing item from an undefined stack b) adding items to a full stack c) removing items from an empty stack d) index out of bounds exception

Answer: removing items from an empty stack Explanation: Removing items from an empty stack is termed as stack underflow.

5. Entries in a stack are "ordered". What is the meaning of this statement? a) A collection of stacks is sortable. b) Stack entries may be compared with the '<' operation. c) The entries are stored in a linked list. d) There is a Sequential entry that is one by one.

Answer: There is a Sequential entry that is one by one.

86. Two main measures for the efficiency of an algorithm are A. Processor and memory B. Complexity and capacity C. Time and space D. Data and space

Answer: Time and space

87. The operation of processing each element in the list is known as A. Sorting B. Merging C. Inserting D. Traversal

Answer: Traversal

80. Heap exhibits the property of a binary tree? a) True b) False

Answer: True Explanation: Yes, Because the leaf nodes are present at height h or h-1, which is a property of complete binary tree.

38. Which of the following real-world scenarios would you associate with a stack data structure? a) piling up of chairs one above the other b) people standing in a line to be serviced at a counter c) offer services based on the priority of the customer d) all of the mentioned

Answer: piling up of chairs one above the other Explanation: Stack follows Last In First Out(LIFO) policy. Piling up of chairs one above the other is based on LIFO, people standing in a line is a queue and if the service is based on priority, then it can be associated with a priority queue.

90. Special node in tree structure which has many child nodes and one parent node is called a. descendant nodes b. root node c. leaf node d. search node

Answer: root node

79. In a max-heap, element with the greatest key is always in the which node? a) Leaf node b) First node of left sub tree c) root node d) First node of right sub tree

Answer: root node Explanation: This is one of the property of max-heap that root node must have key greater than its children.

31. Queues serve major role in a) Simulation of recursion b) Simulation of arbitrary linked list c) Simulation of limited resource allocation d) All of the mentioned

Answer: Simulation of limited resource allocation Explanation: Rest all are implemented using other data structures.

20. Convert the following infix expressions into its equivalent postfix expressions (A + B ⋀D)/(E - F)+G a) (A B D ⋀ + E F - / G +) b) (A B D +⋀ E F - / G +) c) (A B D ⋀ + E F/- G +) d) None of the mentioned

Answer: (A B D ⋀ + E F - / G +) Explanation: Applying the postfix expression evaluation.

56. In a full binary tree if number of internal nodes is I, then number of leaves L are? a) L = 2I b) L = I + 1 c) L = I - 1 d) L = 2I - 1

Answer: L = I + 1 Explanation: Trace with respect to the diagram.

88. Linked lists are best suited A. For relatively permanent collections of data B. for the size of the structure and the data in the structure are constantly changing C. For both of above situation D. For none of above situation

Answer: for the size of the structure and the data in the structure are constantly changing

89. In tree structure diagrams, non-leaf node is called a. search node b. descendant nodes c. external node d. internal node

Answer: internal node

7. What is the value of the postfix expression 6 3 2 4 + - *: a) Something between -5 and -15 b) Something between 5 and -5 c) Something between 5 and 15 d) Something between 15 and 100

Answer: none of the above answer Explanation: On solving the postfix expression the answer comes out to -18. Show your work

42. 'Array implementation of Stack is not dynamic', which of the following statements supports this argument? a) space allocation for array is fixed and cannot be changed during run-time b) user unable to give the input for stack operations c) a runtime exception halts execution d) all of the mentioned

Answer: space allocation for array is fixed and cannot be changed during run-time Explanation: You cannot modify the size of an array once the memory has been allocated, adding fewer elements than the array size would cause wastage of space, and adding more elements than the array size at run time would cause Stack Overflow.

84. Which of the following data structure is not linear data structure? A. Arrays B. Linked lists C. Both of above D. None of above

Answer:None of above

1. Process of inserting an element in stack is called ____________ a) Create b) Push c) Evaluation d) Pop

Answer: Push

26. A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a ? a) Queue b) Stack c) Tree d) Linked list

Answer: Queue

30. A normal queue, if implemented using an array of size MAX_SIZE, gets full when a) Rear = MAX_SIZE - 1 b) Front = (rear + 1)mod MAX_SIZE c) Front = rear + 1 d) Rear = front

Answer: Rear = MAX_SIZE - 1 Explanation: Condition for size of queue.

43. Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N). a) S[N-1]. b) S[N]. c) S[N-2]. d) S[N+1].

Answer: S[N-1]. Explanation: Array indexing start from 0, hence N-1 is the last index.

10. The data structure required to check whether an expression contains balanced parenthesis is? a) Stack b) Queue c) Array d) Tree

Answer: Stack

12. The process of accessing data stored in a serial access memory is similar to manipulating data on a ________ a) Heap b) Binary Tree c) Array d) Stack

Answer: Stack

14. Which data structure is needed to convert infix notation to postfix notation? a) Branch b) Tree c) Queue d) Stack

Answer: Stack

18. Which data structure is used for implementing recursion? a) Queue b) Stack c) Array d) List

Answer: Stack Explanation: Stacks are used for implementation of Recursion.

21. Which of the following statement(s) about stack data structure is/are NOT correct? a) Linked List are used for implementing Stacks b) Top of the Stack always contain the new node c) Stack is the FIFO data structure d) Null link is present in the last node at the bottom of the stack

Answer: Stack is the FIFO data structure Explanation: Stack follows LIFO.

3. In a stack, if a user tries to remove an element from empty stack it is called _________ a) Underflow b) Empty collection c) Overflow d) Garbage Collection

Answer: Underflow

67. Which of the following is not an application of priority queue? a) Huffman codes b) Interrupt handling in operating system c) Undo operation in text editors d) Bayesian spam filter

Answer: Undo operation in text editors Explanation: Undo operation is achieved using a stack.

55. Which of the following is not an advantage of trees? a) Hierarchical structure b) Faster search c) Router algorithms d) Undo/Redo operations in a notepad

Answer: Undo/Redo operations in a notepad Explanation: This is an application of stack.

16. What is the result of the following operation Top (Push (S, X)) a) X b) Null c) S d) None

Answer: X

15. The prefix form of A-B/ (C * D ^ E) is? a) -/*^ACBDE b) -ABCD*^DE c) -A/B*C^DE d) -A/BC*^DE

Answer: -A/B*C^DE Show your work Explanation: Applying the prefix expression evaluation.

22. Consider the following operation performed on a stack of size 5. Push(1); Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); Pop(); Push(5); After the completion of all operation, the number of elements present in stack are a) 1 b) 2 c) 3 d) 4

Answer: 1

83. If we implement heap as maximum heap, adding a new node of value 15 to the left most node of right subtree. What value will be at leaf nodes of the right subtree of the heap. a) 15 and 1 b) 25 and 1 c) 3 and 1 d) 2 and 3

Answer: 15 and 1 Explanation: As 15 is less than 25 so there would be no violation and the node will remain at that position. So, leaf nodes with value 15 and 1 will be at the position in right sub tree.

82. If we implement heap as min-heap, deleting root node (value 1) from the heap. What would be the value of root node after second iteration if leaf node (value 100) is chosen to replace the root at start. a) 2 b) 100 c) 17 d) 3

Answer: 2 Explanation: As the root is deleted and node with value 100 is used as replaced one. There is a violation of property that root node must have value less than its children. So, there will be shuffling of node with value 100 with node of value 2. And thus 2 becomes root. And it will remain to be at root after all the possible operations. So, the value at root will be 2.

19. The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is? a) 600 b) 350 c) 650 d) 588

Answer: 350 Show your work

8. Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? a) 1 b) 2 c) 3 d) 4

Answer: 4 Show your work

54. What is a complete binary tree? a) Each node has exactly zero or two children b) A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from right to left c) A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right d) None of the mentioned

Answer: A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right

13. The postfix form of A*B+C/D is? a) *AB/CD+ b) AB*CD/+ c) A*BC+/D d) ABCD+/*

Answer: AB*CD/+ Show your work Explanation: Applying the postfix expression evaluation.

9. The postfix form of the expression (A+ B)*(C*D- E)*F / G is? a) AB+ CD*E - FG /** b) AB + CD* E - F **G / c) AB + CD* E - *F *G / d) AB + CDE * - * F *G /

Answer: AB+ CD*E - FG /** or AB + CD* E - *F *G / Explanation: Applying the postfix expression evaluation.

28. If the elements "A", "B", "C" and "D" are placed in a queue and are deleted one at a time, in what order will they be removed? a) ABCD b) DCBA c) DCAB d) ABCD

Answer: ABCD Explanation: Queue follows FIFO approach.

6. Which of the following applications may use a stack? a) A parentheses balancing program. b) Tracking of local variables at run time. c) Compiler Syntax Analyzer. d) All of the mentioned

Answer: All of the mentioned Explanation: All are applications of stack.

78. Which of these is an application of linked lists? a) To implement file systems b) For separate chaining in hash-tables c) To implement non-binary trees d) All of the mentioned

Answer: All of the mentioned Explanation: Linked lists can be used to implement all of the above-mentioned applications.

70. What are the advantages of priority queues? a) Easy to implement b) Processes with different priority can be efficiently handled c) Applications with differing requirements d) All of the mentioned

Answer: All of the mentioned Explanation: All of these properties of priority queue help in achieving its applications like Huffman coding, priority scheduling and the like.

66. With what data structure can a priority queue be implemented? a) Array b) List c) Heap d) All of the mentioned

Answer: All of the mentioned Explanation: Priority queue can be implemented using an array, a list, a binary search tree or a heap, although the most efficient one being the heap.

85. Which of the following data structure is linear data structure? A. Trees B. Graphs C. Arrays D. None of above

Answer: Arrays

25. If the elements "A", "B", "C" and "D" are placed in a stack and are deleted one at a time, what is the order of removal? a) ABCD b) DCBA c) DCAB d) ABDC

Answer: DCBA Explanation: Stack follows LIFO(Last In First Out).

51. The number of edges from the root to the node is called __________ of the tree. a) Height b) Depth c) Length d) None of the mentioned

Answer: Depth

29. A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle is? a) Queue b) Circular queue c) Dequeue d) Priority queue

Answer: Dequeue

53. What is a full binary tree? a) Each node has exactly zero or two children b) Each node has exactly two children c) All the leaves are at the same level d) Each node has exactly one or two children

Answer: Each node has exactly zero or two children

73. What is a memory efficient double linked list? a) Each node has only one pointer to traverse the list back and forth b) The list has breakpoints for faster traversal c) An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list d) None of the mentioned

Answer: Each node has only one pointer to traverse the list back and forth Explanation: Memory efficient doubly linked list has been proposed recently which has only one pointer to traverse the list back and forth. The implementation is based on pointer difference.

41. What happens when you pop from an empty stack while implementing using the Stack ADT in Java? a) Undefined error b) Compiler displays a warning c) EmptyStackException is thrown d) NoStackException is thrown

Answer: EmptyStackException is thrown Explanation: The Stack ADT throws an EmptyStackException if the stack is empty and a pop() operation is tried on it.

27. A queue is a ? a) FIFO (First In First Out) list b) LIFO (Last In First Out) list c) Ordered array d) Linear tree

Answer: FIFO (First In First Out) list

33. Which of the following properties is associated with a queue? a) First In Last Out b) First In First Out c) Last In First Out d) None of the mentioned

Answer: First In First Out Explanation: Queue follows First In First Out structure.

52. The number of edges from the node to the deepest leaf is called _________ of the tree. a) Height b) Depth c) Length d) None of the mentioned

Answer: Height

50. In a binary search tree, which of the following traversals would print the numbers in the ascending order? a) Level-order traversal b) Pre-order traversal c) Post-order traversal d) In-order traversal

Answer: In-order traversal Explanation: In a binary search tree, a node's left child is always lesser than the node and right child is greater than the node, hence an in-order traversal would print them in a non-decreasing fashion.

69. What is not a disadvantage of priority scheduling in operating systems? a) A low priority process might have to wait indefinitely for the CPU b) If the system crashes, the low priority systems may be lost permanently c) Interrupt handling d) None of the mentioned

Answer: Interrupt handling Explanation: It is in fact an advantage, interrupts should be given more priority than the task at hand so that the interrupt can be serviced.

61. What is the specialty about the in-order traversal of a binary search tree? a) It traverses in a non increasing order b) It traverses in an increasing order c) It traverses in a random fashion d) None of the mentioned

Answer: It traverses in an increasing order Explanation: As a binary search tree consists of elements lesser than the node to the left and the ones greater than the node to the right, an inorder traversal will give the elements in an increasing order.

23. Which of the following is not an inherent application of stack? a) Reversing a string b) Evaluation of postfix expression c) Implementation of recursion d) Job scheduling

Answer: Job scheduling Explanation: Job Scheduling is not performed using stacks.

57. In a full binary tree if number of internal nodes is I, then number of nodes N are? a) N = 2I b) N = I + 1 c) N = I - 1 d) N = 2I + 1

Answer: N = 2I + 1 Explanation: Trace with respect to the diagram.

58. In a full binary tree if there are L leaves, then total number of nodes N are? a) N = 2L b) N = L + 1 c) N = L - 1 d) N = 2L - 1

Answer: N = 2L - 1 Explanation: Trace with respect to the diagram.

71. Which of the following is false about a doubly linked list? a) We can navigate in both the directions b) It requires more space than a singly linked list c) The insertion and deletion of a node take a bit longer d) None of the mentioned

Answer: None of the mentioned Explanation: A doubly linked list has two pointers 'left' and 'right' which enable it to traverse in either direction. Compared to singly liked list which has only a 'next' pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion requires manipulation of two pointers, hence it takes a bit longer time.

59. Which of the following is false about a binary search tree? a) The left child is always lesser than its parent b) The right child is always greater than its parent c) The left and right sub-trees should also be binary search trees d) None of the mentioned

Answer: None of the mentioned Explanation: All the options hold good for a binary search tree and can be considered as a definition for a BST.

35. What is the time complexity of enqueue operation? a) O(logn) b) O(nlogn) c) O(n) d) O(1)

Answer: O(1) Explanation: Enqueue operation is at the rear end, it takes O(1) time to insert a new item into the queue.

40. What is the time complexity of pop() operation when the stack is implemented using an array? a) O(1) b) O(n) c) O(logn) d) O(nlogn)

Answer: O(1) Explanation: pop() accesses only one end of the structure, and hence constant time.

4. Pushing an element into stack already having five elements and stack size of 5, then stack becomes a) Overflow b) Crash c) Underflow d) User flow

Answer: Overflow

2. Process of removing an element from stack is called __________ a) Create b) Push c) Evaluation d) Pod

Answer: Pod

24. The type of expression in which operator succeeds its operands is? a) Infix Expression b) Prefix Expression c) Postfix Expression d) None of the mentioned

Answer: Postfix Expression

62. What does the following piece of code do? public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); } a) Preorder traversal b) Inorder traversal c) Postorder traversal d) Level order traversal

Answer: Postorder traversal Explanation: In a postorder traversal, first the left child is visited, then the right child and finally the parent.

48. To obtain a prefix expression, which of the tree traversals is used? a) Level-order traversal b) Pre-order traversal c) Post-order traversal d) In-order traversal

Answer: Pre-order traversal Explanation: As the name itself suggests, pre-order traversal can be used.

63. What does the following piece of code do? public void func(Tree root) { System.out.println(root.data()); func(root.left()); func(root.right()); } a) Preorder traversal b) Inorder traversal c) Postorder traversal d) Level order traversal

Answer: Preorder traversal Explanation: In a preorder traversal, first the parent is visited, then the left child and finally the right child.

81. Heap can be used as... a) Priority queue b) Stack c) A decreasing order arrays d) None of the mentioned

Answer: Priority queue Explanation: The property of heap that the value of root must be either greater or less than both of its children makes it work like a priority queue.


संबंधित स्टडी सेट्स

Chapter 6: Managing Social Media Communications and Planning Cycles

View Set

ACCT 210 - Smartbook Questions Chapter 8

View Set

Pharm Adap Quiz: Ch. 27 Antilipemic Drugs

View Set

exam 2 bio drugs and society chapter 5

View Set

PowerPoint L2 Applying Transitions

View Set

OLD Writing: Writing a Paragraph

View Set