0% found this document useful (0 votes)
362 views125 pages

Data Structure... 1 To 5 Units

The document contains 37 multiple choice questions about stacks and queues. Stacks and queues can be implemented using arrays or linked lists. Stacks follow last-in first-out (LIFO) order and are useful for functions calls, parentheses checking, and arithmetic expressions. Queues follow first-in first-out (FIFO) order and are useful for input/output lists. The questions cover stack and queue operations like push, pop, insert, and delete as well as applications and implementations.

Uploaded by

Ronak Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views125 pages

Data Structure... 1 To 5 Units

The document contains 37 multiple choice questions about stacks and queues. Stacks and queues can be implemented using arrays or linked lists. Stacks follow last-in first-out (LIFO) order and are useful for functions calls, parentheses checking, and arithmetic expressions. Queues follow first-in first-out (FIFO) order and are useful for input/output lists. The questions cover stack and queue operations like push, pop, insert, and delete as well as applications and implementations.

Uploaded by

Ronak Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 125

Unit I

STACKS AND QUEUES

MULTIPLE CHOICE QUESTIONS


1. The term "push" and "pop" is related to the _____.
(a) array (b) lists (c) stacks (d) all of above
Answer: c
2. A data structure where elements can be added or removed at either end but not in
the middle is called _____.
(a) linked lists (b) Stacks (c) queues (d) dequeue
Answer: d
3. The Infix equivalent of the prefix * + ab − cd is _____.
(a) (a+b) * (c−d) (b) (a+b) − (c*d) (c) (a*b)−(c+d) (d) (a−b)*(c+d)
Answer: a
4. The postfix equivalent of the prefix * + ab − cd is_____.
(a) ab + cd − * (b) abcd + − * (c) ab + cd * − (d) ab + − cd *
Answer: a
5. The postfix equivalent of the infix expression a+b+c+d is _____.
(a) abcd+++ (b) ab+c+d+ (c) ab+cd++ (d) (a−b)*(c+d)
Answer: b
6. The prefix equivalent of the infix expression a+b+c+d is _____.
(a) +ab+c+d (b) +++abcd (c) ++ab+cd+ (d) abcd++++
Answer: b
7. The postfix equivalent of the infix expression a+b/c*d−e/f is _____.
(a) ab+cd*/ef−/ (b) abcd*+/ef−/ (c) ab+cd*/ef/− (d) abc/d*+ef/−
Answer: d
8. The prefix equivalent of the infix expression a+b/c*d−e/f is _____.
(a) +abc−*/ef (b) +/*−/abcdef (c) −+a*/bcd/ef (d) +a*/bcd−/ef
Answer: c
9. The postfix equivalent of the infix expression a+b/c−d*e−f is _____.
(a) abc/+de*−f− (b) abcd*+/ef−/ (c) ab+cd*/ef/− (d) abc/d*+ef/−
Answer: a
Unit I | 1.1
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

10. The prefix equivalent of the infix expression a+b/c−d*e−f is _____.


(a) +abc−*/ef (b) −−+a/bc*def (c) −+a*/bcd/ef (d) +a*/bcd−/ef
Answer: b
11. The infix equivalent of the postfix ab+cd+ef*−/ is_____.
(a) ((a+b)/( (c+d))−(e*f)) (b) (a+b) − (c+d)/(e*f)
(c) (a+b)*(c+d)−(e/f) (d) ((a+b)/(c+d))−(e*f)
Answer: a
12. The infix equivalent of the postfix ab*cd/+e− is _____.
(a) a+b*c/d−e (b) a*b+c/d−e (c) (a*b)−(c/d)+e (d) a*b−c/d+e
Answer: b
13. The prefix equivalent of the postfix ab*cd/+e− is _____.
(a) +−/abc*de (b) −+*abc/de (c) −+*ab/cde (d) *ab/+cd−e
Answer: c
14. Pick the correct prefix form to the given infix expression: {a*[b/(c−d)*f]/g}/[e+h]
(a) //*a/b*−cdfg+ch (b) abcd−f*/g/*eh+/
(c) //*a*/b−cdfg+eh (d) //*ab*/−cdfg+eh
Answer: c
15. Suppose a circular queue of capacity (n – 1) elements is implemented with an array
of n elements. Assume that the insertion and deletion operation are carried out
using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT
= 0. The conditions to detect queue full and queue empty are
(a) Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
(b) Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR
(c) Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
(d) Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
Answer: a
16. Consider the usual algorithm for determining whether a sequence of parentheses is
balanced. What is the maximum number of parentheses that will appear on the stack
AT ANY ONE TIME when the algorithm analyzes: (()(())(()))
(a) 4 (b) 3 (c) 2 (d) 6
Answer: b
17. Suppose we have an array implementation of the stack class, with ten items in the
stack stored at data[0] through data[9]. The SIZE is 42. Where does the push function
place the new entry in the array?
(a) data[0] (b) data[1] (c) data[9] (d) data[10]
Answer: c
Unit I | 1.2
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

18. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then
removed one at a time, in what order will they be removed?
(a) ABCD (b) ABDC (c) DCAB (d) DCBA
Answer: d
19. What data structure is used to perform recursion?
(a) Stack (b) Queue (c) Linked List (d) Arrays
Answer: a
20. For the expression ((A + B) * C – (D – E)/(F + G)), the equivalent Postfix notation is
(a) AB + C * DE − − / FG + (b) AB + C * DE − FG + /−
(c) AB + C * DE − − FG + / (d) AB + C − DE − * FG + /
Answer: b
21. Which data structure allows deleting data elements from front and inserting at rear?
(a) Stacks (b) Queues
(c) Deques (d) Binary search tree
Answer: b
22. Identify the data structure which allows deletions at one end of the list but insertion
anywhere
(a) Input−restricted deque (b) Output−restricted deque
(c) Priority queues (d) None of above
Answer: c
23. One difference between a queue and a stack is _____.
(a) Queue can be implemented using linked lists, but stack cannot
(b) Stack can be implemented using linked lists, but queues cannot
(c) Queues use two ends of the structure; stacks use only one
(d) Stacks use two ends of the structure, queues use only one
Answer: d
24. Suppose we have a circular array implementation of the queue, with ten items in the
queue stored at data[2] through data[11], the current capacity is 12. Where does the
insert method place the new entry in the array?
(a) data[1] (b) data[0] (c) data[11] (d) data[12]
Answer: b
25. If we have implemented the queue 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 a NONEMPTY queue?
(a) Neither changes (b) Only front changes
(c) Only rear changes (d) An exception is caused
Answer: c

Unit I | 1.3
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

26. If we have implemented the queue 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 deletion into NONEMPTY queue?
(a) Neither changes (b) Only front changes
(c) Only rear changes. (d) An exception is caused
Answer: b
27. If we have implemented the queue 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 a EMPTY queue?
(a) Neither changes (b) Only front changes
(c) Only rear changes (d) Both front and rear change
Answer: d
28. Queues and Stacks can be implemented using either arrays or linked lists.
(a) True (b) False
Answer: a
29. In order to input a list of values and output them in order, you could use a Queue.
(a) True (b) False
Answer: a
30. In order to input a list of values and output them in opposite order, you could use a
Stack.
(a) True (b) False
Answer: a
31. Which of the following is not the type of queue?
(a) Ordinary queue (b) Single ended queue
(c) Circular queue (d) Priority queue
Answer: a
32. Which is/are the application(s) of stack?
(a) Function calls (b) Parentheses check
(c) Evaluation of arithmetic expressions(d) All of the above
Answer: d
33. Stack is also called as _____.
(a) Last in first out (b) First in last out
(c) Last in last out (d) First in first out
Answer: a

Unit I | 1.4
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

34. Queue is also called as _____.


(a) Last in first out (b) First in last out
(c) Last in last out (d) First in first out
Answer: d
35. _____ is very useful in situation when data have to stored and then retrieved in
reverse order.
(a) Stack (b) Queue (c) List (d) Link list
Answer: a
36. Consider the following pseudo code :
declare a stack of characters
while (there are more characters in the word to read)
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
What is written to the screen for the input "carpets"?
(a) serc (b) carpets (c) steprac (d) ccaarrppeettss
Answer: a
37. In the linked list implementation of the stack, where does the push method place the
new entry on the linked list?
(a) Before the first node
(b) At the end of last node
(c) After all other entries that are greater than the new entry.
(d) After all other entries that are smaller than the new entry.
Answer: a
38. What is the value of the postfix expression 6 3 2 4 + − *
(a) 18 (b) −18
(c) 15 (d) Invalid expression
Answer: b

Unit I | 1.5
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

39. What is the value of the postfix expression 23456*+−/


(a) 16 (b) −18
(c) − 15 (d) Invalid expression
Answer: c
40. What is the value of the postfix expression 23456*+−
(a) 16 (b) −18
(c) 15 (d) Invalid expression
Answer: d
41. Here is an infix expression: 4+3*(6*3−12). Suppose that we are using the usual stack
algorithm to convert the expression from infix to postfix notation. What is the
maximum number of symbols that will appear on the stack AT ONE TIME during the
conversion of this expression?
(a) 5 (b) 2 (c) 3 (d) 4
Answer: d
42. The postfix form of the expression (A+ B)*(C*D− E)*F / G is _____.
(a) AB+ CD*E − FG /** (b) AB + CD* E − F **G /
(c) AB + CD* E − *F *G / (d) AB + CDE * − * F *G /
Answer: a
43. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a _____.
(a) Queue (b) Stack (c) Tree (d) Linked List
Answer: a
44. The data structure required to evaluate a postfix expression is _____.
(a) Queue (b) Stack (c) Array (d) Linked−list
Answer: b
45. What data structure would you mostly likely see in a nonrecursive implementation of
a recursive algorithm?
(a) Queue (b) Stack (c) Array (d) Linked−list
Answer: b
46. The postfix form of A*B+C/D is _____.
(a) *AB/CD+ (b) AB*CD/+ (c) A*BC+/D (d) ABCD+/*
Answer: b
47. What is the postfix form of the following prefix *+ab–cd
(a) ab+cd–* (b) abc+*– (c) ab+*cd– (d) ab+*cd–
Answer: a

Unit I | 1.6
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

48. Which data structure is needed to convert infix notation to postfix notation?
(a) Branch (b) Queue (c) Tree (d) Stack
Answer: d
49. What is the result of the following operation done on stack S which is not full?
push (&S, 10); x = pop (&S); where S is a structure containing array and top
(a) x = −1 (b) x = 10 (c) x = Null (d) Error
Answer: b
50. The prefix form of an infix expression p + q − r * t is _____.
(a) + pq − *rt (b) − +pqr * t (c) − +pq * rt (d) − + * pqrt
Answer: c
51. The equivalent prefix expression for the following infix expression
(A+B)−(C+D*E)/F*G is
(a) −+AB*/+C*DEFG (b) /−+AB*+C*DEFG
(c) −/+AB*+CDE*FG (d) −+AB*/+CDE*FG
Answer: a
52. The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is _____.
(a) 600 (b) 350 (c) 650 (d) 588
Answer: b
53. The meaning of FIFO is _____ and it stands for _____.
(a) First In Fast Out, Stack (b) First In First Out, Stack
(c) First In First Out, Queue (d) First In Fast Out, Queue
Answer: c
54. The meaning of LIFO is _____ and it stands for _____.
(a) Last In First Out, Queue (b) Last In First Out, Stack
(c) Last In Fast Out, Stack (d) Last In First Out, Priority Queue
Answer: b
55. Adding data to stack is called _____.
(a) Push (b) Pop (c) Insert (d) Delete
Answer: a
56. Items can be removed from both ends of _____.
(a) queue (b) stack (c) tree (d) dequeue
Answer: d
Unit I | 1.7
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

57. In linked list each node consists of _____.


(a) data and link to next node (b) data only
(c) link only (d) address of first node
Answer: a
58. In linked lists there are no NULL links in _____.
(a) circular linked list (b) singly linked list
(c) doubly linked list (d) empty linked list
Answer: a
59. In stack, the command to access the element at top is _____.
(a) x = pop( ); (b) pop(x); (c) pop(top); (d) top=pop( );
Answer: a
60. The result of evaluating prefix expressions *+++abcdc where, a = 1, b = 2, c = 3 and
d = 4 is _____.
(a) 10 (b) 12 (c) 30 (d) 18
Answer: c
61. The dummy header in linked list contains _____.
(a) first record (b) last record
(c) link to first record (d) link to last record
Answer: c
62. If the sequence of operations (push(1), push(2), pop, push(1), push(2), pop, pop, pop,
push(2), pop), are performed on a stack, the sequence of popped out values are
_____.
(a) 2, 2, 1, 1, 2 (b) 2, 2, 1, 2, 2 (c) 2, 1, 2, 2, 1 (d) 2, 1, 2, 2, 2
Answer: a
63. In evaluating the arithmetic expression 2 * 3 − (4 + 5), using stacks to evaluate its
equivalent post-fix form, which of the following stack configuration is not possible?

