Vous êtes sur la page 1sur 10

Data Structures

Registration No_________________

10

11

12

131

15

16

17

18

19

20

21

22

23

24

25

26

27

38

29

30

Name: ______________________________________________________________________Section _______________

1. Comment on the 2 arrays regarding P and Q:


int *a1[8];

int *(a2[8]);

P. Array of pointers

Q. Pointer to an array

A) a1 is P, a2 is Q

B) a1 is P, a2 is P

C) a1 is Q, a2 is P

D) a1 is Q, a2 is Q

Ans: B

2. The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array
of n integers is
(A) (n)

(B) (logn)

(C) (n)

(D) None of These

Ans: B

3. Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct.
(A) Find the ith largest element
(B) Find the ith smallest element
(C) Delete an element
(D) All of the aboveLet A be a square matrix of size n x n.
Ans: C

4. Consider the following program. What is the expected output?


int C = 100
fori = 1 to n do
for j = 1 to n do
{
Temp = A[i][j] + C
A[i][j] = A[j][i]
A[j][i] = Temp - C
}
fori = 1 to n do

Data Structures
for j = 1 to n do
Output(A[i][j]);

(A) The matrix A itself


(B) Transpose of matrix A
(C) Adding 100 to the upper diagonal elements and subtracting 100 from diagonal elements of A
(D) None of the above

Ans: A

Q1. Let two function as


f (n) = n1/3log4n and g(n) = nlogn
A. f (n) is asymptotically larger than g(n)
B. g(n) is asymptotically larger than f (n)
C. Both A and B are true, each for a particular range of n
D. We cant compare f (n) a n d g(n).

Q2. Whether a list of n numbers has two occurrences of the same number in list can be computed in worst case in time

A. O(nlogn)
B. O(n^2)
C. O(n^3)
D. O(logn)

Q3. If a problem has worst case time complexity (nlogn) and O(n^2). And an algorithm A can solve this problem. Which of
the following are possible?
I A has best case complexity (n)
II A has worst case complexity (n (n))
III A has average case complexity (n3)
IV A has worst case complexity (n)

A. I only
B. III only

Data Structures
C. I and II only
D. I and IV only

Q4 In the following C function, let n >= m.


int fun(n,m)
{
if (n%m ==0) return m;
n = n%m;
return fun(m,n);
}
How many recursive calls are made by this function?
A. theta(logn)
B. omega(n)
C. theta(loglogn)
D. theta(sqrt(n))

Q5. Which of the following functions has the largest growth rate? *
A. n^(1/2)
B. n^100
C. 2^(n/2)
D. 2^(n!)

Q6. The average number of comparisons in sequential search is *


A. n^2
B. n(n-1) / 2
C. n(n+1) / 2
D. (n+1) /2

Q1 :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
b.

Data Structures

Q2: Alice was making an algorithm for displaying the elements in circular headed linked list but got stuck in and
was not able to resolve it. Help her to get out of it by finding out the wrong segment. She wrote
1.
2.
3.
4.

Set PTR := LINK[START]. [Initializes pointer PTR.]


Repeat Steps 3 and 4 while PTR != NULL.
Write INFO[PTR].
Set PTR := LINK[PTR]. [PTR now points to the next node.]
[End of Step 2 loop.]
5. Exit.
(A) step 1
(B) step 2
(C) step 3
(D) step 4
(B)
Q3: In a circular link list there is need of modification of how many pointers while inserting a new node at an end?
(A) 0
(B) 1
(C)2
(D) 3
(C)
Q4: The given procedure inserts a node in a link list at which position?
Insertion (Info, Link, Start, Item)
1. Set Ptr:=Start.
2. Set New:=Alloc(node).
3. Repeat Step 4 while (Link[Ptr]!=NULL).
4. Ptr:=Link[Ptr].
5. Set Info[New]:=Item.
6. Set Link[New]=NULL.
7. Set Link[Ptr]:=New.
(A) In the beginning.
(B) In the end.
(C) Anywhere in the list according to given location.
(D) Node will not be inserted.
(B)
Q 5: In the given question there is list of rooms in hospital connected in a doubly link list. Fill the NEXTLINK and
PREVLINK so that they form an ordering of room numbers. Make a match for corresponding values with given
room numbers.

NSTART =
1F

10
1F
2F

Rooms
650
400
401

NEXTLINK

PREVLINK

Data Structures

2B
3A

450
500

(A) NEXTLINK----2B, 3A, 1F, 10, NULL


