You are on page 1of 72

(!

CS301- Data Structures


LATEST SOLVED MCQS & SUBJECTIVE FROM MIDTERM PAPERS

With Reference
Mega File

18 December 2014
Ijaz Ahmad BS Computer Science
Virtual University of Pakistan
Bhakkar Campus (PBHK01) Pioneer College of Commerce Bhakkar
ijazcs4@gmail.com
Download PDF File without using IDM

1. The memory address of the first element of an array is called _______.


Floor address
Foundation address
First address
Base address
2. __________reduces the burden of maintaining NULL pointer in the last node
Single linked list
Doubly linked list
Circular linked list
None of the given
3. The order of operands in postfix is the __________as that in the infix.
Different
Same
Unusual
None of the above
4. The next field in the last node in a singly-linked list is set to_______.
0
1
5. Two common models of simulation are _____________ and ______________.
Circuit-based simulation and Event-based simulation
Circuit-based simulation and Time-based simulation
Time-based simulation and Event-based simulation
None of the above
6. A queue is a data structure where elements are
Inserted at one end and removed from the other
Inserted at the front and removed from the back.
Inserted and removed from the top.
Inserted at the back and removed from the front.
Inserted and removed from both ends.
7. Each node in singly linked list contains_______
One pointer
Two pointers
No pointer
8. A queue is a ________data structure, whereas a stack is a ________data structure.
FIFO, LIFO
LIFO,FIFO
both of these
none of these

9. If memory address of first node in linked list is 1052 then 3rd node address will be _____. Note:
consider one node takes 1 byte.
1053 Not Sure
1054
1055
none of then
10. Which one of the following is TRUE about recursion?
Recursion extensively uses stack memory.
Recursion extensively uses heap memory.
Iteration is more efficient than iteration.
11. In array list the worst case of removing an element is
To remove an element from the end of the list
o remove an element from the middle of the list
To remove an element from the start of the list
We cannot remove element from an array list
12. Each node in a singly linked list contains two fields, one field called data field while other field
contains:
Pointer to an integer
Pointer to character
Pointer to next node
13. Suppose you are writing a class for Node class and forgot to write the constructor of the class,
the
Compiler will give compile time error
Complier will give run time error
Compiler will automatically generate a default constructor
14. Which of the following operation returns but do not removes top value of the stack?
push
pop
top
16. The principal benefit of a linked list over a conventional array is that the order of the linked
items may be_______ from the order that the data items are stored in memory. Select correct
option:
Same
Identical
Different
Equivalent
17. The next field in the last node in a singly-linked list is set to_______. Select correct option:
0
1

null
false
18. Local variables of a function are stored in,
Binary Search Tree
Stack
Queue
AVL Tree
19. A template is a function or class that is written with a __________data type. Select correct
option:
Specific
Definite
Generic
None of the above.
20. The expression DE+H* is called_______ Select correct option:
Prefix expression
Infix expression
Postfix expression
Hybrid expression

22. In________, a programmer uses two pointers in the node, i.e. one to point to next node
and the other to point to the previous node
Linked list
doubly-link list
array
25. In the linked list implementation of the stack class, where does the push member
function places the new entry on the linked list?
After all other entries that are greater than the new entry.
At the head
After all other entries that are smaller than the new entry.
At the tail
29. Consider the following infix expression. 7/8 + 9 If one converts the above expression
into postfix, what would be the resultant expression?
789/+
78/+9
/78+9
78/9+

30. If numbers 5, 222, 4, 48 are inserted in a queue, which one will be removed first?
48
4
333
5
35. If we use an array for implementing list, then for simplicity, it is good to use the start
index from ________________.
-1
0
1
2

What will out of following postfix expression? 313 476


None

The _____ method of list will position


Start

STL is a ______ that is a part. C++


Lirary

Doubly linked list always has one NULL pointer


True

which of the following is not a data structure ?


Memory Cell

1.

Local variables of a function are stored in,


Select correct option:

Binary Search Tree

Stack
Queue
AVL Tree

2.

Question # 2 of 5 ( Start time: 11:41:31 AM )


When an executable program run, it is loaded in the memory and becomes a_______.
Select correct option:
Thread
.h file

Process
None of the above

3.

In________ the next returns false when it reaches to the last node due to the fact that the
next field of the last node is set to NULL.
Select correct option:

Circular linked list


Triple linked list
Singly linked list
None of the above

4.

A kind of expressions where the operator is present between two operands called
________expressions.
Select correct option:

Infix
Postfix
Prefix
None of the above

5.

Question # 1 of 5 ( Start time: 11:44:44 AM ) Total Marks: 1


Compiler uses which one of the following in Function calls,
Select correct option:

Stack
Queue
Binary Search Tree
AVL Tree

6.

Stack and Queue can be implemented using _______,


Select correct option:

Singly Link List

Binary Tree
Binary Search Tree
AVL Tree

7. Which one of the following is TRUE about recursion?


Select correct option:

Recursive function calls consume a lot of memory.


Recursion extensively uses stack memory.
Recursion extensively uses stack memory.
Iteration is more efficient than iteration

9.

Which boolean expression indicates whether the numbers in two nodes (p and q) are the same.

Assume that neither p nor q is null.


Select correct option:
p == q

p.data == q.data
p.nextNode == q. nextNode
p.data == q

10.

Whenever we call a function, the compiler makes

a stack, the top element of the stack is _____ of the function.


Select correct option:
First argument
Return address

Last argument not sure


None of the above

11._____ is the stack characteristic but _______was implemented because of the size limitation
of the array.
Select correct option:
isFull(),isEmpty()
pop(), push()

isEmpty() , isFull()
push(),pop()

13.

The next field in the last node in a singly-linked list is set to_____.

Select correct option:

0
1

NULL
false

14. The _____ method of list will position the currentNode and lastCurrentNode at the start of the
list.
Select correct option:
Remove
Next

Start
Back

15.

______ is the maximum number of nodes that you can have on a stack-linked list ?

Select correct option:


Zero
2n (where n is the number of nodes in linked list)

Any Number
None of these

17.

Which of the following operations returns top value of the stack?

Select correct option:


push
pop

top
first

18.

It will be efficient to place stack elements at the start of the list because insertion and removal

take _______time.
Select correct option:
Variable

Constant
Inconsistent
None of the above

19.

A template is a function or class that is written with a __________data type.

Select correct option:

Specific
Definite

Generic
None of the above.

21.

To create a _________ we link the last node with the first node in the list.

Select correct option:


Double linked list

Circularly-linked list
Linked list
None of the above

22.

In the calling function, after the execution of the function called, the program continues its

execution form the _______after the function call.


Select correct option:
Previous line

Next line
Beginning
None of the above

26.

Only removes items in reverse order as they were entered.

Select correct option:


Queue

Stack
Both of these
None of these

27.

A queue is a ________data structure, whereas a stack is a ________data structure.

Select correct option:

FIFO, LIFO
LIFO,FIFO
both of these
none of these

28.

The principal benefit of a linked list over a conventional array is that the order of the linked

items may be_____ from the order that the data items are stored in memory.

Select correct option:


Same
Identical

Different
Equivalent

29.

Whenever we call a function, the compiler makes a stack; the top element of the stack is _____

of the function.
Select correct option:

First argument
Return address
Last argument
None of the above

30.

The _____ method of list will position the current Node and lastCurrentNode at the start of the

list.
Select correct option:
Remove
Next

Start
Back

31. _________ is a binary tree where every node has a value, every node's left subtree contains only
values less than or equal to the node's value, and every node's right subtree contains only values that
are greater then or equal ?
Strictly Binary Tree
Binary Search tree

AVL tree

All of these
Is it possible for a member function of a class to activate another member function of the
same class?
a. No.
b. Yes, but only public member functions.

c. Yes, but only private member functions.


d. Yes, both public and private member functions can be activated within another member
function.

Consider this class definition:


class quiz
{
public:
quiz( );
int f( );
int g( ) const;
private:
double score;
};
Which functions can carry out an assignment score=1.0; to the private ember variable score?
a. Both f and g can carry out the assignment.
b. f can carry out the assignment, but not g.
c. g can carry out the assignment, but not f.
d. Neither f nor g can carry out the assignment

In C++, when allocating an array of objects, what constructor is used to initialize all of the
objects in the array?
a. The automatic copy constructor.
b. The constructor specified at the declaration.
c. The default constructor.
d. None of the above.

The list abstract data type (ADT) is used to work with ordered or unordered sequence of
items such as numbers or strings. What of the following implementation of list ADT is best to
answer questions such as "What is the item at position n?"
a. Lists implemented with an array.
b. Doubly-linked lists.
c. Singly-linked lists.
d. Doubly-linked or singly-linked lists are equally best

Consider this function declaration:


void quiz(int i)
{
if (i > 1)

{
quiz(i / 2);
}
cout << "*";
}
How many asterisks are printed by the function call quiz(5)?
a. 3
b. 4
c. 7
d. 8
e. Some other number

Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T?
a. 0
b. 3
c. 4
d. 5

Entries in a stack are Ordered". What is the meaning of this statement?


a. A collection of stacks can be sorted.
b. Stack entries may be compared with the < operation.
c. The entries must be stored in a linked list.
d. There is a first entry, a second entry, and so on.

Which of the following applications may use a stack?


a. A parentheses balancing program.
b. Keeping track of local variables at run time.
c. In-order traversal of a binary tree.
d. All of the above.
When the compiler compiles your program, how is a recursive call treated differently than a
non-recursive function call?
a. Parameters are all treated as reference arguments
b. Parameters are all treated as value arguments
c. There is no duplication of local variables
d. None of the above

(1)
Here is the start of a class declaration: class Foo
{
public:
void x(Foo f);

void y(const Foo f); void z(Foo f) const;


...
Which of the three member functions can change the PRIVATE member variables of the Foo object that
activates the function?
a.
b.
c.
d.
e.

Only x and y
Only x and z
Only y and z
None of three the functions.
All three functions.

(2)

What is the common pattern of writing class definitions?

a.
b.
c.
d.

Member functions and member variables are both private.


Member functions are private, and member variables are public.
Member functions are public, and member variables are private.
Member functions and member variables are both public.

(3)
The Bag ADT is like the List ADT. The Bag ADT does not store items in any particular
order and it allows duplicates. Suppose that the Bag class is efficiently implemented with a fixed array with a
capacity of 4000. Insert appends the new item at the end of the array. Choose the best description of bs
member variables size (count of items in the bag) and data (the array that holds the actual items) after we
execute these statements:
Bag b;
b. insert (5);
b. insert (4);
b.insert(6);
What will be the values of b.size and b.data after the statements?
a.
b.
c.
d.

b.size is 3, b.data[0] is 4, b.data[1] is 5, b.data[2] is 6


b.size is 3, b.data[0] is 5, b.data[1] is 4, b.data[2] is 6
b.size is 3, b.data[0] is 6, b.data[1] is 4, b.data[2] is 5
b.size is 3, b.data[0] is 6, b.data[1] is 5, b.data[2] is 4

(4)
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 carpets?
a. serc
b. carpets
c. steprac
d. ccaarrppeettss

(5)
In the linked list implementation of the stack class, where does the push member function place the
new entry on the linked list?
a.
At the head
b.
At the tail
c.
After all other entries that are greater than the new entry.
d.
After all other entries that are smaller than the new entry.

(6)

One difference between a queue and a stack is:

a.

Queues require dynamic memory, but stacks do not.

b.
c.
d.

Stacks require dynamic memory, but queues do not.


Queues use two ends of the structure; stacks use only one.
Stacks use two ends of the structure, queues use only one.

I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer.
Which of these pointers will change during an insertion into a NONEMPTY queue?
a.
Neither changes
b.
Only front pointer changes.
c.
Only rear pointer changes.
d.
Both change.

I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer.
Which of these pointers will change during an insertion into an EMPTY queue?
a.
Neither changes
b.
Only front pointer changes.
c.
Only rear pointer changes.
Both change.

In a single function declaration, what is the maximum number of statements that may be recursive
calls?
a.
1
b.
2
c.
n (where n is the argument)
There is no fixed maximum

What is the maximum depth of recursive calls a function may make?


a.
1
b.
2
c.
n (where n is the argument)
d.
There is no fixed maximum

In which location do dynamic variables reside?


a.
b.
c.
d.

The code segment.


The data segment.
The heap.
The run-time stack

Which of the following is true regarding the maze generation?


Select correct option: Not Sure
Randomly remove walls until the entrance and exit cells are in the same set
Removing a wall is the same as doing a union operation
Do not remove a randomly chosen wall if the cells it separates are already in the same set
All of the given
Heap can be used to implement
Select correct option:
Stack
Linked list
Queue
Priority Queue

Question: ( Marks: 1 ) - Please choose one


In a complete binary tree of depth 5 the number of non-leaf nodes is

15
32
16
31

Question: ( Marks: 1 ) - Please choose one


Which of the following is NOT a linear data structure?

Linked List
Stack
Queue
Tree (page 121)

Recursive function calls are implemented internally using a data structure

Stack
Link-List
Tree
Queue

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


A queue where the de-queue operation depends not on FIFO, is called a priority queue
False

True Page101
Question No: 2 ( Marks: 1 ) - Please choose one
The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should
Use better data structures
Increase the hard disk space (Page 5)
Use the better algorithm
Use as much data as we can store on the hard disk

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


Consider the function X as under
int X (int& Value)
{
return Value;
}
Now a and b are integers in a calling function. Which one of the following is a valid call to the above function
X.
a = X (b) ;
a = X (&b) ;
a = X (*b) ;
None of the given options
Here function argument passing by reference method is used, so when we call a function we will give the
variable reference as parameter.

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


In the call by value methodology, a copy of the object is passed to the called function.
False
True(Page 202)

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


The tree data structure is a
Linear data structure
Non-linear data structure(Page 112)
Graphical data structure
Data structure like queue
Question No: 6 ( Marks: 1 ) - Please choose one
When should you use a const reference parameter?

Whenever the parameter has huge size.


Whenever the parameter has huge size, the function changes the parameter within its body, and
you do NOT want these changes to alter the actual argument.
Whenever the parameter has huge size, the function changes the parameter within its body, and you DO
want these changes to alter the actual argument.
Whenever the parameter has huge size, and the function does not change the parameter within its body.
Declaring a parameter as a const simply means that the function cant change the value of its parameters.

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


Here is the start of a C++ class declaration:
class foo
{
public:
void x(foo f);
void y(const foo f);
void z(foo f) const;
...
Which of the three member functions can alter the PRIVATE member variables of the foo object that activates
the function?
Only x can alter the private member variables of the object that activates the function.
Only y can alter the private member variables of the object that activates the function.
Only z can alter the private member variables of the object that activates the function.
Two of the functions can alter the private member variables of the object that activates the
function.
Only the x and y can alter the private member variable of the foo class object. Last Option is more
Correct but not exact. In the last option the two function name are not mentioned

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


What is the maximum depth of recursive calls a function may make?
1
2
n (where n is the argument)
There is no fixed maximum
Question No: 9 ( Marks: 1 ) - Please choose one
Suppose n is the number of nodes in a complete Binary Tree then maximum steps required for a search
operation are,
Log2 (n+1) -1(Page 139)
Log2 (n+1)
Log2 (n) 1
Log2 (n)
Question No: 10 ( Marks: 1 ) - Please choose one
In the linked list implementation of the stack class, where does the push member function places the new entry
on the linked list?

At the head(Page 53)


At the tail
After all other entries that are greater than the new entry.
After all other entries that are smaller than the new entry.

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


Suppose we have a circular array implementation of the queue class, with ten items in the queue stored at
data[2] through data[11]. The CAPACITY is 42, i.e., the array has been declared to be of size 42. Where does
the push member function place the new entry in the array?
data[1]
data[2]
data[11]
data[12]

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


The expression AB+C* is called?
Prefix expression
Postfix expression (Page 70)
Infix expression
None of these

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


_________ is a binary tree where every node has a value, every node's left subtree contains only values less
than or equal to the node's value, and every node's right subtree contains only values that are greater then or
equal?
Strictly Binary Tree
Binary Search tree (sure)
AVL tree
All of these

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


Consider the following binary search tree (BST):

If node A in the BST is deleted, which two nodes are the candidates to take its place?
J and I
H and E
D and E
L and M
Question No: 15 ( Marks: 1 ) - Please choose one
Lets call the node as that requires re-balancing. Consider the two cases given below:
1) An insertion into left sub tree of the left child of a
2) An insertion into right sub tree of the right child of a.
Which of the following statement is correct about these two cases?
1) The insertion occurs outside (i.e., left-left or right-right) in cases 1 and 2 single rotation can fix the balance
in
these two cases.
2) The insertion occurs inside ((i.e., left-left or right-right) in cases 1 and 2. single rotation cannot fix the
balance in these two cases
Question No: 16 ( 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: 17
AVL Tree is,
Non Linear data structure
Linear data structure
Hybrid data structure (Mixture of Linear and Non Linear)
None of the given options.

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


Which one of the following statement is NOT correct .
In linked list the elements are necessarily to be contiguous
In linked list the elements may locate at far positions in the memory
In linked list each element also has the next to it
In an array the elements are contiguous

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


Each operator in a postfix expression refers to the previous ________ operand(s).
One
Two (Page 67)
Three
Four

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


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(Page 213)
None of the given options

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


Suppose currentNode refers to a node in a linked list (using the Node class with member variables called data
and nextNode). What statement changes currentNode so that it refers to the next node?
currentNode ++;
currentNode = nextNode;
currentNode += nextNode;
currentNode = currentNode->nextNode;

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


A queue where the de-queue operation depends not on FIFO, is called a priority queue
False
True (Page 101)

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


Which one is a self- referential data type?
Stack
Queue
Link list
All of these

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


Each node in doubly link list has,
1 pointer
2 pointers (Page 39)
3 pointers
4 pointers

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


I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of
these pointers will change during an insertion into an EMPTY queue?
Neither changes
Only front pointer changes.
Only rear pointer changes.
Both change.
Question No: 10 ( Marks: 1 ) - Please choose one
Consider the following tree.

How many of the nodes have at least one sibling?


8
7
5
6
A sibling is an element that shares the same parent with another element

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


The nodes with no successor are called _________
Root Nodes
Leaf Nodes
Both of these
None of these

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


AVL Tree is,
Non Linear data structure Click here for detail
Linear data structure
Hybrid data structure (Mixture of Linear and Non Linear)
None of the given options.

Question No: 13 ( 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: 14 ( Marks: 1 ) - Please choose one


A binary search tree should have minimum of one ________ node/s at each level,
One
Two
Three
Four

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


Consider the following statements.
(i) A binary tree can contain at least 2L Nodes at level L.
(ii) 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.
(iii) The total number of nodes (Tn ) in a complete binary tree of depth d is 2 d+1 - 1 .
(iv) The height of the complete binary tree can be written as h = log 2 (Tn+1)-1 where Tn is Total number of
Nodes.

Which one of the following is correct in respect of the above statements regarding the Binary trees?
(i) and (iii) only
(i), (ii) and (iii) only
(ii) and (iii) only
(ii), (iii) and (iv) only

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


+ is a _________operator.
Unary
Binary(Page 64)
Ternary
None of the above

MIDTERM EXAMINATION
Spring 2010
Question No: 1 ( M a r k s: 1 )
A subscript of an array may be an integer or an integer expression.
True Click here for detail
False

Question No: 2 ( M a r k s: 1 )
Doubly Linked List always has one NULL pointer.
True
False(Page 43)

Question No: 3 ( M a r k s: 1 )
In which of the traversal method, the recursive calls can be used to traverse a binary tree ?
In preorder traversal only (Page 143)
In inorder traversal only
In postorder traversal only
All of the given options

Question No: 4 ( M a r k s: 1 )
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(Page 213)
None of the given options

Question No: 5 ( M a r k s: 1 )
Suppose currentNode refers to a node in a linked list (using the Node class with member variables called data
and nextNode). What boolean expression will be true when cursor refers to the tail node of the list?
(currentNode == null)
(currentNode->nextNode == null)
(nextNode.data == null)
(currentNode.data == 0.0)
Question No: 6 ( M a r k s: 1 ) - Please choose one
Suppose that the class declaration of SomeClass includes the following function prototype.
bool LessThan( SomeClass anotherObject );
Which of the following tests in the client code correctly compares two class objects alpha and beta?
if (alpha < beta)
if (alpha.LessThan(beta)) Click here for detail
if (LessThan(alpha, beta))
if (LessThan(alpha).beta)
Question No: 7 ( M a r k s: 1 )
In C what is the operation that you can not do with primitive types?
Assign a value to primitive type using a literal
Declare primitive types to be constant using the Const keyword
Create a new instance of primitive type with New keyword Click here for Detail
None of these
Question No: 8 ( M a r k s: 1 )
The operation for adding an entry to a stack is traditionally called :
add
append
insert
push(Page 53)
Question No: 9 ( M a r k s: 1 )
The operation for removing an entry from a stack is traditionally called:
delete
peek
pop(Page 53)
remove
Question No: 10 ( M a r k s: 1 )
Consider the following sequence of push operations in a stack:
stack.push(7);
stack.push(8);
stack.push(9);
stack.push(10);
stack.push(11);
stack.push(12);

7 8 9 10 11 12
9 8 11 10 7 12
9 10 8 11 12 7
9 10 8 12 7 11
Question No: 11 ( M a r k s: 1 )
________ is the maximum number of nodes that you can have on a stack-linked list ?
Zero
2n (where n is the number of nodes in linked list)
Any Number Click here for detail
None of these
Question No: 12 ( M a r k s: 1 )
Which of the following can be used to reverse a string value,
StackClick here for detail
Queue
Both of these
None of these
Question No: 14
AVL Tree is,
( M a r k s: 1 )
Non Linear data structure Click here for detail
Linear data structure
Hybrid data structure (Mixture of Linear and Non Linear)
None of the given options.
Question No: 15 ( M a r k s: 1 )
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 hasnt 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 optionsClick here for detail
Question No: 16 ( M a r k s: 1 )
An array is a group of consecutive related memory locations.
True Click here for detail
False

MIDTERM EXAMINATION
Spring 2010
Question No: 1 ( Marks: 1 ) - Please choose one
In an array we can store data elements of different types.
True
False (Page 7)
Question No: 2 ( Marks: 1 ) - Please choose one
In an array list the current element is
The first element Click here for detail
The middle element
The last element
The element where the current pointer points to
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 Click here for detail
Call by passing reference of the argument
Call by passing the address of the argument
Question No: 4 ( Marks: 1 ) - Please choose one
Which one of the following statements is NOT correct?
Array size can be changed after its creation. Click here for detail
Link List size can be changed after its creation
Binary Search Tree size can be changed after its creation
AVL Tree size can be changed after its creation
Question No: 5 ( Marks: 1 ) - Please choose one
Suppose that the class declaration of SomeClass includes the following function prototype. bool LessThan(
SomeClass
anotherObject );
Which of the following tests in the client code correctly compares two class objects alpha and beta?
if (alpha < beta)
if (alpha.LessThan(beta))
if (LessThan(alpha, beta))
if (LessThan(alpha).beta)
Question No: 6 ( Marks: 1 ) - Please choose one
A queue is a----- data structure, whereas a stack is a -----data structure.
FIFO, LIFO (Page 161,54)
LIFO,FIFO
none of these
both of these

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


Which one of the following operators has higher priority than all of others?
Multiplication operator
Minus operator
Plus operator
Exponentiation operator
Question No: 8 ( Marks: 1 ) - Please choose one
Each node in Binary Search Tree has
1 pointer
2 pointers
3 pointers
4 pointers
Question No: 9 ( Marks: 1 ) - Please choose one
Four statements about trees are below. Three of them are correct. Which one is INCORRECT?
Trees are recursively defined multi-dimensional data structures tree
The order of a tree indicates a maximum number of children allowed at each node of the
A search tree is a special type of tree where all values (i.e. keys) are ordered
If Tree1's size is greater than Tree2's size, then the height of Tree1 must also be greater than Tree2's height.
Click here for detail
Question No: 10 ( Marks: 1 ) - Please choose one
Which of the following is "TRUE" about arrays,
We can increase the size of arrays after their creation.
We can decrease the size of arrays after their creation.
We can increase but can't decrease the size of arrays after their creation.
We can neither increase nor decrease the array size after their creation.
Question No: 11 ( Marks: 1 ) - Please choose one
Searching an element in an AVL tree take maximum in AVL tree,
Log2(n+1)
time (where n is no. of nodes
Log2(n+1) -1
1.44 Log2n (Page 227)
1.66 Log2n

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


There is/are case/s for rotation in an AVL tree,
1
3
2
4(Page 229)

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


Consider the following statements.
(i) A binary tree can contain at least 2L Nodes at level L.
(ii) A complete binary tree of depth d is a binary tree that contains 2L Nodes at each level L
between 0 and d, both inclusive.
(iii) The total number of nodes (Tn ) in a complete binary tree of depth d is 2 d+1 - 1 .
(iv) The height of the complete binary tree can be written as h = log 2 (Tn+1)-1 where Tn is
Total number of Nodes.
Which one of the following is correct in respect of the above statements regarding the Binary trees?
(i) and (iii) only
(i), (ii) and (iii) only
(ii) and (iii) only
(ii), (iii) and (iv) only Click here for detail

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


Consider the following infix expression.
5 + 6/2
If one converts the above expression into postfix, what would be the resultant expression?
56/ + 2
562/+ (Page 66)
56/2+
/62 + 5

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


Which of the following is a non linear data structure?
Linked List
Stack
Queue
Tree(Page 112)

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


+ is a operator.
Unary
Binary (Page 64)
Ternary
None of the above

MIDTERM EXAMINATION
Spring 2010
1. Addition of new items in stack make the pointer ------------ by 2

a. Increment, bits

b. Increment, bytes
c. Decrement, bits
d. Decrement, bytes

Click here for detail

2. Next item in a linked list is known as


a. Index
b. Item
c. Node
Click here for detail
d. Child
3. What will be the postfix notation of 5+6/2.
a. 56+/2
b. 562+/
c. 562/+(Page 66)
d. 5+62/
4. In an AVL tree to delete a parent with two childs in a straight line following rotations will be required:a. Single
b. Double
c. Triple
d. None.
5. To check the depth of an AVL tree following time will be taken:a. 1.66 Log2n
b. 1.44 Log2n (Page 227)
c. Log2 (n+1)-1
d. 1.66 Log2n (n+1)
6. BST is a Structure:a. Linear
b. Non Linear
c. Circular
d. None of Above

Click here for detail

7. After creation of an array:a. Size can be increase but can not be decreased.
b. Size can be decreased but can not be increased.
c. Size can neither be increased nor be decreased. Click here for detail
d. Size can be increased and can also be decreased.
8. Each node in a BST has Pointers:a. 1
b. 2
Click here for detail
c. 3
d. 4

9. Highest Operators Precedence is of the following operator:a. Plus


b. Minus
c. MultiplyClick here for detail
d. Exponentiation
10. Following are the linear data structures:a. Stacks
b. Queues
c. Both a & b (Page 52, 87)
d. None of the above
11. Each entry which points to a null value in a Singly Linked List is known as:a. Node
b. First Node
c. Last Node
d. Head Node

12. Non recursive calls are faster than the Recursive calls.
a. True (Page 323)
b. False
13. Tree data structure is a
a. Linear
b. Non Linear (Page 112)
c. Circular
d. None of Above

14. What will be the valid postfix notation of A+B*C-D


a. ABC+*Db. ABC*+D- (According to rule)
c. ABCD+-*
d. AB+D*C

15. When an operator is used in between two operands this is which type of notation
a. Prefix
b. Postfix
c. Infix (Page 64)
d. None of the Above

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


Which one of the following is a valid postfix expression?
ab+c*d abc*+d- (According to rule)
abc+*d (abc*)+dQuestion No: 2 ( Marks: 1 ) - Please choose one
The tree data structure is a
Linear data structure
Non-linear data structure (Page 112)
Graphical data structure
Data structure like queue
Question No: 3 ( Marks: 1 ) - Please choose one
A Compound Data Structure is the data structure which can have multiple data items of same type or of
different types. Which of the following can be considered compound data structure?
Arrays Click here for detail
LinkLists
Binary Search Trees
All of the given options
Question No: 4 ( Marks: 1 ) - Please choose one
Suppose a pointer has been declared in main but has not assigned any variable address then
That pointer points to First byte in main function
That pointer contains a NULL value
None of these
That pointer points to any memory address

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


Here is the start of a C++ class declaration:
class foo
{
public:
void x(foo f);
void y(const foo f);
void z(foo f) const;
...
Which of the three member functions can alter the PRIVATE member variables of the foo object that
activates the function?
Only x can alter the private member variables of the object that activates the function.
Only y can alter the private member variables of the object that activates the function.
Only z can alter the private member variables of the object that activates the function.

Two of the functions can alter the private member variables of the object that activates the function.
Only the x and y can alter the private member variable of the foo class object. Last Option is more correct but
not exact. In the last option the two function name are not mentioned
Question No: 6 ( Marks: 1 ) - Please choose one
The operation for removing an entry from a stack is traditionally called:
delete
peek
pop (Page 53)
remove
Question No: 7 ( Marks: 1 ) - Please choose one
Which statement of the following statements is incorrect?
Lists can be implemented by using arrays or linked lists
A list is a sequence of one or more data items
Stack is a special kind of list in which all insertions and deletions take place at one end
Stacks are easier to implement than lists
Question No: 8 ( Marks: 1 ) - Please choose one
Parameters in function call are passed using,
Stack (Page 80)
Queue
Binary Search Tree
AVL Tree
Question No: 9 ( Marks: 1 ) - Please choose one
Consider the following sequence of push operations in a stack:
stack.push(7);
stack.push(8);
stack.push(9);
stack.push(10);
stack.push(11);
stack.push(12);
7 8 9 10 11 12
9 8 11 10 7 12
9 10 8 11 12 7
9 10 8 12 7 11

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


What is the maximum depth of recursive calls a function may make?
1
2
n (where n is the argument)
There is no fixed maximum

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


Consider the following function:
void test_a(int n)
{
cout << n << " ";
if (n>0)
test_a(n-2);
}
What is printed by the call test_a(4)?
420
024
02
24
Question No: 12 ( Marks: 1 ) - Please choose one
Queue follows,
Last in First out
First in Last out
First in First out(Page 87)
None of these
Question No: 13 ( Marks: 1 ) - Please choose one
is a binary tree where every node has a value, every node's left subtree contains only values less than or equal
to the
node's value, and every node's right subtree contains only values that are greater then or equal ?
Strictly Binary Tree
Binary Search tree
Click here for detail
AVL tree
All of these
Question No: 14 ( Marks: 1 ) - Please choose one
Four statements about trees are below. Three of them are correct. Which one is INCORRECT?
Trees are recursively defined multi-dimensional data structures
Click here for detail
The order of a tree indicates a maximum number of childen allowed at each node of the tree
A search tree is a special type of tree where all values (i.e. keys) are ordered
If Tree1's size is greater than Tree2's size, then the height of Tree1 must also be greater than
Tree2's height.
Question No: 15 ( 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: 16 ( Marks: 1 ) - Please choose one


Is a data structure that can grow easily dynamically at run time without having to copy existing elements?
Array
List
Both of these
None of these

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


Which one of the following statement is NOT correct .
In linked list the elements are necessarily to be contiguous
Click here for detail
In linked list the elements may locate at far positions in the memory
In linked list each element also has the address of the element next to it
In an array the elements are contiguous
Question No: 2 ( Marks: 1 ) - Please choose one
In a program a reference variable, say x, can be declared as
int &x ;
Click here for detail
int *x ;
int x ;
None of the given options
Question No: 3 ( Marks: 1 ) - Please choose one
Linked lists are collections of data items "lined up in a row" , insertions and deletions can be made only
at the front and the back of a linked list.
True
False
Click here for detail

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


A Linear Data Structure is the data structure in which data elements are arranged in a sequence or a
linear list. Which of the following is Non Linear Data Structure?
Arrays
LinkLists
Binary Search Trees
Click here for detail
None of these

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


A queue where the de-queue operation depends not on FIFO, is called a priority queue
False
True (Page 101)

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


Which one of the following statements is correct?

size is fixed once it is created


Link List size is fixed once it is created.
Binary Search Tree size is fixed once it is created
AVL Tree size is fixed once it is created

Click here for detail

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


Which one of the following is correct about pointers?
They always point to different memory locations
They may point to a single memory location
The address of two pointer variables is same
None of these

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


Which of the following abstract data types are NOT used by Integer Abstract Data type group?

Int
float
Click here for detail
long

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


The operation for adding an entry to a stack is traditionally called :
add
append
insert
push(Page 53)
Question No: 10 ( Marks: 1 ) - Please choose one
The operation for removing an entry from a stack is traditionally called:
delete
peek
pop(Page 53)
remove

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


We can add elements in QUEUE From _________
Front
Rear (Page 91)
From Both Rare and Front
None of these

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


The difference between a binary tree and a binary search tree is that ,a binary search tree has
two children per node whereas a binary tree can have none, one, or two children per node
Click here for detail
in binary search tree nodes are inserted based on the values they contain
in binary tree nodes are inserted based on the values they contain

of these
Question No: 13 ( Marks: 1 ) - Please choose one
Suppose n is the number of nodes in a complete Binary Tree then maximum steps required for a search
operation are,
Log2 (n+1) -1 (Page 139)
Log 2 (n+1)
Log 2 (n) 1
Log 2 (n)
Question No: 14 ( Marks: 1 ) - Please choose one
The following is a segment of a C program.
int pqr(BinaryNode t)
{ if (t == null )
return -1;
else
return 1+max(pqr(t.left),pqr(t.right)) }
Identify, what the above program intend(s) to do?
Compute the height of a binary tree using an in-order traversal
Compute the height of a binary tree using a pre-order traversal
Compute the depth of a binary tree using a pre-order traversal
Compute the depth of a
binary tree using a post-order traversal
Question No: 15 ( Marks: 1 ) - Please choose one
Consider the following infix expression:
3 + 5 * 6 7 * (8 + 5)
Which of the following is a correct equivalent expression(s) for the above?
3 65+*7 5 8 + -*
3 657 5 8+* + -*
3 5 6+*7 8 5 + -*
3 5 6 * + 7 8 5 + * -

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


An array is a group of consecutive related memory locations.
TrueClick here for detail
False
Question No: 17
( Marks: 1 )

Is this a correct statement? Give answer in Yes or No.


A node cannot be deleted, when the node to be deleted has both left and right subtrees.
False ---- No, it can be deleted.
Question No: 18 ( Marks: 1 )
Deleting a leaf node in binary search tree involves setting ______ pointer/s of that nodes parent as null.
1
2
3
4

Select the one FALSE statement about binary trees:


a. Every binary tree has at least one node.
b. Every non-empty tree has exactly one root node.
c. Every node has at most two children.
d. Every non-root node has exactly one parent.

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

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
In the statement int x[6]; , we cannot assign any value to x because x is
not an value.
True
False

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

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

We can add elements in QUEUE From _________

Front
Rear
From Both Rare and Front
None of these

Consider the following tree.

How many descendants does the root have?


5
6
7
8

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 2L
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.

The following are statements related to queues.


1. The last item to be added to a queue is the first item to be removed
2. A queue is a structure in which both ends are not used
3. The last element hasnt to wait until all elements preceding it on the queue
are removed
4. 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
The________ method of list data structure removes the element residing at the current position.

Add
next
remove
find

The depth of a binary tree is


Select correct option:
Total number of nodes in the tree
Number of leaf nodes in the tree
Number of non-leaf nodes in the tree
Maximum level of a leaf*

In which traversal method, the recursive calls can be used to traverse a binary tree ?
Select correct option:
In preorder traversal only
In inorder traversal only
In postorder traversal only
All of the given options*

Which of the following statement is false?


Select correct option:
Arrays are dense lists and static data structure
data elements in linked list need not be stored in adjecent space in memory
pointers store the next data element of a list*
linked lists are collection of the nodes that contain information part and next pointer

Which of the following statement related to deleting nodes from a binary search tree is NOT
correct ?
Select correct option:
The node to be deleted has no children; the node can be deleted without any
adjustment. Delete the leaf node and set reference from its parent to null reference.
The node to be deleted has two sub-trees. The method to be used is to replace the node
being deleted by the rightmost child of its left sub-tree.
The node to be deleted has two sub-trees. The method to be used is to replace the node
being deleted by the leftmost child of its right sub-tree.
The node to be deleted has no children; the node can be deleted with very few
adjustments to the tree.* (not sure)

Which one of the following calling method does not change the original value of the argument in
the calling function?
Select correct option:
Call by passing reference of the argument
Call by passing the address of the argument
Call by passing the value of the argument*
None of the given options
In-order traversal method traverses the data in
Select correct option:
Non sorted order
Random order
Sorted order*
None of the given
The depth of a complete binary tree is given by _________
Select correct option:
Dn = n log2n
Dn = n log2n+1
Dn = log2n
Dn = log2(n+1)-1*

If we write functions for recursive and non recursive in order traversal method of BST, what will
be the difference between its functions prototypes?
Select correct option:
Different return types
Different function names*
Different arguments list
Nothing will be different

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


Select correct option:
int &x ;*
int *x ;
int x ;
None of the given options

Which one is not the property of binary tree?


Select correct option:
Every node in binary tree should have maximum two children.
Only one node should have two parents.*

Sibling nodes should have same parent.


None of given options.

1. Here is a piece of code from inset method of BST, to search the correct position of newly
created node.
while( *info != *(p->getInfo()) && q != NULL ) { p = q;
if( *info < *(p->getInfo()) ) q = p->getLeft();
else q = p->getRight(); }
If there are 8 levels in a tree then, how many times the while loop will be executed.
Select correct option:
4
8*
10
16

During in-order traversal using recursive calls, if we found a node is NULL.


It means this node will satisfy following condition.
Select correct option:
It will not have left child
It will not have right child
It will not have both left and right children
None of given options *

During deletion of node from BST, if we found this node dont have in-order successor and
predecessor.
It means this node is __________.
Select correct option:
Left most node in the binary search tree
Right most node in binary search tree
Root node * (not sure)
None of given options

Longest path from root node to farthest leaf node is called ________ of tree
Select correct option:
Level
Length
Depth *
Node level

Binary search algorithm cannot be applied to ____


Select correct option:
sorted linked list *
sorted binary trees
sorted linear array
None of given options

Deleting a _____ node in BST is a _______ case


Select correct option:
Root, simplest
Left child, simplest
Right child, simplest
Leaf, simplest *

Which one is not the property of binary tree?


Select correct option:
Every node in binary tree should have maximum two children.
Only one node should have two parents. *
Sibling nodes should have same parent.
None of given options.

In-order traversal method traverses the data in


Select correct option:
Non sorted order
Random order
Sorted order *
None of the given

In which traversal method, the recursive calls can be used to traverse a binary tree ?
Select correct option:
In preorder traversal only
In inorder traversal only
In postorder traversal only
All of the given options *
Question # 5 of 10 ( Start time: 02:07:23 AM ) Total Marks: 1
Which one is the correct function call for the following function of calculating cube? int
cube(int& num) { . . . }
Select correct option:
cube(&num)
cube(&&num)

cube(*num)
cube(num) *
Question # 6 of 10 ( Start time: 02:08:02 AM ) Total Marks: 1
The depth of a complete binary tree is given by _________
Select correct option:
Dn = n log2n
Dn = n log2n+1
Dn = log2n
Dn = log2(n+1)-1 *

Question # 7 of 10 ( Start time: 02:08:41 AM ) Total Marks: 1


1. Here is a piece of code from inset method of BST, to search the correct position of newly
created node. while( *info != *(p->getInfo()) && q != NULL ) { p = q; if( *info < *(p>getInfo()) ) q = p->getLeft(); else q = p->getRight(); } If there are 8 levels in a tree then, how
many times the while loop will be executed.
Select correct option:
4
8*
10
16
Question # 8 of 10 ( Start time: 02:09:22 AM ) Total Marks: 1
If we write functions for recursive and non recursive inorder traversal method of BST, what will
be the difference between its functions prototypes?
Select correct option:
Different return types
Different function names *
Different arguments list
Nothing will be different
Question # 9 of 10 ( Start time: 02:09:43 AM ) Total Marks: 1
When converting binary tree into extended binary tree, all the original nodes in binary tree are
____
Select correct option:
Internal nodes on extended tree*
External nodes on extended tree
Vanished on extended tree
None of above
(dont know)
Question # 10 of 10 ( Start time: 02:10:07 AM )
Total Marks: 1
A binary tree whose every node has either zero or two children is called _________
Select correct option:
Complete binary tree

Binary search tree


Strictly binary tree *
None of above
Quiz Start Time: 09:51 PM
Time Left
66
sec(s)
Question # 4 of 10 ( Start time: 09:52:58 PM ) Total Marks: 1
Leaf node of binary search tree contains ________
Select correct option:
One Null pointer
Three Null pointers
Two Null pointers*
All of the given

Quiz Start Time: 09:51 PM


Time Left
52
sec(s)
Question # 9 of 10 ( Start time: 09:55:42 PM ) Total Marks: 1
During deletion of node from BST, if we found this node dont have in-order successor and
predecessor.
It means this node is __________.
Select correct option:
1 Left most node in the binary search tree
2 Right most node in binary search tree*
3 Root node
4 None of given options

Quiz Start Time: 09:51 PM


Time Left
51
sec(s)
Question # 10 of 10 ( Start time: 09:56:53 PM )
Total Marks: 1
Longest path from root node to farthest leaf node is called ________ of tree
Select correct option:
Level
Length
Depth*
Node level
Quiz Start Time: 10:20 PM

Time Left
72
sec(s)
Question # 6 of 10 ( Start time: 10:22:50 PM ) Total Marks: 1
Suppose there is a BST with elements, 13,3,14,1,4,18 and 2. Now if the method insert(4) is
called, which message will be displayed?
Select correct option:
Node is inserted in root
Node is inserted in left subtree
Node is inserted in right subtree
Node already exist in the tree*

Quiz Start Time: 10:20 PM


Time Left
62
sec(s)
Question # 8 of 10 ( Start time: 10:24:41 PM ) Total Marks: 1
Which of the following statement is false?
Select correct option:
1 Arrays are dense lists and static data structure
2 data elements in linked list need not be stored in adjecent space in memory
3 pointers store the next data element of a list*
4 linked lists are collection of the nodes that contain information part and next pointer

Sub-tree of binary search tree should be ________.


Select correct option:
Binary tree*
Binary search tree
Complete binary tree
None of given options
In-order traversal method traverses the data in
Select correct option:
Non sorted order
Random order
Sorted order*
None of the given
A binary tree whose every node has either zero or two children is called _________

Select correct option:


Complete binary tree
Binary search tree
Strictly binary tree*
None of above
To represent hierarchical relationship between elements, which data structure is suitable?
Select correct option:
Dequeue
Priority
Stack
Tree*
In which traversal method, the recursive calls can be used to traverse a binary tree ?
Select correct option:
In preorder traversal only
In inorder traversal only
In postorder traversal only
All of the given options*
The post order traversal of a binary tree is DEBFCA. Find out the pre order traversal
Select correct option:
1ABFCDE*(not sure)
2ADBFEC
3ABDECF
4ABDCEF

For a perfect binary tree of height 4. What will be the sum of heights of nodes?
31
30 27
26
For a perfect binary tree of height h, having N nodes, the sum of heights of nodes is
_____________.
N (h 1)
N (h + 1)
N1
N1+h
If we want to find median of 50 elements, then after applying buildHeap method, how many
times deleteMin method will be called ?
5
25

35
50

Which of the following heap method increase the value of key at position p by the amount
delta?
increaseKey(p,delta)
decreaseKey(p,delta)
preculateDown(p,delta)
remove(p,delta)
www.vuzs.net
The main reason of using heap in priority queue is
improve performance
code is readable
less code
heap can't be used in priority queues
The total number of nodes on 10th level of a perfect binary tree are :
256
512
1024
Can't be determined
Which property of equivalence relation is satisfied if we say: Ahmad R(is related to) Ahmad
Reflexivity
Symmetry
Transitivity
All of the above
Which of the following heap method lowers the value of key at position p by the amount
delta?
increaseKey(p,delta)
decreaseKey(p,delta)
preculateDown(p,delta)
remove(p,delta)
We can build a heap in _____ time.
Linear
Exponential

Polynomial
None of the given options
we can build a heap in linear time using n calls of percolate_down()

If a tree has 50 nodes, then the total edges/links in the tree will be :
55
51
50
49 N-1= 49

Consider the following sequence of push operations in a stack:


stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
stack.push(5);
stack.push(6);
You can insert as many stack.pop()s as you like in the above sequence of stack.pushs to
get a desired output. Which of the following cannot be an output?
A. 123456
B. 325416
C. 342561
D. 342615
E. 342165
If memory address of first node in linked list is 1052 then 3rd node address
will be _____. Note: consider one node takes 1 byte.
Select correct option:
1053
1054
1055
None of given options

The memory address of the first element of an array is called _______.


Select correct option:
Floor address
Foundation address
First address
Base address

Each node in doubly link list has,


Select correct option:
1 pointer

2 pointers (Page 39)


3 pointers
4 pointers

---------------When an executable program runs, it is loaded in the computer memory and


becomes a_________.
Select correct option:
Thread
.h file
Process
None of the above
---------------------

Suppose you are writing a class for Node class and forgot to write the
constructor of the
class, then

Compiler will give compile time error


Complier will give run time error
Compiler will automatically generate a default constructor

If we use an array for implementing list, then for simplicity, it is good to


use the start
index from ________________.
-1
0
1
2
What will out of following postfix expression? 3 1 3 * + 4 7 6 + - * 2 5 +
61
62
63
ans 62
-----------------

Consider a max heap, represented by the following array; 40,30,20,10,15,16,17,18,4


After inserting a nodes with value 35.Which of following is the updated max heap?
40,30,20,10,15,16,17,8,4,35
40,30,20,10,35,16,17,8,4,15
40,35,20,10,30,16,17,8,4,15
40,35,20,10,15,16,17,18,4,30

A Threaded Binary Tree is a binary tree in which every node that does not have a
right child has a THREAD (in actual sense, a Link) ___________Successor.
Preorder
Inorder
Postorder
Leveloder

Which of the following is a property of binary tree?


A Binary tree with N internal nodes has 2+N links, N-1 links to internal nodes and N+1 links to
external nodes
A Binary tree with N internal nodes has 2*N links, N-1 links to internal nodes and N+1 links to
external nodes.
A Binary tree with N internal nodes has 2-N links, N-1 links to internal nodes and N+1 links to
external nodes.
A Binary tree with N internal nodes has 2N links, N+1 links to internal nodes and N-1 links
to external nodes.

A Threaded Binary tree is a binary tree in which every node that does not have a
right child has a THREAD (in actual sense, a link)_____________ successor.
Preoder
Inorder
Postorder
Levelorder
If there are 56 internal nodes in a binary tree then how many external nodes this
binary tree will have?
54
55
56
57

Which of the following statement is correct?


A threaded Binary tree is a binary tree in which every node that does not have a left
child has a THREAD (in actual sense, a link) to its INORDER successor.
A threaded Binary tree is a binary tree in which every node that does not have a
right child has a THREAD (in actual sense, a link) to its PREORDER successor.
A threaded Binary tree is a binary tree in which every node that does not have a left
child has a THREAD (in actual sense, a link) to its INORDER successor.
A threaded Binary tree is a binary tree in which every node that does not have a right
child has a THREAD (in actual sense, a link) to its POSTORDER predecessor.

It is necessary fro Huffman encoding tree to be,


AVL tree
Binary tree
Complete binary Tree
None of these

A binary tree with 45 internal nodes has _________ links to external nodes.

44
45
46
90

In which of the following tree, parent nodes has key greater than or equal to its
both children?
Max heap
Binary search tree
Threaded Binary tree
Complete Binary tree

If one pointer of the nodes in a binary tree is NULL then it will be a/an
Inner node
Leaf node
External node
Root node

If there are N external nodes is a binary tree then what will be the no. of the
internal nodes in this binary tree?
N-1
N
N+1
N+2

See the below code and fill the appropriate answer for? Void
fastlnorder(TreeNod+p) {while((p+nextInorder(p)) !+ ? ) cout << p->getInfo();}
Dummy
rootNode
LTH
RTH

In threaded binary tree, the NULL pointer are replaced by the.


Preorder successor or Predecessor
Inorder successor or predecessor
Postorder successor or predecessor
NULL pointer are not replaced

In which of the following tree, parent nodes has a key greater than or equal to its
both children?
Max heap
Binary search tree
Threaded Binary three
Complete Binary tree

In Complete binary tree the bottom level is filled from _______.


Left to right

Right to left
Not filled at all
None of the given options

If the bottom level of a binary tree is NOT completely filled, depicts that the tree is
NOT a ________
Complete Binary tree
Threaded Binary Tree
Expression tree
Perfectly compete Binary tree

If an expression tree is correct then its root should have,


An operator
(
)
an operand

In threaded binary tree, the NULL pointers are replaced by the.


Preorder successor or predecessor
Inorder successor or predecessor
Postorder successor or predecessor
NULL pointer are not replaced

A complete binary tree is a tree that is ________ filled, with the possible
exception of the bottom level.
Partially
Completely
Incompletely
Partly

If the bottom level of a binary tree is not completely filled, depicts that the tree is
not a _________.
Expression tree
Threaded binary tree
Complete binary tree
Perfectly complete binary tree

An expression tree will always be a,


Complete binary tree
Binary search tree
Heap AVL tree

Which of the following is a property of binary tree?


A binary tree of N external nodes has N internal node
A Binary tree of N internal nodes has N+1 external node
A Binary tree of N external nodes has N+1 internal node
A Binary tree of N internal has N-1 external node

In a threaded binary tree which nodes have NULL child pointers,


All leaf nodes
Nodes other then leaf nodes
Root Node
None of the nodes

In threaded binary tree, the NULL pointers are replaced by the


preorder successor or predecessor
inorder successor or predecessor
postorder successor or predecessor
NULL pointers are not replaced

A complete binary tree is a tree that is _______ filled, with the possible exception
of the bottom level.
partially
completely
incompletely
partly

Which one of the following is TRUE about iteration?


Iterative function calls consumes a lot of memory
Threaded Binary Trees use the concept of iteration
Iteration extensively uses stack memory
Recursion is more efficient than iteration

We implement the heap by ____________ .


Threaded Tree
AVL tree
Complete binary tree
Expression

Which of the following statement concerning heaps is NOT true?


Traversing a heap in order provides access to the data in numeric or alphabetical
order.
Removing the item at the top provides immediate access to the key value with highest
(or lowest) priority.
Inserting an item is always done at the end of the array, but requires maintaining the
heap property.
A heap may be stored in an array.

Which of the following statement concerning heaps is NOT true?


A heap can be stored in a binary search tree.
A heap can be stored in an array.
A heap can be used to implement a priority queue.
A heap can be used to sort data.

A complete binary tree is a tree that is _________ filled, with the possible
exception of the bottom level.
partially
completely
incompletely
partly

By using __________we avoid the recursive method of traversing a Tree, which


makes use of stacks and consumes a lot of memory and time.
Binary tree only
Heap data structure
Huffman encoding

Which of the following statement is true about dummy node of threaded binary
tree?
The left pointer of dummy node points to the itself while the right pointer points to the
root of tree.
The left pointer of dummy node points to the root node of the tree while the right pointer
points itself i.e. to dummy node.
The left pointer of dummy node points to the root node of the tree while the right pointer
is always NULL.
The right pointer of dummy node points to the itself while the left pointer is always
NULL.
Threaded binary tree

When a complete binary tree, represented by an array then for any array element
at position i, the parent is at position ______ .
2i-1
2i
2i+1
floor(i/2)

When a complete binary tree represented by an array then if right child is at


position 5 then left child will be at position _____
2
3
4
6

A binary tree with N internal nodes has _____ links, _______ links to internal
nodes and ________ links to external nodes.
2N, N-1, N+1
N-1, 2N, N+1
N+1, 2N, N-1
N+1, N-1, 2N

If a binary tree has N + 1 external nodes then,


It has N internal nodes.
It has N-1 internal nodes.
It has N/2 internal nodes.
It has N+2 internal nodes.

A binary tree with 45 internal nodes has _______links to external nodes.


44
45
46
90

Consider a binary tree, represented by the following array: 10,7,9,5,2,1,6,3,4 This


is a ________.
Min heap
Max heap (Not Sure)
Threaded binary tree
Binary Search tree

Consider a binary tree, represented by the following array: A,B,C,D,E,F,G,I Is it a


strictly binary tree ?
Yes
No

In threaded binary tree the NULL pointers are replaced by the


preorder successor or predecessor
inorder successor or predecessor
inorder successor or predecessor
NULL pointers are not replaced

Consider a binary tree, represented by the following array: A,B,C,D,E,F,G,H,I,J,K,L


Is it a strictly binary tree?
Yes
No

We implement the heap by ______________ .


Threaded Tree
AVL tree
Complete binary tree
Expression

If there are 56 internal nodes in a binary tree then how many external nodes this
binary tree will have?
54
55
56

57

Which of the following statements is correct property of binary trees?


A binary tree with N internal nodes has N+1 internal links.
A binary tree with N external nodes has 2N internal nodes.
A binary tree with N internal nodes has N+1 external nodes.
None of above statement is a property of the binary tree.

Which of the following is a property of binary tree?


A binary tree of N external nodes has N internal node.
A binary tree of N internal nodes has N+ 1 external node.
A binary tree of N external nodes has N+ 1 internal node.
A binary tree of N internal nodes has N- 1 external node.

Which of the following statement is true about dummy node of threaded binary
tree?
The left pointer of dummy node points to the itself while the right pointer points to
the root of tree.
The left pointer of dummy node points to the root node of the tree while the
right pointer points itself i.e. to dummy node
The left pointer of dummy node points to the root node of the tree while the right
pointer is always NULL.
The right pointer of dummy node points to the itself while the left pointer is
always NULL.

If the bottom level of a binary tree is NOT completely filled, depicts that the tree is
NOT a
Expression tree
Threaded binary tree
complete Binary tree
Perfectly complete Binary tree

Which of the following statement is correct about find(x) operation:


A find(x) on element x is performed by returning exactly the same node
that is found.
A find(x) on element x is performed by returning the root of the tree containing
x.
A find(x) on element x is performed by returning the whole tree itself containing
x.
A find(x) on element x is performed by returning TRUE.

If there are 23 external nodes in a binary tree then what will be the no. of internal
nodes in this binary tree?
23
2
21

22
f there are N external nodes in a binary tree then what will be the no. of internal nodes
in this binary tree?
N -1
N+1
N+2
N

Which of the following statement is correct?


A Threaded Binary Tree is a binary tree in which every node that does not have
a left child has a THREAD (in actual sense, a link) to its INORDER
successor.
A Threaded Binary Tree is a binary tree in which every node that does not have
a right child has a THREAD (in actual sense, a link) to its PREOREDR successor.
A Threaded Binary Tree is a binary tree in which every node that does not
have a right child has a THREAD (in actual sense, a link) to its INORDER
successor.
A Threaded Binary Tree is a binary tree in which every node that does not have
a right child has a THREAD (in actual sense, a link) to its POSTORDER successor.

By using __________we avoid the recursive method of traversing a Tree, which


makes use of stacks and consumes a lot of memory and time.
Binary tree only
Threaded binary tree
Heap data structure
Huffman encoding

Consider a min heap, represented by the following array:


10,30,20,70,40,50,80,60
After inserting a node with value 31.Which of the following is the updated min
heap?
10,30,20,31,40,50,80,60,70
10,30,20,70,40,50,80,60,31
10,31,20,30,40,50,80,60,31
31,10,30,20,70,40,50,80,60

In complete binary tree the bottom level is filled from ________.


Left to right
Right to left
Not filled at all
None of the given options

In case of deleting a node from AVL tree, rotation could be prolong to the root
node.
Yes
No


When an array of object is created dynamically then there is no way to provide
parameterized constructors for array of objects.
True
Flase

The _____ of the in a binary tree is defined as


the height of its left sub tree
minus the height
of its right sub
tree. Height
Balance
Depth
None of above
Question # 2 of 10 Total Marks: 1
In which case of insertion a single rotation can
make the AVL tree balanced?
An insertion into left subtree of the left child of .
An insertion into right subtree
of the left child of . An
insertion into left subtree of the
right child of . None of above.

Question # 3 of 10 Total Marks: 1


The _____ of a binary tree is the maximum
levels of its leaves (also called
the depth)?
Level
Width

Height
None of the above

Question # 4 of 10 Total Marks: 1


Maximum time an insertion operation can take in AVL tree is? Here Log
stands for Log to the base of 2.
Log(n)
1.44 Log (n)
1.66 Log (n)
Log (n+1)

Question # 5 of 10 Total Marks: 1


Which one of the following is to more close to AVL Tree?
BST
Complete BST
Heap
None of above
Imrangee
Question # 6 of 10 Total Marks: 1
Which of the following data structure is of linear type?
Strings
Queues
Lists
All of above

Question # 7 of 10 Total Marks: 1


A binary search tree (BST) every node has two or zero node is
called_____.

Complete BST
BST
Extended BST
None of above

Question # 8 of 10 Total Marks: 1


Which data structure allows inserting elements at the back and
removing
from the front?
Stacks
Queues
BST
Deques
Question # 9 of 10 Total Marks: 1
BST violates the condition of AVL when any node has a balance equal
to____
2 or -2
1 or -1
0
None of above
Question # 10 of 10 Total Marks: 1
Incase of insertion of left outer node in BST we apply___
Single right rotation to make it AVL
Single left rotation to make it AVL
Double rotation, first left then right rotation.
None of above

1. Which data structure allows deleting data elements from front and
inserting at rear?
a. Stacks
b. Queues
c. Deques
d. Binary search tree
2. Identify the data structure which allows deletions at both ends of
the list but insertion at
only one end.
Input-restricted deque
b. Output-restricted deque
a.

c. Priority queues
d.None of above
3. Which of the following data structure is non-linear type?
a. Strings
b. Lists
c. Stacks
d.None of above
4. Which of the following data structure is linear type?
a. Strings
b. Lists

c. Queues
d. All of above
5. To represent hierarchical relationship between elements, which data
structure is not
suitable?
a. Deque
b. Priority
c. Tree
d. All of above
6. A binary tree whose every node has either zero or two children is
called
a. Complete binary tree
b.Binary search tree
c.Extended binary tree
d.None of above
7. The depth of a complete binary tree is given by
a. Dn = n log2n
b. Dn = n log2n+1
c. Dn = log2n
d. Dn= log2n+1

8. When representing any algebraic expression E which uses only binary


operations in a
2-tree,
a. the variable in E will appear as external nodes and operations in
internal nodes
b.the operations in E will appear as external nodes and variables in
internal nodes
c.the variables and operations in E will appear only in internal nodes
d.the variables and operations in E will appear only in external nodes
9. A binary tree can easily be converted into q 2-tree
a. by replacing each empty sub tree by a new internal node
b. by inserting an internal nodes for non-empty node
c. by inserting an external nodes for non-empty node
d. by replacing each empty sub tree by a new external node
10. When converting binary tree into extended binary tree, all the
original nodes in binary tree
are
a. internal nodes on extended tree
b. external nodes on extended tree
c. vanishedon extended tree
d.None of above

11. The post order traversal of a binary tree is DEBFCA. Find out the
pre order traversal
a. ABFCDE
b.ADBFEC
c.ABDECF
d.ABDCEF
12. Which of the following sorting algorithm is of divide-and-conquer
type?
a. Bubble sort
b. Insertion sort
c. Quick sort
d. All of above
13. An algorithm that calls itself directly or indirectly is known as
a. Sub algorithm
b. Recursion
c. Polish notation
d. Traversal algorithm
14. In a binary tree, certain null entries are replaced by special
pointers which point to nodes
higher in the tree for efficiency. These special pointers are called
a. Leaf

b. branch
c. path
d. thread
15. The in order traversal of tree will yield a sorted listing of elements of
tree in
a. Binary trees
b. Binary search trees
c. Heaps
d. None of above
16. In a Heap tree
a. Values in a node is greater than every value in left sub tree and
smaller
than right sub tree
b. Values in a node is greater than every value in children of it
c. Both of above conditions applies
d. None of above conditions applies
17. In a graph if e=[u, v], Then u and v are called
a. endpoints of e
b. adjacent nodes
c. neighbors
d. all of above

18. A connected graph T without any cycles is called


a. a tree graph
b. free tree
c. a tree
d .All of above
19. In a graph if e=(u, v) means
a. u is adjacent to v but v is not adjacent to u
b. e begins at u and ends at v
c. u is processor and v is successor
d. both b and c
20. If every node u in G is adjacent to every other
node v in G, A graph is said to be
a. isolated
b. complete
c.finite
d.strongly connected

Subjective
Cs301- current midterm paper (NOV 2009,10,11,12,)

Define Reference Variable, Dangling Reference & Const


Answer:
In the C++ programming language, a reference is a simple reference datatype
that is less powerful but safer than the pointer type inherited from C. The
name C++ reference may cause confusion, as in computer science a reference is
a general concept datatype, with pointers andC++ references being specific
reference datatype implementations
Dangling Reference & Const
Dangling pointers and wild pointers in computer encoding are pointers that
do not point to a valid object of the suitable type. These are special cases of
violations of memory safety
Define Complete Binary tree
Answer:
"A complete binary tree is a binary tree with the additional property that
every node must have exactly two children if an internal node, and zero
children if a leaf node."

Write APPLIICATION OF BST


Answer:
Binary tree is useful structure when two-way decisions are made at each
point. Suppose we want to find all duplicates in a list of the following
numbers: 14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5 This list may
comprise numbers of any nature. For example, roll numbers, telephone
numbers or voters list. In addition to the presence of duplicate number, we
may also require the frequency of numbers in the list. As it is a small list, so
only a cursory view may reveal that there are some duplicate numbers
present in this list. Practically, this list can be of very huge size ranging to
thousands or millions.
What normally is the sequence of operations while constructing an AVL tree?
Answer:
Basic operations of an AVL tree involve carrying out the same actions as would be carried out on an
unbalanced binary search tree, but modifications are precede or followed by one or more operations called tree
rotations.
Define the following
The Height of the Tree:

The definition of height of a tree is:


The height of a binary tree is the maximum level of its leaves (also called
the depth).
The balance of a node:
The balance of a node is defined as:
The balance of a node in a binary tree is defined as the height of its left
subtree minus height of its right subtree.

Give the names of basic Queue Operations


Ans:
Definition: A collection of items in which only the earliest added item may be accessed.
Basic operations are add (to the tail) or enqueue and delete (from the head) or dequeue.
Delete returns the item removed. Also known as "first-in, first-out" or FIFO.

Give one benefit of using Stack.


In computer science, a stack is a last in, first out (LIFO) abstract data type and data
structure. A stack can have any abstract data type as an element, but is characterized by
only two fundamental operations: push and pop. the data structure itself enforces the
proper order of calls.

Lets call the node as a that requires re-balancing. Consider the two cases given
below:
1) An insertion into left subtree of the left child of a
2) An insertion into right subtree of the right child of a.
Which of the following statement is correct about these two cases.
1) The insertion occurs outside (i.e., left-left or right-right) in cases 1 and 2. single
rotation can fix the balance in these two cases.
2) The insertion occurs inside ((i.e., left-left or right-right) in cases 1 and 2. single
rotation cannot fix the balance in these two cases

Give short answers of the following questions:


1. Why List wastes less memory as compared to Arrays.
Ans:
1. Linked lists do not need contiguous blocks of memory; extremely large data sets
stored in an array might not be able to fit in memory.
2. Linked list storage does not need to be preallocated (again, due to arrays needing
contiguous memory blocks).
3. Inserting or removing an element into a linked list requires one data update, inserting
or removing an element into an array requires n (all elements after the modified index
need to be shifted).
Array is a collection of same data type. In linked list there are two field one is address
and other is pointer. In array elements are arranged in a specific order

2. Why we can change the size of list after its creation when we can not do that in
simple arrays.
Some how the answer will be same as part 1 because Inserting or removing an element
into a linked list requires one data update, inserting or removing an element into an array
requires n (all elements after the modified index need to be shifted).
Array is a collection of same data type. The size of array is mentioned with its
declaration. in arrays the elements are in contiguous position. one must after another.
while in linked list we gave the address of next element in the next part of node.

What would the state of a stack be after the following operations?


create stack
push A onto stack
push F onto stack
push X onto stack
pop item from stack
push B onto stack
pop item from stack
pop item from stack
A Remening On The Stack

What are the applications of Binary Tree.


Answer:
Binary tree is useful structure when two-way decisions are made at each point.
Suppose we want to find all duplicates in a list of the following numbers: 14, 15, 4, 9,
7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

What is difference between call by reference and call by value?


Answer:
One application is to find duplicates in a list of numbers.
Let a given list be" 12 34 56 89 33 11 89
the first number in the list is placed in a node that is established as the root of a binary
tree. Each number is compared with the node in the root, if the number is larger, we
search the right sub-tree else we search the left sub-tree. If the sub-tree is empty, the
number is not a duplicate and this will be added as a new node.
2. Binary trees can be used for sorting a given list such that, if we take the first number as
root, the numbers less than that number will be transfered to left sub-tree and the greater
numbers to right sub-tree.
3. Binary trees are also used for developing the huffman codes.

What is the functionality of the following method of BST class


TreeNode<int>* function(TreeNode<int>* tree)
{

if( tree == NULL )


return NULL;
if( tree->getLeft() == NULL )
return tree; // this is it.
return function( tree->getLeft() );
}

a) Write a C++ statement that declares a valid reference of int i;


b) What is the benefit of reference and where can we use it?
In the last lecture we were discussing about reference variables, we saw three examples; call
by value, call by reference and call by pointer. We saw the use of stack when a function is
called by value, by reference or by pointer. The arguments passed to the function and local
variables are pushed on to the stack. There is one important point to note that in this course,
we are using C/C++ but the usage of stack is similar in most of the computer languages like
FORTRAN and Java . The syntax we are using here is C++ specific, like we are sending a
parameter by pointer using & sign. In Java, the native data types like int, float are passed by
value and the objects are passed by reference. In FORTRAN, every parameter is passed by
reference. In PASCAL, you can pass a parameter by value or by reference like C++. You
might have heard of ALGOL, this language had provided another way of passing parameter
called call by name. These kinds of topics are covered in subjects like

Determine what the following recursive mystery function computes when given a
pointer to the root node of a binary tree.
struct bt_s { int key; struct bt_s *left, *right; } bt_t;
int MFunc (bt_t *T) {
int N1, N2;
if (T == NULL) return -1;
N1 = MFunc(T->left);
N2 = MFunc(T->right);
return (N1 > N2 ? N1 : N2) + 1;
}

Is the given tree is an AVL tree? If Not then redraw is so that it becomes AVL

You might also like