Data Structures
Data Structures
Following are the multiple choice questions (MCQs) or objective questions from Data Structures and Algorithms. The questions are set from the topics such as arrays, records, pointers, linked lists, stacks, queues, recursion, trees, sorting and searching.
Set - 1
1. 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 2. The time factor when determining the efficiency of algorithm is measured by a. Counting microseconds b. Counting the number of key operations c. Counting the number of statements d. Counting the kilobytes of algorithm 3. The space factor when determining the efficiency of algorithm is measured by a. Counting the maximum memory needed by the algorithm b. Counting the minimum memory needed by the algorithm c. Counting the average memory needed by the algorithm d. Counting the maximum disk space needed by the algorithm 4. Which of the following case does not exist in complexity theory a. Best case b. Worst case c. Average case d. Null case 5. 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 6. The Average case occur in linear search algorithm
a. When Item is somewhere in the middle of the array b. When Item is not in the array at all c. When Item is the last element in the array d. When Item is the last element in the array or is not there at all 7. 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 8. The complexity of linear search algorithm is a. O(n) b. O(log n) c. O(n2) d. O(n log n) 9. The complexity of Binary search algorithm is a. O(n) b. O(log ) c. O(n2) d. O(n log n) 10. The complexity of Bubble sort algorithm is a. O(n) b. O(log n) c. O(n2) d. O(n log n) 11. The complexity of merge sort algorithm is a. O(n) b. O(log n) c. O(n2) d. O(n log n) 12. The indirect change of the values of a variable in one module by another module is called a. internal change b. inter-module change c. side effect d. side-module update 13. Which of the following data structure is not linear data structure? a. Arrays b. Linked lists
c. Both of above d. None of above 14. Which of the following data structure is linear data structure? a. Trees b. Graphs c. Arrays d. None of above 15. The operation of processing each element in the list is known as a. Sorting b. Merging c. Inserting d. Traversal 16. Finding the location of the element with a given value is: a. Traversal b. Search c. Sort d. None of above 17. 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 18. Linked lists are best suited 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 19. 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 20. 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
Answers
1. Two main measures for the efficiency of an algorithm are c. Time and space 2. The time factor when determining the efficiency of algorithm is measured by b. Counting the number of key operations 3. The space factor when determining the efficiency of algorithm is measured by a. Counting the maximum memory needed by the algorithm 4. Which of the following case does not exist in complexity theory d. Null case 5. The Worst case occur in linear search algorithm when d. Item is the last element in the array or is not there at all 6. The Average case occur in linear search algorithm a. When Item is somewhere in the middle of the array 7. The complexity of the average case of an algorithm is a. Much more complicated to analyze than that of worst case 8. The complexity of linear search algorithm is a. O(n) 9. The complexity of Binary search algorithm is b. O(log n) 10. The complexity of Bubble sort algorithm is c. O(n2) 11. The complexity of merge sort algorithm is d. O(n log n) 12. The indirect change of the values of a variable in one module by another module is called c. side effect 13. Which of the following data structure is not linear data structure? d. None of above 14. Which of the following data structure is linear data structure? c. Arrays 15. The operation of processing each element in the list is known as d. Traversal
16. Finding the location of the element with a given value is: b. Search 17. Arrays are best data structures a. for relatively permanent collections of data 18. Linked lists are best suited b. for the size of the structure and the data in the structure are constantly changing 19. Each array declaration need not give, implicitly or explicitly, the information about c. the first data from the set to be stored 20. 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
Data structures & Algorithms Multiple Choice Questions (MCQs) Objective Set 2
Set - 2
1. The memory address of the first element of an array is called a. floor address b. foundation address c. first address d. base address 2. The memory address of fifth element of an array can be calculated by the formula a. LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words per memory cell for the array b. LOC(Array[5])=Base(Array[5])+(5-lower bound), where w is the number of words per
memory cell for the array c. LOC(Array[5])=Base(Array[4])+(5-Upper bound), where w is the number of words per memory cell for the array d. None of above 3. Which of the following data structures are indexed structures? a. linear arrays b. linked lists c. both of above d. none of above 4. 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 sublist c. There must be mechanism to delete and/or insert elements in list d. none of above 5. 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 are more than 1000. 6. Two dimensional arrays are also called a. tables arrays b. matrix arrays c. both of above d. none of above 7. A variable P is called pointer if a. P contains the address of an element in DATA. b. P points to the address of first element in DATA c. P can store only memory addresses d. P contain the DATA and the address of DATA 8. Which of the following data structure can't store the non-homogeneous data elements? a. Arrays b. Records c. Pointers
d. None 9. Which of the following data structure store the homogeneous data elements? a. Arrays b. Records c. Pointers d. None 10. Each data item in a record may be a group item composed of sub-items; those items which are indecomposable are called a. elementary items b. atoms c. scalars d. all of above 11. The difference between linear array and a record is a. An array is suitable for homogeneous data but hte data items in a record may have different data type b. In a record, there may not be a natural ordering in opposed to linear array. c. A record form a hierarchical structure but a lienear array does not d. All of above 12. Which of the following statement is false? a. Arrays are dense lists and static data structure b. data elements in linked list need not be stored in adjecent space in memory c. pointers store the next data element of a list d. linked lists are collection of the nodes that contain information part and next pointer 13. Binary search algorithm can not be applied to a. sorted linked list b. sorted binary trees c. sorted linear array d. pointer array 14. 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
15. The situation when in a linked list START=NULL is a. underflow b. overflow c. housefull d. saturated 16. Which of the following is two way list? a. grounded header list b. circular header list c. linked list with header and trailer nodes d. none of above 17. Which of the following name does not relate to stacks? a. FIFO lists b. LIFO list c. Piles d. Push-down lists 18. The term "push" and "pop" is related to the a. array b. lists c. stacks d. all of above 19. A data structure where elements can be added or removed at either end but not in the middle a. Linked lists b. Stacks c. Queues d. Deque 20. When inorder traversing a tree resulted E A C K F H D B G; the preorder traversal would return a. FAEKCDBHG b. FAEKCDHGB c. EAFKHDCBG d. FEAKDCHBG
Answers
1. The memory address of the first element of an array is called d. base address 2. The memory address of fifth element of an array can be calculated by the formula a. LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words per memory cell for the array 3. Which of the following data structures are indexed structures? a. linear arrays 4. Which of the following is not the required condition for binary search algorithm? c. There must be mechanism to delete and/or insert elements in list 5. Which of the following is not a limitation of binary search algorithm? d. binary search algorithm is not efficient when the data elements are more than 1000. 6. Two dimensional arrays are also called c. both of above 7. A variable P is called pointer if a. P contains the address of an element in DATA. 8. Which of the following data structure can't store the non-homogeneous data elements? a. Arrays 9. Which of the following data structure store the non-homogeneous data elements? b. Records 10. Each data item in a record may be a group item composed of sub-items; those items which are indecomposable are called d. all of above 11. The difference between linear array and a record is d. All of above 12. Which of the following statement is false? c. pointers store the next data element of a list 13. Binary search algorithm can not be applied to a. sorted linked list 14. When new data are to be inserted into a data structure, but there is no available space; this situation is usually called b. overflow 15. The situation when in a linked list START=NULL is a. underflow 16. Which of the following is two way list?
d. none of above 17. Which of the following name does not relate to stacks? a. FIFO lists 18. The term "push" and "pop" is related to the c. stacks 19. A data structure where elements can be added or removed at either end but not in the middle d. Deque 20. When inorder traversing a tree resulted E A C K F H D B G; the preorder traversal would return b. FAEKCDHGB
Data structures & Algorithms Multiple Choice Questions (MCQs) Objective Set 3
Set - 3
1. Which data structure allows deleting data elements from front and inserting at rear? a. Stacks b. Queues c. Deques d. Binary search tree 2. Identify the data structure which allows deletions at both ends of the list but insertion at only one end. a. Input-restricted deque b. Output-restricted deque c. Priority queues d. None of above 3. Which of the following data structure is non-linear type? a. Strings b. Lists c. Stacks d. None of above 4. Which of the following data structure is linear type? a. Strings
b. Lists c. Queues d. All of above 5. To represent hierarchical relationship between elements, which data structure is suitable? a. Deque b. Priority c. Tree d. All of above 6. A binary tree whose every node has either zero or two children is called a. Complete binary tree b. Binary search tree c. Extended binary tree d. None of above 7. The depth of a complete binary tree is given by a. Dn = n log2n b. Dn = n log2n+1 c. Dn = log2n d. Dn = log2n+1 8. When representing any algebraic expression E which uses only binary operations in a 2-tree, a. the variable in E will appear as external nodes and operations in internal nodes b. the operations in E will appear as external nodes and variables in internal nodes c. the variables and operations in E will appear only in internal nodes d. the variables and operations in E will appear only in external nodes 9. A binary tree can easily be converted into q 2-tree a. by replacing each empty sub tree by a new internal node b. by inserting an internal nodes for non-empty node c. by inserting an external nodes for non-empty node d. by replacing each empty sub tree by a new external node 10. When converting binary tree into extended binary tree, all the original nodes in binary tree are a. internal nodes on extended tree b. external nodes on extended tree c. vanished on extended tree d. None of above 11. The post order traversal of a binary tree is DEBFCA. Find out the pre order traversal a. ABFCDE b. ADBFEC c. ABDECF d. ABDCEF 12. Which of the following sorting algorithm is of divide-and-conquer type? a. Bubble sort b. Insertion sort c. Quick sort d. All of above 13. An algorithm that calls itself directly or indirectly is known as a. Sub algorithm b. Recursion c. Polish notation d. Traversal algorithm
14. In a binary tree, certain null entries are replaced by special pointers which point to nodes higher in the tree for efficiency. These special pointers are called a. Leaf b. branch c. path d. thread 15. The in order traversal of tree will yield a sorted listing of elements of tree in a. Binary trees b. Binary search trees c. Heaps d. None of above 16. In a Heap tree a. Values in a node is greater than every value in left sub tree and smaller than right sub tree b. Values in a node is greater than every value in children of it c. Both of above conditions applies d. None of above conditions applies 17. In a graph if e=[u, v], Then u and v are called a. endpoints of e b. adjacent nodes c. neighbors d. all of above 18. A connected graph T without any cycles is called a. a tree graph b. free tree c. a tree d. All of above 19. In a graph if e=(u, v) means a. u is adjacent to v but v is not adjacent to u b. e begins at u and ends at v c. u is processor and v is successor d. both b and c 20. If every node u in G is adjacent to every other node v in G, A graph is said to be a. isolated b. complete c. finite d. strongly connected
Answers:
1. Which data structure allows deleting data elements from front and inserting at rear? b. Queues 2. Identify the data structure which allows deletions at both ends of the list but insertion at only one end.
a. Input-restricted deque 3. Which of the following data structure is non-linear type? d. None of above 4. Which of the following data structure is linear type? d. All of above 5. To represent hierarchical relationship between elements, which data structure is suitable? c. Tree 6. A binary tree whose every node has either zero or two children is called c. Extended binary tree 7. The depth of a complete binary tree is given by d. Dn = log2n + 1 8. When representing any algebraic expression E which uses only binary operations in a 2-tree, a. the variable in E will appear as external nodes and operations in internal nodes 9. A binary tree can easily be converted into q 2-tree d. by replacing each empty sub tree by a new external node 10. When converting binary tree into extended binary tree, all the original nodes in binary tree are a. internal nodes on extended tree 11. The post order traversal of a binary tree is DEBFCA. Find out the pre order traversal c. ABDECF 12. Which of the following sorting algorithm is of divide-and-conquer type? c. Quick sort 13. An algorithm that calls itself directly or indirectly is known as b. Recursion 14. In a binary tree, certain null entries are replaced by special pointers which point to nodes higher in the tree for efficiency. These special pointers are called d. thread 15. The in order traversal of tree will yield a sorted listing of elements of tree in b. Binary search trees 16. In a Heap tree b. Values in a node is greater than every value in children of it 17. In a graph if e=[u, v], Then u and v are called d. all of above 18. A connected graph T without any cycles is called d. All of above 19. In a graph if e=(u, v) means d. both b and c 20. If every node u in G is adjacent to every other node v in G, A graph is said to be b. complete
#include<stdio.h> void main() { int s=0; while(s++<10) { if(s<4 && s<9) continue; printf("\n%d\t",s); } }
1) 2) 3) 4) 1 1 4 4 2 2 5 5 3 3 6 6 456789 10 7 8 9 10 789
# include<stdio.h> # define a 10 main() { printf("%d..",a); foo(); printf("%d",a); } void foo() { #undef a #define a 50 }
1) 2) 3) 4) 10..10 10..50 Error 0
#include <stdio.h> void main() { int I=3,*j,**k; j=&I; k=&j; printf("%d%d%d",*j,**k,*(*k)); } What is the output of the above program code?
1) 2) 3) 4)
int initialize(NODE **circle) { if ((*circle = (NODE *)malloc(sizeof(NODE))) == NULL) return 0; (*circle)->next = NULL; (*circle)->previous = NULL; return 1; }
1) 2) 3) 4) The node circle is assigned to NULL The size of the node circle is assigned to NULL Both the pointers next and previous are assigned to NULL None of these options
3) 5 4) error
i. write characters to a file ii. takes 2 parameters iii. returns a character iv. requires a file pointer
1) 2) 3) 4)
all are true all are false only i and ii are true only i,ii and iv are true
To delete a dynamically allocated array named `a`, the correct statement is 1) 2) 3) 4) delete delete delete delete a; a[0]; []a; [0]a;
#include<stdio.h> void swap(int&, int&); void main() { int a = 10,b=20; swap (a++,b++); printf("\n%d\t%d\t",a, b); } void swap(int& x, int& y) { x+=2; y+=3; }
1) 2) 3) 4) 14, 24 11, 21 10, 20 Error
1) 2) 3) 4)
25 13 11 10
within OOP is called ________________ . 1) 2) 3) 4) extendibility expansion capacity virtual extension scalability
#include<stdio.h> void main() { int s=0; while(s++<10) { if(s<4 && s<9) continue; printf("\n%d\t",s); } }
3) 4 5 6 7 8 9 10 <ANS>
# include<stdio.h> # define a 10 main() { printf("%d..",a); foo(); printf("%d",a); } void foo() { #undef a #define a 50 }
1) 10..10 <ANS>
Answer of Question No. 6 --> Array passed as an argument to a function is interpreted as 3) Address of the first element of the array <ANS>
3) 333
<ANS>
int initialize(NODE **circle) { if ((*circle = (NODE *)malloc(sizeof(NODE))) == NULL) return 0; (*circle)->next = NULL; (*circle)->previous = NULL; return 1; }
1) 2) 3) 4)
The node circle is assigned to NULL The size of the node circle is assigned to NULL Both the pointers next and previous are assigned to NULL None of these options
i. write characters to a file ii. takes 2 parameters iii. returns a character iv. requires a file pointer
4) only i,ii and iv are true <ANS>
#include<stdio.h> void swap(int&, int&); void main() { int a = 10,b=20; swap (a++,b++); printf("\n%d\t%d\t",a, b); } void swap(int& x, int& y) { x+=2; y+=3; }
4) Error <ANS>
<ANS>
Which of the following programming technique focuses on the algorithm. 1) 2) 3) 4) Procedural language Object oriented language Object based language Structural language
Correct 9. Which of the following ways below is a pre order traversal? Correct 10. Which of the following ways below is a In order traversal? You answered: Root->right sub tree-> left sub tree Incorrect Correct answer: left sub tree-> root->right sub tree 11. Which of the following linked list below have last node of the list pointing to the first node? Correct 12. Items in a priority queue are entered in a _____________ order You answered: none of the above Incorrect Correct answer: random 13. A tree cannot contain cycles. Correct 14. Breadth First search is used in Correct 15. A ___________ tree is a tree where for each parent node, there is only one associated child node You answered: rooted complete binary tree Incorrect Correct answer: degenerate tree 16. In graphs, A hyperedge is an edge that is allowed to take on any number of _____________ Correct 17. An empty list is the one which has no You answered: address Incorrect Correct answer: both a and b above
18. Key value pair is usually seen in You answered: Both a and b Incorrect Correct answer: Hash tables 19. In a heap, element with the greatest key is always in the ___________ node You answered: first node of left sub tree Incorrect Correct answer: root 20. In _____________tree, the heights of the two child subtrees of any node differ by at most one You answered: Red black tree Incorrect Correct answer: AVL tree
C Test Breakdown:
1. Can include files be nested? You answered: No Incorrect Correct answer: Yes 2. From which of the following libraries below, calloc() belongs to? You answered: malloc.h Incorrect Correct answer: both a and b above 3. What is the main difference between calloc() and malloc()? You answered: malloc() initializes the allocated memory to ZERO
Incorrect Correct answer: malloc() takes a single argument while calloc() needs two arguments 4. Exit() is same as return? Correct 5. Which of the following below is/are valid C keywords? You answered: integer Incorrect Correct answer: int 6. What are the total number of keywords in C? You answered: 33 Incorrect Correct answer: 32 7. What is the purpose of \r ? You answered: places cursor in end of line Incorrect Correct answer: places cursor in start of line 8. What will be the of the following program? float x = 3.3; int i; i = (int) x; print i; You answered: 3.3 Incorrect Correct answer: 3 9. Is the format below correct to create a pointer? i = *pi; You answered: Yes Incorrect Correct answer: No
10. rand() function returns a _value Correct 11. Is the following code correct to create a structure? typedef struct { ... } x2; Correct 12. The compiler in C ignores all text from a _________ until then end of a line. You answered: ** Incorrect Correct answer: // 13. Which of the following operators cannot be overloaded? You answered: Both a and b above Incorrect Correct answer: :: 14. Which of the following operators below have the highest priority when evaulating? You answered: * Incorrect Correct answer: () 15. What is the purpose of getc() for? You answered: both and b above Incorrect Correct answer: read a character from a file 16. ______________ is used to write formatted output with variable argument lists You answered: vsprintf Incorrect Correct answer: all of above 17. Can getch() be used to echo the input? You answered: Yes Incorrect
Correct answer: No 18. Is **p and &(*p) same? Correct 19. What is the difference between a structure and a union? Correct 20. ___________ will immediately jump to the end of the current block of code You answered: continue Incorrect Correct answer: break 21. Importance of "auto" specifier You answered: Automatically initializes a variable to 0;. Incorrect Correct answer: Indicates that a variable's memory will automatically be preserved. 22. How to read a character from the keyboard and will store it in the variable a. Correct 23. How is a logical AND represented in C? You answered: || Incorrect Correct answer: && 24. int i = 2 * 3 + 4 * 5; Value of i: You answered: 22 Incorrect Correct answer: 26 25. Which one is used for moving blocks of binary data that are of arbitrary size and position in memory? Correct
26. _________________ function to read a specified number of elements from a file. You answered: fileread() Incorrect Correct answer: fread() 27. What function should be used to release allocated memory which is no longer needed? You answered: dealloc() Incorrect Correct answer: free() 28. int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; Value of z: You answered: 11 Incorrect Correct answer: 10 29. How do we delete a dynamically allocated array named `i`? You answered: delete i[0]; Incorrect Correct answer: delete i; 30. void main() { int i; printf("%d",i^i); } You answered: cannot compile Incorrect Correct answer: 0 31. fputs function is used to 1. write characters to a file 2. takes 2 parameters 3. returns a character 4. requires a file pointer You answered: all are false
Incorrect Correct answer: only 1,2 and 4 are true 32. Output of the following program: main() { char str[]="S\065AB"; printf("\n%d", sizeof(str)); } You answered: 6 Incorrect Correct answer: 5 33. Explain the feature of stack. You answered: Any element can be accessed from it directly Incorrect Correct answer: All operations are at one end 34. main() { struct { int i; }abc; (*abc)->i=10; printf("%d",abc.i); } What is the output of this program? You answered: address of i Incorrect Correct answer: program will not compile 35. The size of a structure can be determined by a. size of variable name b. size of (struct tag) Correct 36. How do we declare a float pointer? You answered: *float ptr;
Incorrect Correct answer: float *ptr; 37. void main() { int I=5,*j,**k; j=&I; k=&j; printf("%d%d%d",*j,**k,*(*k)); } What is the output of the above program code? You answered: 666 Incorrect Correct answer: 555 38. When an Array passed as an argument to a function, it is interpreted as Correct 39. What is the output of the following code? # define i 20 main() { printf("%d..",i); fun(); printf("%d",i); } void fun() { #undef i #define i 30 } You answered: 20..30 Incorrect Correct answer: 20..20 40. What is the output of the following code? void main()
{ int i=0; while(i++<10) { if(i<5 && i<9) continue; printf("\n%d\t",i); } } You answered: 1 2 3 4 5 6 7 8 9 Incorrect Correct answer: 5 6 7 8 9 10 41. What is the output of the following code? void main() { char str =`Z`; printf("\n%c",str); } You answered: Error Incorrect Correct answer: Z 42. void main() { int a=5,b=10; char x=1,y=0; if(a,b,x,y) { printf("MAIN"); } } What is the output? You answered: MAIN is printed Incorrect Correct answer: Nothing is printed