(a (b 5 (c (d) 9

4 4 9 3
6 6 6 2
Answer: d

Unit I | 1.8
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

64. The postfix expression for the infix expression


A + B* (C + D) / F + D*E is _____.
(a) AB + CD + *F / D + E* (b) ABCD + *F / + DE* +
(c) A*B + CD / F*DE ++ (d) A + *BCD / F*DE ++
Answer: b
65. Which of the following is essential for converting an infix expression to the postfix
form efficiently?
(a) An operator stack
(b) An operand stack
(c) An operator stack and an operand stack
(d) A parse tree
Answer: a
66. Identify the data structure which allows deletions at one end of the list but insertion
at both ends.
(a) Input−restricted deque (b) Output−restricted deque
(c) Priority queues (d) None of above
Answer: b
67. Identify the data structure which allows deletions at both end of the list but insertion
at one end.
(a) Input−restricted deque (b) Output−restricted deque
(c) Priority queues (d) None of above
Answer: a
68. Identify the data structure which allows deletions as per the priority.
(a) Input−restricted deque (b) Output−restricted deque
(c) Priority queues (d) dequeue
Answer: c
69. In array implementation of stack stack full condition is _____.
(a) top equal to one less than size of stack
(b) top is equal to 0
(c) top is equal to NULL
(d) top is equal to −1
Answer: c

Unit I | 1.9
DATA STRUCTURES AND FILES (SE IT) STACKS AND QUEUES

70. Which out of these is a non-linear data-structure _____.


(a) arrays (b) linked-lists (c) queues (d) tree
Answer: d
71. A stack is a data-structure in which elements are stored and retrieved by _____.
(a) FIFO method (b) LIFO method
(c) FCFS method (d) None of the above
Answer: b
72. The different types of arrays are _____.
(a) One and Multi-dimensional (b) int and float
(c) int,char, float (d) One and Two dimensional
Answer: c
73. An array is passed into a function _____.
(a) by value (b) by reference
(c) element by element (d) Any of the above
Answer: b
74. A queue is a data-structure in which elements are stored and retrieved by _____.
(a) FIFO method (b) LIFO method
(c) FCFS method (d) None of the above
Answer: a
75. If an array with the name, A exists which of the following statements is incorrect
(a) A++ (b) printf(“%d”,*(A+1))
(c) printf(“%u”,A+1) (d) All are correct
Answer: a
76. An uninitialized pointer is known as _____.
(a) dangling pointer (b) NULL pointer
(c) generic pointer (d) None of the above
Answer: a
77. The unary operator used with pointer variable to indirectly access the contents of
memory location pointed to by the pointer is called _____.
(a) Address-of operator (b) dot operator
(c) indirection operator (d) asterisk operator
Answer: c
Unit I | 1.10
Unit I
Introduction to C Programming

Q.1 _____is the logical or mathematical model of a particular organization of data.


A Structure
B Variable
C Functions
D Data structures
Answer D

Q.2 Array is used to represent


A A list of data items of integer data type
B A list of data items of real data type
C A list of data items of different data type
D A list of data items of same data type
Answer D

Q.3 Array name is


A An array variable
B A keyword
C A common name shared by all elements
D Not used in program
Answer C

Q.4 One- dimensional array is known as


A Vector
B Table
C Matrix
D An array of arrays
Answer A

Q.5 The array elements are represented by


A Index values
B Sub scripted variables
C Array name
D Size of an array
Answer B

Q.6 Array elements occupy


A Subsequent memory locations
B Random location for each elements
C Varying length of memory location for each elements
D No space in memory
Answer A

Q.7 The address of the starting elements an array is


A Represented by sub scripted variable of the starting elements
B Cannot be specified
C Represented by the array name
D Not used by the compiler
Answer C

Data Structures
Unit I
Introduction to C Programming
Q.8 Identify the wrong statement
A Subscripts are also known as indices
B Array variable and sub scripted variable are same
C Array name and sub scripted variable are different
D Array name and sub scripted variable are same
Answer D

Q.9 Array subscripts in c always start at


A -1
B 0
C 1
D Any value
Answer B

Q.10 Identify the correct declaration


A Int a[10] [10];
B Int a[10,10] ;
C Int a(10) (10);
D Int a (10,10) ;
Answer A

Q.11 Maximum number of elements in the array declaration int x[10]; is


A 9
B 10
C 11
D Undefined
Answer B

Q.12 The elements of the following array x are


A x[0],x[1],x[2],x[3],x[4]
B x[1],x[2],x[3],x[4],x[5]
C x(0)x(1),x(2),x(3),x(4)
D x(0),x(1),x(2),x(3),x(4)
Answer A

Q.13 Maximum number of elements in the declaration int y [5][8];is


A 28
B 32
C 35
D 40
Answer D

Q.14 Array declaration


A Requires the number of elements to be specified
B Does not require the number of elements to be specified
C Assumes default size of 0
D In not necessary
Answer A

Q.15 Identify the wrong expression given int a [10];


Data Structures
Unit I
Introduction to C Programming
A a[-1]
B a[10]
C a[0]
D ++a
Answer D

Q.16 To initialize a 5 elements array all having value 0 is given by


A int num [5]= {0};
B int num [5]= {0, 0, 0, 0, 0};
C Both option
D int num [5]= {1};
Answer C

Q.17 The value within the [ ] in an array declaration specifies


A Subscript value
B Index value
C Size of an array
D Value of the array element
Answer C

Q.18 In the syntax given below, expression can be


if ( expression )
statement ;
A relational expression
B valid expression
C arithmetic expressions
D All of the above
Answer B

Q.19 What is the op of the code given below

if ( 3 + 2 - 5 )

printf ( "F" ) ;

if ( a = 10 )

printf ( "T1" ) ;

if ( -5 )

printf ( "T2" ) ;
A F, T1, T2
B T1, T2
C F, T1
D none of the above
Answer B

Q.20 What is the op of the code given below

Data Structures
Unit I
Introduction to C Programming

int i = 200 ;

if ( i = 5 )

printf ( "True" ) ;

else

printf ( "false" ) ;
A false
B True
C syntax error
D none of the above
Answer B

Q.21 What is the op of the code given below

int i = 200 ;

if ( i = 5 );

printf ( "false" ) ;
A false
B syntax error
C no output
D none of the above
Answer A

Q.22 What is the op of the code given below

main( )

int i = 1 ;

while (i <= 10 ) ;

printf (i = i + 1) ;

}
A syntax error
B infinite loop
C prints values from 1to 10

Data Structures
Unit I
Introduction to C Programming
D none of the above
Answer B

Q.23 What is the op of the code given below

main( )

for ( i = 10 ; i ; i -- )

printf ( "%d", i ) ;

}
A syntax error
B infinite loop
C prints values from 10 to 1
D prints values from 10 to 0
Answer C

Q.24 What is the op of the code given below

i=1;

for ( i < 4 ; j = 5 ; j = 0 )

printf ( "%d", i ) ;
A syntax error
B infinite loop
C prints values
D none of the above
Answer C

Q.25 What is the op of the code given below

main( )

int i = 1 ;

for ( ; i <= 10 ; )

printf ( "%d\n", i ) ;

i=i+1;

Data Structures
Unit I
Introduction to C Programming

}
A syntax error
B infinite loop
C prints values from 1to 10
D none of the above
Answer C

Q.26 What is the op of the code given below

for( i=0;i<=10;i++)

if(i==5)

Break;

Printf(“try”);

}
A prints try four times
B prints try five times
C prints try ten times
D none of the above
Answer B

Q.27 What is error in following declaration?


stuct outer
int a;
struct inner
{
char c;
};
};
A Nesting of structure is not allowed in c.
B It is necessary to initialize the member variable.
C Inner structure must have name.
D Outer structure must have name.
Answer C

Q.28 What is the similarity between a structure, union and enumeration?


A All of them let you define new values
B All of them let you define new data types
C All of them let you define new pointers
D All of them let you define new structures
Answer B
Data Structures
Unit I
Introduction to C Programming

Q.29 Which of the following are themselves a collection of different data types?
A string
B structures
C char
D All of the mentioned
Answer B

Q.30 Which operator connects the structure name to its member name?
A -
B <-
C .
D Both (b) and (c)
Answer C

Q.31 Among the following which is not primitive data type?


A Int
B Float
C structure
D char
Answer D

Q.32 Which of the following cannot be a structure member?


A Another structure
B Function
C Array
D None of the mentioned
Answer B

Q.33 What is the output of this C code?


#include <stdio.h>
struct student

int no;

char name[20];

}
void main()

struct student s;

s.no = 8;

Data Structures
Unit I
Introduction to C Programming
printf("hello");

}
A Compile time error
B Nothing
C hello
D Varies
Answer A

Q.34 Number of bytes in memory taken by the below structure is


struct test
{

int k;
char c;
};
A Multiple of integer size
B integer size+character size
C Depends on the platform
D Multiple of word size
Answer B

Q.35 The time complexities of thee algorithms is as given below. Choose the slowest
algorithm.
A O(n0.5)
B O(n)
C O(logn)
D None of these
Answer B

Q.36 The correct syntax to access the member of the ith structure in the array of
structures is?
Assuming: struct temp
{
int b;
}s[50];
A s.b.[i];
B s.b[i]
C s[i].b;
D none of these
Answer C

Q.37 Which of the following uses structure?


A Array of structures
B Linked Lists
C Binary Tree
D All of the mentioned
Answer D
Data Structures
Unit I
Introduction to C Programming

Q.38 What is the correct syntax to declare a function foo() which receives an array of
structure in function?
A void foo(struct *var);
B void foo(struct *var[]);
C void foo(struct var);
D None of the mentioned
Answer A

Q.39 What will happen if in a C program you assign a value to an array element whose
subscript exceeds the size of array?
A The element will be set to 0.
B The compiler would report an error.
C The program may crash if some important data gets overwritten.
D The array size would appropriately grow.
Answer C

Q.40 What does the following declaration mean?


int (*ptr)[10];
A ptr is array of pointers to 10 integers
B ptr is a pointer to an array of 10 integers
C ptr is an array of 10 integers
D ptr is an pointer to array
Answer B

Q.41 In C, if you pass an array as an argument to a function, what actually gets


passed?
A Value of elements in array
B First element of the array
C Base address of the array
D Address of the last element of array
Answer C

Q.42 What will be the output of the program #include<stdio.h>


int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A 2, 1, 15
B 1, 2, 5
C 3, 2, 15
D 2, 3, 20
Answer D

Data Structures
Unit I
Introduction to C Programming
Q.43 What will be the output of the program if the array begins 1200 in memory?
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0]);
return 0;
}
A 1200, 1202
B 1200, 1200
C 1200, 1204
D 1200, 1202
Answer B

Q.44 What will be the output of the program in Turb C (under DOS)?
#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
A 1, 2, 3, 4, 5,
B Garbage value, 1, 2, 3, 4,
C 0, 1, 2, 3, 4,
D 2, 3, 4, 5, 6,
Answer B

Q.45 function call strcmp("abc","ABC") will return


A positive number
B negative number
C zero
D one
Answer A

Q.46 what will be the output of following program #include<stdio.h>


#include<conio.h>
#include<string.h>
int main()
{
char str[]={'h','e','l','l','o','/0'};
int n;
n=strlen(str);
printf("%d",n);
}
A 5
B 6
Data Structures
Unit I
Introduction to C Programming
C 4
D 7
Answer A

Q.47 what will be the output of following program #include<stdio.h>


#include<conio.h>
#include<string.h>
int main()
{
char s='x'; printf("%d",s); }
A integer value
B character value
C garbadge value
D none of these
Answer A

Q.48 What is error in following declaration? struct


outer
{
int a;
struct inner
{
char c;
}; };
A Nesting of structure is not allowed in c.
B It is necessary to initialize the member variable.
C Inner structure must have name.
D Outer structure must have name.
Answer C

Q.49 What is the similarity between a structure, union and enumeration?


A All of them let you define new values
B All of them let you define new data types
C All of them let you define new pointers
D All of them let you define new structures
Answer B

Q.50 The size of a pointer data type is


A 2 bytes
B 4 bytes
C 8 bytes
D dependent on the machine and your implementation of C
Answer D

Q.51 Given the C declaration


float t1, *t2=&t1;
which variable contains "garbage"?
A t1
B t2
C *t2
Data Structures
Unit I
Introduction to C Programming
D a and c
Answer D

Q.52 The indirection operator in C is the


A &
B @
C *
D ^
Answer C

Q.53 If the two strings are identical, then strcmp() function returns
A -1
B 1
C 0
D YES
Answer C

Q.54 The library function used to find the first occurrence of a character in a string is
A strnstr()
B laststr()
C strrchr()
D strstr()
Answer D

Q.55 Which of the following function is more appropriate for reading in a multi-word
string?
A printf();
B scanf();
C gets();
D getc()
Answer C

Q.56 Given the C code segment below


int *p, s, *t=&s, u=s;
s=100;
++(*t);
p=t;
++(*p);
After the above code segment, *p would contain
A 99
B 100
C 101
D 102
Answer D

Q.57 Which of the following function is correct that finds the length of a string?
A int xstrlen(char *s)
{ int length=0;
while(*s!='\0')
{ length++;
Data Structures
Unit I
Introduction to C Programming
s++;
}
return (length);
}
B int xstrlen(char s)
{
int length=0;
while(*s!='\0')
length++;
s++;
return (length);
}
C int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
length++;
return (length);
}
D int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
s++;
return (length);
}
Answer A

Q.58 A pointer variable may be initialized with


A any non-zero integer value
B any address in the computer's memory
C the address of an existing variable
D a and c only
Answer B

Q.59 A pointer variable is designed to store ________.


A any legal C value
B a float value
C a memory address
D none of these
Answer C

Q.60 The correct syntax to send an array as a parameter to function:


A func(&array);
B func(array);
C func(*array);
D func(array[size]);
Answer B

Q.61 What is the ascii value of '\0'


Data Structures
Unit I
Introduction to C Programming
A 48
B 125
C 0
D none of these
Answer C

Q.62 What does strcmp() returns if strings are not same


A A non zero value which is the difference of string lengths.
B 0
C 1
D none of these
Answer A

Q.63 What is the output of this C code?


#include <stdio.h>
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
A 10
B some garbadge value
C Compile time error
D Segmentation fault
Answer A

Q.64 int x[3]= {1,2,3};


the address of x[2]is 65498, i.e. the base address of the array is _____
A 65494
B 65492
C 65496
D none of these
Answer A

Q.65 What is the output of following program


Main()
{
char str[10] = {0,0,0,0,0,0,0,0,0,0}
char *s;
int i;
s = str;
For(i=0 ; i<=9; i++)
{
If(*s)
Printf("%c", *s);
Data Structures
Unit I
Introduction to C Programming
S++;
}
}
A No output
B 0000000000
C 48 48 48 48 48 48 48 48 48 48
D none of these
Answer A

Q.66 int long k[4] the total memory occupied by the array is ________.
A 16
B 8
C 4
D 32
Answer A

Q.67 Which of the following are themselves a collection of different data types?
A string
B structures
C char
D All of the mentioned
Answer B

Q.68 Which operator connects the structure name to its member name?
A -
B <-
C .
D Both (b) and (c)
Answer C

Q.69 Which of the following cannot be a structure member?


