0% found this document useful (0 votes)
12 views25 pages

Data-Structure-And-Algorithms (Set 2)

dsa mcq

Uploaded by

Surya A
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)
12 views25 pages

Data-Structure-And-Algorithms (Set 2)

dsa mcq

Uploaded by

Surya A
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/ 25

Data Structure and Algorithms (DSA)

2 of 4 sets

101. A sort which compares adjacent elements in a list and switches wherever
necessary is _______
A. insertion sort
B. bubble sort
C. selection sort
D. none of these
Answer:B

102. Which of the following sorting method is the slowest?


A. quick sort
o m
B. merge sort
. c
C. bubble sort
te
D. none of these
a
Answer:C
q M
c
M
103. Consider that n elements are to be sorted.The worst case complexity of bubble
sort is____
A. o(1)
B. o(log2n)
C. o(n)
D. o(n2)
Answer:D

104. In bubble sort,for a file of size n,after p iterations number of records in proper
position is____
A. n-p
B. n-p+1
C. n-p+2
D. p
Answer:A
105. In bubble sort,for a file of size n,during each pth pass the number of last
records left out are____
A. n-p
B. n-p+1
C. p
D. p-1
Answer:D

106. Given a file size n the number of times a given file is passed through in bubble
sort is____
A. n2
B. n-1
C. nlogn
D. logn
Answer:A

107. Total number of comparision in bubble sort is____


A. o(nlogn)
B. o(n2)
C. o(n)
D. none of these
Answer:B

108. 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. bubble sort
D. merge sort
Answer:B

109. The selection sort is basically a method of repeated


A. interchange
B. searching
C. position adjustment
D. none of these

View all MCQ's at McqMate.com


Answer:C

110. In selection sort of n elements,how many times is the swp function called in the
complete execution of the algorithm?
A. 1
B. n-1
C. n(n-1)/2
D. none of these
Answer:B

111. If two string are identical then strcmp() function returns____


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

112. How will you print\n on screen?


A. printf("\\n");
B. printf(\\\n\);
C. echo\\\\n;
D. printf("\\\\n");
Answer:D

113. Following function is used to find the first occurrence of given string in
another string
A. strchar
B. strnset
C. strstr
D. strrchr
Answer:D

114. Which of the following is more appropriate for reading a multi_word string?
A. printf
B. scanf
C. put

View all MCQ's at McqMate.com


D. gets
Answer:D

115. What will be the output of the following code? Int


main(){printf("Hello","Word\n");return 0;}
A. hello
B. hello world
C. world
D. none of these
Answer:A

116. What will be the output of the following code? Int main(){char str[9]="My
Computer";printf("%s\n",str);return 0;}
A. mycompute
B. syntax error
C. runtime error
D. none of these
Answer:B

117. Pointer is a___________


A. a keyword used to create a variable
B. a variable that stores the address of some instruction
C. a variable that stores the address of some other variable
D. all of the above
Answer:C

118. ____operator is used to get the value stored at address stored in pointer
variable
A. *
B. &
C. dot
D. +
Answer:A

119. Which of the following statement is true about char ****a ?


A. a is pointer to a pointer to a pointer to char

View all MCQ's at McqMate.com


B. a is pointer to a pointer to a pointer to char
C. a is a pointer to a char pointer
D. a is a pointer to a pointer to a char
Answer:B

120. Are *ptr++ and ++*ptr are same?


A. no they are not same
B. yes they are one and the same
C. depends upon the value of ptr
D. none of these
Answer:A

121. What will be the output of the following code? Void main(){int a=10;int
*b=&a;int **c=&b;printf("%d %d %d",a,*b,**c);}
A. 10 10 garbage
B. 10 garbage garbage
C. 10 10 10
D. syntax error
Answer:C

122. Which of the following is a collection of different data type elements?


A. array
B. structure
C. string
D. all of the above
Answer:B

123. What is the similarity between structure,union and enum?


A. all of them let you define new values
B. all of them let you define new pointers
C. all of them let you define new structure
D. all of them let you define new data types
Answer:D

124. Which of the following can not be a structure member?


A. another structure

View all MCQ's at McqMate.com


B. array
C. function
D. none of these
Answer:C

125. 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

126. a-> is systematically correct if_____


A. a is a pointer to a structure in which b is a field
B. a and b are structure
C. a is a structure and b is a pointer to a structure
D. a is a pointer to a structure and b is a structure
Answer:A

127. How many bits are absolutely necessary to store an ASCII character ?
A. 7
B. 8
C. 15
D. 16
Answer:A

128. The result of 0001 1010 / 0001 0101 is


A. 0001 1111
B. 1111 0001
C. 0001 0000
D. none of these
Answer:A

129. The result of 0001 1010 & 0000 1000 is ___


A. 0001 1111

View all MCQ's at McqMate.com


B. 1111 0001
C. 0000 1000
D. none of these
Answer:C

130. The result of 0001 1010 ~ 0100 0011 is


A. 0101 1001
B. 1010 0100
C. 0000 0010
D. none of these
Answer:B

131. The result of 0001 1010^0001 0000 is____


A. 0101 1001
B. 1010 0100
C. 0000 0010
D. none of these
Answer:C

132. The result of 0001 1010 << 2 is____


A. 0101 1100
B. 0110 1000
C. 0001 1110
D. none of these
Answer:B

133. The result of 0001 1010 >>2 is____


A. 0101 1100
B. 0010 1110
C. 0000 0110
D. none of these
Answer:C

134. The most significant bit is lost in following operation


A. <<

View all MCQ's at McqMate.com


B. >>
C. &
D. /
Answer:A

135. The result of i)true AND false II)false or false


