Data Structures and Algorithms Final review

¡Supera tus tareas y exámenes ahora con Quizwiz!

24) If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the removal? a) 1234 b) 4321 c) 3241 d) None of the above

Answer: a 1234 Explanation: The answer is a, i.e., 1234. The queue follows the FIFO principle in which the element inserted first will be removed first.

15) Which of the following is the infix expression? a) A+B*C b) +A*BC c) ABC+* d) None of the above

Answer: a A+B*C Explanation: The answer is a, i.e., A+B*C because, in infix notation, all the operators appear between the operands.

31) Which of the following that determines the need for the Circular Queue? a) Avoid wastage of memory b) Access the Queue using priority c) Follows the FIFO principle d) None of the above

Answer: a Avoid wastage of memory Explanation: The answer is a, i.e., Avoid wastage of memory. In a linear queue, there are chances of wastage of memory because if the rear is pointing to the last element whereas the front is pointing to the element other than the first element; it means that spaces allocated before the front are free, but it cannot be reused as rear cannot be incremented. In contrast, the last element is connected to the first element in a circular queue; if initial spaces are vacant, then rear can be incremented by using the statement (rear+1) mod max where max is the size of the array. Therefore, we conclude that the circular queue avoids wastage of memory.

21. Which of the following is the most widely used external memory data structure? a) B-tree b) Red-black tree c) AVL tree d) Both AVL tree and Red-black tree

Answer: a B-tree Explanation: In external memory, the data is transferred in form of blocks. These blocks have data valued and pointers. And B-tree can hold both the data values and pointers. So B-tree is used as an external memory data structure.

15. What is a bit array? a) Data structure that compactly stores bits b) Data structure for representing arrays of records c) Array in which elements are not present in continuous locations d) An array in which most of the elements have the same value

Answer: a Data structure that compactly stores bits Explanation: It compactly stores bits and exploits bit-level parallelism.

35) How many Queues are required to implement a Stack? a) 3 b) 2 c) 1 d) 4

Answer: b 2 Explanation: The answer is b because one queue is required to perform the push operation while the other queue is used to perform the pop operation.

8) Which one of the following is the size of int arr[9] assuming that int is of 4 bytes? a) 9 b) 36 c) 35 d) None of the above

Answer: b 36 Explanation: The answer is b because the size of int type data is 4 bytes. The array stores 9 elements, so the size of the array is 9*4=36 bytes.

45) What would be the output after performing the following operations in a Deque? Insertfront(10); Insertfront(20); Insertrear(30); Insertrear(40); Deletefront(); Insertfront(50); Deleterear(); Display(); a) 10, 20, 30 b) 50, 10, 30 c) 40, 20, 30 d) None of the above

Answer: b 50, 10, 30 Explanation: The answer is b.

44) Which of the following data structure allows you to insert the elements from both the ends while deletion from only one end? a) Input-restricted queue b) Output-restricted queue c) Priority queue d) None of the above

Answer: b Output-restricted queue Explanation: The answer is b. The output-restricted queue is one of the types of the Deque data structure in which insertion is allowed from both the ends but the deletion is allowed from only one end.

13) Which data structure is mainly used for implementing the recursive algorithm? a) Queue b) Stack c) Binary tree d) Linked list

Answer: b Stack Explanation: The answer is b. Recursion means calling the function itself again. Stack is used to maintain the previous records of the function.

1. If two trees have same structure and but different node content, then they are called _ a. Synonyms trees b. Joint trees c. Equivalent trees d. Similar trees

D Similar trees

she left 30 blank ig

30 is blank

9. The total number of comparisons in a bubble sort is .... A. O(n logn) B. O(2n) C. O(n2) D. O(n)

Ans. A ) O(n logn)

8. sorting is good to use when alphabetizing a large list of names. A. Merge B. Heap C. Radix D. Bubble

Ans. C Radix

1. Finding the location of a given item in a collection of items is called ...... A. Discovering B. Finding C. Searching D. Mining

Ans. C searching

1. The time complexity of quicksort is ........ A. O(n) B. O(logn) C. O(n2) D. O(n logn)

Ans. D O(n logn)

1. Quick sort is also known as ........ A. merge sort B. tree sort C. shell sort D. partition and exchange sort

Ans. D partition and exchange sort

1. If two trees have same structure and node content, then they are called a. Synonyms trees b. Joint trees c. Equivalent trees d. Similar trees

Ans: C Equivalent

1. The number of edges in a complete graph of n vertices is a. n(n+1)/2 b. n(n-1)/2 c. n2/2 d. n

B n(n-1)/2

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

Answer: a -A/B*C^DE Explanation: Infix Expression is A-B/(C*D^E)This can be written as: A-(B/(C*(D^E)))Thus prefix expression is -A/B*C^DE.

50) Which of the following is the time complexity to search an element in the linked list? a. O(1) O(n) O(logn) O(nlogn) Answer: O(n)

Answer: O(n) Explanation: The answer is O(n). The worst-case time complexity to search an element in the linked list is O(n) because if we have to find the last element then we need to traverse till the nth node.

21) Which one of the following node is considered the top of the stack if the stack is implemented using the linked list? a) First node b)Second node c) Last node d) None of the above

Answer: a First node Explanation: The answer is a, i.e., First node. As we know, that last inserted element in the stack is considered as the top of the stack. Whenever the element is added to the linked list, it is always added at the beginning of the list. Therefore, we can say that the first node in the linked list is considered as the top of the stack.

47) If circular queue is implemented using array having size MAX_SIZE in which array index starts with 0, front points to the first element in the queue, and rear points to the last element in the queue. Which one of the following conditions used to specify that the circular queue is empty? a) Front=rear= -1 b) Front=rear=0 c) Front=rear+1 d) None of the above

Answer: a Front=rear= -1 Explanation: The answer is a, i.e., front=rear= -1. When the circular queue is empty means that no element is available in the queue then the front and rear are initialized with a -1 value.

7) What is the output of the below code? #include <stdio.h> int main() { int arr[5]={10,20,30,40,50}; printf("%d", arr[5]); return 0; } a) Garbage value b) 10 c) 50 d) None of the above

Answer: a Garbage value Explanation: The answer is a because the indexing in an array starts from 0, so it starts from arr[0] to arr[4]. If we try to access arr[5] then the garbage value will be printed.

30) The time complexity of enqueue operation in Queue is __ a) O(1) b) O(n) c) O(logn) d) O(nlogn)

Answer: a O(1) Explanation: The answer is a, i.e., O(1). In Queue, the insertion is performed at the rear end, which is directly accessible; therefore, it takes O(1) time to insert an element in a Queue.

14) Which data structure is required to convert the infix to prefix notation? a) Stack b) Linked list c) Binary tree d) Queue

Answer: a Stack Explanation: The answer is a, i.e., stack. Stack is a data structure used to reverse the order of the operators in the expression. It is also used as a storage structure that stores all the operators and print all the operators when all the operands have appeared.

10) When the user tries to delete the element from the empty stack then the condition is said to be a ____ a) Underflow b) Garbage collection c) Overflow d) None of the above

Answer: a Underflow Explanation: The answer is a. Underflow is a condition that occurs when user tries to implement the pop operation in the empty stack.

29. Which is the most appropriate data structure for reversing a word? a) stack b) queue c) graph d) tree

Answer: a stack Explanation: Stack is the most appropriate data structure for reversing a word because stack follows LIFO principle.

23. What will be the output of the following program? main() { char str[]="san foundry"; int len = strlen(str); int i; for(i=0;i<len;i++) push(str[i]); // pushes an element into stack for(i=0;i<len;i++) pop(); //pops an element from the stack } a) yrdnuof nas b) foundry nas c) sanfoundry d) san foundry

Answer: a yrdnuof nas Explanation: First, the string 'san foundry' is pushed one by one into the stack.When it is popped, the output will be as 'yrdnuof nas'.

32) Which one of the following is the correct way to increment the rear end in a circular queue? a) rear =rear+1 b) (rear+1) % max c) (rear % max) + 1 d) None of the above

