Data Structures and Algorithms - Set 5
Data Structures and Algorithms - Set 5
For large values of y, the return value of the function f best approximates (GATE CS 2003)
a) x^y
b) e^x
c) ln(1 + x)
d) x^x
Answer (b)
The function f() is implementation of Taylors Series to calculates e^x
More is the value of y more precise value of e^x will be returned by f()
References:
http://en.wikipedia.org/wiki/E_%28mathematical_constant%29
2. In the worst case, the number of comparisons needed to search a singly linked list of
length n for a given element is (GATE CS 2002)
a) log 2 n
b) n/2
c) log 2 n 1
d) n
Answer(d)
In the worst case, the element to be searched has to be compared with all elements of linked list.
3. The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a
Max Heap. The resultant Max Heap is.
Answer (a)
Answer(a)
5. A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow
from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location
of the topmost element in each of the stacks. If the space is to be used efficiently, the
condition for stack full is (GATE CS 2004)
a) (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
b) top1 + top2 = MAXSIZE
c) (top1= MAXSIZE/2) or (top2 = MAXSIZE)
d) top1= top2 -1
Answer(d)
If we are to use space efficiently then size of the any stack can be more than MAXSIZE/2.
Both stacks will grow from both ends and if any of the stack top reaches near to the other top
then stacks are full. So the condition will be top1 = top2 -1 (given that top1 < top2)