A. i)is true and ii)is true
B. i)is true and ii)is false
C. i)is false and ii)is true
D. i)is false and ii)is false
Answer:D

136. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr); return 0;
}
A. 320
B. 1
C. 64
D. none of the above
Answer:C

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

View all MCQ's at McqMate.com


138. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
char c=125;
c=c+10;
printf("%d",c); return 0;
}
A. 135
B. +inf
C. -121
D. -8
Answer:C

139. What will be output if you will compile and execute the following c code?
#include<stdio.h> int main(){
float a=5.2;
if(a==5.2)
printf("Equal");
else if(a<5.2)
printf("Less than");
else
printf("Greater than"); return 0;
}
A. equal
B. less than
C. greater than
D. compiler error
Answer:B

140. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x); return 0;
}
A. 21
B. 18
C. 12

View all MCQ's at McqMate.com


D. compiler error
Answer:A

141. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else{
break;
} return 0;
}
A. it will print nothing
B. -3
C. -2
D. compiler error
Answer:D

142. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int a=10;
printf("%d %d %d",a,a++,++a); return 0;
}
A. 12 11 11
B. 12 10 10
C. 11 11 12
D. 10 10 12
Answer:A

143. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
char *str="Hello world";
printf("%d",printf("%s",str)); return 0;
}

View all MCQ's at McqMate.com


A. 10hello world
B. 11hello world
C. hello world12
D. hello world13
Answer:D

144. What will be output if you will compile and execute the following c code?
#include <stdio.h>
#include <string.h>
int main(){
char *str=NULL;
strcpy(str,"cquestionbank");
printf("%s",str); return 0;
}
A. cquestionbank
B. cquestionbank\\0
C. (null)
D. it will print nothing
Answer:C

145. #include <stdio.h>


#include <string.h>
int main(){
int i=0;
for(;i<=2;)
printf(" %d",++i); return 0;
}
A. 0 1 2 3
B. 0 1 2
C. 1 2 3
D. compiler error
Answer:C

146. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int x;
for(x=1;x<=5;x++);
printf("%d",x); return 0;

View all MCQ's at McqMate.com


}
A. 4
B. 5
C. 6
D. compiler error
Answer:C

147. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
printf("%d",sizeof(5.2)); return 0;
}
A. 2
B. 4
C. 8
D. 10
Answer:C

148. What will be output if you will compile and execute the following c code?
#include <stdio.h>
#include <string.h>
int main(){
char c='\08';
printf("%d",c); return 0;
}
A. 8
B. \8\
C. 9
D. compiler error
Answer:D

