DATA STRUCTURE 1- What data structure can be used to check if a syntax has balanced paranthesis? A - queue B - tree C - list D - stack Answer : D Explanation Stack uses LIFO method which is good for checking matching paranthesis. 2. What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); }
A Prints all nodes of linked lists B Prints all nodes of linked list in reverse order C Prints alternate nodes of Linked List D Prints alternate nodes in reverse order B 3 - Which of the following asymptotic notation is the worst among all? A - Ο(n+9378) B - Ο(n 3 ) C - n Ο(1) D - 2 Ο(n) D 4 - Which of the following searching techniques do not require the data to be in sorted form A - Binary Search B Linear search
C-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear search can work even if the data is not sorted. 5 - Which method can find if two vertices x & y have path between them? A - Depth First Search B - Breadth First Search C - Both A & B D - None A or B Answer : C Explanation By using both BFS and DFS, a path between two vertices of a connected graph can be determined. 6 - Tower of hanoi is a classic example of A - divide and conquer B - recursive approach C - B but not A
D - Both A & B Answer : D Explanation The recursive approach of tower of hanoi uses divide and conquer method. 7.Which of the following is true about linked list implementation of stack? a. In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end. b. In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning. c. Both of the above d. None of the above D 8.The result evaluating the postfix expression 10 5 + 60 6 / * 8 is A 284 B 213 C 142 D 71
C 9.Which of the following can be solved by dynamic programming approach? A All pair shortest path problem B 0/1 Knapsack problem C- None of the above D - All of the above Answer : D Explanation All mentioned use dynamic programming approach. Before solving the in-hand sub-problem, dynamic algorithm will try to examine the results of previously solved sub-problems. The solutions of sub-problems are combined in order to achieve the best solution. 10 - Recursion uses more memory space than iteration because A - it uses stack instead of queue. B - every recursive call has to be stored. C - both A & B are true. D - None of the above are true.
Answer : B Explanation Recursion uses stack but the main reason is, every recursive call needs to be stored separately in the memory. Q 11 - What is the worst case run-time complexity of quicksort sort algorithm? A - Ο(n 2 ) B - Ο(n log n ) C - Ο(n 3 ) D - Ο(n) Answer : A Explanation 3 cases 1)All numbers are equal 2)Numbers are in decreasing order 3) Numbers are in increasing order 12. How many stacks are needed to implement a queue. How many queues are needed to implement a stack.
a)1, 1 b)2,1 c)1,2 d)2,2 D 13.Which algorithm is used to construct minimum spanning tree? A.Prims and krushkal algo B.Prims and dijkstras algo C.Krushkal and dijkstras D.Prims and krushkal and dijkstras algo A 14. How many distinct binary search trees can be created out of 4 distinct keys? A 4 B 14
C 24 D 42 14 Catalan no: (2n)!/(n!*(n+1)!) 15. Which of the following traversal outputs the data in sorted order in a BST? A Preorder B B Inorder C Postorder D Level order 16. What are the worst-case complexities of insertion and deletion of a key in a binary search tree? A Θ(logn) for both insertion and deletion B Θ(n) for both insertion and deletion
C Θ(n) for insertion and Θ(logn) for deletion D Θ(logn) for insertion and Θ(n) for deletion B 17.A max-heap is a heap where the value of each parent is greater than or equal to the values of its children. Which of the following is a max-heap? A A B B C C D D
B 18. Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap? A 25,12,16,13,10,8,14 B 25,12,16,13,10,8,14 C 25,14,16,13,10,8,12 D 25,14,12,13,10,8,16 C 19.What is the content of the array after two delete operations on the correct answer to the previous question(deleting root node)? A 14,13,12,10,8 B 14,12,13,8,10 C 14,13,8,12,10
D 14,13,12,8,10 D 20.The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing (CLOSED HASHING)with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table? A A B B C C D D
C open addressing =CLOSED HASHING closed addressing=open HASHING Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternate locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, which indicates that there is no such key in the table. Well known probe sequences include: linear probing in which the interval between probes is fixed--often at 1. quadratic probing in which the interval between probes increases linearly (hence, the indices are described by a quadratic function). double hashing in which the interval between probes is fixed for each record but is computed by another hash function. 21.Which of the following statement(s) is TRUE? I. A hash function takes a message of arbitrary length and generates a fixed length code. II.A hash function takes a message of fixed length and generates a code of variable length.
III.A hash function may give the same hash value for distinct messages. A.I only B.II and III only C.I and III only D.II only C 22. The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is A MNOPQR B NQMPOR C QMNPRO
D QMNPOR C 23.Consider the DAG with Consider V = {1, 2, 3, 4, 5, 6}, shown below. Which of the following is NOT a topological ordering? A 1 2 3 4 5 6 B 1 3 2 4 5 6 C 1 3 2 4 6 5 D 3 2 4 1 6 5 D 24.Worst case complexity and average case complexity of Height of binary search tree is (complexity is in Big O) a)log n, n
b)n, log n c)n,n d)log n,log n C 25.The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes and minimum number of nodes in a binary tree of height h is: a)2^(h+1) 2^(h)-1 b) 2^(h+1)-1 2^(h-1)-1 c) 2^(h+1)-1 2^(h) d) 2^(h) 2^(h+1)-1 C 26. In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is a)log 2 n c)n d) log 2 n 1 d)n/2 B
27. You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list? a) Delete the first element b) Insert a new element as a first element c) Delete the last element of the list d) Add a new element at the end of the list C 28. Consi der the follo wing functi on to traver se a linked list.
void traver se(str uct Node *head ) { whi le (head- ->nex t!= NUL L) { p rintf(" %d ", head- >data ); h ead = head- >next ; } }
Whic h of the follo wing is FA LSE about above functi on? a.th e funct ion may crash
when the linke d list is empt y b.th e funct ion does n't print the
last node when the linke d list is not empt y c.th e funct ion is impl emen
ted incor rectl y beca use it chan ges head C 29. Predict the output of following program #include <stdio.h> int f(int n) { if(n <= 1) return 1;
} if(n%2 == 0) return f(n/2); return f(n/2) + f(n/2+1); int main() { printf("%d", f(11)); return 0; } A)3 B)4 C)5 D)STACK OVERFLOW C 30. Here is an infix notation ((A+B)*C-(D-E))^(F+G). Choose the correct postfix notation of the above from the given options. a. AB+CD*E--FG+^ b. AB+C*DE--FG+^ c. AB+C*DE-FG-+^ d. A+BC*DE-FG-+^ B
31. What is the best time complexity of bubble sort? a)n 2 b)logn c)n d)nlogn C int main() { int arr[] = {10, 20, 30, 400, 50}, i, j, isswapped; int n = sizeof(arr) / sizeof(*arr),t; isswapped = 1; for(i = 0; i < n - 1 && isswapped; ++i) { isswapped = 0; for(j = 0; j < n - i - 1; ++j) { if (arr[j] > arr[j + 1]) { t=arr[j];
arr[j]=arr[j+1]; arr[j+1]=t; } isswapped = 1; } } for(i = 0; i < n; ++i) printf("%d ", arr[i]); return 0; } 32. The auxiliary space of insertion sort is O(1), what does O(1) mean? a.the memory (space) required to process the data is not constant. b.it means the amount of extra memory Insertion Sort consumes doesn't depend on the input. The algorithm should use the same amount of memory for all inputs. c.it takes only 1 kb of memory.
c.it is the speed at which the elements are traversed B