A Another structure
B Function
C Array
D None of the mentioned
Answer B

Q.70 Which of the following structure declaration will throw an error?


A struct temp
{ }s;
main(){}
B struct temp{};
struct temp s;
main(){};
C struct temp s;
struct temp {};
main(){};
D None of the mentioned
Answer D

Data Structures
Unit I
Introduction to C Programming
Q.71 Which of the following uses structure?
A Array of structures
B Linked Lists
C Binary Tree
D All of the mentioned
Answer D

Q.72 What is the correct syntax to declare a function foo() which receives an array of
structure in function?
A void foo(struct *var);
B void foo(struct *var[]);
C void foo(struct var);
D None of the mentioned
Answer A

Q.73 What is the output of this C code?


#include <stdio.h>
struct student
{
int no;
char name[20];
}
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
A Compile time error
B Nothing
C hello
D Varies
Answer A

Q.74 Number of bytes in memory taken by the below structure is


struct test

int k;
char c;
};
A Multiple of integer size
B integer size+character size
C Depends on the platform
D Multiple of word size
Answer B

Q.75 The correct syntax to access the member of the ith structure in the array of
structures is?
Data Structures
Unit I
Introduction to C Programming
Assuming: struct temp
{
int b;
}s[50];
A s.b.[i];
B s.b[i]
C s[i].b;
D none of these
Answer C

Q.76 comment on output of this c code


#include <stdio.h>
struct temp
{
int a;
int b;
int c;
};
void main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
A No Compile time error, generates an array of structure of size 3
B No Compile time error, generates an array of structure of size 9
C Compile time error, illegal declaration of a multidimensional array
D Compile time error, illegal assignment to members of structure
Answer A

Q.77 What is the output of this C code? (Assuming size of int be 4)


#include <stdio.h>
struct temp
{
int a;
int b;
int c;
} p[] = {0};
void main()
{
printf("%d", sizeof(p));
}
A 4
B 12
C 16
D Can’t be estimated due to ambigous initialization of array
Answer B

Q.78 What is the output of this C code?


#include <stdio.h>
struct student
{
Data Structures
Unit I
Introduction to C Programming
char *name;
};
struct student s[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
printf("%s%s", s[0].name, s[1].name);
s[1].name = "turing";
printf("%s%s", s[0].name, s[1].name);
}
A alan alan alan turing
B alan alan turing turing
C alan turing alan turing
D Run time error
Answer A

Q.79 In the following code, the P2 is Integer Pointer or Integer?


typedef int *ptr;
ptr p1, p2;
A Integer
B Integer pointer
C Error in declaration
D None of above
Answer B

Q.80 What will be the output of the program?


#include<stdio.h>
int main()
{
int y=128;
const int x=y;
printf("%d\n", x);
return 0;
}
A 128
B Garbage value
C error
D 0
Answer A

Q.81 What is the output of this C code?


#include <stdio.h>
int main()
{
int c = 2 ^ 3;
printf("%d\n", c);
}
A 1
B 8
Data Structures
Unit I
Introduction to C Programming
C 9
D 0
Answer A

Q.82 What is the output of this C code?


#include <stdio.h>
int main()
{ int a = 2;
if (a >> 1)
printf("%d\n", a);
}
A 0
B 1
C 2
D No output
Answer C

Q.83 Most appropriate sentence to describe unions is


A Union are like structures
B Union contain members of different data types which share the same storage area
in memory
C Union are less frequently used in program
D Union are used for set operations
Answer B

Q.84 If initialization is a part of a structure, then storage class can be


A Automatic
B Register
C Static
D Anything
Answer D

Q.85 Which of the following comments about union are true?


A Union is a structure whose members share the same storage area
B Size allocated for union is the size of its member needing the maximum storage
C Only one of the members of union can be assigned a value at a particular time
D All of these
Answer D

Q.86 Comment on the output of this C code?


#include <stdio.h>
int main()
{
char *a = {"p", "r", "o", "g", "r", "a", "m"};
printf("%s", a);
}
A Output will be program
B Output will be p
C No output
D Compile-time error
Data Structures
Unit I
Introduction to C Programming
Answer D

Q.87 Arrays are best data structures


A for relatively permanent collections of data
B for the size of the structure and the data in the structure are constantly changing
C for both of above situation
D for none of above situation
Answer A

Q.88 Each array declaration need not give, implicitly or explicitly, the information
about
A the name of array
B the data type of array
C the first data from the set to be stored
D the index set of the array
Answer C

Q.89 The elements of an array are stored successively in memory cells because
A by this way computer can keep track only the address of the first element and the
addresses of other elements can be calculated
B the architecture of computer memory does not allow arrays to store other than
serially
C both of above
D none of above
Answer A

Q.90 From faster to slower, the correct ordering of the complexity classes O[1],O[n2],
O[log2 n], O[log2(n2)], O[n] is:
A O[1], O[log2(n2)], O[log2 n], O[n2], O[n]
B O[n], O[n2], O[log2 n], O[log2(n2)], O[1]
C O[log2 n], O[1], O[n], O[n2], O[log2(n2)]
D O[1], O[log2 n], O[log2(n2)], O[n], O[n2]
Answer D

Q.91 What kind of data structure would you use to store information about a set of
customers and to look up a customer's address knowing only the last name?
A structure
B array of structures
C two-dimensional ARRAY
D structure containing a string for each
customer
Answer B

Q.92 Which algorithm is most similar to the way many people would sort a hand of
cards?
A insertion sort
B Bubble sort
C selection sort
D None of above
Answer A
Data Structures
Unit I
Introduction to C Programming

Q.93 What will be output when you will execute following c code?
#include<stdio.h>
void main()
{
char arr[7]="Network";
printf("%s",arr);
}
A Network
B N
C Garbage value
D None of above
Answer C

Q.94 This function accepts a pointer to a string as an argument, and it returns the
length of the string (not including the null terminator).
A numchar
B strlength
C strlen
D countstring
Answer C

Q.95 The strcpy function's arguments are:


A two character arrays
B two addresses
C one array and one pointer
D None of these
Answer B

Q.96 This function concatenates the contents of one string with another string.
A strcopy
B strappend
C strcat
D stradd
Answer C

Q.97 To define an array that will store students' last names of up to 25 characters in
length, which is an appropriate statement?
A char lastName[25];
B string lastName[25];
C char lastName[26];
D string lastName[24];
Answer C

Q.98 The smallest element of an array’s index is called its


A lower bound.
B upper bound.
C range.
D extraction.
Answer A
Data Structures
Unit I
Introduction to C Programming

Q.99 If the address of A[1][1] and A[2][1] are 1000 and 1010 respectively and each
element
occupies 2 bytes then the array has been stored in _________ order.
A row major
B column major
C matix major
D A
Answer

Q.100 An ADT is defined to be a mathematical model of a user-defined type along with


the collection
of all ____________ operations on that model.
A Cardinality
B Assignment
C Primitive
D Structured
Answer C

Q.101 An array declared int A[100] is to be passed as a parameter to a function. Which


of the following may be used to declare the function's formal parameter?
A int *P
B int P[]
C int p
D 1 and 2
Answer D

Q.102 are *ptr++ and ++*ptr are same?


A no they are not same
B yes they are same
C depends on the value of ptr
D none of these
Answer A

Q.103 choose the meaning of statement const int *ptr


A one cannot change the pointer ptr
B one can change the value pointed by ptr
C both a and b
D none of these
Answer B

Q.104 a short integer occupies 2 bytes, an ordinary integer 4 bytes and long integer
consists of 8 bytes of memory. A structure is defined as struct ABC
{ short x;
int y;
long z;
}abc[10];
total memory required for abc is
A 40
B 24
Data Structures
Unit I
Introduction to C Programming
C 15
D 140
Answer D

Q.105 a double occupies 8 bytes, an ordinary integer 4 bytes and char consists of 1 byte
of memory. A union is defined as
union test
{
double x;
int y[10];
char z;
}abc[10];
total memory required for test is
A 8
B 4
C 80
D 40
Answer D

Q.106 choose the correct option


I. the '.' operator can be used to access structure elements using a structure
variable
II. The -> can be used to access structure using pointer to structure variable
A I and II are false
B I is false and II is true
C I and II are true
D I is true and II is false
Answer C

Q.107 choose the correct option


I. structure can contain elements of different size
II. Union elements cannot be of different size
A I and II are false
B I is false and II is true
C I and II are true
D I is true and II is false
Answer D

Q.108 choose correct option


I. a union cannot be nested in structure
II. Nested unions are allowed
A I and II are false
B I is false and II is true
C I and II are true
D I is true and II is false
Answer B

Q.109 the result of 00011010 | 00010101 is


A 11111
B 11110001
Data Structures
Unit I
Introduction to C Programming
C 10000
D none of these
Answer A

Q.110 what does this means


char *name[3]
A pointer to character
B pointer to array of character
C array of character pointers
D None of above
Answer C

Q.111 what is the output of following


char str1[]="hi",str2;
char *s1=str1,*s2=str2;
s2=s1;
printf("%s",str2);

A hi
B h
C compile time error
D none of these
Answer A

Q.112 what is the output of following


char str1[]="hi",str2;
str2=str1;
printf("%s",str2);
A hi
B h
C compile time error
D none of these
Answer C

Q.113 the members of the union are accessed by______


A dot operator
B pointer -> operator
C both a and b
D none of these
Answer C

Q.114 what is the error in following code


struct data
{
int x=10;
struct data *p;
};
A error in int x=10
B there is no any error
C linker error
Data Structures
Unit I
Introduction to C Programming
D none of these
Answer A

Q.115 choose the correct statement


int main()
{
union data
{
int I;
char a[2];
};
union data a1={100};
return 0;
}
(I) a1 can be initialized in this way
(II) to initialize char a[2] the dot operator is used
A only I is true
B only II is true
C both I and II are true
D both are false
Answer C

Q.116 if two strings are identical then strcmp() function returns


A -1
B 1
C 0
D none of these
Answer C

Q.117 What is the output of this C code?


#include <stdio.h>
#include<string.h>
int main()
{ char s[]="hi";
printf("%d\n", *(s+strlen(s));
return 0;
}
A 0
B i
C ASCII value of i
D syntax error
Answer A

Q.118 What is the output of this C code?


#include <stdio.h>
int main()
{
static char s[]="the wise son";
int i = 0, char ch;
ch=s[++i];
Data Structures
Unit I
Introduction to C Programming
printf("%c\n", ch);
ch=s[i++];
printf("%c\n", ch);

}
A he
B hh
C ee
D syntax error
Answer B

Q.119 What is the output of this C code?


int main()
{ static char str[]="Teena";
str[0]='M';
printf("%s\n", str);
str="Meena";
printf("%s\n", str);
}
A Teena Meena
B Teena Teena
C Syntax error
D none of these
Answer C

Q.120 What is (void*)0?


A Representation of NULL pointer
B Representation of void pointer
C Error
D None of above
Answer A

Q.121 A pointer is
A A keyword used to create variables
B A variable that stores address of an instruction
C A variable that stores address of other variable
D All of the above
Answer C

Q.122 The operator used to get value at address stored in a pointer variable is
A *
B &
C &&
D ||
Answer A

Q.123 A pointer variable may be initialized with


A any non-zero integer value
B any address in the computer's memory
C the address of an existing variable
Data Structures
Unit I
Introduction to C Programming
D a and c only
Answer B

Q.124 How many of the following string declarations are correct?

char string1 = "Hello";


char string2[] = "Hello";
char string3[5] = "Hello";
char string4[6] = {'H','e','l','l','o','\0'};
A None
B 1
C 3
D ALL
Answer C

Q.125 Which one of the following sentences is true?


A Function calls always use the call-by-value method.
B All the arguments of a function must be of the same data type.
C Passing an array to a function involves a pointer.
D Every function must return a value.
Answer C

Q.126 A structured data type and variable is declared as follows:


struct person
{ char name[40];
int age;
char gender;
} someone = {"Francis Doolittle", 20, 'm'};
How many of the following statements are valid?
person another = someone;
someone.name = "Joseph Q. Chang";
gender = (char) age;
A None
B 1
C 2
D ALL
Answer A

Q.127 11 ^ 5
What does the operation shown above produce?
A 1
B 6
C 8
D 14
Answer D

Q.128 From the following data structures which is Non primitive data structure?
A Int
B Stacks
C Char
Data Structures
Unit I
Introduction to C Programming
D Float
Answer B

Q.129 Variables that can be accessed by functions within its scope are called as
A Global
B Search
C Local
D Nonlocal
Answer C

Q.130 Which of the following is not true for main() function?

A It is the first function to be called when the program starts execution.

B The function main() invokes other functions within it.

C It returns an int value to the environment that called the program.

D Recursive call is not allowed for main()


Answer D

Q.131 Which of the following is correct for header files?

A Header files are also called as library files.

B They carry two important things: the definitions and prototypes of functions
being used in a program
C stdio.h is a header file that contains definition and prototypes of commands like
printf and scanf
D All of above are correct
Answer D

Q.132 Control structure of the form


if (condition)
{
Statements;
}
else
{
Statements;
}
Above structure has

A Single Alternative
B Double Alternative
C Multiple Alternative
Data Structures
Unit I
Introduction to C Programming
D No Alternative
Answer B

Q.133 printf() is a standard function of category


A Output
B Input
C Input-Output
D it’s not a function
Answer A

Q.134 break statement in ‘C’ is used to


A Come out of if statement
B Come out of loop
C Come out of switch-case
D Come out of either switch-case or loop
Answer D

Q.135 Function when called by value, can return at the max

A Two
B As many as
C One
D Zero
Answer C

Q.136 In C, if you pass an array as an argument to a function, what actually gets


passed?

A Value of elements in array

B First element of the array


C Base address of the array

D Address of the last element of array


Answer C

Q.137 When we mention the prototype of a function?


A Defining
B Declaring
C Prototyping
D Calling
Answer B

Q.138 Which statement of the following allocates memory to store forty real numbers.
A float a[40];
B float a(40);
C int a(40);
D float a{40};
Answer A
Data Structures
Unit I
Introduction to C Programming

Q.139 What would be output of following program


void main ( )
{
int a=10;
if (a=>0)
{ printf(“Correct”);
}
else
{ printf(“Wrong”);
}
}
A Correct
B Wrong
C No output
D Error
Answer A

Q.140 void main()


{
int x = 10, y = 15;
x = x++;
y = ++y;
printf(“%d, %d ”, x, y);
}
A 10, 15
B 10, 16
C 11, 16
D 11, 15
Answer C

Q.141 What many times following statement executes if n=5


for(i=0;i<n;i- -)
{
printf(“%d”, ++i);
}
A infinite times
B 5 times
C single time
D Error in loop
Answer A

Q.142 What will be output if you will compile and execute the
following ‘C’ code?

#include<stdio.h>
int main()
Data Structures
Unit I
Introduction to C Programming
{
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x);
return (0);
}
A 21
B 18
C 12
D Compiler error
Answer A

