0% ont trouvé ce document utile (0 vote)
45 vues23 pages

Dsa MCQS

Le document aborde l'importance des structures de données en programmation, en soulignant leur rôle dans l'efficacité du traitement et de l'organisation des données. Il explique également les types de structures de données, comme les tableaux, les files d'attente et les arbres binaires, ainsi que des concepts tels que les types de données abstraits (ADT) et la complexité temporelle des algorithmes. Enfin, il traite des algorithmes de recherche et de parcours, notamment BFS et DFS, et leurs applications dans divers contextes.

Transféré par

wafflerick69
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
45 vues23 pages

Dsa MCQS

Le document aborde l'importance des structures de données en programmation, en soulignant leur rôle dans l'efficacité du traitement et de l'organisation des données. Il explique également les types de structures de données, comme les tableaux, les files d'attente et les arbres binaires, ainsi que des concepts tels que les types de données abstraits (ADT) et la complexité temporelle des algorithmes. Enfin, il traite des algorithmes de recherche et de parcours, notamment BFS et DFS, et leurs applications dans divers contextes.

Transféré par

wafflerick69
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF ou lisez en ligne sur Scribd
1, Why are data structures important in computer programming? a) To improve the speed of processing large amounts of data b) To manage and organize data efficiently c) To reduce the memory footprint of a program d) All of the above Answer: d) All of the above 2. Which of the following is NOT a reason to use data structures? a) Efficient storage and retrieval of data b) Simplifying complex algorithms e) To increase the code’s complexity unnecessarily d) Managing relationships among data items Answer: c) To increase the code’s complexity unnecessarily 4, Which data structure is most suitable for implementing a "to-do list" where tasks are processed in the order they are added? a) Stack b) Queue c) Hash Table d) Graph Answer: b) Queue 5. When handling large datasets, why is it essential to use the right data structure? © scanned wth onENScmner a) To make the program visually appealing b) To ensure faster access and modification of data c) To avoid the need for algorithms d) To make debugging easier Answer: b) To ensure faster access and modification of data 6. What is the primary purpose of an array as a data structure? a) To store non-contiguous data b) To maintain a hierarchical structure c) To store elements of the same data type in contiguous memory locations d) To map key-value pairs Answer: c) To store elements of the same data type in contiguous memory locations 7. Which of the following applications would most likely use a graph as its underlying data structure? a) Text editor b) Social network c) Calculator d) Weather forecasting Answer: b) Social network 1. What is an Abstract Data Type (ADT)? a) A type of programming language b) A data structure implementation with fixed operations c) ‘A mathematical model for data with a set of operations d) A specific implementation of a data structure Answer: c) A mathematical model for data with a set of operations 2. Which of the following is an example of an Abstract Data Type (ADT)? a) Array b) Linked List c) Queue d) Pointer © scanned wth onENScmner Answer: c) Queue 3. What is the key characteristic of an ADT? 4) It specifies both implementation and usage b) It focuses only on what operations can be performed, not how they are implemented c) It does not include any operations d) It requires a specific data structure Answer: b) It focuses only on what operations can be performed, not how they are implemented 4. Which of the following is an operation associated with the Queue ADT? a) Push b) Pop c) Enqueue d) Peek Answer: c) Enqueue 5. Which ADT is best suited for handling function calls in a program? ) Queue b) Stack c) Priotity Queue d) Deque Answer: b) Stack 6. Which of these data structures does NOT implement an ADT directly? a) Array b) Linked List c) Compiler Instructions d) Hash Table Answer: c) Compiler Instructions 7. Why are ADTs useful in programming? a) They reduce the complexity of algorithms b) They abstract the implementation details for better modularity © scanned wth onENScmner c) They are faster to execute d) They directly interact with the hardware Answer: b) They abstract the implementation details for better modularity 1. What does time complexity of an algorithm represent? a) The total time required to write the code b) The amount of time required to execute an algorithm as a function of input size c) The space required to store input data d) The efficiency of the computer hardware Answer: b) The amount of time required to execute an algorithm as a function of input size 2. What is the Big-O notation used for? a) To measure the exact execution time of an algorithm b) To describe the upper bound of an algorithm's time complexity c) To measure the space usage of a program d) To identify the programming language efficiency Answer: b) To describe the upper bound of an algorithm's time complexity 3. Which of the following denotes the space complexity of an algorithm? a) Amount of memory required to store the code b) Amount of memory required by an algorithm, including input data and auxiliary storage c) The runtime of the algorithm in seconds d) The ‘memory required by the operating system Answer: b) Amount of memory required by an algorithm, including input data and auxiliary storage 4. What is the time complexity of searching for an element in an unsorted array? a) O(1) b) O(n) €) Odlog n) d) On? Answer: b) O(n) © scanned wth onENScmner 5. What is the space complexity of an iterative algorithm that only uses constant extra memory? a) O(1) b) O(n) €) Ollog n) d) O(n’) Answer: a) O(1) 8. Ifa recursive algorithm makes multiple recursive calls, what generally happens to its space complexity? a) It becomes constant b) It increases with the depth of recursion ¢) It decreases with each recursive call d) It is independent of recursion depth Answer: b) It increases with the depth of recursion 2. Which operation is used to add an element to the stack? a) Push b) Pop c) Enqueue d) Dequeue Answer: a) Push 3. Which operation is used to remove the top element from a stack? a) Push b) Pop c) Peek d) Insert Answer: b) Pop 5. What happens when you try to pop an element from an empty stack? a) The operation is ignored b) A new element is added to the stack ¢) Stack Overflow occurs d) Stack Underflow occurs © scanned wth onENScmner Answer: d) Stack Underflow occurs 6. Which of the following applications uses stacks? a) Function call management in recursion b) Expression evaluation c) Backtracking algorithms d) Allof the above Answer: d) All of the above 7. What is the time complexity of the Push and Pop operations in a stack implemented using an array? a) O(1) b) O(n) ¢) O(log n) d) O(n?) Answer: a) O(1) 3. Which operation is used to remove an element from the front of the queue? a) Push b) Pop c) Enqueue d) Dequeue Answer: d) Dequeue 4. What happens when you try to dequeue from an empty queue? a) The operation is ignored b) A new element is added to the queue c) Queue Overflow occurs d) Queue Underflow occurs Answer: d) Queue Underflow occurs 5. What is a cireular queue? a) A queue that uses a circular array to connect the last position back to the first b) A queue where the elements form a circle in memory © scanned wth onENScmner ©) A queue that cannot be implemented using arrays d) A queue where elements are act random order Answer: a) A queue that uses a circular array to connect the last position back to the first 7. What is the time complexity of enqueue and dequeue operations in a queue implemented using a linked list? a) O(1) b) O(n) ¢) Oddog a) d) O(n?) Answer: a) O(1) 8. In which scenario would you use a priority queue instead of a standard queue? a) When elements need to be processed in the order they arrive b) When elements need to be processed based on their priority c) When implementing stack-like behavior d) When processing ‘elements randomly Answer: b) When elements need to be processed based on their priority 10. Which of the following applications use queues? a) CPU task scheduling b) Breadth-First Search (BFS) c) Handling requests in web servers d) All of the above Answer: d) All of the above 1. What is a linked list? a) A data structure that stores elements in contiguous memory locations b) A data structure consisting of nodes, where each node points to the next node c) A collection of sorted elements d) A data structure used only for stack implementation Answer: b) A data structure consisting of nodes, where each node points to the next node 2. What are the basic components of a node in a singly linked list? a) Data and address of the next node b) Data and address of the previous node c) Data the next node, and address of the previous node d) Data and an index ssed in address of © scanned wth onENScmner Answer: a) Data and address of the next node 3. What is the time complexity of inserting an element at the beginning of a singly linked list? a) O(1) b) O(n) ¢) O(log n) d) O(n? Answer: a) O(1) 8. Which of the following is NOT true about linked lists? a) Linked lists have dynamic memory allocation b) Linked lists require more memory than arrays because of the storage of pointers c) Random access of elements is possible in linked lists d) Insertion and deletion are easier in linked lists compared to arrays Answer: c) Random access of elements is possible in linked lists 10. Which of the following applications uses linked lists? a) Dynamic memory allocation b) Implementing stacks and queues c) Graph adjacency representation d) Ail of the above Answer: d) All of the above 1. What is a binary tree? a) A tree data structure where each node can have at most two children b) A tree data structure where each node can have at most three children c) A tree where each node has exactly two children d) A tree that contains only numeric data Answer: a) A tree data structure where each node can have at most two children 2. Ina binary tree, the topmost node is called: a) Parent b) Leaf © scanned wth onENScmner ) Root d) Child Answer: c) Root 10. Which of the following applications uses binary trees? a) Expression evaluation in compilers b) Binary search operations c) Huffman coding for data ‘compression d) All of the above Answer: d) All of the above 2. In which traversal is the root node visited before its children? a) Preorder traversal b) Postorder traversal c) Inorder traversal d) Level order traversal Answer: a) Preorder traversal 7. Which traversal is used to evaluate an arithmetic expression stored in a binary tree? a) Preorder traversal b) Postorder traversal c) Inorder traversal d) Level order traversal Answer: b) Postorder traversal (It evaluates the expression by first calculating subtrees before ‘combining results.) 10. Ina binary tree, which traversal will give the same result for a tree with only one node? a) Preorder traversal b) Postorder traversal c) Inorder traversal d) All of the above © scanned wth onENScmner Answer: d) All of the above 11. What is the time complexity of any depth-first traversal (Preorder, Inorder, Postorder) for a binary tree with n nodes? a) O(log n) b) O(n) c) O(n log n) d) O(n?) Answer: b) O(n) 1. What is a Binary Search Tree (BST)? a) A binary tree where nodes have at most two children b) A binary tree where all left descendants are smaller, and all right descendants are larger than the root c) A binary tree where all nodes are balanced d) A tree where elements are stored in sorted order Answer: b) A binary tree where all left descendants are smaller, and all right descendants are larger than the root 2. What is the time complexity of searching an element in a Binary Search Tree in the worst case? a) OC) b) O(log m) e) O(n) d) O(n og n) Answer: c) O(n) (In the worst case, the BST can become skewed, resembling a linked list.) 3. Which traversal of a Binary Search Tree (BST) gives the nodes in sorted order? a) Preorder traversal b) Postorder traversal c) Level order traversal d) Inorder traversal Answer: d) Inorder traversal © scanned wth onENScmner ‘5. What is the time complexity of inserting an element into a balanced Binary Search Tree? a) O(1) b) Oog n) ¢) O(a) d) O(e?) Answer: b) O(log n) 6. If you want to delete a node with two children in a BST, which node replaces the deleted node? a) Its immediate parent b) Its immediate left child c) Its inorder suce: 4) Its immediate right child Answer: c) Its inorder successor or inorder predecessor 7. What happens when you search for an element that does not exist ina BST? a) It throws an error b) It returns NULL or a failure flag ¢) It traverses all nodes and stops d) It deletes the root node Answer: b) It returns NULL of a failure flag 9. Which of the following is NOT true for a Binary Search Tree (BST)? a) The left subtree contains only nodes with values less than the root b) The right subtree contains only nodes with values greater than the root c) Both left and right subtrees must also be BSTs d) ABST allows duplicate elements Answer: d) A BST allows duplicate elements LL. Which of the following is NOT an application of binary trees? ) Hierarchical data representation b) Implementation of heaps sor or inorder predecessor © scanned wth onENScmner ) Sorting elements in O(1) time d) Expression parsing and evaluation, Answer: c) Sorting elements in OC) time 13. Which application uses binary trees to optimize searching in large datasets? a) Hashing b) AVL Trees c) Sorting algorithms d) Data compression Answer: b) AVL Trees Answer: c) Data compression 18. In compilers, binary trees are used for: a) Code generation b) Syntax analysis c) Expression evaluation d) All of the above Answer: d) Alll of the above 19. Which binary tree ensures balance after every insertion and deletion? a) Complete Binary Tree b) AVL Tree c) Binary Search Tree d) Huffman Tree Answer: b) AVL Tre 20. Which of the following traversal techniques is used for decision tree evaluation? a) Inorder traversal b) Preorder traversal © scanned wth onENScmner ) Postorder traversal d) Level order traversal Answer: b) Preorder traversal 1. What is the primary difference between BFS (Breadth-First Search) and DFS (Depth- First Search)? a) BFS uses a queue, and DFS uses a stack b) BFS uses recursion, and DFS uses iteration c) BFS explores nodes in depth-first order, and DFS explores nodes level by level d) Both traverse the graph in the same order Answer: a) BES uses a queue, and DFS uses a stack 2.1n BES traversal of a graph, which data structure is used? a) Stack b) Queue c) Priority Queue d) Linked List Answer: b) Queue 3. Which of the following is true about DFS traversal? a) DFS uses a queue b) DES always produces a unique traversal for a graph c) DFS can be implemented using recursion or a stack d) DFS cannot visit all nodes in a connected graph. Answer: c) DFS can be implemented using recursion or a stack 6. In DES, when a vertex is first encountered, it is: a) Enqueued b) Pushed onto the stack c) Visited and skipped d) Immediately removed from the graph Answer: b) Pushed onto the stack © scanned wth onENScmner 8. In which of the following cases is DFS preferred over BFS? a) Finding the shortest path in an unweighted graph b) Finding a solution in a game tree or maze where the path is very deep c) Traversing all nodes level by level d) When the graph is very wide Answer: b) Finding a solution in a game tree or maze where the path is very deep 9. Which data structure is typically used for iterative implementation of DFS? a) Queue b) Stack c) Heap d) Linked List Answer: b) Stack 10. In BFS traversal, what happens when a vertex is dequeued? a) It is pushed back into the queue b) Its unvisited adjacent vertices are enqueued c) It is marked as not visited d) All adjacent vertices are ignored Answer: b) Its unvisited adjacent vertices are enqueued 11. What is a key application of BFS in graphs? a) Topological sorting b) Finding strongly connected components c) Finding the shortest path in an unweighted graph d) Detecting cycles in a graph Answer: c) Finding the shortest path in an unweighted graph 12. In which graph traversal does backtracking occur? a) BFS b) DFS © scanned wth onENScmner ‘) Both BFS and DFS d) None of the above Answer: b) DFS 13. In BFS traversal, what ensures all nodes at the same level are visited before moving to the next level? a) Stack data structure b) Recursion c) Queue data structure d) Hash table Answer: c) Queue data structure 15. Which of the following is NOT true about BFS and DFS? a) BFS uses more memory than DES in general b) BES is implemented using a queue, while DFS uses a stack c) BFS is more suitable for unweighted shortest path problems d) DES always guarantees the shortest path in a graph Answer: d) DFS always guarantees the shortest path in a graph 17. What is the key disadvantage of DFS compared to BFS? a) DFS cannot handle weighted graphs b) DFS uses more memory than BFS c) DFS can get stuck in an infinite loop in cyclic graphs without a visited check d) DFS cannot traverse all nodes in a graph Answer: c) DFS can get stuck in an infinite loop in cyclic graphs without a visited check 18. Which traversal is most suitable for detecting cycles in an undirected graph? a) BFS only b) DFS only c) Both BFS and DFS d) Neither BFS not DFS Answer: c) Both BFS and DFS © scanned wth onENScmner 19. How can BFS be modified to detect connected components in an undirected graph? ) Maintain a visited array and start BFS from unvisited nodes b) Use a stack instead of a queue c) Traverse only the root node d) BFS cannot detect connected components Answer: a) Maintain a visited array and start BFS from unvisited nodes 20. If a graph has a high branching factor (many nodes connected to each vertex), which traversal is more memory efficient? a) BFS b) DFS c) Both use the same memory d) Neither BFS nor DFS ‘Answer: b) DFS 1. What is the primary objective of Kruskal’s and Prim’s algorithms? a) Finding the shortest path in a graph b) Finding the minimum spanning tree (MST) of a graph c) Finding strongly connected components d) Detecting cycles in a graph Answer: b) Finding the minimum spanning tree (MST) of a graph 10. Which of the following statements is true for both Kruskal’s and Prim’s alg a) They can only work on connected graphs b) They always produce the same Minimum. Spanning Tree (MST) for a given graph c) They work efficiently only for directed graphs d) They use a queue to maintain nodes Answer: b) They always produce the same Minimum Spanning Tree (MST) for a given graph ms? © scanned wth onENScmner 13. Kruskal’s algorithm is more suitable than Prim’s when: a) The graph is dense b) The graph is sparse c) The graph has fewer vertices and more edges d) ‘The graph is directed Answer: b) The graph is sparse 14, What is the main advantage of Prim’s algorithm over Kruskal’s algorithm for dense graphs? a) Prim’s algorithm avoids sorting edges b) Prim’s algorithm guarantees an optimal solution c) Prim’s algorithm works faster using adjacency matrices d) Prim’s algorithm does not require a priority queue Answer: c) Prim’s algorithm works faster using adjacency matrices 16. If a graph has V vertices and E edges, what is the space complexity of Prim’s algorithm using an adjacency matrix? a) O(V) b) O(V2) c) OLE) d) OLV log E) Answer: b) O(V2) 17. Which of the following graphs cannot have a Minimum Spanning Tree (MST)? a) A disconnected graph b) A connected graph c) A weighted undirected graph d) A complete graph Answer: a) A disconnected graph 18, What is a key limitation of Kruskal’s algorithm? © scanned wth onENScmner a) It requires sorting all edges first, which can be inefficient for large graphs b) It cannot handle graphs with negative weights c) It works only for directed graphs d) It does not work on ‘connected graphs Answer: a) It requires sorting all edges first, which can be inefficient for large graphs 19. In Prim’s algorithm, if a priority queue is used, what is its purpose? a) To store all edges of the graph b) To keep track of the minimum weight edges connecting visited vertices to unvisited vertices c) To detect cycles in the graph d) To randomly select the next edge Answer: b) To keep track of the minimum weight edges connecting visited vertices to unvisited vertices 1. Which of the following is NOT an application of graphs? a) Shortest path finding b) Social network modeling c) Sorting a list of numbers d) Web page ranking Answer: c) Sorting a list of numbers 3. What is the primary application of a graph in a computer network? a) Sorting data packets b) Modeling communication between computers c) Finding minimum spanning trees d) Scheduling tasks Answer: b) Modeling communication between computers 5. Which of the following applications uses a directed graph? a) Web page linking and ranking b) Airline route networks c) Road networks in cities d) Electrical power grids © scanned wth onENScmner Answer: a) Web page linking and ranking 6. Graphs are used in social networks to: a) Calculate network packet transmission b) Represent friendships or connections between users c) Rank websites based on connections d) Schedule CPU tasks Answer: b) Represent friendships or connections between users 8. In graph theory, how are cities and roads represented in a road navigation system? a) Cities are vertices, and roads are edges b) Cities are edges, and roads are vertices ¢) Both cities and roads are vertices d) Both cities and roads are edges Answer: a) Cities are vertices, and roads are edges LL. Which of the following real-world problems can be solved using the Minimum Spanning ‘Tree (MST)? a) Ranking web pages b) Designing network cables with minimum cost c) Finding the shortest path in a city d) Detecting cycles in a network Answer: b) Designing network cables with minimum cost 16. Which graph traversal method is most suitable for web crawling? a) Depth-First Search (DFS) b) Breadth-First Search (BFS) c) Dijkstra’s Algorithm d) Floyd- Warshall Algorithm Answer: b) Breadth-First Search (BFS) © scanned wth onENScmner 17. Graphs are used in Artificial Intelligence to represent: a) Neural networks b) Decision trees and state spaces c) Sorting algorithms d) Binary search operations Answer: b) Decision trees and state spaces 20. Which of the following graph representations is used to model a computer network? ) Directed graph b) Undirected graph c) Both directed and undirected graphs d) Weighted graph only Answer: c) Both directed and undirected graphs 1. What is the primary requirement for applying Binary Search? a) The array should be sorted b) The array should be unsorted ) The array should have distinct ‘elements d) The array size should be a power of 2 Answer: a) The array should be sorted 2. What is the time complexity of Binary Search in the worst case? a) O(n) b) O(log m) c) O(n log n) d) OU) Answer: b) O(/og n) 5. Which of the following is a characteristic of Binary Search? a) It is recursive but cannot be implemented iteratively b) It can be implemented both recursively and iteratively c) It cannot find duplicate elements d) It can work on an unsorted array Answer: b) It can be implemented both recursively and iteratively © scanned wth onENScmner 8, What is the space complexity of Binary Search for an iterative implementation? a) OC) b) O(log m) ¢) O(a) d) O(n og n) Answer: a) O(1) 9. In the recursive implementation of Binary Search, what is the space complexity? a) O(1) b) O(log n) ¢) O(n) A) (4?) Answer: b) O(log n) 10. Binary Search can be used to find: a) The first occurrence of a key in a sorted array b) The last occurrence of a key in a sorted array c) The position of an element if duplicates exist d) All of the above Answer: d) All of the above 16. Binary Search is most efficient when: a) Data is sorted and static (unchanging) b) Data is dynamic and frequently updated c) Data is, small and unsorted d) Data contains only distinct elements, Answer: a) Data is sorted and static (unchanging) 18. What is the best-case time complexity of Binary Search? © scanned wth onENScmner a) O(log n) b) O(n) e) OC) d) O(n log n) Answer: c) O(1) Explanation: The best case occurs when the middle element is the target. 20. Which of the following scenarios is NOT suitable for Binary Search? a) Data is sorted and stored in an array b) Data is unsorted c) Data does not change frequently d) Data has a small number of elements Answer: b) Data is unsorted 1, What is the average-case time complexity of the Quick Sort algorithm? a) O(n) b) O(a log n) ¢) O(e2) d) O(log n) Answer: b) O(n log n) 2. What is the worst-case time complexity of Quick Sort? a) O(n log n) b) O(4?) c) O(n) d) OClog n) Answer: b) O(n?) 5. Which of the following is NOT true about Quick Sort? a) It is an in-place sorting algorithm b) It requires additional space proportional to the input size © scanned wth onENScmner ) It works efficiently for large datasets d) It uses a pivot to partition the array Answer: b) It requires additional space proportional to the input size 8. Quick Sort is considered better than Merge Sort for: a) Small datasets b) Linked lists c) Arrays with duplicate values d) In-place sorting for large datasets, Answer: d) In-place sorting for large datasets 12. Which partition scheme is most commonly used in Quick Sort? a) Lomuto partition scheme b) Hoare partition scheme c) Median-of-three partition scheme d) ‘None of the above Answer: a) Lomuto partition scheme 13. Which of the following statements is correct regarding Quick Sort? ) Quick Sort is stable b) Quick Sort is not stable c) Quick Sort cannot sort duplicate elements d) Quick Sort requires O(n) extra space Answer: b) Quick Sort is not stable 18. Quick Sort is faster than Heap Sort when: a) The dataset is extremely small b) The dataset is already sorted c) It is implemented for large, in-memory datasets d) The input has many duplicate elements Answer: ¢) It is implemented for large, in-memory dataset © scanned wth onENScmner

Vous aimerez peut-être aussi