Answer: b (rear+1) % max Explanation: The answer is b. It ensures that the rear will have the value from 0 to max-1; if the rear end points to the last position, and we increment the rear end using (rear+1) % max, then rear will point to the first position in the queue.

46) In a circular queue implementation using array of size 5, the array index starts with 0 where front and rear values are 3 and 4 respectively. Determine the array index at which the insertion of the next element will take place. a) 5 b) 0 c) 1 d) 2

Answer: b 0 Explanation: The answer is b, i.e., 0. As it is mentioned in the question that the size of the array is 5; therefore, the range would be from 0 to 4. In a circular queue, the last element is connected to the first element; the value of rear is 4 so when we increment the value then it will point to the 0th position of the array.

12. Which of the following points is/are not true about Linked List data structure when it is compared with an array? a) Random access is not allowed in a typical implementation of Linked Lists b) Access of elements in linked list takes less time than compared to arrays c) Arrays have better cache locality that can make them better in terms of performance d) It is easy to insert and delete elements in Linked List

Answer: b Access of elements in linked list takes less time than compared to arrays Explanation: To access an element in a linked list, we need to traverse every element until we reach the desired element. This will take more time than arrays as arrays provide random access to its elements.

16. Which of the following tree data structures is not a balanced binary tree? a) Splay tree b) B-tree c) AVL tree d) Red-black tree

Answer: b B-tree Explanation: All the tree data structures given in options are balanced, but B-tree can have more than two children.

42) A linear data structure in which insertion and deletion operations can be performed from both the ends is___ a) Queue b) Deque c) Priority queue d) Circular queue

Answer: b Deque Explanation: The answer is b, i.e., Deque. The deque is a data structure in which both insertion and deletion can be performed from both the ends whereas, in Queue, insertion can be done from one end and deletion can be performed from another end.

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

Answer: b Dequeue Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we will follow first in first out principle for insertion and deletion of elements. Element with least priority will be deleted in a priority queue.

19. Which algorithm is used in the top tree data structure? a) Backtracking b) Divide and Conquer c) Branch d) Greedy

Answer: b Divide and Conquer Explanation: Top tree is a type of data structure which is based on unrooted dynamic binary tree and is used to solve path related problems. It allows an algorithm called divide and conquer.

4) Which of the following is the advantage of the array data structure? a) Elements of mixed data types can be stored. b) Easier to access the elements in an array c) Index of the first element starts from 1. d) Elements of an array cannot be sorted

Answer: b Easier to access the elements in an array Explanation: The answer is b because the elements in an array are stored in a contiguous block of memory, so it is easier to access the elements of an array through indexing.

40) Which of the following principle is used if two elements in the priority queue have the same priority? a) LIFO b) FIFO c) Linear tree d) None of the above

Answer: b FIFO Explanation: The answer is b, i.e., FIFO. In a priority queue, if two or more elements have the same priority then they are arranged based on the FIFO principle.

26) Which of the following principle does Queue use? a) LIFO principle b) FIFO principle c) Linear tree d) Ordered array

Answer: b FIFO principle Explanation: The answer is FIFO principle. Here, FIFO stands for First-In-First-Out. It means that the element which is inserted first will also be removed first.

31. Which of the following is the simplest data structure that supports range searching? a) AA-trees b) K-d trees c) Heaps d) binary search trees

Answer: b K-d trees Explanation: K-d trees are the simplest data structure that supports range searching and also it achieves the respectable running time.

50) Which of the following is the time complexity to search an element in the linked list? a) O(1) b) O(n) c) O(logn) d) O(nlogn)

Answer: b O(n) Explanation: The answer is O(n). The worst-case time complexity to search an element in the linked list is O(n) because if we have to find the last element then we need to traverse till the nth node.