Q.143 Within a switch statement.


A continue can be used but break cannot be used
B Both continue and break can be used
C continue cannot be used but break can be used
D Neither continue nor break can be used
Answer C

Q.144 Which of the following declaration of for statement is syntactically correct?


A for();
B for(;);
C for(,);
D for(;;);
Answer D

Q.145 In switch case statement shown as


switch(ch)
{

}
ch can have data type as
A float
B User defined
C int or char
D int only
Answer C

Q.146 Control structure of the form nested if-else has.


A Single Alternative
B Double Alternative
C Multiple Alternative
D No Alternative
Answer C

Q.147 What would be output of following program


void main()
Data Structures
Unit I
Introduction to C Programming
{
int a,b;
b=sizeof(a);
printf(“%d”,b);
}

A 1
B 2
C 4
D 8
Answer B

Q.148 What will happen if in a C program you assign a value to an array element whose
subscript exceeds the size of array?.
A The element will be set to 0.

B The compiler would report an error.

C The program may crash if some important data gets overwritten.

D The array size would appropriately grow.


Answer C

Q.149 What will be the output of the program ?

#include<stdio.h>

int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A 2, 1, 15
B 1, 2, 5
C 3, 2, 15
D 2, 3, 20
Answer C

Q.150 What will be the output of the program in Turb C (under DOS)?

#include<stdio.h>

int main()
{
Data Structures
Unit I
Introduction to C Programming
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)


printf("%d, ", arr[i]);

return 0;
}
A 1, 2, 3, 4, 5
B 0, 1, 2, 3, 4
C Garbage Value, 1, 2, 3, 4
D 2, 3, 4, 5, 6
Answer C

Q.151 What will be the output of the program if the array begins 1200 in memory?
A 1200, 1202, 1204
B 1200, 1200, 1200
C 1200, 1204, 1208
D 1200, 1202, 1200
Answer B

Q.152 The keyword used to transfer control from a function back to the calling function
is.
A switch
B return
C go back
D go to
Answer B

Q.153 Two main measures for the efficiency of an algorithm are


A Processor and memory
B Complexity and capacity
C Time and space
D Data and space
Answer C

Q.154 Which of the following case does not exist in complexity theory
A Best case
B Worst case
C Average case
D Null case
Answer D

Q.155 The Worst case occur in linear search algorithm when

A Item is somewhere in the middle of the array


B Item is not in the array at all
C Item is the last element in the array

Data Structures
Unit I
Introduction to C Programming
D Item is the last element in the array or is not there at all
Answer C

Q.156 The complexity of the average case of an algorithm is

A Much more complicated to analyze than that of worst case


B Much more simpler to analyze than that of worst case
C Sometimes more complicated and some other times simpler than that of worst
case
D None or above
Answer C

Q.157 Arrays are best data structures

A for relatively permanent collections of data


B for the size of the structure and the data in the structure are constantly changing
C for both of above situation
D for none of above situation
Answer A

Q.158 The elements of an array are stored successively in memory cells because

A by this way computer can keep track only the address of the first element and the
addresses of other elements can be calculated by this way computer can keep
track only the address of the first element and the addresses of other elements can
be calculated
B the architecture of computer memory does not allow arrays to store other than
serially
C both of above
D none of above
Answer A

Q.159 When new data are to be inserted into a data structure, but there is no available
space; this situation is usually called.

A underflow
B overflow
C housefull
D saturated
Answer B

Q.160 Which one of the following is not a linear data structure?


A Array
B Binary Tree
C Queue
D Stack
Answer B

Q.161 The keyword used to transfer control from a function back to the calling function
is
Data Structures
Unit I
Introduction to C Programming
A switch
B goto
C go back
D return
Answer D

