You are on page 1of 8

THE TEST ON DSA

(1)
What does the following function return, if q contains the address of the first element in a linked list

int function(NODE *q)
{
int c = 0;
while( q != NULL)
{
q = q->link;
c++;
}
return (c);
} ?
The value of the last node of the linked list
The value of the first elements of the linked list
The address of the last element of the linked list
The number of elements in a linked list
(2)
The hash function is
H1(k) = k % 50.
In the case of collision, the hash function used is
H(k) = (H1(k) + M x H2(k)) % 50
where H1(k) = k % 50 and H2(k) = k % 20.
M is initialized to 0 and is incremented by 1 each time a collision occurs.
This could be categorized under which of the following collision detection technique? ?
Linear Probing
Quadratic Probing
Re-Hashing
Double Hashing
(3) Linear Search is best for ... ?
Large arrays
Small or Large, but unsorted arrays
Small arrays
Small or Large, but sorted arrays
(4) Minimum how many stacks are needed to implement a queue ?
1
3
Cannot be implemented
2
A quicksort algorithm is used to sort an array of N elements.If all the N values were 0 then what would be the time c
Page 1 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532
(5) omplexity of quicksort that uses first element as the pivot. ?
O(N*N)
O(1)
O(N)
O(N log N)
(6) The disadvantage of Binary Search is ?
It has the overhead of sorting
It may not work for floating point numbers
Its performance depends on the position of the search element in the array
It may not work for strings
(7)
Let S be the original stack and S1 and S2 the two additional stacks then the following pseudo code is to reverse the st
ack S:

while (S not empty)
{
push(S1,pop(S));
}

while(S1 not empty)
{
push(S2,pop(S1));
}

while(S2 not empty)
{
push(S,pop(S2));
} ?
True
False
Not Answer
(8)
What does the following function do if S is an array used to implement a stack

float peep ( float S[], int *t, int i)
{
float val;
if( (*t-i+1) > 0)
{
val = S[*t-i+1];
return val;
}
} ?
Returns the ith value from top of the stack
Returns the value at the top of the stack
Page 2 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532
It gives a compilation error
Returns the value at the ith postion of the array
(9) Which among the following are applications of queues ?
Queues keep track of events waiting to be handled, like multiple button clicks
Queues are used for evaluation of arithmetic expressions
Queues are used in parsing
Queues keep track of processes waiting for a turn in the CPU
(10) Which among the following is true for doubly linked list ?
The left pointer of the right most node and no condition on the left most node
The right pointer of the right most node and no condition on the left most node
The left pointer of the right most node and right pointer of the left most node are null
The left pointer of the left most node and right pointer of the right most node are null
(11) You want to find the nth element of a set of numbers. If you store the numbers in a list _________________ ?
Finding the nth element is slower if it was stored in an array
Finding the nth element is faster if it was stored in an array
Finding the nth element takes the same amount of time across all data structures
Finding the nth element is slower if it was stored in a hash table
(12) The time complexity of insertion sort in worst case is? ?
n(n-1)/4
n(n+1)/4
n(n-1)/2
n(n+1)/2
(13) Subjective Question to be done on server ?

Page 3 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532
PR Attribute ID Marks New Marks
DSA_1 4 4
DSA_2 9 8
DSA_3 3 2
(14)
Algorithms A and B solve the same problem. Time complexity of A is in O(n^2) and that of B is in O
(n). Which among the following can you guarantee? ?
A is having less executable instructions than B
A is having more number of functions than B
A is having less number of functions than B
A is having more executable instructions than B
(15)
Let S and S1 be two stacks and Q be the additional Queue then what is the result after following pseudo code is exec
uted:

while (S not empty)
{
Q.insert(pop(S));
}

while(Q not empty)
{
push(S1,Q.delete());
} ?
S and S1 are same
None of them
S1 is reverse of S
S and S1 will be different
(16)
Assume that a structure for a Binary Search Tree exists.
What does the following function do?

int function(root)
{
current = root;
while (current->left != NULL)
{
current = current->left;
}
return(current->data);
} ?
Page 4 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532

The above snipet will return the lefmost child of the Binary search tree.
Which is nothing but the minimum element of the tree

eg: consider series: 4 2 5 6 3 1 8 7

4
/ \
2 5
/ \ \
1 6 8
/
7

In above list 4 is root, according to the code, it travels the nodes 4,2,1 at 1 the left is null.
so that the while loop will be terminated and data at that position 1 will be returned back.

