![Page 1: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/1.jpg)
DATA STRUCTURE
1- What data structure can be used to check if a syntax hasbalanced paranthesis ?
A - queue
B - tree
C - list
D - stack
Answer : DExplanationStack uses LIFO method which is good for checking matchingparanthesis.
2. What does the following function do for a given Linked Listwith first node as head?
void fun1(struct node* head){ if(head == NULL) return;
fun1(head->next); printf("%d ", head->data);}
![Page 2: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/2.jpg)
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 worstamong all?
A - Ο(n+9378)
B - Ο(n3)
C - nΟ(1)
D - 2Ο(n)
D
4 - Which of the following searching techniques do not requirethe data to be in sorted form
A - Binary Search
B – Linear search
![Page 3: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/3.jpg)
C-Both A and B
D-None of the above
Answer : AExplanationBoth binary requires data set to be in sorted form. Linear searchcan work even if the data is not sorted.
5 - Which method can find if two vertices x & y have pathbetween them?
A - Depth First Search
B - Breadth First Search
C - Both A & B
D - None A or B
Answer : CExplanationBy using both BFS and DFS, a path between two vertices of aconnected 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
![Page 4: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/4.jpg)
D - Both A & B
Answer : DExplanationThe recursive approach of tower of hanoi uses divide andconquer method.
7.Which of the following is true about linked listimplementation of stack?a. In push operation, if new nodes are inserted at thebeginning of linked list, then in pop operation, nodes mustbe removed from end.b. In push operation, if new nodes are inserted at the end, then inpop operation, nodes must be removed from the beginning.c. Both of the aboved. None of the above
D
8.The result evaluating the postfix expression 10 5 + 60 6 / * 8– isA 284
B 213
C 142
D 71
![Page 5: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/5.jpg)
C
9.Which of the following can be solved by dynamicprogramming approach?
A – All pair shortest path problem
B – 0/1 Knapsack problem
C- None of the above
D - All of the above
Answer : DExplanationAll mentioned use dynamic programming approach. Beforesolving the in-hand sub-problem, dynamic algorithm will try toexamine the results of previously solved sub-problems. Thesolutions of sub-problems are combined in order to achieve thebest 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.
![Page 6: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/6.jpg)
Answer : BExplanationRecursion uses stack but the main reason is, every recursivecall needs to be stored separately in the memory.
Q 11 - What is the worst case run-time complexity of quicksortsort algorithm?
A - Ο(n2)
B - Ο(nlog n)
C - Ο(n3)
D - Ο(n)
Answer : AExplanation3 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.
![Page 7: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/7.jpg)
a)1 , 1
b)2 ,1
c)1,2
d)2,2
D
13.Which algorithm is used to construct minimum spanningtree?
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 outof 4 distinct keys?
A 4
B 14
![Page 8: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/8.jpg)
C 24
D 42
14Catalan no:(2n)!/(n!*(n+1)!)
15.Which of the following traversal outputs the data in sortedorder in a BST?
A Preorder
B Inorder
C Postorder
D Level order
B
16.What are the worst-case complexities of insertion and deletionof a key in a binary search tree?A Θ(logn) for both insertion and deletion
B Θ(n) for both insertion and deletion
![Page 9: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/9.jpg)
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 isgreater than or equal to the values of its children. Which of thefollowing is a max-heap?
A A
B B
C C
D D
![Page 10: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/10.jpg)
B
18.Consider a binary max-heap implemented using an array. Whichone 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 operationson 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
![Page 11: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/11.jpg)
D 14,13,12,8,10
D
20.The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into aninitially empty hash table of length 10 using open addressing(CLOSED HASHING)with hash function h(k) = k mod 10 andlinear probing. What is the resultant hash
table?A A
B B
C C
D D
![Page 12: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/12.jpg)
C
open addressing =CLOSED HASHING
closed addressing=OPEN HASHING
Open addressing, or closed hashing, is a method of collisionresolution in hash tables. With this method a hash collision isresolved by probing, or searching through alternate locations inthe array (the probe sequence) until either the target record isfound, or an unused array slot is found, which indicates thatthere is no such key in the table.
Well known probe sequences include: linear probing in whichthe interval between probes is fixed--often at 1. quadraticprobing in which the interval between probes increases linearly(hence, the indices are described by a quadraticfunction). double hashing in which the interval between probesis fixed for each record but is computed by another hashfunction.
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.
![Page 13: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/13.jpg)
III.A hash function may give the same hash value for distinctmessages.
A.I onlyB.II and III onlyC.I and III onlyD.II only
C
22.The Breadth First Search algorithm has been implemented usingthe queue data structure. One possible order of visiting thenodes of the following graph
isA MNOPQR
B NQMPOR
C QMNPRO
![Page 14: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/14.jpg)
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 ofHeight of binary search tree is (complexity is in Big O)
a)log n , n
![Page 15: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/15.jpg)
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 edgesin any root to leaf path. The maximum number of nodes andminimum 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 tosearch a singly linked list of length n for a given element is
a)log2n
c)n
d) log2n – 1
d)n/2
B
![Page 16: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/16.jpg)
27. You are given pointers to first and last nodes of a singlylinked list, which of the following operations are dependent onthe 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.Considerthefollowingfunction totraverse alinkedlist.
![Page 17: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/17.jpg)
voidtraverse(structNode*head){ while(head-->next !=NULL) { printf("%d ",head->data); head =head->next; }}
![Page 18: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/18.jpg)
Which ofthefollowingis FALSE aboutabovefunction?
a.Th
e
funct
ion
may
crash
![Page 19: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/19.jpg)
when
the
linke
d list
is
empt
y
b.Th
e
funct
ion
does
n't
the
![Page 20: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/20.jpg)
last
node
when
the
linke
d list
is not
empt
y
c.Th
e
funct
ion is
impl
emen
![Page 21: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/21.jpg)
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;
![Page 22: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/22.jpg)
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 givenoptions. a. AB+CD*E--FG+^ b. AB+C*DE--FG+^ c. AB+C*DE-FG-+^ d. A+BC*DE-FG-+^
B
![Page 23: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/23.jpg)
31. What is the best time complexity of bubble sort?
a)n2
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];
![Page 24: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/24.jpg)
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 notconstant.
b.It means the amount of extra memory Insertion Sort consumesdoesn't depend on the input. The algorithm should use the sameamount of memory for all inputs.
c.It takes only 1 kb of memory .
![Page 25: A Prints all nodes of linked lists - GEHU CS/IT Deptt · PDF fileC-Both A and B D-None of the above Answer : A Explanation Both binary requires data set to be in sorted form. Linear](https://reader034.vdocuments.us/reader034/viewer/2022051600/5a9e545b7f8b9a2e688d9d64/html5/thumbnails/25.jpg)
c.It is the speed at which the elements are traversed
B