PREVLINK----3A, NULL, 1F, 2F, 2B
(B) NEXTLINK----NULL, 2F, 2B, 3A, 10
PREVLINK----3A, NULL, 1F, 2F, 2B
(C) NEXTLINK----NULL, 10, 2B, 3A, 1F
PREVLINK----3A, NULL, 1F, 2F, 2B
(D) NEXTLINK----NULL, 2F, 2B, 3A, 10
PREVLINK----10, 1F, 2F, 2B, NULL
(B.)
Q6: Linked List are known as
1. Self Calling Function
2. Self Referential Function
3. Self Calling Structures
4. Self Referential Structures
(4.)
Q7: The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the
list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the
contents of the list after the function completes execution?
struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
Run on IDE

Data Structures

(A) 1,2,3,4,5,6,7
(B) 2,1,4,3,6,5,7
(C) 1,3,2,5,4,7,6
(D) 2,3,4,5,6,7,1

Answer: (B)
1. To evaluate an expression without any embedded function calls:
(A) One stack is enough
(B) Two stacks are needed
(C) As many stacks as the height of the expression tree are needed
(D) A Turing machine is needed in the general case
Answer: (A)
2. What is the minimum number of queue needed to implement priority queue?
A.1
B.2
C.3
D.5
Ans.: B
3. Which of the following is a collection of items into which items can be inserted arbitrarity and from which only
the smallest item can be removed?
A. Descending priority queue
B. Ascending priority queue
C. Fifo queue
D. None of these
Ans-B
4. Number of "ADD" and "REMOVE" operations required to access n/2th elements of a queue of "n" elements so
that the original queue remain the same after the access is (take help of another queue.)
A. 4*n
B. 2*n
C. 4*n-1
D. 2*n-1
Ans-A
5. The five items:A,B,C,D, and E are pushed in a stack, one after the other starting from A.The stack is popped four
times and each element is inserted in a queue.Then two elements are deleted from the queue and pushed back on the
stack.Now one item is popped from the stack.
The popped item is
A.E
B.B
C.C
D.D
Ans-D

Data Structures

1. A binary search tree contains the value 1, 2, 3, 4, 5, 6, 7, 8. The tree is traversed in pre-order and the values
are printed out. Which of the following sequences is a valid output?
(a) 5 3 1 2 4 7 8 6(b) 5 3 1 2 6 4 8 7
(c) 5 3 2 4 1 6 7 8 (d) 5 3 1 2 4 7 6 8
Ans (d)
2. A complete n-ary tree is one in which every node has 0 or n sons. If x is the number of internal nodes of a
complete n-ary tree, the number of leaves in it is given by
(a) x(n 1) +1

(b) xn - 1

(c) xn + 1

(d) x(n+1)

Ans (a)
3. The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number
of nodes in a binary tree of height h is:
(a) 2h -1 (b) 2h-1 1
(c) 2h+1 -1 (d) 2h+1
ANS C

4. The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:
(a) n/2 (b) (n-1)/3 (c) (n-1)/2 (d) (2n+1)/3
ANS (D)
5. A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the
heap is given below:
10, 8, 5, 3, 2
Two new elements '1' and '7' are inserted in the heap in that order. The level-order traversal of the heap after
the insertion of the elements is:
(a) 10, 8, 7, 5, 3, 2, 1
(b) 10, 8, 7, 2, 3, 1, 5
(c) 10, 8, 7, 1, 2, 3, 5
(d) 10, 8, 7, 3, 2, 1, 5
ANS D

6. The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in
the pseudocode below is invoked as height (root) to compute the height of a binary tree rooted at the tree
pointer root.

Data Structures

The appropriate expression for the two boxes B1 and B2 are


(a) B1 : (1 + height(n->right)), B2 : (1 + max(h1,h2))
(b) B1 : (height(n->right)), B2 : (1 + max(h1,h2))
(c) B1 : height(n->right), B2 : max(h1,h2)
(d) B1 : (1 + height(n->right)), B2 : max(h1,h2)
ANS A
7. The characters a to h have the set of frequencies based on the first 8 Fibonacci numbers as follows
a : 1, b : 1, c : 2, d : 3, e : 5, f : 8, g : 13, h : 21
A Huffman code is used to represent the characters. What is the sequence of characters corresponding to the
following code?
110111100111010
A)
B)
C)
D)
Ans A

fdheg
ecgdf
dchfg
fehdg

Data Structures
1) The number of distinct minimum spanning trees for the weighted graph below is ____

A.
B.
C.
D.

1
3
6
12

Answer: 6

2) Consider the directed graph given below. Which one of the following is TRUE?
(A) The graph doesnt have any topological ordering
(B) Both PQRS and SRPQ are topological ordering
(C) Both PSRQ and SPRQ are topological ordering
(D) PSRQ is the only topological ordering
Answer (C)
3)The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in decreasing order. Which of the
following sequences cannot be the degree sequence of any graph?
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1
(A) I and II
(B) III and IV
(C) IV only
(D) II and IV
Answer (D)

Data Structures

Vous aimerez peut-être aussi