0% found this document useful (0 votes)
20 views3 pages

Data Structures and Algorithms - Set 5

The document contains 5 questions from past GATE CS exams about data structures and algorithms: 1. A C function is given that calculates e^x using Taylor series approximation. The function best approximates e^x for large values of y. 2. The worst case number of comparisons needed to search a singly linked list of length n is n, since the element may need to be compared to all elements. 3. Questions are asked about time complexities of operations, heap properties, and efficient implementation of two stacks in a single array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Data Structures and Algorithms - Set 5

The document contains 5 questions from past GATE CS exams about data structures and algorithms: 1. A C function is given that calculates e^x using Taylor series approximation. The function best approximates e^x for large values of y. 2. The worst case number of comparisons needed to search a singly linked list of length n is n, since the element may need to be compared to all elements. 3. Questions are asked about time complexities of operations, heap properties, and efficient implementation of two stacks in a single array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Data Structures and Algorithms | Set 5

Following questions have been asked in GATE CS exam.

1. Consider the following C function.

float f(float x, int y)


{
float p, s; int i;
for (s=1, p=1, i=1; i < y; i ++)
{
p*= x/i;
s+=p;
}
return s;
}

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

e^x = 1 + x + x^2/2! + x^3/3! + ---

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)

4. Consider the following three claims


I (n + k)^m = (n^m), where k and m are constants
II 2^(n + 1) = 0(2^n)
III 2^(2n + 1) = 0(2^n)
Which of these claims are correct? (GATE CS 2003)
(a) I and II
(b) I and III
(c) II and III
(d) I, II and III

Answer(a)

(I) (n+m)^k = n^k + c1*n^(k-1) + ... k^m = (n^k)


(II) 2^(n+1) = 2*2^n = O(2^n)

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)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy