Sie sind auf Seite 1von 11

WWW.VUTUBE.EDU.

PK
MIDTERM EXAMINATION
Spring 2010
CS301- Data Structures
Ref No: 1128537
Time: 60 min
Marks: 38

Question No: 1 ( Marks: 1 ) - Please choose one

In the statement int x[6]; , we cannot assign any value to x because x is not an lvalue.

► True

► False

Question No: 2 ( Marks: 1 ) - Please choose one

What will be postfix expression of the following infix expression?


Infix Expression : a+b*c-d

► ab+c*d-

► abc*+d-

► abc+*d-

► abcd+*-

Question No: 3 ( Marks: 1 ) - Please choose one


Which one of the following calling methods does not change the original value of the
argument in the calling function?

► None of the given options

► Call by passing the value of the argument

► Call by passing reference of the argument

► Call by passing the address of the argument

Question No: 4 ( Marks: 1 ) - Please choose one

In a program a reference variable, say x, can be declared as

► int &x ;

► int *x ;

► int x ;

► None of the given options

Question No: 5 ( Marks: 1 ) - Please choose one

A tree is an AVL tree if

► Any one node fulfills the AVL condition

► At least half of the nodes fulfill the AVL condition

► All the nodes fulfill the AVL condition

► None of the given options


Question No: 6 ( Marks: 1 ) - Please choose one

Consider the following pseudo code


declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
What is written to the screen for the input "apples"?

► selpa

► selppa

► apples

► aaappppplleess

Question No: 7 ( Marks: 1 ) - Please choose one

In the following C++ code, how many function calls are made?

int x, y, z;
x = 2;
y = 3 + x;
z = foobar(x,y);

►1

►4

►7

►8
Question No: 8 ( Marks: 1 ) - Please choose one

We can add elements in QUEUE From _________

► Front

► Rear

► From Both Rare and Front

► None of these

Question No: 9 ( Marks: 1 ) - Please choose one

Consider the following tree.

How many of the nodes have at least one sibling?

►8

►7

►5

►6

Question No: 10 ( Marks: 1 ) - Please choose one


Consider the following tree.

How many descendants does the root have?

►5

►6

►7

►8

Question No: 11 ( Marks: 1 ) - Please choose one

Below is a binary search tree. If we delete the value 50 using the algorithm we discussed,
what value will be in the root of the remaining tree?

► 50

► 60
► 70

► 80

Question No: 12 ( Marks: 1 ) - Please choose one

We access elements in AVL Tree in,

► Linear way only

► Non Linear way only

► Both linear and non linear ways

► None of the given options.

Question No: 13 ( Marks: 1 ) - Please choose one

Which of the following statement regarding binary tree is NOT correct.

► A binary tree can contain at least 2L Nodes at level L.

► A complete binary tree of depth d is a binary tree that contains 2 L Nodes at each level
L between 0 and d, both inclusive.

► The total number of nodes (Tn ) in a complete binary tree of depth d is 2 d+1 - 1 .

► The height of the complete binary tree can be written as h = log 2 (Tn+1)-1 where Tn is
Total number of Nodes.

Question No: 14 ( Marks: 1 ) - Please choose one


The following are statements related to queues.

(i) The last item to be added to a queue is the first item to be removed
(ii)A queue is a structure in which both ends are not used
(iii)The last element hasn’t to wait until all elements preceding it on the queue are
removed
(iv) A queue is said to be a last-in-first-out list or LIFO data structure.

Which of the above is/are related to normal queues?

► (iii) and (ii) only

► (i), (ii) and (iv) only

► (ii) and (iv) only

► None of the given options

Question No: 15 ( Marks: 1 ) - Please choose one

The________ method of list data structure removes the element residing at the
current position.
► Add

► next

► remove

► find

Question No: 16 ( Marks: 1 ) - Please choose one

it will be efficient to place stack elements at the start of the list because insertion and
removal take _______time.

► Variable

► Constant

► Inconsistent

► None of the above

Question No: 17 ( Marks: 2 )

Assume that numbers 1, 312, 8, 34, 11 are pushed on a stack, three numbers are popped,
then numbers 12, 44 are pushed on the stack, and one number is popped. What are the
final contents of the stack?
Ans:
11,34,8,44,12,312,1

Question No: 18 ( Marks: 2 )

How we can avoid the problem of Dangling reference

Ans:

To avoid dangling reference, don’t return the reference of a local variable


(transient) from a function.

Question No: 19 ( Marks: 2 )

Traverse the following tree in inorder and postorder


15
/\
2 11

Ans:

Post order traversal:


Traversal order will be LEFT,RIGHT,ROOT

IN THIS CASE IS,

11.2.15

In-order traversal:

Traversal order will be LEFT,ROOT,RIGHT

IN THIS CASE we got data in sorted form………

11.15.2
Question No: 20 ( Marks: 3 )

The nodes of a binary tree have data 1, 2, 3, 4. The in-order traversal of the tree
yields 2,1,4,3. The postorder traversal is 2, 4, 3, 1. The root of the tree is at level 0.

Q3: Which value is in the right child of the root? (1 Pt)

(A) 1 (B) 2 (C) 3 (D) 4 (E) none

Ans:

C(3)

Question No: 21 ( Marks: 3 )

In which cases of insertion we require double rotations to make tree balance?

Ans:

Question No: 22 ( Marks: 5 )

Write a recursive function that given a Binary Search Tree and a low and a high
value, prints all records (data values) in that Binary Search Tree that fall between
the two values ( Our function will print all those values which are between the low
and high value we will pass to that function).

For full credit, the function PrintRange should visit as few nodes as possible.
It's prototype is given below,

int PrintRange(Node* root, int low, int high);

Suppose that the following is a balanced AVL tree. Insert a new node p into the tree. Then the
resulting tree may or may not remain balanced.
Ans:
int PrintRange(Node* root, int low, int high);

BinarySearch(A[0..N-1], value, low, high) {


if (high < low)
return -1 // not found
mid = low + ((high - low) / 2)
if (A[mid] > value)
return BinarySearch(A, value, low, mid-1)
else if (A[mid] < value)
return BinarySearch(A, value, mid+1, high)
else
return mid // found
}

Question No: 23 ( Marks: 5 )

How many
(i) balanced;
(ii) unbalanced;

insertions are possible in this AVL tree?Choose the right answer:

(a) (i) 8, (ii) 10


(b) (i) 6, (ii) 12
(c) (i) 12, (ii) 06
(d) (i) 03, (ii) 06
(e) (i ) 10, (ii) 08

Das könnte Ihnen auch gefallen