Q.162 Which of the following is the correct order of evaluation for the below
expression?
z=x+y*z/4%2-1
A */%+-=
B =*/%+-
C /*%-+=
D *%/-+=
Answer A

Q.163 In C, if you pass an array as an argument to a function, what actually gets


passed?
A Value of elements in array
B First element of the array
C Base address of the array
D Address of the last element of array
Answer C

Q.164 Passing an array to the function is known as


A Function Called by Value
B Function Called by reference
C Both A) &B)
D None of these
Answer B

Q.165 Recursive functions are executed in a?


A First In First Out Order
B Load Balancing
C Parallel Fashion
D Last In First Out Order
Answer D

Q.166 The Default Parameter Passing Mechanism is called as


A Call by Value
B Call by Reference
C Call by Address
D Call by Name
Answer A

Q.167 The extra key inserted at the end of the array is called a,
A End key.
B Stop key.
C Sentinel.
D Transposition
Answer C
Data Structures
Unit I
Introduction to C Programming

Q.168 What will be output of following c program?


#include<stdio.h>
void main()
{
int i;
for(i=0;i<5;i++)
{
x=0;
printf("%d",x);
x++;
}
}

A 01234
B 0000
C Infinite loop
D Compilation error
Answer B

Q.169 How many times "India" is get printed?


#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("India");
}
return 0;
}
A Infinite times
B 11 times
C 10 times
D 0 times
Answer D

Q.170 Comment on the following two declarations?


int a[] = {{1, 2, 3}, {2, 3, 4}}; -------------- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}}; -------------- 2
A 1 will work, 2 will not
B 1 and 2, both will work
C 1 won’t work, 2 will work
D Neither of them will work
Answer C
Data Structures
Unit I
Introduction to C Programming

Q.171 Functions can return structure in c?


A true
B False
C Depends on the compiler
D Depends on the standard
Answer A

Q.172 What will be output of following c program?


void main( )
{
int i,j;
for(i=1;i<=4; i++)
{
for(j=1;j<=i; j++)
{
printf(“%d”, i);
}
printf(“\n”);
}
}
A 1
22
333
4444
B 1
12
123
1234
C 1121231234
D 1223334444
Answer B

Q.173 There are four different algorithm A1, A2, A3, A4 to solve the given problem
with the order log(n) , (nlogn),(log n)/n, n/logn respectively. Which is the best
algorithm ?
A A1
B A2
C A3
D A4
Answer D

Q.174 Time complexity of three algorithms given as :O(n), O(n¬2 ) and O(logn). Which
should execute slowest for large value of n?
A O(n¬2 )
B O(logn)
C O(n)
D None of these
Answer D

Data Structures
Unit I
Introduction to C Programming

Q.175 The space factor when determining the efficiency of algorithm is measured by
______
A Counting the maximum amount of memory needed by the algorithm
B Counting the minimum amount of memory needed by the algorithm
C Counting the average memory needed by the algorithm
D Counting maximum disk space needed by an algorithm
Answer D

Q.176 The time factor when determine by the efficiency of algorithm is measured by
_____
A Counting seconds
B Counting the kilobyte of algorithm
C Counting key operations
D Counting the number of statements
Answer C

Q.177 The worst case occur in linear search algorithm when searching_________
A Item is somewhere in the middle of the array
B Item is not in the array at all
C Item is the last element in the array
D Item is the last element in the array or not present in the array
Answer D

Q.178 Which of the following does not exist in the algorithmic complexity?
A Best case
B Worst case
C Average case
D Null case
Answer D

Q.179 The concept of order big O is important because__________


A It can be used to determine the best algorithm that solves the given problem
B It determine the maximum size of a problem that can be solved in a given amount
of time .
C It is the lower bound of growth rate of algorithm
D both (a) and (b)
Answer D

Q.180 What are the first and second arguments of fopen?


A A character string containing the name of the file & the second argument is the
mode
B A character string containing the name of the user & the second argument is the
mode
C A character string containing file pointer & the second argument is the mode
D None of the mentioned
Answer A

Q.181 For binary files, a ___ must be appended to the mode string.
A Nothing
Data Structures
Unit I
Introduction to C Programming
B “b”
C “binary”
D “01”
Answer B

Q.182 What will fopen will return, if there is any error while opening a file?
A Nothing
B EOF
C NULL
D Depends on compiler
Answer C

Q.183 In C language, FILE is of which data type?


A int
B char *
C struct
D None of the mentioned
Answer C

Q.184 What is meant by ‘a’ in the following C operation?


fp = fopen("Random.txt", "a");
A Attach
B Append
C Appprehend
D Add
Answer B

Q.185 If the mode includes b after the initial letter, what does it indicates?
A text file
B big text file
C binary file
D blueprint text
Answer C

Q.186 EOF is an integer type defined in stdio.h & has a value ____________
A 1
B 0
C NULL
D -1
Answer D

Data Structures
Unit II
Searching and Sorting Algorithms
Q.1 The worst case occurs in linear search algorithm when .......
A Item is somewhere in the middle of the array
B Item is not in the array at all
C Item is the last element in the array
D Item is the last element in the array or item is not there at all
Answer D

Q.2 If the number of records to be sorted is small, then ...... sorting can be efficient.
A Merge
B Heap
C Selection
D Bubble
Answer C

Q.3 What will be the output of the program ?


#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A 2, 1, 15
B 1, 2, 5
C 3, 2, 15
D 2, 3, 20

Data Structures
Unit II
Searching and Sorting Algorithms
Answer C

Q.4 The complexity of sorting algorithm measures the ...... as a function of the
number n of items to be sorter.
A average time
B running time
C average-case complexity
D case-complexity
Answer B

Q.5 What will be the output of the program in Turb C (under DOS)?
>

int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)


printf("%d, ", arr[i]);

return 0;
}
A 1, 2, 3, 4, 5,
B Garbage value, 1, 2, 3, 4,
C 0, 1, 2, 3, 4,
D 2, 3, 4, 5, 6,
Answer B

Q.6 A sorting technique that guarantees that records with

Data Structures
Unit II
Searching and Sorting Algorithms
the same primary key occurs in the same order in the
sorted list as in the original unsorted list is said to be
A Stable
B Consistent
C External
D Linear
Answer A

Q.7 You want to check whether a given set of items is


sorted. Which of the following sorting methods will be
most efficient if it is already in sorted order?
A bubble sort
B Selection sort
C insertion sort
D none of these
Answer C

Q.8 Which of the following is not a limitation of binary search algorithm?


A must use a sorted array
B requirement of sorted array is expensive when a lot of insertion and deletions
are needed
C there must be a mechanism to access middle element directly
D binary search algorithm is not efficient when the data elements more than
1500.
Answer D

Q.9 The Average case occurs in linear search algorithm


A when item is somewhere in the middle of the array
B when item is not the array at all
C when item is the last element in the array
D Item is the last element in the array or item is not there at all

Data Structures
Unit II
Searching and Sorting Algorithms
Answer A

Q.10 How will you free the allocated memory ?


A remove(var-name);
B free(var-name);
C delete(var-name);
D dalloc(var-name);
Answer B

Q.11 Binary search algorithm cannot be applied to


A sorted linked list
B sorted binary trees
C sorted linear array
D pointer array
Answer D

Q.12 Complexity of linear search algorithm is .........


A O(n)
B O(logn)
C O(n2)
D O(n logn)
Answer A

Q.13 Sorting algorithm can be characterized as ......


A Simple algorithm which require the order of n2 comparisons to sort n items.
B Sophisticated algorithms that require the O(nlog2n) comparisons to sort items.
C Both of the above
D None of the above
Answer C

Q.14 State True or False for internal sorting algorithms.

Data Structures
Unit II
Searching and Sorting Algorithms
i)Internal sorting are applied when the entire collection if data to be sorted is
small enough that the sorting can take place within main memory.
ii)The time required to read or write is considered to be significant in evaluating
the performance of internal sorting.
A i-True, ii-True
B i-True, ii-False
C i-False, ii-True
D i-False, ii-False
Answer B

Q.15 What will be the output of the program in Turb C (under DOS)?
#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)


printf("%d, ", arr[i]);

return 0;
}
A 1, 2, 3, 4, 5,
B Garbage value, 1, 2, 3, 4,
C 0, 1, 2, 3, 4,
D 2, 3, 4, 5, 6,
Answer B

Q.16 The complexity of merge sort algorithm is ......


A O(n)

Data Structures
Unit II
Searching and Sorting Algorithms
B O(logn)
C O(n2)
D O(n logn)
Answer D

Q.17 .......... is putting an element in the appropriate place in a sorted list yields a
larger sorted order list.
A Insertion
B Extraction
C Selection
D Distribution
Answer A

Q.18 ............order is the best possible for array sorting algorithm which sorts n item.
A O(n logn)
B O(n2)
C O(n+logn)
D O(logn)
Answer C

Q.19 ......... is rearranging pairs of elements which are out of order, until no such pairs
remain.
A Insertion
B Exchange
C Selection
D Distribution
Answer B

Q.20 ............ is the method used by card sorter


A Radix sort
B Insertion

Data Structures
Unit II
Searching and Sorting Algorithms
C Heap
D Quick
Answer A

Q.21 Which of the following sorting algorithm is of divide and conquer type?
A Bubble sort
B Insertion sort
C Merge sort
D Selection sort
Answer C

Q.22 ........ sorting algorithm is frequently used when n is small where n is total
number of elements.
A Heap
B Insertion
C Bubble
D Quick
Answer B

Q.23 Which of the following sorting algorithm is of priority queue sorting type?
A Bubble sort
B Insertion sort
C Merge sort
D Selection sort
Answer D

Q.24 Which of the following is not the required condition for binary search
algorithm?
A The list must be sorted
B There should be the direct access to the middle element in any sub list
C There must be mechanism to delete and/or insert elements in list.

Data Structures
Unit II
Searching and Sorting Algorithms
D Number values should only be present
Answer C

Q.25 Partition and exchange sort is ........


A quick sort
B tree sort
C heap sort
D bubble sort
Answer A

Q.26 Which of the following is not a stable sorting algorithm?


A Insertion Sort
B Selection Sort
C Bubble Sort
D Merge Sort
Answer B

Q.27 Which of the following is not an in-place sorting algorithm?


A Selection Sort
B Quick Sort
C Heap Sort
D Merge Sort
Answer D

Q.28 Running merge sort on an array of size n which is already sorted is


A O(n)
B O(nlogn)
C O(n2)
D None
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.29 The time complexity of a quick sort algorithm which makes use of median,
found by an O(n) algorithm, as pivot element is
A O(n2)
B O(nlogn)
C O(nloglogn)
D O(n)
Answer B

Q.30 Which of the following is not a noncomparison sort?


A Counting sort
B Bucket sort
C Radix sort
D Shell sort
Answer D

Q.31 The time complexity of heap sort in worst case is


A O(logn)
B O(n)
C O(nlogn)
D O(n2)

Answer C

Q.32 If the given input array is sorted or nearly sorted, which of the following
algorithm gives the best performance?
A Insertion Sort
B Selection Sort
C Quick Sort
D Merge Sort
Answer A

Data Structures
Unit II
Searching and Sorting Algorithms
Q.33 Which of the following algorithm pays the least attention to the ordering of the
elements in the input list?
A Insertion Sort
B Selection Sort
C Quick Sort
D None
Answer B

Q.34 Consider the situation in which assignment operation is very costly. Which of
the following sorting algorithm should be performed so that the number of
assignment operations is minimized in general?
A Insertion Sort
B Selection Sort
C Heap Sort
D None
Answer B

Q.35 Time complexity of bubble sort in best case is


A θ (n)
B θ (nlogn)
C θ (n2)
D θ (n(logn) 2)
Answer A

Q.36 Given a number of elements in the range [0….n3]. which of the following
sorting algorithms can sort them in O(n) time?
A Counting sort
B Bucket sort
C Radix sort
D Quick sort
Answer C

Data Structures
Unit II
Searching and Sorting Algorithms

Q.37 Which of the following algorithms has lowest worst case time complexity?
A Insertion Sort
B Selection Sort
C Quick Sort
D Heap Sort
Answer D

Q.38 Which of the following sorting algorithms is/are stable


A Counting sort
B Bucket sort
C Radix sort
D All of the above

Marks 1
Q.39 What will be output if you will compile and execute the following c code?
#include<stdio.h>
#include<conio.h>
#define x 5+2
void main()
{
int i;
i=x*x*x;
printf("%d",i);
}
A 343
B 27
C 133
D compiler error
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.40 What will be output if you will compile and execute the following c code?
#include<stdio.h>
#include<conio.h>
void main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr);
}
A 320
B 1
C 64
D compiler error
Answer C

Q.41 Which of the following sorting method will be the best if number of swapping
done is the only measure of efficienty?
A bubble sort
B Selection sort
C insertion sort
D none of these
Answer B

Q.42 What is the time complexity of selection sort for n number of elements?
A O(n*n)
B O(n(logn))
C O(log n)
D O(2n)
Answer A

Q.43 The way a card game player arranges his cards as he picks them up one by one,
is an example of

Data Structures
Unit II
Searching and Sorting Algorithms
A bubble sort
B Selection sort
C insertion sort
D none of these
Answer C

Q.44 A sorting technique that guarantees that records with the same primary key
occurs in the same order in the sorted list as in the original unsorted list is said
to be
A Stable
B Consistent
C External
D Linear
Answer A

Q.45 Choose the correct statements


A Internal sorting is used if the number of items to be sorted is very large.
B External sorting is used if the number of items to be sorted is very large
C External sorting needs auxilary storage
D Both (b) & (c)
Answer D

Q.46 The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 19, 5, 13
in ascending order, using bubble sort is
A 11
B 12
C 13
D 14
Answer D

Data Structures
Unit II
Searching and Sorting Algorithms
Q.47 A sort which iteratively passes through a list to exchange the first element with
any element less than it and then repeats with a new first element is called
A insertion sort
B bubble sort
C selection sort
D none of these
Answer C

Q.48 A sort which compares adjacent elements in a list and switches where necessary
is
A insertion sort
B bubble sort
C selection sort
D none of these
Answer B

Q.49 Which of the following best describes sorting ?


A Accessing and processing each record exactly once
B Finding the location of the record with a given key
C Arranging the data (record) in some given order
D Adding a new record to the data structure
Answer C

Q.50 The worst case time required to search a given element in a sorted linked list of
length n is
A O(1)
B O(log2 n)
C O(n)
D O(n log2 n)
Answer C

Data Structures
Unit II
Searching and Sorting Algorithms
Q.51 Which of the following sorting algorithm has the running time that is least
dependant on the initial ordering of the input?
A Insertion Sort
B Quick Sort
C Merge Sort
D Selection Sort
Answer D

Q.52 Time complexity to sort elements of binary search tree is


A O(n)
B O(nlogn)
C O(n2)
D O(n2logn)
Answer A

Q.53 The lower bound on the number of comparisons performed by


comparison-based sorting algorithm is
A Ω (1)
B Ω (n)
C Ω (nlogn)
D Ω (n2)
Answer C

Q.54 Which of the following algorithm(s) can be used to sort n integers in range
[1…..n3] in O(n) time?
A Heap
B Quick
C Merge
D Radix
Answer D

Data Structures
Unit II
Searching and Sorting Algorithms
Q.55 Which of the following algorithm design technique is used in the quick sort
algorithm?
A Dynamic programming
B Backtracking
C Divide-and-conquer
D Greedy method
Answer C

Q.56 Merge sort uses


A Divide-and-conquer
B Backtracking
C Heuristic approach
D Greedy approach
Answer A

Q.57 For merging two sorted lists of size m and n into sorted list of size m+n, we
require comparisons of
A O(m)
B O(n)
C O(m+n)
D O(logm + logn)
Answer C

Q.58 A sorting technique is called stable if it


A Takes O(nlogn) times
B Maintains the relative order of occurrence of non-distinct elements
C Uses divide-and-conquer paradigm
D Takes O(n) space
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.59 In a heap with n elements with the smallest element at the root, the seventh
smallest element can be found in time
A θ (nlogn)
B θ (n)
C θ (logn)
D θ (1)
Answer A

Q.60 What would be the worst case time complexity of the insertion sort algorithm, if
the inputs are restricted to permutation of 1…..n with at most n inversion?
A θ (n2)
B θ (nlogn)
C θ (n1.5)
D θ (n)
Answer D

Q.61 In a binary max heap containing n numbers, the smallest element can be found
in time
A θ (n)
B θ (logn)
C θ (loglogn)
D θ (1)
Answer A

Q.62 The time complexity of linear search algorithm over an array of n elements is
A O (log2 n)
B O(n)
C O(n log2 n)
D 0 (n2)
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.63 The time required to search an element in a linked list of length n is
A O(log2 n)
B O(n)
C O(1)
D 0 (n2)
Answer B

Q.64 The worst case time required to search a given element in a sorted linked list of
length n is
A O(1)
B O(log2 n)
C O(n)
D O(n log2 n)
Answer B

Q.65 For a linear search in an array of n elements the time complexity for best, worst
and average case are ......., ....... and ........ respectively
A O(n), O(1), and O(n/2)
B O(1), O(n) and O(n/2)
C O(1),O(n) and O(n)
D O(1), O(n) and (n-1/2)
Answer C

Q.66. The average time required to perform a successful sequential search for an
element in an array A(1 : n) is given by
A (n + 1)/2
B log2n
C n(n + 1)/2
D n2
Answer A

Data Structures
Unit II
Searching and Sorting Algorithms
Q.67 Using the standard algorithm, what is the time required to determine that a
number n is prime?
A Linear time
B Logarithmic time
C Constant time
D Quadratic time
Answer A

Q.68 The average time required to perform a successful sequential search for an
element in an array A (1 : n) is given by
A (n+1)/2
B n (n + 1)/2
C log(n/2)
D n2
Answer A

Q.69 Which of the following is false?


A A serial search begins with the first array element
B A serial search continues searching, element by element, either until a match is
found or until the end of the array is encountered
C A serial search is useful when the amount of data that must be search is small
D For a serial search to work, the data in the array must be arranged in either
alphabetical or numerical order
Answer D

Q.70 A search begins the search with the element that is located in the middle of the
array
A Serial
B Random
C Parallel
D Binary

Data Structures
Unit II
Searching and Sorting Algorithms
Answer D

Q.71 Fibonacci Search is a ------------------------technique


A comparison-based
B Sorting based
C Mapping based
D None of the above
Answer A

Q.72 Fibonacci Search uses __________to search an element in a sorted array.


A Factorial numbers
B Fibonacci numbers
C Catalan Numbers
D Prime numbers
Answer B

Q.73 Fibonacci Search divides given array in ___________


A Equal parts
B unequal parts
C More than 2 parts
D None of the above
Answer B

Q.74 Fibonacci Search uses following algorithm


A Divide-and-conquer
B Backtracking
C Heuristic approach
D Greedy approach
Answer A

Q.75 Following is the similarity between binary and Fibonacci search

Data Structures
Unit II
Searching and Sorting Algorithms
A Search method divides given array in unequal parts
B uses division operator to divide range
C examines relatively closer elements in subsequent steps
D Has Log n time complexity.
Answer D

Q.76 Binary search is different from Fibonacci search in following point


A Works for sorted arrays
B A Divide and Conquer Algorithm.
C uses + and -. operator to divide range
D Has Log n time complexity.
Answer C

Q.77 The worst case occur in linear search algorithm when searching _______
A Item is somewhere in the middle of the array
B Item is not in the array at all
C Item is the last element in the array
D Item is the last element in the array or not present in the array
Answer D

Q.78 Binary search requires average number of comparisons :


A log2n
B log2n(log2n)
C n2
D log2n(n log2n)
Answer A

Q.79 Which of the following does not exist in the algorithm complexity ?
A Best case
B Worst case
C Average case

Data Structures
Unit II
Searching and Sorting Algorithms
D Null case
Answer D

Q.80 The time complexity of binary search is ________


A O(n)
B O(logn)
C O(nlogn)
D O(n2)
Answer B

Q.81 Big oh notation is defined for ______


A Searching
B Optimality
C Time and space complexity
D None of these
Answer C

Q.82 What is the time complexity of bubble sort for n number of elements?
A O(log n)
B O(n(logn))
C O(n*n)
D O(2n)
Answer C

Q.83 What is the time complexity of insertion sort for n number of elements?
A O(n(logn))
B O(n*n)
C O(2n)
D O(log n)
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.84 What is the time complexity of selection sort for n number of elements?
A O(n*n)
B O(n(logn))
C O(log n)
D O(2n)
Answer A

Q.85 The worst case time required to search a given element in a sorted linked list of
length n is
A O(1)
B O(log2 n)
C O(n)
D O(n log2 n)
Answer C

Q.86 Which of the following best describes sorting ?


A Accessing and processing each record exactly once
B Finding the location of the record with a given key
C Arranging the data (record) in some given order
D Adding a new record to the data structure
Answer C

Q.87 A sort which compares adjacent elements in a list and switches where necessary
is
A insertion sort
B bubble sort
C selection sort
D none of these
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.88 A sort which iteratively passes through a list to exchange the first element with
any element less than it and then repeats with a new first element is called
A insertion sort
B bubble sort
C selection sort
D none of these
Answer C

Q.89 A search begins the search with the element that is located in the middle of the
array
A Serial
B Random
C Parallel
D Binary
Answer D

Q.90 The number of interchanges required to sort 5, 1, 6, 2,4 in ascending order


using Bubble Sort is
A 6
B 5
C 7
D 8
Answer B

Q.91 For a linear search in an array of n elements the time complexity for best, worst
and average case are ......., ....... and ........ respectively
A O(n), O(1), and O(n/2)
B O(1), O(n) and O(n/2)
C O(1),O(n) and O(n)
D O(1), O(n) and (n-1/2)
Answer C

Data Structures
Unit II
Searching and Sorting Algorithms

Q.92 The average successful search time for sequential search on 'n' items is
A n/2
B (n-1)/2
C (n+1)/2
D log (n)+1
Answer C

Q.93 A characteristic of the data that binary search uses but the linear search ignores
is the___________
A Order of the elements of the list
B Length of the list
C Maximum value in list
D Type of elements of the list
Answer A

Q.94 Which of the following is false?


A A binary search begins with the middle element in the array
B A binary search continues having the array either until a match is found or until
there are no more elements to search
C If the search argument is greater than the value located in the middle of the
binary, the binary search continues in the upper half of the array
D For a binary search to work, the data in the array must be arranged in either
alphabetical or numerical order
Answer C

Q.95 Suppose DATA array contains 1000000 elements. Using the binary search
algorithm, one requires only about n comparisons to find the location of an item
in the DATA array, then n is
A 60
B 45

Data Structures
Unit II
Searching and Sorting Algorithms
C 20
D None of these
Answer C

Q.96 The Worst case occur in linear search algorithm when


A Item is somewhere in the middle of the array
B Item is not in the array at all
C Item is the last element in the array
D Item is the last element in the array or is not there at all
Answer D

Q.97 The Average case occur in linear search algorithm


A Item is somewhere in the middle of the array
B Item is not in the array at all
C Item is the last element in the array
D Item is the last element in the array or is not there at all
Answer A

Q.98 What is the advantage of linear search?


A Fast
B Time consuming
C Does not needs a sorted array
D Needs a sorted array
Answer C

Q.99 What is the disadvantage of a binary search


A Fast
B Time consuming
C Does not needs a sorted array
D Needs a sorted array
Answer C

Data Structures
Unit II
Searching and Sorting Algorithms

Q.100 If the search item lies in the upper half in case of binary search which is the
correct set of statements.
A top = mid + 1;
B top = mid - 1;
C bot = mid + 1;
D bot = mid - 1;
Answer D

Q.101 What is the time taken by the binary search algorithm to search a key ‘k’ in a
sorted array of ‘n’ elements?
A O(log2 n)
B O(n)
C O(n2)
D O(2n)
Answer C

Q.102 ------------------is a search for data that uses an index to locate the item
A Binary search
B Sequential search
C Indexed search
D Jump search
Answer C

Q.103 The space factor when determining the efficiency of algorithm is measured by
A Counting the maximum memory needed by the algorithm
B Counting the maximum memory needed by the algorithm
C Counting the average memory needed by the algorithm
D Counting the kilobytes of algorithm
Answer A

Data Structures
Unit II
Searching and Sorting Algorithms
Q.103 How many number of swaps required to sort n elements using selection sort in
worst case?
A O(n)
B O(n2)
C O(nlogn)
D O(log2n)
Answer A

Q.104 How many number of shifts required to sort n elements using Insertion sort in
worst case
A O(n)
B O(n2)
C O(nlogn)
D O(log2n)
Answer B

Q.105 How many number of swaps required to sort n elements using Bubble Sort in
worst case?
A O(n)
B O(n2)
C O(nlogn)
D O(log2n)
Answer B

Q.106 ____________ passes are required to sort n data using bubble sort
A N
B n-1
C n-2
D n+2
Answer B

Data Structures
Unit II
Searching and Sorting Algorithms
Q.107 Selection sort is called as_______
A divide sort
B (log n)sort
C Iinterchanged sort
D Exchange sort
Answer C

Q.108 Bubble sort is called as_______


A divide sort
B (log n)sort
C Interchange sort
D Exchange sort
Answer D

Q.109 When a function is recursively called all automatic variables are


A Stored in stack
B Stored in queue
C Stored in array
D Stored in linked list
Answer A

Q.110 There are four different Algorithms A1, A2, A3, A4 to solve the given problem
with the order log(n), (nlogn), log(logn), n/logn respectively. Which is the best
algorithm?
A A1
B A2
C A3
D A4
Answer A

Q.111 The time complexity of linear search algorithm over an array of n elements is

Data Structures
Unit II
Searching and Sorting Algorithms
A O (log2 n)
B O(n)
C O(n log2 n)
D O(n2)
Answer B

Q.112 The time required to search an element in a linked list of length n is


A O(log2 n)
B O(n)
C O(1)
D O (n2)
Answer B

Q.113 The order of the binary search algorithm is


A N
B n2
C nlog(n)
D log(n)
Answer D

Q.114 A characteristic of the data that binary search uses but the linear search ignores
is the___________
A Order of the elements of the list
B Length of the list
C Maximum value in list
D Type of elements of the list
Answer A

Q.115 Which of the following sorting procedure is the slowest?


A Quick sort
B Heap sort

Data Structures
Unit II
Searching and Sorting Algorithms
C Shell sort
D Bubble sort
Answer D

Q.116 A machine took 200 sec to sort 200 names, using bubble sort. In 800 sec, it can
approximately sort
A 400 names
B 800 names
C 750 names
D 800 names
Answer A

Q.117 Given a file of size n the number of times a given file is passed through in
bubble sort is

A n2
B n–1
C n log n
D None of the above
Answer B

Q.118 In bubble sort, for a file of size n, after p iterations number of records in proper
positions is
A n–p
B n-p+1
C P
D None of the above
Answer A

Q.119 For a file of size n, during each pth pass the number of last records left out are

Data Structures
Unit II
Searching and Sorting Algorithms
A n–p
B P
C p–1
D None of the above
Answer C

Q.120 A sort which iteratively passes through a list to exchange the first element with
any element less than it and then repeats with a new first element is called
A insertion sort
B selection sort
C heap sort
D quick sor
Answer B

Q.121 Which of the following sorting methods will be the best if number of swappings
done, is the only measure of efficienty?
A Bubble sort
B Selection sort
C Insertion sort
D Quick sort
Answer B

Q.121 What is the number of swaps required to sort n elements using selection sort, in
the worst case?
A T(n)
B T(n log n)
C T(n2)
D .T(n2 log n)
Answer A

Q.122 Staright selection sort is basically a method of repeated

Data Structures
Unit II
Searching and Sorting Algorithms
A Interchange
B Searching
C position adjustment
D None of the above
Answer C

Q.123 Which of the following sorting algorithms does not have a worst case running
time of O(n2)?
A Insertion sort
B Merge sort
C Quick sort
D Bubble sort
Answer B

Q.124 Merge sort uses


A divide and conquer strategy
B backtracking approach
C heuristic search
D greedy approach
Answer A

Q.125 Assume 5 buffer pages are available to sort a file of 105 pages. The cost of
sorting using m-way merge sort is
A 206
B 618
C 840
D 926
Answer C

Q.126 A desirable choice for the partitioning element in quick sort is


A First element of the list

Data Structures
Unit II
Searching and Sorting Algorithms
B Last element of the list
C Randomly chosen element of the list
D Median of the list
Answer A

Q.127 Quick sort is also known as


A Merge sort
B Heap sort
C Bubble sort
D None of these
Answer D

Q.128 A sort which relatively passes through a list to exchange the first element with
any element less than it and then repeats with a new first element is called
A Insertion sort
B Selection sort
C Heap sort
D Quick sort
Answer D

Data Structures
Unit III
Stack & Queue

Q.1 Process of inserting an element in stack is called ____________


A Create
B Push
C Evaluation
D Pop
Answer B

Q.2 Process of removing an element from stack is called __________


A Create
B Push
C Evaluation
D Pop
Answer D

Q.3 In a stack, if a user tries to remove an element from an empty stack it is called
_________
A Underflow
B Empty collection
C Overflow
D Garbage Collection
Answer A

Q.4 Pushing an element into stack already having five elements and stack size of 5, then
stack becomes ___________
A Overflow
B Crash
C Underflow
D User flow
Answer A

Q.5 What is the value of the postfix expression 6 3 2 4 + – *?


A 1
B 40
C 74
D -18
Answer D

Q.6 The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
A AB+ CD*E - FG /**
B AB + CD* E - F **G /
C AB + CD* E - *F *G /
D AB + CDE * - * F *G /
Answer A

Q.7 The data structure required for Breadth First Traversal on a graph is?
A Stack
B Array
Data Structures
Unit III
Stack & Queue
C Queue
D Tree
Answer C

Q.8 A queue follows __________


A FIFO ( First In First Out) principle
B LIFO (Last In First Out) principle
C Ordered array
D Linear tree
Answer A

Q.9 Circular Queue is also known as ________


A Ring Buffer
B Square Buffer
C Rectangle Buffer
D Curve Buffer
Answer A

Q.10 If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted
one at a time, in what order will they be removed?
A ABCD
B DCBA
C DCAB
D ABDC
Answer A

Q.11 Stack is referred as


A Last in First out (LIFO)
B First in First out (FIFO)
C Last In Last Out
D First in First out
Answer A

Q.12 Stack is data structure in which all insertion and deletions of entries are made at
A One end
B In the middle
C Both ends
D Any position
Answer A

Q.13 A queue is data structure in which all insertion and deletions are made
respectively at
A Rear & front
B Front and rear
C Front and front
D Rear and rear
Answer A

Data Structures
Unit III
Stack & Queue
Q.14 Which data structure is required to convert the infix to prefix
notation?
A Stack
B Linked List
C Binary Tree
D Queue
Answer A

Q.15 Which one of the following node is considered the top of the stack
if the stack is implemented using the linked list?
A First node
B Second node
C Last node
D None of the above
Answer A

Q.16 A list of elements in which enqueue operation takes place from one
end, and dequeue operation takes place from one end is__
A Binary tree
B Stack
C Queue
D Linked List
Answer C

Q.17 Which one of the following is not the type of the Queue?
A Linear queue
B Circular queue
C Double ended queue
D Single ended queue
Answer D

Q.18 Which one of the following is the overflow condition if linear queue
is implemented using an array with a size MAX_SIZE?
A Rear=front
B Rear=front+1
C Rear=MAX_SIZE-1
D Rear=MAX_SIZE
Answer C

Q.19 Which one of the following is the overflow condition if a circular


queue is implemented using array having size MAX?
A Rear= MAX-1
B Rear=MAX
C Front=(rear+1) mod MAX
D None of the above
Answer C

Q.20 The time complexity of enqueue operation in Queue is __


Data Structures
Unit III
Stack & Queue
A O(1)
B O(n)
C I(logn)
D O(nlogn)
Answer A

Q.21 Which of the following that determines the need for the Circular
Queue?
A Avoid wastage of memory
B Access the Queue using priority
C Follows the FIFO principle
D None of the above
Answer A

Q.22 Which one of the following is the correct way to increment the rear
end in a circular queue?
A rear =rear+1
B (rear+1) % max
C (rear % max) + 1
D None of the above
Answer B

Q.23 In the linked list implementation of queue, where will the new
element be inserted?
A At the middle position of the linked list
B At the head position of the linked list
C At the tail position of the linked list
D None of the above
Answer C

Q.24 How many Queues are required to implement a Stack?


A 3
B 2
C 1
D 4
Answer B

Q.25 The necessary condition to be checked before deletion from the


Queue is__
A Overflow
B Underflow
C Rear value
D Front value
Answer B

Q.26 Which data structure is the best for implementing a priority queue?
A Stack
B Linked list
Data Structures
Unit III
Stack & Queue
C Array
D Heap
Answer D

Q.27 Which of the following principle is used if two elements in the


priority queue have the same priority?
A LIFO
B FIFO
C Linear tree
D None of the above
Answer B

Q.28 In the Deque implementation using singly linked list, what would
be the time complexity of deleting an element from the rear end?
A O(1)
B O(n2)
C O(n)
D O(nlogn)
Answer C

Q.29 One difference between stack and queue is


A Queue requires dynamic memory, but stack does not
B Stack requires dynamic memory, but queue does not
C Queue uses two ends of structure; stack uses one end
D Stack uses two ends of structure; queue uses one end
Answer C

Q.30 Stack is used for


A CPU Resource Allocation
B Breadth First Traversal
C Recursion
D None of the above
Answer C

Q.31 push() and pop() functions are found in


A queues
B lists
C stacks
D trees
Answer C

Q.32 Minimum number of queues required for priority queue implementation?


A 5
B 4
C 3
D 2
Answer D

Data Structures
Unit III
Stack & Queue
Q.33 What data structure is used for breadth first traversal of a graph?
A Queue
B Stack
C List
D None of the above
Answer A

Q.34 A queue data-structure can be used for −


A expression parsing
B recursion
C resource allocation
D all of the above
Answer C

Q.35 Prefix notation is also known as


A Reverse Polish Notation
B Reverse Notation
C Polish Reverse Notation
D
Polish Notation

Answer D

Q.36 In conversion from prefix to postfix using stack data-structure, if operators and
operands are pushed and popped exactly once, then the run-time complexity is
A Ο(1)
B Ο(n)
C Ο(log n)
D Ο(n2)
Answer B

Q.37 If queue is implemented using arrays, what would be the worst run time complexity
of queue and dequeue operations?
A Ο(n), Ο(n)
B Ο(n), Ο(1)
C Ο(1), Ο(n)
D Ο(1), Ο(1)
Answer D

Q.38 Queue data structure works on


A LIFO
B FIFO
C FILO
D none of the above
Answer B

Q.39 Which of the following uses FIFO method


A Queue
B Stack
Data Structures
Unit III
Stack & Queue
C Hash Table
D Binary Search Tree
Answer A

Q.40 What data structure can be used to check if a syntax has balanced parenthesis ?
A queue
B tree
C list
D stack
Answer D

Data Structures
Unit IV
Linked List

Q.1 In a circular linked list


A Components are all linked together in some sequential manner.
B There is no beginning and no end.
C Components are arranged hierarchically.
D Forward and backward traversal within the list is permitted.
Answer B

Q.2 A linear collection of data elements where the linear node is given by means of
pointer is called?
A Linked list
B Node list
C Primitive list
D None
Answer A

Q.3 Which of the following operations is performed more efficiently by doubly


linked list than by singly linked list?
A Deleting a node whose location in given
B Searching of an unsorted list for a given item
C Inverting a node after the node with given location
D Traversing a list to process each node
Answer A

Q.4 In linked list each node contains minimum of two fields. One field is data field to
store the data second field is?
A Pointer to character
B Pointer to integer
C Pointer to node
D Node
Answer C

Q.5 What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
A O(1)
B O(n)
C θ (n)
D θ (1)
Answer C

Q.6 What would be the asymptotic time complexity to add an element in the linked
list?
A O(1)
B O(n)
C O(n2)
D None
Answer B

Data Structures
Unit IV
Linked List
Q.7 What would be the asymptotic time complexity to find an element in the linked
list?
A O(1)
B O(n)
C O(n2)
D None
Answer B

Q.8 What would be the asymptotic time complexity to insert an element at the second
position in the linked list?
A O(1)
B O(n)
C O(n2)
D None
Answer A

Q.9 A variant of linked list in which last node of the list points to the first node of the
list is?
A Singly linked list
B Doubly linked list
C Circular linked list
D Multiply linked list
Answer C

Q.10 In doubly linked lists, traversal can be performed?


A Only in forward direction
B Only in reverse direction
C In both directions
D None
Answer C

Q.11 A variant of the linked list in which none of the node contains null pointer is?
A Singly linked list
B Doubly linked list
C Circular linked list
D None
Answer C

Q.12 In circular linked list, insertion of node requires modification of?


A One pointer
B Two pointers
C Three pointers
D None
Answer B

Q.13 In a circular linked list


A Components are all linked together in some sequential manner.
B There is no beginning and no end.
Data Structures
Unit IV
Linked List
C Components are arranged hierarchically.
D Forward and backward traversal within the list is permitted.
Answer B

Q.14 A linear collection of data elements where the linear node is given by means of
pointer is called?
A Linked list
B Node list
C Primitive list
D None of the above
Answer A

Q.15 Which of the following operations is performed more efficiently by doubly


linked list than by singly linked list?
A Deleting a node whose location in given
B Searching of an unsorted list for a given item
C Inverting a node after the node with given location
D Traversing a list to process each node
Answer A

Q.16 What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
A O(1)
B O(n)
C θ (n)
D θ (1)
Answer C

Q.17 In doubly linked lists, traversal can be performed?


A Only in forward direction
B Only in reverse direction
C In both directions
D None of the above
Answer C

Q.18 What kind of linked list is best to answer question like “What is the item at
position n?”
A Singly linked list
B Doubly linked list
C Circular linked list
D Array implementation of linked list
Answer D

Q.19 A variation of linked list is circular linked list, in which the last node in the list
points to first node of the list. One problem with this type of list is?
A It wastes memory space since the pointer head already points to the first node and
thus the list node does not need to point to the first node.
B It is not possible to add a node at the end of the list.

Data Structures
Unit IV
Linked List
C It is difficult to traverse the list as the pointer of the last node is now not NULL
D All of above
Answer C

Q.20 A linear collection of data elements where the linear node is given by means of
pointer is called
A linked list
B node list
C primitive list
D None of these
Answer A

Q.21 The time required to delete a node x from a doubly linked list having n nodes is
A O (n)
B O (log n)
C O (1)
D O (n log n)
Answer C

Q.22 A collection of data items of similar type arranged in a sequence is termed as?
A Memory space
B Static data structure
C Data structure
D List
Answer D

Q.23 A linked list is a linear collection of homogeneous elements called______.


A Runtime
B Nodes
C Pointers
D None of the above
Answer B

Q.24 Depending on what on what can a linked list be classified into various other
types?
A The number of pointers in a node
B The purpose for which the pointers are maintained
C Both (a) and (b)
D None of the above
Answer C

Q.25 In a singly-linked list (linear linked list), how many fields does each node
consists of?
A One
B Three
C Two
D Zero
Answer C
Data Structures
Unit IV
Linked List

Q.26 The last node of the singly-linked list contains__________.


A Info
B NULL
C Next
D None of the above
Answer B

Q.27 A linked list contains a list pointer variable _____that stores the address of the
first node of the list.
A Start
B NULL
C Next
D Empty list
Answer A

Q.28 To maintain a linked list in memory, how many parallel arrays of equal size are
used?
A One
B Two
C Three
D Four
Answer B

Q.29 As memory is allocated dynamically to a linked list, a new node can be inserted
anytime in the list. For this, the memory manager maintains a special linked list
known as___________.
A Free pool
B Memory bank
C Free storage list
D All of the above
Answer C

Q.30 What does create a node mean?


A Defining its structure
B Allocating memory to it
C Initialization
D All of the above
Answer D

Q.31 _________a list means accessing its elements one by one to process all or some
of the elements.
A Traversing
B Creating
C Linking
D None of the above
Answer A

Data Structures
Unit IV
Linked List
Q.32 Searching a value (say, item) in a linked list means finding the position of the
node, which stores ___________ as its value?
A Node
B Item
C info
D None of the above
Answer B

Q.33 A situation where the user tries to delete a node from an empty linked list is
termed as___________.
A Underflow
B Overflow
C Pointers
D None of the above
Answer A

Q.34 To delete a node from the end of a linked list, the list is traversed up to the last
______.
A Pointer
B Node
C List
D None of the above
Answer B

Q.35 Since a doubly-linked list allows traversing in both the forward and backward
directions, it is also referred to as a___________.
A Multi-way list
B One-way list
C Two-way list
D None of the above
Answer C

Q.36 Direct or random access of elements is not possible in ...............


A Linked list
B Array
C String
D None
Answer A

Q.37 To implement Sparse matrix dynamically, the following data structure is used
A Trees
B Graphs
C Priority Queues
D Linked List
Answer D

Q.38 Applications of Linked List are


A Simulation, event driven systems

Data Structures
Unit IV
Linked List
B Postfix and prefix manipulations
C Dictionary systems, polynomial manipulations
D Fixed block storage allocation, garbage collection
Answer D

Q.39 Overflow condition in linked list may occur when attempting to .............
A Create a node when free space pool is empty
B Traverse the nodes when free space pool is empty
C Create a node when linked list is empty
D None of these
Answer A

Q.40 Linked lists are not suitable data structures for which one of the following
problems?
A Insertion sort
B Binary search
C Radix sort
D Polynomial manipulation
Answer B

Q.41 Generally collection of Nodes is called as __________.


A Stack
B Linked List
C Heap
D Pointer
Answer B

Q.42 A linear collection of data element given by mean of pointer is called


______________.
A Linked List
B Queue
C Stack
D Graph
Answer A

Q.43 Which of the following is not a type of Linked List ?


A Doubly Linked List
B Singly Linked List
C Circular Linked List
D Hybrid Linked List
Answer D

Q.44 Linked list is generally considered as an example of _________ type of memory


allocation.
A Static
B Dynamic
C Compile time
D None
Data Structures
Unit IV
Linked List
Answer B

Q.45 Each Node contain minimum two fields one field called data field to store data.
Another field is of type _________.
A Pointer to Class
B Pointer to an Integer
C Pointer to Character
D Pointer to Node
Answer D

Q.46 Consider the Singly linked list having n elements. What will be the time taken to
add an node at the end of linked list if Pointer is initially pointing to first node of
the list.
A O(1)
B O(n-1)
C O(n)
D O(n^2)
Answer B

Q.47 Pointer is pointing to the first element of the Node then time require to Insert
Element to second position is __________.
A O(n)
B O(1)
C O(n^2)
D O(n-1)
Answer B

Q.48 Consider a linked list of n elements. What is the time taken to insert an element
after element pointed by same pointer ?
A O(n)
B O(log n)
C O(n-1)
D O(1)
Answer D

Q.49 The concatenation of two lists is to be performed in O(1) time. Which of the
following implementations of a list could be used ?
A Array Implementation of List
B Singly Linked List
C Circular Doubly Linked List
D Doubly Linked List
Answer C

Q.50 Time require to find any element of the linked list is ______
A O(n)
B O(1)
C O(n^2)
D None of these

Data Structures
Unit IV
Linked List
Answer A

Q.51 struct node *current = start->next


what "current" will contain if it is variable of type struct node ?
A Address of 2nd Node
B Address Field of 2nd Node
C Data Field of 2nd Node
D None of these
Answer A

Q.52 Consider the following linked list and linked list representation. what will be the
value of following statement ?
start->next->next->next->data
struct node {

int data;

struct node *next;

}*start = NULL;

A 12
B 30
C 15
D 25
Answer D

Q.53 In Linked list implementation, a node carries information regarding _______.


A Link
B Data
C Data & link
D None
Answer C

Q.54 A linked list in which the last node of Linked list points to the first is called a
_________.
A Doubly Linked List
B Circular Linked List
C Singly Linked List
D None
Answer B

Q.55 A doubly linked list performs traversal in _________.


A Any direction
B Circular direction
C Either direction
Data Structures
Unit IV
Linked List
D None of the above
Answer C

Q.56 Linked list data structure usage offers considerable saving in


A Space utilization
B Computational time
C Space utilization & computational time
D None of the above
Answer C

Q.57 Consider linked list is used to implement the Stack then which of the following
node is considered as Top of the Stack ?
A Any Node
B Last Node
C First Node
D Middle Node
Answer C

Q.58 The link field in the last node of the linked list contains _________.
A Link to the first node
B Zero value
C Pointer to the next element location
D None of the above
Answer B

Q.59 When new element is added in the middle of singly linked list then ________.
A Only elements that appear after the new element need to be moved
B Only elements that appear before the new element need to be moved
C No need to move element
D Only elements that appear after the new element and before need to be moved
Answer C

Q.60 Which of the following operation is performed more efficiently in doubly linked
list ?
A Inserting a node at given position
B Deleting a node at given position
C Searching a node at given position
D None of these
Answer B

Q.61 If in a linked list address of first node is 1020 then what will be the address of
node at 5th position ?
A 1036
B 1028
C 1038
D None of these
Answer D

Data Structures
Unit IV
Linked List
Q.62 In Circular Linked List insertion of a node involves the modification of ____
links.
A 3
B 4
C 1
D 2
Answer D

Q.63 The time required to search an element in a linked list of length n is


A O(1)
B O(n)
C O (n2)
D O(log2 n)
Answer B

Q.64 The worst case time required to search a given element in a sorted linked list of
length n is
A O(1)
B O(n)
C O (n2)
D O(log2 n)
Answer B

Q.65 If a list contains no elements it is said to be


A Hollow
B Empty
C Finite
D inFinite
Answer B

Q.66 In a linked list array, objects are referred to as


A Instances
B Attributes
C Nodes
D Entity
Answer C

Q.67 Linked list uses


A Random memory allocation
B Static memory allocation
C Fixed memory allocation
D Dynamic memory allocation
Answer D

Q.68 Number of elements stored in any list is called its


A Positioning
B Sequencing
C Model
Data Structures
Unit IV
Linked List
D Length
Answer D

Q.69 An ordered sequence of data items are known to be


A Entities
B Relations
C Elements
D Instances
Answer C

Q.70 First link node of list is accessed from a pointer named


A Tail
B Head
C Terminator
D Initiator
Answer B

Q.71 A linked list is made up of a set of objects known as


A Nodes
B Arrays
C Entities
D Instances
Answer A

Q.72 Beginnning of any list is called its


A Pointer
B head
C Terminator
D Initiator
Answer C

Data Structures
Unit V
Trees

Q.1 The number of edges from the root to the node is called __________ of the tree.
A Height
B Depth
C Length
D Width
Answer B
Explanation: The number of edges from the root to the node is called depth of the
tree.

Q.2 The number of edges from the node to the deepest leaf is called _________ of the
tree.
A Height
B Depth
C Length
D Width
Answer A
Explanation: The number of edges from the node to the deepest leaf is called
height of the tree.

Q.3 What is a full binary tree?


A Each node has exactly zero or two children
B Each node has exactly two children
C All the leaves are at the same level
D Each node has exactly one or two children
Answer A
Explanation: A full binary tree is a tree in which each node has exactly 0 or 2
children.

Q.4 What is a complete binary tree?


A Each node has exactly zero or two children
B A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from right to left
C A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from left to right
D A tree In which all nodes have degree 2
Answer C
Explanation: A binary tree, which is completely filled, with the possible
exception of the bottom level, which is filled from left to right is called complete
binary tree. A Tree in which each node has exactly zero or two children is called
full binary tree. A Tree in which the degree of each node is 2 except leaf nodes is
called perfect binary tree.

Q.5 What is the average case time complexity for finding the height of the binary
tree?
A h = O(loglogn)
B h = O(nlogn)
C h = O(n)

Data Structures
Unit V
Trees
D h = O(log n)
Answer D
Explanation: The nodes are either a part of left sub tree or the right sub tree, so
we don’t have to traverse all the nodes, this means the complexity is lesser than
n, in the average case, assuming the nodes are spread evenly, the time complexity
becomes O(logn).

Q.6 Which of the following is not an advantage of trees?


A Hierarchical structure
B Faster search
C Router algorithms
D Undo/Redo operations in a notepad
Answer D
Explanation: Undo/Redo operations in a notepad is an application of stack.
Hierarchical structure, Faster search, Router algorithms are advantages of trees.

Q.7 In a full binary tree if number of internal nodes is I, then number of leaves L are?
A L = 2*I
B L=I+1
C L=I–1
D L = 2*I – 1
Answer B
Explanation: Number of Leaf nodes in full binary tree is equal to 1 + Number of
Internal Nodes i.e L = I + 1

Q.8 In a full binary tree if number of internal nodes is I, then number of nodes N are?
A N = 2*I
B N=I+1
C N=I–1
D N = 2*I + 1
Answer D
Explanation: Relation between number of internal nodes(I) and nodes(N) is N =
2*I+1.

Q.9 In a full binary tree if there are L leaves, then total number of nodes N are?
A N = 2*L
B N=L+1
C N=L–1
D N = 2*L – 1
Answer D
Explanation: The relation between number of nodes(N) and leaves(L) is N=2*L-
1.

Q.10 Which of the following is incorrect with respect to binary trees?


A Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k
B Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes
C Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log
(N + 1))

Data Structures
Unit V
Trees
D Let T be a binary tree with N nodes. Then the number of levels is at least
floor(log (N + 1))
Answer D
Explanation: In a binary tree, there are atmost 2k nodes in level k and 2k-1 total
number of nodes. Number of levels is at least ceil(log(N+1)).

Q.11 Construct a binary tree by using postorder and inorder sequences given below.
Inorder: N, M, P, O, Q
Postorder: N, P, Q, O, M

Data Structures
Unit V
Trees
C

Answer D

Q.12 Construct a binary search tree by using postorder sequence given below.
Postorder: 2, 4, 3, 7, 9, 8, 5.
A

Data Structures
Unit V
Trees
B

Answer B

Q.13 Construct a binary tree using inorder and level order traversal given below.
Inorder Traversal: 3, 4, 2, 1, 5, 8, 9
Level Order Traversal: 1, 4, 5, 9, 8, 2, 3

Data Structures
Unit V
Trees
A

Answer A

Q.14 For the tree below, write the in-order traversal.

Data Structures
Unit V
Trees

A 6, 2, 5, 7, 11, 2, 5, 9, 4
B 6, 5, 2, 11, 7, 4, 9, 5, 2
C 2, 7, 2, 6, 5, 11, 5, 9, 4
D 2, 7, 6, 5, 11, 2, 9, 5, 4
Answer A

Q.15 Select the code snippet which performs in-order traversal.


A

Answer B

Q.16 What is the space complexity of the in-order traversal in the recursive fashion? (d
is the tree depth and n is the number of nodes)
Data Structures
Unit V
Trees
A O(1)
B O(nlogd)
C O(logd)
D O(d)
Answer D

Q.17 What is the time complexity of level order traversal?


A O(1)
B O(n)
C O(logn)
D O(nlogn)
Answer B

Q.18 Which of the following graph traversals closely imitates level order traversal of a
binary tree?
A Depth First Search
B Breadth First Search
C Depth & Breadth First Search
D Binary Search
Answer B
Explanation: Both level order tree traversal and breadth first graph traversal
follow the principle that visit your neighbors first and then move on to further
nodes.

Q.19 In a binary search tree, which of the following traversals would print the numbers
in the ascending order?
A Level-order traversal
B Pre-order traversal
C Post-order traversal
D In-order traversal
Answer D

Q.20 In postorder traversal of binary tree right subtree is traversed before visiting root.
A True
B False
Answer A
Explanation: Post-order method of traversing involves – i) Traverse left subtree
in post-order, ii) Traverse right subtree in post-order, iii) visit the root.

Q.21 What is the possible number of binary trees that can be created with 3 nodes,
giving the sequence N, M, L when traversed in post-order.
A 15
B 3
C 5
D 8
Answer C

Q.22 The post-order traversal of a binary tree is O P Q R S T. Then possible pre-order

Data Structures
Unit V
Trees
traversal will be ________
A TQRSOP
B TOQRPS
C TQOPSR
D TQOSPR
Answer

Q.23 A binary search tree contains values 7, 8, 13, 26, 35, 40, 70, 75. Which one of the
following is a valid post-order sequence of the tree provided the pre-order
sequence as 35, 13, 7, 8, 26, 70, 40 and 75?
A 7, 8, 26, 13, 75, 40, 70, 35
B 26, 13, 7, 8, 70, 75, 40, 35
C 7, 8, 13, 26, 35, 40, 70, 75
D 8, 7, 26, 13, 40, 75, 70, 35
Answer D

Q.24 Which of the following pair’s traversals on a binary tree can build the tree
uniquely?
A post-order and pre-order
B post-order and in-order
C post-order and level order
D level order and preorder
Answer B
Explanation: A binary tree can uniquely be created by post-order and in-order
traversals.

Q.25 A full binary tree can be generated using ______


A post-order and pre-order traversal
B pre-order traversal
C post-order traversal
D in-order traversal
Answer A
Explanation: Every node in a full binary tree has either 0 or 2 children. A binary
tree can be generated by two traversals if one of them is in-order. But, we can
generate a full binary tree using post-order and pre-order traversals.

Q.26 The maximum number of nodes in a tree for which post-order and pre-order
traversals may be equal is ______
A 3
B 1
C 2
D 5
Answer B
Explanation: The tree with only one node has post-order and pre-order traversals
equal.

Q.27 The steps for finding post-order traversal are traverse the right subtree, traverse
the left subtree or visit the current node.

Data Structures
Unit V
Trees
A True
B False
Answer B
Explanation: Left subtree is traversed first in post-order traversal, then the right
subtree is traversed and then the output current node.

Q.28 The pre-order and in-order are traversals of a binary tree are T M L N P O Q and
L M N T O P Q. Which of following is post-order traversal of the tree?
A LNMOQPT
B NMOPOLT
C LMNOPQT
D OPLMNQT
Answer A

Q.29 For a binary tree the first node visited in in-order and post-order traversal is
same.
A True
B False
Answer B

Q.30 Find the post-order traversal of the binary tree shown below.

A PQRSTUVWX
B WRSQPVTUX
C SWTQXUVRP
D STWUXVQRP
Answer C
Explanation: In post-order traversal the left subtree is traversed first and then the
right subtree and then the current node. So, the post-order traversal of the tree is,
S W T Q X U V R P.

Q.31 For the tree below, write the pre-order traversal.

Data Structures
Unit V
Trees

A 2, 7, 2, 6, 5, 11, 5, 9, 4
B 2, 7, 5, 2, 6, 9, 5, 11, 4
C 2, 5, 11, 6, 7, 4, 9, 5, 2
D 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer A
Explanation: Pre order traversal follows NLR(Node-Left-Right).

Q.32 For the tree below, write the post-order traversal.

A 2, 7, 2, 6, 5, 11, 5, 9, 4
B 2, 7, 5, 2, 6, 9, 5, 11, 4
C 2, 5, 11, 6, 7, 4, 9, 5, 2
D 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer C
Explanation: Post order traversal follows LRN(Left-Right-Node).

Q.33 Select the code snippet which performs pre-order traversal.


A

Data Structures
Unit V
Trees
B

Answer A
Explanation: Pre-order traversal follows NLR(Node-Left-Right).

Q.34 Select the code snippet which performs post-order traversal.


A

Data Structures
Unit V
Trees
D

Answer A
Explanation: Post order traversal follows NLR(Left-Right-Node).

Q.35 What is the time complexity of pre-order traversal in the iterative fashion?
A O(1)
B O(n)
C O(logn)
D O(nlogn)
Answer B
Explanation: Since you have to go through all the nodes, the complexity becomes
O(n).

Q.36 What is the space complexity of the post-order traversal in the recursive fashion?
(d is the tree depth and n is the number of nodes)
A O(1)
B O(nlogd)
C O(logd)
D O(d)
Answer D
Explanation: In the worst case we have d stack frames in the recursive call, hence
the complexity is O(d).

Q.37 To obtain a prefix expression, which of the tree traversals is used?


A Level-order traversal
B Pre-order traversal
C Post-order traversal
D In-order traversal
Answer B
Explanation: As the name itself suggests, pre-order traversal can be used.

Q.38 Consider the following data. The pre order traversal of a binary tree is A, B, E, C,
D. The in order traversal of the same binary tree is B, E, A, D, C. The level order
sequence for the binary tree is _________
A A, C, D, B, E
B A, B, C, D, E
C A, B, C, E, D
D D, B, E, A, C
Answer B

Q.39 Consider the following data and specify which one is Preorder Traversal
Sequence, Inorder and Postorder sequences.
S1: N, M, P, O, Q
Data Structures
Unit V
Trees
S2: N, P, Q, O, M
S3: M, N, O, P, Q
A S1 is preorder, S2 is inorder and S3 is postorder
B S1 is inorder, S2 is preorder and S3 is postorder
C S1 is inorder, S2 is postorder and S3 is preorder
D S1 is postorder, S2 is inorder and S3 is preorder
Answer C

Q.40 What is the maximum number of children that a binary tree node can have?
A 0
B 1
C 2
D 3
Answer C

Q.41 The following given tree is an example for?


A Binary tree
B Binary search tree
C Fibonacci tree
D AVL tree
Answer A
Explanation: The given tree is an example for binary tree since has got two
children and the left and right children do not satisfy binary search tree’s
property, Fibonacci and AVL tree.

Q.42 A binary tree is a rooted tree but not an ordered tree.


A True
B False
Answer B
Explanation: A binary tree is a rooted tree and also an ordered tree (i.e) every
node in a binary tree has at most two children.

Q.43 How many common operations are performed in a binary tree?


A 1
B 2
C 3
D 4
Answer C
Explanation: Three common operations are performed in a binary tree- they are
insertion, deletion and traversal.

Q.44 What is the traversal strategy used in the binary tree?


A depth-first traversal
B breadth-first traversal
C random traversal
D Priority traversal
Answer B
Explanation: Breadth first traversal, also known as level order traversal is the

Data Structures
Unit V
Trees
traversal strategy used in a binary tree. It involves visiting all the nodes at a given
level.

Q.45 How many types of insertion are performed in a binary tree?


A 1
B 2
C 3
D 4
Answer B
Explanation: Two kinds of insertion operation is performed in a binary tree-
inserting a leaf node and inserting an internal node.

Q.46 What operation does the following diagram depict?

A inserting a leaf node


B inserting an internal node
C deleting a node with 0 or 1 child
D deleting a node with 2 children
Answer C
Explanation: The above diagram is a depiction of deleting a node with 0 or 1
child since the node D which has 1 child is deleted.

Q.47 General ordered tree can be encoded into binary trees.


A True
B False
Answer A
Explanation: General ordered tree can be mapped into binary tree by representing
them in a left-child-right-sibling way.

Q.48 How many bits would a succinct binary tree occupy?


A n+O(n)
B 2n+O(n)
C n/2
D n
Answer B
Explanation: A succinct binary tree occupies close to minimum possible space
established by lower bounds. A succinct binary tree would occupy 2n+O(n) bits.

Q.49 The average depth of a binary tree is given as?

Data Structures
Unit V
Trees
A O(N)
B O(√N)
C O(N2)
D O(log N)
Answer D
Explanation: The average depth of a binary tree is given as O(√N). In case of a
binary search tree, it is O(log N).

Q.50 How many orders of traversal are applicable to a binary tree (In General)?
A 1
B 4
C 2
D 3
Answer D
Explanation: The three orders of traversal that can be applied to a binary tree are
in-order, pre-order and post order traversal.

Q.51 If binary trees are represented in arrays, what formula can be used to locate a left
child, if the node has an index i?
A 2i+1
B 2i+2
C 2i
D 4i
Answer A
Explanation: If binary trees are represented in arrays, left children are located at
indices 2i+1 and right children at 2i+2.

Q.52 Using what formula can a parent node be located in an array?


A (i+1)/2
B (i-1)/2
C i/2
D 2i/2
Answer B
Explanation: If a binary tree is represented in an array, parent nodes are found at
indices (i-1)/2.

Q.53 Which of the following properties are obeyed by all three tree – traversals?
A Left subtrees are visited before right subtrees
B ight subtrees are visited before left subtree
C Root node is visited before left subtree
D Root node is visited before right subtree
Answer A
Explanation: In preorder, inorder and postorder traversal the left subtrees are
visited before the right subtrees. In Inorder traversal, the Left subtree is visited
first then the Root node then the Right subtree. In postorder traversal, the Left
subtree is visited first, then Right subtree and then the Root node is visited.

Q.54 Construct a binary tree using the following data.

Data Structures
Unit V
Trees
The preorder traversal of a binary tree is 1, 2, 5, 3, 4. The inorder traversal of the
same binary tree is 2, 5, 1, 4, 3.
A

Answer D

Q.55 Which of the following is false about a binary search tree?

Data Structures
Unit V
Trees
A The left child is always lesser than its parent
B The right child is always greater than its parent
C The left and right sub-trees should also be binary search trees
D In order sequence gives decreasing order of elements
Answer D
Explanation: In order sequence of binary search trees will always give ascending
order of elements. Remaining all are true regarding binary search trees.

Q.56 What is the specialty about the in-order traversal of a binary search tree?
A It traverses in a non-increasing order
B It traverses in an increasing order
C It traverses in a random fashion
D It traverses based on priority of the node
Answer B
Explanation: As a binary search tree consists of elements lesser than the node to
the left and the ones greater than the node to the right, an inorder traversal will
give the elements in an increasing order.

Q.57 What does the following piece of code do?

A Preorder traversal
B Inorder traversal
C Postorder traversal
D Level order traversal
Answer C
Explanation: In a postorder traversal, first the left child is visited, then the right
child and finally the parent.

Q.58 What does the following piece of code do?

A Preorder traversal
B Inorder traversal
C Postorder traversal
D Level order traversal
Answer A
Explanation: In a preorder traversal, first the parent is visited, then the left child
and finally the right child.

Data Structures
Unit V
Trees
Q.59 What are the worst case and average case complexities of a binary search tree?
A O(n), O(n)
B O(logn), O(logn)
C O(logn), O(n)
D O(n), O(logn)
Answer D
Explanation: Worst case arises when the tree is skewed(either to the left or right)
in which case you have to process all the nodes of the tree giving O(n)
complexity, otherwise O(logn) as you process only the left half or the right half
of the tree.

Q.60 Construct a binary search tree with the below information.


The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12.
A

Data Structures
Unit V
Trees
D

Answer C

Q.61 What is an AVL tree?


A a tree which is balanced and is a height balanced tree
B a tree which is unbalanced and is a height balanced tree
C a tree with three children
D a tree with atmost 3 children
Answer A
Explanation: It is a self-balancing tree with height difference atmost 1.

Q.62 Why we need to a binary tree which is height balanced?


A to avoid formation of skew trees
B to save memory
C to attain faster memory access
D to simplify storing
Answer A
Explanation: In real world dealing with random values is often not possible, the
probability that u are dealing with non random values(like sequential) leads to
mostly skew trees, which leads to worst case. hence we make height balance by
rotations.

Q.63 What is the maximum height of an AVL tree with p nodes?


A p
B log(p)
C log(p)/2
D p
⁄2
Answer B
Explanation: Consider height of tree to be ‘he’, then number of nodes which totals
to p can be written in terms of height as N(he)=N(he-1)+1+N(he-2). since N(he)
which is p can be written in terms of height as the beside recurrence relation which
on solving gives N(he)= O(logp) as worst case height.

Q.64 The no of external nodes in a full binary tree with n internal nodes is?
A n
B n+1
C 2n
D 2n + 1
Data Structures
Unit V
Trees
Answer B

Q.65 Which type of traversal of binary search tree outputs the value in sorted order?
A Pre-order
B In-order
C Post-order
D None
Answer B

Q.66 The node which does not have children is referred as


A Parent node
B Root node
C Leaf node
D Siblings
Answer C

Q.67 A binary tree in which all the leaves are on the same level is called as
A Complete Binary tree
B Strictly Binary Tree
C Binary Search Tree
D Full Binary Tree
Answer D

Q.68 The Children of same parent are called as


A Adjacent node
B Non leaf node
C Siblings
D Leaf node
Answer C

Q.69 A tree with null vertices, consists of ____________ edges.


A n-1
B n-2
C n
D log ( n )
Answer A

Q.70 The maximum number of nodes at any level is _________


A n
B 2^n
C n+1
D 2n
Answer B

Q.71 For the binary tree shown in figure the in-order traversal sequence is

Data Structures
Unit V
Trees

A ABCDEFGHIJK
B HIDEBFJKCGA
C HDIBEAFCJGK
D ABDHIECFGJK
Answer C

Q.72 For the binary tree shown in figure the pre-order traversal sequence is

A ABCDEFGHIJK
B HIDEBFJKCGA
C HDIBEAFCJGK
D ABDHIECFGJK
Answer D

Q.73 For the binary tree shown in figure the pre-order traversal sequence is

A ABCDEFGHIJK
B HIDEBFJKCGA
Data Structures
Unit V
Trees
C HDIBEAFCJGK
D ABDHIECFGJK
Answer B

Data Structures

You might also like