49) What would be the time complexity if user tries to insert the element at the end of the linked list (head pointer is known)? a) O(1) b) O(n) c) O(logn) d) O(nlogn)

Answer: b O(n) Explanation: The answer is b, i.e., O(n). As it is mentioned in the above question that head pointer is known, so to insert the node at the end of the linked list; we have to traverse till the nth node. Therefore, the time complexity would be O(n).

17) Which of the following is not the correct statement for a stack data structure? a) Arrays can be used to implement the stack b) Stack follows FIFO c) Elements are stored in a sequential manner d) Top of the stack contains the last inserted element

Answer: b Stack follows FIFO Explanation: The answer is b because Stack does not follow FIFO. It follows LIFO.

38) The necessary condition to be checked before deletion from the Queue is__ a) Overflow b) Underflow c) Rear value d) Front value

Answer: b Underflow Explanation: The answer is b, i.e., Underflow. Before deleting an element from the Queue, we first need to check whether the Queue is empty or not.

25. What is an AVL tree? a) a tree which is unbalanced and is a height balanced tree b) a tree which is balanced and is a height balanced tree c) a tree with at most 3 children d) a tree with three children

Answer: b a tree which is balanced and is a height balanced tree Explanation: It is a self-balancing tree with height difference at most 1.

48) Consider the implementation of the singly linked list having the head pointer only in the representation. Which of the following operations can be performed in O(1) time? i) Deletion of the last node in the linked list ii) Insertion at the front of the linked list iii) Deletion of the first node in the linked list iv) Insertion at the end of the linked list a.) ii b) both ii and iii c) both i and iv d) both i and ii

Answer: b both ii and iii Explanation: The answer is b. As it is mentioned in the above question that there is only head pointer pointing to the front node in the list so it will take O(1) time to insert at the front as well as to delete the first node from the list. If we try to insert the node at the end or delete the last node then it will take O(n) time as we need to traverse till the n elements.

28. What is the use of the bin data structure? a) to have efficient traversal b) to have efficient region query c) to have efficient deletion d) to have efficient insertion

Answer: b to have efficient region query Explanation: Bin data structure allows us to have efficient region queries. A frequency of bin is increased by one each time a data point falls into a bin.

20) The minimum number of stacks required to implement a stack is __ a) 1 b) 3 c) 2 d) 5

Answer: c 2 Explanation: The answer is 2. In Queue, one stack is required for the enqueue operation, and another stack will be used for the dequeue operation. The first stack is considered as the input stack whereas the second stack is considered as the output stack.

24. Which of the following data structure can provide efficient searching of the elements? a) binary search tree b) unordered lists c) 2-3 tree d) treap (tree & heap)

Answer: c 2-3 tree Explanation: The average case time for lookup in a binary search tree, treap and 2-3 tree is O(log n) and in unordered lists it is O(n). But in the worst case, only the 2-3 trees perform lookup efficiently as it takes O(log n), while others take O(n).

18) If the elements '1', '2', '3' and '4' are added in a stack, so what would be the order for the removal? a) 1234 b) 2134 c) 4321 d) None of the above

Answer: c 4321 Explanation: The answer is c because stack follows LIFO, which means that the element inserted at the last will be removed first.

19) What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1? a) 12 b) 11 c) 5 d) 4

Answer: c 5

34. What is a dequeue? a) A queue implemented with both singly and doubly linked lists b) A queue with insert/delete defined for front side of the queue c) A queue with insert/delete defined for both front and rear ends of the queue d) A queue implemented with a doubly linked list

Answer: c A queue with insert/delete defined for both front and rear ends of the queue Explanation: A dequeue or a double ended queue is a queue with insert/delete defined for both front and rear ends of the queue.

34) In the linked list implementation of queue, where will the new element be inserted? a) At the middle position of the linked list b) At the head position of the linked list c) At the tail position of the linked list d) None of the above

Answer: c At the tail position of the linked list Explanation: The answer is c. If the queue is implemented using linked list, then the new element will be inserted at the tail position of the linked list as Queue follows FIFO principle in which new element will always be added at the end of the Queue.

