22
DATA STRUCTURE (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST 1 - What data structure can be used to check if a syntax has balanced paranthesis ? A - queue B - tree C - list D - stack 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

(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

  • Upload
    vankien

  • View
    254

  • Download
    9

Embed Size (px)

Citation preview

Page 1: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

DATA STRUCTURE(AMCAT)

ASPIRING MINDS COMPUTER ADAPTIVE TEST

1- What data structure can be used to check if a syntax hasbalanced paranthesis ?

A - queue

B - tree

C - list

D - stack

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);}

A Prints all nodes of linked lists

Page 2: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

B Prints all nodes of linked list in reverse order

C Prints alternate nodes of Linked List

D Prints alternate nodes in reverse order

3 - Which of the following asymptotic notation is the worstamong all?

A - Ο(n+9378)

B - Ο(n3)

C - nΟ(1)

D - 2Ο(n)

4 - Which of the following searching techniques do not requirethe data to be in sorted form

A - Binary Search

B – Linear search

C-Both A and B

D-None of the above

Page 3: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

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

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

Page 4: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

8.The result evaluating the postfix expression 10 5 + 60 6 / * 8– isA 284

B 213

C 142

D 71

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

10 - Recursion uses more memory space than iteration because

A - it uses stack instead of queue.

Page 5: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

B - every recursive call has to be stored.

C - both A & B are true.

D - None of the above are true.

Q 11 - What is the worst case run-time complexity of quicksortsort algorithm?

A - Ο(n2)

B - Ο(nlog n)

C - Ο(n3)

D - Ο(n)

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

Page 6: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

13.Which algorithm is used to construct minimum spanningtree?

1) Prims and krushkal algo

2) Prims and dijkstras algo

3) Krushkal and dijkstras

4) Prims and krushkal and dijkstras algo

14.How many distinct binary search trees can be created outof 4 distinct keys?

A 4

B 14

C 24

D 42

15.

Page 7: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

Which of the following traversal outputs the data in sortedorder in a BST?

A Preorder

B Inorder

C Postorder

D Level order

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

C Θ(n) for insertion and Θ(logn) for deletion

D Θ(logn) for insertion and Θ(n) for deletion

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 the

Page 8: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

following is a max-heap?

A A

B B

C C

DD

18.Consider a binary max-heap implemented using an array. Whichone of the following array represents a binary max-heap?

Page 9: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

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

D 14,13,12,8,10

Page 10: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

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 11: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

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 12: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

D QMNPOR

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

24.Worst case complexity and average case complexity ofHeight of binary search tree is (complexity is in Big O)

a)log n , n

Page 13: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

b)n, log n

c)n,n

d)log n,log n

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

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

Page 14: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

28.Considerthefollowingfunction totraverse alinked

Page 15: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

list.

voidtraverse(structNode*head){ while(head-->next !=NULL) { printf("%d ",head->data); head =head->next; }}

Page 16: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

29.Which ofthefollowingis FALSE aboutabovefunction?

a.Th

e

funct

ion

may

crash

Page 17: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

when

the

linke

d list

is

empt

y

b.Th

e

funct

ion

does

n't

print

the

Page 18: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

last

node

when

the

linke

d list

is not

empt

y

c.Th

e

funct

ion is

impl

emen

Page 19: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

ted

incor

rectl

y

beca

use it

chan

ges

head

30. Predict the output of following program

#include <stdio.h>int f(int n){ if(n <= 1) return 1;

Page 20: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

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

31. 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-+^

Page 21: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table

32. What is the best time complexity of bubble sort?

a)n2

b)logn

c)n

d)nlogn

33. 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 .

c.It is the speed at which the elements are traversed

Page 22: (AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST A B · PDF file(AMCAT) ASPIRING MINDS COMPUTER ADAPTIVE TEST ... A - queue B - tree C - list D - stack 2. ... initially empty hash table