149. What will be output if you will compile and execute the following c code?
#include<stdio.h>
#define call(x,y) x##y
int main(){
int x=5,y=10,xy=20;
printf("%d",xy+call(x,y)); return 0;
}
A. 35

View all MCQ's at McqMate.com


B. 510
C. 15
D. 40
Answer:D

150. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int * call();
int main(){ int *ptr;
ptr=call();
printf("%d",*ptr); return 0;
} int * call(){
int a=25;
a++;
return &a;
}
A. 25
B. 26
C. any adress
D. garbage value
Answer:D

151. 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

152. What will be output if you will compile and execute the following c code?
#include<stdio.h> int main(){
int array[]={10,20,30,40};
printf("%d",-2[array]); return 0;
}

View all MCQ's at McqMate.com


A. -60
B. -30
C. 60
D. garbage value
Answer:B

153. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
int i=10;
static int x=i;
if(x==i)
printf("Equal");
else if(x>i)
printf("Greater than");
else
printf("Less than"); return 0;
}
A. equal
B. less than
C. greater than
D. compiler error
Answer:D

154. What will be output if you will compile and execute the following c code?
#include<stdio.h>
#define max 5;
int main(){
int i=0;
i=max++;
printf("%d",i++); return 0;
}
A. 5
B. 6
C. 7
D. 0
Answer:D

View all MCQ's at McqMate.com


155. What will be output if you will compile and execute the following c code?
#include<stdio.h>
int main(){
double far* p,q;
printf("%d",sizeof(p)+sizeof q); return 0; }
A. 12
B. 8
C. 4
D. 1
Answer:A

156. C language was invented by


A. abacus
B. charles babage
C. thomson
D. dennis ritchie
Answer:D

157. The data type created by the data abstraction process is called
A. class
B. structure
C. abstract data type
D. user defined data type
Answer:C

158. A variable which is visible only in the function in which it is defined, is called
A. static
B. auto
C. external
D. local
Answer:D

159. Unsigned integers occupies


A. two bytes
B. four bytes
C. one bytes

View all MCQ's at McqMate.com


D. eight bytes
Answer:C

160. Which of the following data structure is linear type ?


A. strings
B. lists
C. queues
D. all of the above
Answer:D

161. 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

162. Which data structure allows deleting data elements from front and inserting
at rear?
A. stack
B. queue
C. dequeue
D. binary search tree
Answer:B

163. Queue is a -------------- List .


A. fifo
B. lifo
C. lilo
D. liso
Answer:A

164. Stack is a -------------List.


A. lifo
B. fifo

View all MCQ's at McqMate.com


C. lilo
D. lito
Answer:A

165. A node in a linked list must contain at least


A. three fields
B. two fields
C. four fields
D. one field
Answer:B

166. An algorithm is made up of two independent time complexities f (n) and g (n).
Then the complexities of the algorithm is in the order of
A. f(n) x g(n)
B. max ( f(n),g(n))
C. min (f(n),g(n))
D. f(n) + g(n)
Answer:B

167. Big O notation is defined for


A. time and space complexity
B. optimality
C. seaching
D. none of the above
Answer:A

168. Consider that n elements are to be sorted. What is the worst case time
complexity of Bubble sort?
A. o(1)
B. o(log2n)
C. o(n)
D. o(n^2)
Answer:D

169. The complexity of Binary search algorithm is


A. o(n)

View all MCQ's at McqMate.com


B. o(log n)
C. o(n2)
D. o(n log n)
Answer:B

170. The complexity of linear search algorithm is


A. o(n)
B. o(log n)
C. o(n2)
D. o(n log n)
Answer:A

171. Which of the following data structure is linear data structure?


A. trees
B. graphs
C. arrays
D. none of above
Answer:C

172. What is the maximun number of dimensions an array in C may have?

A. two
B. eight
C. twenty
D. theoratically no limit. the only practical limits are memory size and compilers
Answer:D

173. An external variable


A. is globally accessible by all functions
B. has a declaration
C. will be initialized to 0 if not initialized
D. all of these
Answer:D

View all MCQ's at McqMate.com


174. The declaration "unsigned u" indicates u is a/an

