Data Structures Test - 5 - PDF Flipbook

Data Structures Test - 5

276 Views
92 Downloads
PDF 4,336,442 Bytes

Download as PDF

REPORT DMCA


GATE
CSE

Data
Structures

Test-05Solutions


DATA STRUCTURES
1. ln XML, DOCTYPE declaration specifies to include a reference

to _ file.
a) Document type Definition
b) Document type declaration
c) Document transfer def ignition
d) Document type language
Answer: (a)
Solution:
The document type (DOCTYPE) declaration consists of an
internal or references an external Documents type definition
(DTD). It can also have a combination of both internal and
external DTD defines the constrains on the structure of an XML
documentation.
2. The output of the following program is

main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i = 2; i < 6; ++i)
x[x[i]] = x[i];
for (i = 0; i < 8; ++i)
printf("%d", x[i]);
}

1


a) 1 2 3 3 5 5 7 8
b) 1 2 3 4 5 6 7 8
c) 8 7 6 5 4 3 2 1
d) 1 2 3 5 4 6 7 8
Answer: (a)
Solution:

X[ ] = 1 2 3 4 5 6 7 8
01 2 3 4 567

i = 2, x[x [2]] = x [2] ⟹ x[3] =3
i = 2, x[x [3]] = x [3] ⟹ x[3] =3
i = 2, x[x [4]] = x [4] ⟹ x[5] =5
i = 2, x[x [5]] = x [5] ⟹ x[5] =5
X[ ] = 1 2 3 4 5 6 7 8
3. The number of edges in a regular graph of degree d and n
vertices is
a) maximum of n, d
b) n + d
c) nd
d) nd/2
Answer: (d)
4. The friend functions are used in situations where;
a) We want to have access to unrelated classes
b) Dynamic binding is required
c) Exchange of data between classes to take place
d) none of the above

2


Answer: (c)
Solution:
friend functions are functions defined outside a class (i.e., not
number functions), but class declares to be friend so that they
can use the class private members this is commonly used in
operator overloading
This friend specifier allows the designated class access to
protected data or functionally within the class making the friend
statement
5. Which of the following need not necessarily be a saved on a
Context Switch between processes?
a) General purpose register
b) Translation look-aside buffer
c) Program counter
d) Stack pointer
Answer: (b)
Solution:
Translation look-aside buffer need not necessarily be saved on a
context switch between processes. ln a process content switch,
the state of the first process must be saved somehow.
So, that when the scheduler gets back to the execution of the
first process, it can restore this state and continue.
6. Merge sort uses
a) divide and conquer strategy
b) backtracking approach

3


c) heuristic search
d) greedy approach
Answer: (a)
7. How many values can be held by an array A (‒1.... m, 1, .... m)?
a) m
b) m2
c) m (m + 1)
d) m (m + 2)
Answer: (d)
8. __________ of a system is the structure or structures of the
system which comprise software elements, the externally visible
properties of these elements and the relationship amongst them.
a) Software construction
b) Software evolution
c) Software architecture
d) Software reuse
Answer: (c)
Solution:
The software architecture of a program or computing system is
the structure or structures of the system, which comprise
software elements the externally visible properties of those
elements and the relationships among them.

4


9. Assume that x and y are non-zero positive integers. What does
the following program segment perform?
While (x! = 0)
{
if (x > y)
x=x‒y
else
y = y ‒ x;
Print f ("%d", x);
a) Computes LCM of two numbers
b) Computes GCD of two numbers
c) Divides large number with small number
d) Subtracts smaller number from large number
Answer: (b)
Solution:
Given algorithm is Euclidean algorithm to computes greatest
common divisor (gcd) of two numbers
function gcd(a, b)
while (a ≠ b)
if a > b
a: = a – b;
else
b: = b – a;
return a;

5


10. In a linked list of n elements which is pointed by an external
pointer, what is the time taken to delete the element which is
successor of the element pointed to by a given pointer?
a) O(1)
b) O(log2n)
c) O(n)
d) O(n log2n)
Answer: (a)

11. What is the time required to search an element in a linked list
of length n?
a) O(log2n)
b) O(n)
c) O(n log2n)
d) O(n2)
Answer: (b)

12. A Hash Function f defined as f(key) = keymod7. With linear
probing while inserting the keys 37, 38, 72, 48, 98, 11, 56 into a
table indexed from 0, in which location key 11 will be stored
(Count Table index 0 as 0th location)?
a) 3
b) 4
c) 5
d) 6
Answer: (c)

6


Solution:
1. 32% 7 = 4
2. 38% 7 = 3
3. 72% 7 = 2
4. 48% 7 = 6
5. 98% 7 = 0
6. 11% 7 = 4
7. 56% 7 = 0
11 Will be placed at 5th index

13. Repeated execution of simple computation may cause
compounding of
a) round-off errors
b) syntax errors
c) runtime errors
d) logic errors
Answer: (a)
Solution:
A round-off error, also called rounding error is the difference
between the calculated approximation of a number and its exact
mathematical value due to rounding. Repeated execution of
simple computation may cause compounding of round-off
errors.

7


14. The following program
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}

a) prints 012
b) prints 123
c) prints 3 consecutive, but unpredictable numbers
d) prints 111
Answer: (b)
Solution:
Variable ‘x’ is static and hence will be initialized to 0

inc ( ) → print ‘1’
inc ( ) → print ‘2’
inc ( ) → print ‘3’
inc ( ) → print ‘123’
Hence, it print ‘1’

8


15. In Java, after executing the following code what are the values
of x, y and z?
int x, y = 10, z =12;
x = y++ + z++;
a) x = 22, y = 10, z = 12
b) x = 24, y = 10, z = 12
c) x = 24, y = 11, z = 13
d) x = 22, y = 11, z = 13
Answer: (d)
Solution:
‘y’ and ‘z’ have post increment operator, so the value of 'x' will
be calculated first, then their value will be incremented.
Hence x becomes 22 and y and z 11 and 13 respectively.

16. Which of the following statements is correct?
a) Every class containing abstract method must not be declared
abstract.
b) Abstract class cannot be directly initiated with 'new'operator.
c) Abstract class cannot be initiated.
d) Abstract class contains definition of implementation
Answer: (b)
Solution:
if a class includes abstract methods then the class itself must be
declaredx abstract abstract class cannot be directly initiated with
new operator, since abstract class does not contain any
defination of implementation .

9


it is not possible to create an abstract object Abstract class
cannot be initiated, means we cannot create an object to abstract
class. We can create subclass to abstract class.
Abstract classes are classes that cantain one or more abstract
methods an abstract method is method that is declared, but
contains no implementation abstract classes may not be
instantiated, and required sub clasess to provide implementation
for the abstract methods.
17. Which of the following is a tabular listing of contents of
certain registers and memory locations at different times during
execution of a program?
a) Loop program
b) Program trace
c) Subroutine program
d) Byte sorting program
Answer: (b)
18. Consider the following program fragment

If (a > b) if(b > c) s1; else s2;
s2 will be executed if
a) a < = b
b) b > c
c) b > = c and a < = b
d) a > b and b < = c
Answer: (b)

10


Solution:
The program fragment can be written as:

if(a > n)
{

if(b > c)
{
S1;
}

else
{
S2;
}
}

Hence s2 will be executed when first if condition is true and
second is false
Hence, if (a > b) and (b

Data Loading...