1) How can we describe an array in the best possible way? a. The Array shows a hierarchical structure. b. Arrays are immutable. c. Container that stores the elements of similar types d. The Array is not a data structure

Answer: c Container that stores the elements of similar types Explanation: The answer is c because array stores the elements in a contiguous block of memory of similar types. Therefore, we can say that array is a container that stores the elements of similar types.

41) Which of the following statement is not true regarding the priority queue? a) Processes with different priority can be easily handled b) Easy to implement c) Deletion is easier d) None of the above

Answer: c Deletion is easier Explanation: The answer is c. i.e., deletion is easier. In worst case, the deletion is not easier as we have to traverse to the n elements until the element to be removed is not found.

26. What is the time complexity for searching a key or integer in Van Emde Boas data structure? a) O (M!) b) O (log M!) c) O (log (log M)) d) O (M2)

Answer: c O (log (log M)) Explanation: In order to search a key or integer in the Van Emde Boas data structure, the operation can be performed on an associative array. Hence, the time complexity for searching a key or integer in Van Emde Boas data structure is O (log (log M)).

43) In the Deque implementation using singly linked list, what would be the time complexity of deleting an element from the rear end? a) O(1) b) O(n2) c) O(n) d) O(nlogn)

Answer: c O(n) Explanation: The answer is O(n) because we need to traverse till the n element to delete the element from the rear end.

11) If the size of the stack is 10 and we try to add the 11th element in the stack then the condition is known as___ a) Underflow b) Garbage collection c) Overflow d) None of the above

Answer: c Overflow Explanation: The answer is c because the stack is full with its 10 elements, and inserting one more element in a stack will lead to the stack overflow.

9) Which one of the following is the process of inserting an element in the stack? a) Insert b) Add c) Push d) None of the above

Answer: c Push Explanation: The answer is c. In stack, the process of inserting an element is known as a push operation.

25) A list of elements in which enqueue operation takes place from one end, and dequeue operation takes place from one end is__ a) Binary tree b) Stack c) Queue d) Linked list

Answer: c Queue Explanation: The answer is Queue. Queue is a data structure in which insertion takes place from one end, and deletion takes place from one end.

23) What is another name for the circular queue among the following options? a) Square buffer b) Rectangle buffer c) Ring buffer d) None of the above

Answer: c Ring buffer Explanation: The circular queue is also known as a ring buffer. In a circular queue, the last element is connected back to the first element of the queue that forms a circle. Therefore, the structure of a circular queue is also known as a ring structure.

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

Answer: c Single ended queue Explanation: Queue always has two ends. So, single ended queue is not the type of queue.

5) Which of the following highly uses the concept of an array? a) Binary Search tree b) Caching c) Spatial locality d) Scheduling of Processes

Answer: c Spatial locality Explanation: The answer is c, i.e., Spatial locality. Here, spatial locality means that the instruction accessed recently, then the nearby memory location would be accessed in the next iteration. As we know that in an array, all the elements are stored in a contiguous block of memory, so spatial locality is accessed quickly.

13. Which data structure is based on the Last In First Out (LIFO) principle? a) Tree b) Linked List c) Stack d) Queue

Answer: c Stack Explanation: The data structure that follows the Last In First Out (LIFO) principle is the Stack. It operates like a stack of objects, making it suitable for specific-order management.

6) Which of the following is the disadvantage of the array? a) Stack and Queue data structures can be implemented through an array. b) Index of the first element in an array can be negative c) Wastage of memory if the elements inserted in an array are lesser than the allocated size d) Elements can be accessed sequentially.

Answer: c Wastage of memory if the elements inserted in an array are lesser than the allocated size Explanation: The answer is c. For example, if we have an array of size 10 elements and we have inserted only 5 elements in an array then there is a wastage of 5 memory blocks which cannot be utilized by another variable.

20. What is the need for a circular queue? a) easier computations b) implement LIFO principle in queues c) effective usage of memory d) to delete elements based on priority

Answer: c effective usage of memory Explanation: In a linear queue, dequeue operation causes the starting elements of the array to be empty, and there is no way you can use that space, while in a circular queue, you can effectively use that space. Priority queue is used to delete the elements based on their priority. Higher priority elements will be deleted first whereas lower priority elements will be deleted next. Queue data structure always follows FIFO principle.

29) Which one of the following is the overflow condition if a circular queue is implemented using array having size MAX? a) rear= MAX-1 b) rear=MAX c) front=(rear+1) mod max d) None of the above

Answer: c front=(rear+1) mod max Explanation: The answer is c, i.e., front=(rear+1) mod max. The overflow condition for the linear queue is rear =MAX-1 as there is no space left in the Queue if rear = MAX-1. On the other hand, in a circular queue, the overflow condition is front=(rear+1) mod max because the last element is connected to the first element in a circular queue.

28) Which one of the following is the overflow condition if linear queue is implemented using an array with a size MAX_SIZE? a) rear = front b) rear = front+1 c) rear=MAX_SIZE -1 d) rear = MAX_SIZE

Answer: c rear=MAX_SIZE -1 Explanation: The answer is c, i.e., rear=MAX_SIZE-1. As the size of the array is MAX_SIZE, so we can insert the elements till MAX_SIZE-1. If we try to insert the elements of size MAX_SIZE or more than MAX_SIZE in a queue, then it leads to the overflow condition.

16) Which of the following is the prefix form of A+B*C? a) A+(BC*) b) +AB*C c) ABC+* d) +A*BC

Answer: d +A*BC Explanation: The answer is d. The prefix notation means all the operators that appear before operand.

22) Consider the following stack implemented using stack. #define SIZE 11 struct STACK { int arr[SIZE]; int top=-1; } What would be the maximum value of the top that does not cause the overflow of the stack? a) 8 b) 9 c) 11 d) 10

Answer: d 10 Explanation: The answer is 10. The maximum size of the array is 11; therefore, we can insert 11 elements in the stack. The top value is initialized by -1, and on every insertion, the top value gets incremented.

14. Which of the following application makes use of a circular linked list? a) Recursive function calls b) Undo operation in a text editor c) Implement Hash Tables d) Allocating CPU to resources

Answer: d Allocating CPU to resources Explanation: Generally, round robin fashion is employed to allocate CPU time to resources which makes use of the circular linked list data structure. Recursive function calls use stack data structure. Undo Operation in text editor uses doubly linked lists. Hash tables uses singly linked lists.

12) Which one of the following is not the application of the stack data structure a) String reversal b) Recursion c) Backtracking d) Asynchronous data transfer

Answer: d Asynchronous data transfer Explanation: The answer is d. The first three options are the stack applications, but option d is not a stack application. The queue data structure is used for synchronization between the processes.

36) Which one of the following is not the application of the Queue data structure? a) Resource shared between various systems b) Data is transferred asynchronously c) Load balancing d) Balancing of symbols

Answer: d Balancing of symbols Explanation: The answer is d. The options a, b, and c are the applications of the Queue data structure while option d, i.e., balancing of symbols is not the application of the Queue data structure. The option a, i.e., resource shared between various system is the application of the Queue data structure as it allows to align all the requests for the resource in a queue. The option b, i.e., data is transferred asynchronously is a application of the Queue data structure. Here asynchronously means that the data received at the different rate as sent. The option c, i.e., load balancing is also an application of the Queue data structure because all the requests from the client are stored in the Queue, and it distributes the requests to the client one by one. The option d, i.e., balancing of symbols is an application of the stack data structure.

1. Which of following data structure is more appropriate for implementing quick sortiteratively? (A) Deque (B) Queue (C) Stack (D) Priority queue

C Stack

