340+ Data Structure and Algorithms (DSA) Solved MCQs

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. bubble sort
102.

Which of the following sorting method is the slowest?

A. quick sort
B. merge sort
C. bubble sort
D. none of these
Answer» C. bubble sort
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. o(n2)
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. n-p
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. p-1
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. n2
107.

Total number of comparision in bubble sort is____

A. o(nlogn)
B. o(n2)
C. o(n)
D. none of these
Answer» B. o(n2)
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. selection sort
109.

The selection sort is basically a method of repeated

A. interchange
B. searching
C. position adjustment
D. none of these
Answer» C. position adjustment
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. n-1
111.

If two string are identical then strcmp() function returns____

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

How will you print\n on screen?

A. printf("\\n");
B. printf(\\\n\);
C. echo\\\\n;
D. printf("\\\\n");
Answer» D. printf("\\\\n");
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. strrchr
114.

Which of the following is more appropriate for reading a multi_word string?

A. printf
B. scanf
C. put
D. gets
Answer» D. gets
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. hello
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. syntax error
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. a variable that stores the address of some other variable
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
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. a is pointer to a pointer to a pointer to char
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. no they are not same
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. 10 10 10
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. structure
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. all of them let you define new data types
124.

Which of the following can not be a structure member?

A. another structure
B. array
C. function
D. none of these
Answer» C. function
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. both a and b
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. a is a pointer to a structure in which b is a field
127.

How many bits are absolutely necessary to store an ASCII character ?

A. 7
B. 8
C. 15
D. 16
Answer» A. 7
128.

The result of 0001 1010 / 0001 0101 is

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

The result of 0001 1010 & 0000 1000 is ___

A. 0001 1111
B. 1111 0001
C. 0000 1000
D. none of these
Answer» C. 0000 1000
130.

The result of 0001 1010 ~ 0100 0011 is

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

The result of 0001 1010^0001 0000 is____

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

The result of 0001 1010 << 2 is____

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

The result of 0001 1010 >>2 is____

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

The most significant bit is lost in following operation

A. <<
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. i)is false and ii)is false
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. 64
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. 27
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. -121
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. less than
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
D. compiler error
Answer» A. 21
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. compiler error
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. 12 11 11
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;
}

A. 10hello world
B. 11hello world
C. hello world12
D. hello world13
Answer» D. hello world13
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. (null)
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. 1 2 3
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;
}

A. 4
B. 5
C. 6
D. compiler error
Answer» C. 6
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. 8
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. compiler error
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
B. 510
C. 15
D. 40
Answer» D. 40
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. garbage value
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. inner structure must have name
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;
}

A. -60
B. -30
C. 60
D. garbage value
Answer» B. -30
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. compiler error
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. 0
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. 12
156.

C language was invented by

A. abacus
B. charles babage
C. thomson
D. dennis ritchie
Answer» D. dennis ritchie
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. abstract data type
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. local
159.

Unsigned integers occupies

A. two bytes
B. four bytes
C. one bytes
D. eight bytes
Answer» C. one bytes
160.

Which of the following data structure is linear type ?

A. strings
B. lists
C. queues
D. all of the above
Answer» D. all of the above
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. base address of the array
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. queue
163.

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

A. fifo
B. lifo
C. lilo
D. liso
Answer» A. fifo
164.

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

A. lifo
B. fifo
C. lilo
D. lito
Answer» A. lifo
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. two fields
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. max ( f(n),g(n))
167.

Big O notation is defined for

A. time and space complexity
B. optimality
C. seaching
D. none of the above
Answer» A. time and space complexity
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. o(n^2)
169.

The complexity of Binary search algorithm is

A. o(n)
B. o(log n)
C. o(n2)
D. o(n log n)
Answer» B. o(log n)
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. o(n)
171.

Which of the following data structure is linear data structure?

A. trees
B. graphs
C. arrays
D. none of above
Answer» C. arrays
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. theoratically no limit. the only practical limits are memory size and compilers
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. all of these
174.

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

A. unsigned character
B. unsigned integer
C. character
D. none of\ these
Answer» B. unsigned integer
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. which may require less storage than normal integers
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. none of these
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. rings the bell
178.

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


A. local variables
B. internal variables
C. external variable
D. global variables
Answer» D. global variables
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. time and space
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. item is last element in the array or is not there at all.
181.

the terms push and pop are related to

A. stack
B. queue
C. array
D. none of the above
Answer» A. stack
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);
return 0;
}

A. 40 40
B. 20 20
C. 20
D. error
Answer» D. error
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. the array must be sorted.
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. queues use two ends of the structure; stacks use only one.
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. dcba
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)
D. o(42)
Answer» B. o(n²)
187.

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

A. constant
B. linear
C. logarithmic
D. quadratic
Answer» B. linear
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. return
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. till stack overflows
190.

What will be the output of the program? #include<stdio.h>
int i;
int fun();

int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}

A. hello
B. hi hello
C. no output
D. infinite loop
Answer» A. hello
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. null
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. circularly
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
D. link
Answer» D. link
194.

The link list also contains a list pointer variable called start or ________.

A. name
B. field
C. node
D. link
Answer» A. name
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. doubly
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. free storage
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. garbage collection
198.

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

A. underflow
B. overflow
C. compaction
D. free storage
Answer» B. overflow
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. header
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. linked list
Tags
  • Question and answers in Data Structure and Algorithms (DSA),
  • Data Structure and Algorithms (DSA) multiple choice questions and answers,
  • Data Structure and Algorithms (DSA) Important MCQs,
  • Solved MCQs for Data Structure and Algorithms (DSA),
  • Data Structure and Algorithms (DSA) MCQs with answers PDF download