Which is the minimum element of the entire tree.
PR Attribute ID Marks New Marks
DSA_4 4 4
(17)
Assume that you have a very large array of elements. You are required to sort this array. The main contraint here is
the space rather than time. Which among the following algorithm is not an ideal choice? ?
Quick Sort
Bubble Sort
Insertion Sort
Merge Sort
(18)
unsigned int str_hash
(unsigned char *string, unsigned int buckets, unsigned in alphabet_size, unsigned int hash_limit)
{
int i = 0;
unsigned int accum;

while ((string[i] != 0) && (i < hash_limit))
i++;

if (i < hash_limit)
hash_limit = i;

accum = (unsigned int) string[hash_limit - 1];

for (i = hash_limit - 2; i >= 0; i--)
accum = string[i] + (accum * alphabet_size);

Page 5 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532
return accum % buckets;
}
What is this function trying to do?
Note: buckets is the array size which is a prime number, alphabet_size is the number of all possible characters, hash
_limit is the length of a string and string is a string. ?

The above function is just an hashing algorithm and it is going to return a value which is in
between 0 and buckets.

Explanation:
-----------
It is accepting the
String,
buckets(size),
number of all possible characters,
length of the string.

1)The first while loop is trying to find out number of existing characters in the given string.
It is taking the condition string[i] != 0 and this while will be repeated maximum of string
length times. And minimum number depends on the condition string[i] != 0

2)The if statement is going to to fix the value of hash_limit to the number of characters avalable
in the string.

3)The initial value of accum will be the ascci value of the last character in the given string.

4)Now for loop is repeated for i-1 time (i.e from characters 0 to i-1) in reverse order. The step
accum = ascci val(string[i]) + (recent accum val * alphabet_size), this will be repeated for i
times.

5)Finally we have a large unsigned int val in accum, it wad divided with some specified primenumber
and the reminder is returned back.
PR Attribute ID Marks New Marks
DSA_4 4 4
(19)
Think about a server to which all ATM clients of a particular bank is connected. There are requests coming from di
fferent ATM centers and the server has to verify the user name and password and do the transaction also. There cou
ld be successful and failure requests. There could be requests from other banks? ATM also. Some customers may sp
end more time than others.

Which all data structures could be involved for implementing the same? Conceptualize your answer. Would you go f
or an array implementation or linked list implementation? Justify your answer. ?
Page 6 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532

According to the above situation. The requeasts are comming from several ATMs. There wont be any
limit.

It beter to choose the linked lists insted of arrays. Many of the customeres may do transactions
same time from different ATM centers. And no customer may do the transaction at some point of time.

Disadvantage of using arrays
----------------------------
1)Fixed amount of memory have to be allocated.

2)Though there is no transaction, the memory will be still allocated.

3)some times the fixed memory may not be sufficient to serve the customers in busy timings.

Advantage of arrays
-------------------
1)We can overcome all the above disadvantages using linked lists.

2)Enough space can be allocated and deallocated depending up on the requirement.

3)No addtional space is used.

Another data structure have to be included , that is queues.


Implementation of Queues using linked lists
PR Attribute ID Marks New Marks
DSA_1 2 2
DSA_3 4 2
(20)
Consider the following set of integers.
{20,25,57,48,37,12,92,86,33}
If one uses the quick sort algorithm to sort the above set of integers, how many pivot values are required
to completely sort the file?
Note: you may choose middle element as a pivot. ?
5
8
3
9
(21) Which is the best data structure for round robin algorithm for CPU scheduling? ?
Stack implemented using queues
Doubly linked list
Circular queue
Queue implemented using stacks
(22)
int MFunc(tree *T)
{
int N1,N2;
if(T == NULL)
return -1;
N1 = MFunc(T->left);
N2 = MFunc(T->right);
Page 7 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532




return (N1 > N2 ? N1 : N2) + 1;.
}
If T points to root of a tree, what does this function do? Explain. ?

The given function will return the height of the tree.

Logic:
-----
1) It is done recursivly, the finction having N1, N2 which are again calling the same function.

2)N1 will receive the height the left sub tree

3)N2 will receive the height of the right sub tree

4)Finally return statement is identifying the maximun value among N1 and N2, and it is returning
max+1 to the previous call.

5)T will be NULL onely when the tree is empty. when come to the leaf nodes. When the call is made
at leaf level the value -1 will be returned.

6)Finally the function will retrn the hieght of the tree, which is nothing but number of levels in
the tree.
PR Attribute ID Marks New Marks
DSA_4 4 4
Page 8 of 8
2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=446&s2=20532

You might also like