37) Which of the following option is true if implementation of Queue is from the linked list? a) In enqueue operation, new nodes are inserted from the beginning and in dequeue operation, nodes are removed from the end. b) In enqueue operation, new nodes are inserted from the end and in dequeue operation, nodes are deleted from the beginning. c) In enqueue operation, new nodes are inserted from the end and in dequeue operation, nodes are deleted from the end. d) Both a and b

Answer: d Both a and b In enqueue operation, new nodes are inserted from the beginning and in dequeue operation, nodes are removed from the end. & In enqueue operation, new nodes are inserted from the end and in dequeue operation, nodes are deleted from the beginning. Explanation: The answer is d. As we know that Queue has two ends, i.e., one for the insertion and another one for the deletion. If Queue is implemented using Linked list then it can be done in either of the ways.

22. Which of the following is also known as Rope data structure? a) Linked List b) Array c) String d) Cord

Answer: d Cord Explanation: Array is a linear data structure. Strings are a collection and sequence of codes, alphabets or characters. Linked List is a linear data structure having a node containing data input and the address of the next node. The cord is also known as the rope data structure.

33) Consider the following code. int fun() { if(isEmpty()) { return -10; } else { int n; n= q[front]; front++; return n; } } Which operation does the above code perform? a) Enqueue b) Dequeue c) Return the front element d) Both b and c

Answer: d Dequeue & Return the front element Explanation: The answer is d because two operations are performed in the above code. The first one is returning the value of the front with the help of the statement n=q[front], and the second operation is dequeue (deleting an element) by using the statement front++.

39) Which data structure is the best for implementing a priority queue? a) Stack b) Linked list c) Array d) Heap

Answer: d Heap Explanation: The answer is d, i.e., Heap. All the data structures that are given in the above options can be used to implement a priority queue but the most efficient way of implementing a priority queue is heap data structure.

10. The data structure required for Breadth First Traversal on a graph is? a) Array b) Stack c) Tree d) Queue

Answer: d Queue Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices which are unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent vertex list will be considered to add further unvisited vertices of the graph. To get the first unvisited vertex we need to follows First In First Out principle. Queue uses FIFO principle.

27) Which one of the following is not the type of the Queue? a) Linear Queue b) Circular Queue c) Double ended Queue d) Single ended Queue

Answer: d Single ended Queue Explanation: The answer is d. i.e., single ended queue. Queue has two ends in which one end is used for the insertion and another end is used for the deletion. Therefore, it is not possible for the Queue to have a single ended queue.

27. The optimal data structure used to solve Tower of Hanoi is _________a) Tree b) Heap c) Priority queue d) Stack

Answer: d Stack Explanation: The Tower of Hanoi involves moving of disks 'stacked' at one peg to another peg with respect to the size constraint. It is conveniently done using stacks and priority queues. Stack approach is widely used to solve Tower of Hanoi.

18. Which of the following data structures can be used for parentheses matching? a) binary tree b) queue c) priority queue d) stack

Answer: d stack Explanation: For every opening brace, push it into the stack, and for every closing brace, pop it off the stack. Do not take action for any other character. In the end, if the stack is empty, then the input has balanced parentheses.

32. What is the advantage of a hash table as a data structure? a) easy to implement b) faster access of data c) exhibit good locality of reference d) very efficient for less number of entries

Answer: d very efficient for less number of entries Explanation: Ternary heap is a type of data structure in the field of computer science. It is a part of the Heap data structure family. It is a priority queue type of data structure that follows all the property of heap.


Conjuntos de estudio relacionados

Chapter 18: Sterilization and Disinfection

View Set

EAQ CARDIOVASCULAR AND RESPIRATORY HW #2

View Set

Upper and lower motor neuron syndromes

View Set

Texas Real Estate 1 practice exam questions

View Set

2.4 Revising and Editing (pg. 72-83)

View Set

MC: Exam 2 (End of ch. questions)

View Set

Physical Science: Atmosphere Review

View Set

Concepts of Professional Nursing - Asepsis and Infection Control PrepU

View Set

Psyc Chapter 9 Motivation & Emotion

View Set