You are on page 1of 9

THE TEST ON DSA

TimeLeft=1:14:54
1
In selecting the pivot for quicksort, the best choice
for optimal partitioning is: ?
The last element of the array 3Mark
The first element of the array
The median of the array.
The middle element of the array
2
Analyse this structure and choose the correct option.

typedef struct node_s
{
struct node_s * prev;
struct node_s * next;
} node_t ; ?
This could be a node in a doubly linked list 6Mark
The syntax is incorrect
There is no problem, but this can not be a node of doubly
linked list
A linking error would occur because no data is present
3
We need to implement a queue using a circular
array. If DATA is a circular array of CAPACITY
elements, and rear is an index into that array, what
will be the index for the element after rear? ?
(rear + 1) % CAPACITY 4Mark
rear + (1 % CAPACITY)
rear % (1 + CAPACITY)
(rear % 1) + CAPACITY
Page 1 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
4
The worst-case time for binary search to find out a
single item in an array is in _________________ ?
Quadratic time 6Mark
Constant time
Logarithmic time
Linear time
5
For any 2 stacks S1 and S2 what will be the output of
the following code: ?
stack_code1.txt
1 4 9 25 36 5Mark
7 6 5 4 3 2 1
49 36 25 16 9
36 25 16 9 1
6
typedef struct T
{
int data;
struct T * left;
struct T *right;
} Node;

static Node* Leaf;

int function1 (int data )
{
Node *current = root;//Assume that root is defined
Leaf->data = data; // Assume that Leaf is defined as
type node
while ( ( current != NULL) && (current->data !=
Leaf->data ) )
{
if (current->data > data)
Page 2 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
{
current = current->left;
}
else
{
current = current->right;
}
}
return (current != Leaf);
}
What is this function trying to do? Explain. ?

4Mark
7
In the given BST if we want to insert a new node
with value 62 where will it be inserted ?
tree3.GIF
At the root 5Mark
As a left child of node having value 150
As a left child of node having value 5
As the left child of the node having value 75
8
A newspaper route has recently been computerized.
Information about each of the 100 customers is
stored in individual records containing first name,
last name, and payment due. In writing a computer
program to process the customer records, the
programmer is uncertain whether to add a
procedure to sort the records.If the records are first
sorted, what will be the maximum number of
comparisons needed with a binary search to find a
particular customer's record? ?
7 5Mark
Page 3 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
5
50
100
9
Mergesort makes two recursive calls. Which
statement is true after these recursive calls finish,
but before the merge step ?
Elements in each half of the array are sorted amongst
themselves.
3Mark
Elements in the first half of the array are less than or equal to
elements in the second half of the array.
None of these.
The array elements form a heap.
10 Subjective Question to be done on server ?

4Mark
11
int hash(char *str, int table_size)
{
int sum=0;

if (str==NULL) return -1;

for( ; *str; str++) sum += *str;

return sum % table_size;
}
What is this function trying to do? Explain from
hashing point of view.
Assume that this function is invoked as hash("I hate
you", 10) and then hash("I love you", 10). What
Page 4 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
problem do you see in this scenario? ?

4Mark
12
The following while loop is to remove duplicates
from an existing list having a head pointer pointing
to the first node.Which code will replace ____

current=head;
while(current->next!=NULL)
{
if (current->data == current->next->data)
{
____
}
else
{
current = current->next;
}
} ?
p=current->next->next;free(current);current->next = p; 5Mark
p=current->next;free(p);
p=current->next;free(current->next);current->next=p;
p= current->next->next;free(current->next);current->next = p;
13
"p" and "q" are pointers to a node of the linked list,
"head" points to the first node of the list, "next"
points to the next node in the list, which of the
following is true for the following piece of code:

for (p=head, q = head; p!=NULL ;q = p)
{
Page 5 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
p = p->next;
free(q);
} ?
Deletes all nodes 5Mark
Deletes all but the last node
Does not delete any node
The program will crash
14
If a queue is implemented with a linked list, keeping
track of a front node and a rear node with two
reference variables. Which of these reference
variables will change during an insertion into an
EMPTY queue ?
Both change 3Mark
Only rear changes
Neither changes
Only front changes
15
Assume that there is a server that serves different
requests from clients. There are clients who have to
be given the service immediately. There are requests
which has to be served immediately. In general there
is a need of keeping an order also.
What all data structures would you use here?
Reason your answer. ?

4Mark
16 The worst case of linear search is when ?
Neither Option 1 nor Option 2 3Mark
Option 2: The element is not present in the array
Page 6 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
Option 1: The element is present in the last location of the
array
Either Option 1 or Option 2
17
Let ' s' be a stack and push and pop be functions
implementing the Insertion and Deletion operations
in a Stack. push takes 2 parameters: the stack and
the element to be inserted , pop takes a single
parameter: the stack. What will be the contents of
the stack after the following operations: push(s,A),
push(s,B), push(s,C), pop(s), pop(s), push(s, D), push
(s, E), pop(s) ?
A D 4Mark
D E
C E
A E
18
6, 8, 4, 3, and 1 are inserted into a data structure in
that order. An item is deleted using only a basic data
structure operation. If the deleted item is a 1, the
data structure cannot be a ?
Queue 6Mark
Tree
Stack
Hash Table
void MyFun(Tree *temp)
{
if(temp!=NULL)
{
MyFun(temp->left);
if(temp->left == NULL && temp->right==NULL)
{
Page 7 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302
19
c++;
}
MyFun(temp->right);
}
}

What is the significance of the value c if this function
is invoked as MyFun(root), where root is root of a
BST? Explain. ?

4Mark
20
It is not a good idea to use binary search to find a
value in a sorted linked list of values. Why? ?
Binary search may not work for a linked list 3Mark
Binary search using a linked list would usually be much slower
than Linear search
It is not possible to sort a linked list, but sorted data is needed
for binary search.
Linked list uses dynamic memory allocation. So the number of
items are not known.
21
If the array is already sorted, then the running time
for merge sort is: ?
O(1) 3Mark
O(n*log n)
O(n)
O(n^2)
22
Which algorithm is having highest space
complexity? ?
Quick Sort 3Mark
Page 8 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302




Bubble sort
Merge Sort
Insertion Sort
submit
Page 9 of 9
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=487&s2=20302

You might also like