A. unsigned character
B. unsigned integer
C. character
D. none of\ these
Answer:B

175. A declaration "short int" is used for variables

A. which have a short duration in a program


B. which have short names
C. which may require less storage than normal integers
D. all of these
Answer:C

176. Which of the following 'C' type is not a primitive data structure?

A. int
B. float
C. char
D. none of these
Answer:D

177. The program fragment


int i = 263 ;
putchar (i) ;
prints

A. 263
B. ascii equivalent of 263
C. rings the bell
D. garbage
Answer:C

178. The variables which can be accessed by all modules in a program, are called

View all MCQ's at McqMate.com


A. local variables
B. internal variables
C. external variable
D. global variables
Answer:D

179. The main measures of efficiency of an algorithm are


A. processor and memory
B. complexity and capacity
C. time and space
D. data and space
Answer:C

180. The worst case occures in linear search algorithms when


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

181. the terms push and pop are related to


A. stack
B. queue
C. array
D. none of the above
Answer:A

182. What will be the output of the program? #include<stdio.h>


int main()
{
int X=40;
{
int X=20;
printf("%d ", X);
}
printf("%d\n", X);

View all MCQ's at McqMate.com


return 0;
}
A. 40 40
B. 20 20
C. 20
D. error
Answer:D

183. What additional requirement is placed on an array, so that binary search may
be used to locate an entry?
A. the array elements must form a heap
B. the array must have at least 2 entries.
C. the array must be sorted.
D. the array\s size must be a power of two.
Answer:C

184. One difference between a queue and a stack is:


A. queues require dynamic memory, but stacks do not.
B. stacks require dynamic memory, but queues do not
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:C

185. 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

186. Which of the following formulas in big-O notation best represent the
expression n²+35n+6?
A. o(n³)
B. o(n²)
C. o(n)

View all MCQ's at McqMate.com


D. o(42)
Answer:B

187. What term is used to describe an O(n) algorithm


A. constant
B. linear
C. logarithmic
D. quadratic
Answer:B

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

189. How many times the program will print "Amrutvahini" ? #include<stdio.h>
int main()
{
printf("Amrutvahini");
main();
return 0;
}
A. infinite times
B. 32767 times
C. 65535 times
D. till stack overflows
Answer:D

190. What will be the output of the program? #include<stdio.h>


int i;
int fun();

int main()
{
while(i)

View all MCQ's at McqMate.com


{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}
A. hello
B. hi hello
C. no output
D. infinite loop
Answer:A

191. In a linked list, the pointer of the last node contains a special value, called the
______ pointer.
A. null
B. zero
C. link
D. next pointer
Answer:A

192. In a ________ linked list, the last node's link field points to the first node of
the list.
A. circularly
B. linearly
C. sequentially
D. indexed
Answer:A

193. The second part of the node, is called _______ field, and contains the address
of the next node in the list.
A. pointer
B. field
C. node

View all MCQ's at McqMate.com


D. link
Answer:D

194. The link list also contains a list pointer variable called start or ________.
A. name
B. field
C. node
D. link
Answer:A

195. A ________ linked list is a linked list structure in which each node has a
pointer to both its successor and predecessor.
A. circularly
B. doubly
C. linear
D. sequential
Answer:B

196. _______ list is a special list that is maintained, which consists of unused
memory cells.
A. linear
B. doubly linked
C. circularly linked
D. free storage
Answer:D

197. _______ is a technique using which a computer periodically collects all the
deleted space onto the free storage list.
A. garbage collection
B. garbage compaction
C. linked list
D. free storage
Answer:A

198. _______ attacks the problem of fragmentation by moving all the allocated
blocks to one end of memory, thus combining all the holes.

View all MCQ's at McqMate.com


A. underflow
B. overflow
C. compaction
D. free storage
Answer:B

199. A ________ linked list is a linked list which always contains a special node,
called the header node.
A. circular
B. grounded
C. header
D. doubly
Answer:C

200. A polynomial can be represented in a _______ by just storing the coefficient


and exponent of each term.
A. array
B. linked list
C. queue
D. stack
Answer:B

View all MCQ's at McqMate.com

You might also like

pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy