Data Structure and Alogrithm MCQs,data structures and algorithms questions and answers pdf,Data Structures and Algorithms Multiple Choice Questions and Answers pdf,data structure mcqs,Data Structures Algorithms Questions and Answers

Explanation: Binary search uses divide and conquer by halving the remaining search interval at each step.
Explanation: In C, an array of three integers can be initialized with braces: int arr[3] = {1, 2, 3};
Explanation: For n elements, insertion sort makes n−1 passes through the unsorted portion in its usual formulation.
Explanation: Removing an item from an empty stack is stack underflow, because no element is available to pop.
Explanation: Binary search compares the target with the middle element of the current search interval.
Explanation: An algorithm is a finite, well-defined sequence of steps for solving a problem; computers can execute algorithms to perform tasks.
Explanation: The Fibonacci sequence starts 0, 1, and each subsequent term is the sum of the previous two terms.
Explanation: Quick sort is also known as partition-exchange sort because it partitions elements around a pivot and recursively sorts the partitions.
Explanation: Time complexity describes how an algorithm's running time grows as input size increases.
Explanation: Sorting algorithm complexity commonly describes how its running time grows with the number n of input items.
Explanation: The key (also called the search key or target) is the value being searched for.
Explanation: Recursion can define Fibonacci terms in terms of earlier terms. A naive recursive implementation is inefficient for larger n; iteration or memoization is usually preferable.
Explanation: Starting with [1, 2, 4, 3], the first bubble-sort pass moves 4 past 3, giving [1, 2, 3, 4]; a second pass confirms no swaps are needed in an optimized version, so two passes/iterations are counted by this question's convention.
Explanation: Bubble sort has average- and worst-case time complexity O(n²). An optimized version can run in O(n) on already sorted input.
Explanation: A data structure organizes data items and defines how they are related and accessed.
Explanation: Linear search checks elements one by one. Its worst case occurs when the target is last or absent, requiring up to n comparisons.
Explanation: A tree represents hierarchical relationships through parent-child links, making it suitable for hierarchies such as file systems.
Explanation: Internal sorting sorts data held in main memory. Sorting that relies on external storage such as disks or tapes is external sorting; the source's marked answer is reversed.
Explanation: Merge sort has O(n log n) average-case time complexity because it divides the input into levels of merging, with linear work per level.
Explanation: Searching is the operation of locating a target element or determining whether it exists in a data structure.
Explanation: Iterative binary search takes O(log n) time because the search interval is approximately halved on every iteration.
Explanation: Data is central to programming because programs process, transform, store, and retrieve data.
Explanation: For a sorted array, binary search is generally more efficient than linear search for large inputs, taking O(log n) time. No single search algorithm is fastest in every situation.
Explanation: Data structures may be classified by their nature, purpose, and lifetime, so all listed criteria can be used.
Explanation: Merge sort is stable when implemented in the standard way, preserving the relative order of equal-key elements.
Explanation: Trees are non-linear data structures because nodes can branch into hierarchical relationships rather than forming one sequential list.
Explanation: Binary search requires sorted data and repeatedly examines the middle element; it does not search sequentially through every item.
Explanation: Merge sort is stable by nature when implemented conventionally and is well suited to sequential-access storage. The source leaves the answer blank; option (d) appears to be the intended answer, but the claim that it outperforms heap sort in most practical situations is not universally true.
Explanation: Insertion sort mirrors arranging playing cards: take each new card and insert it into the correct position among the already ordered cards.
Explanation: The recursive factorial relation is fact(n) = n × fact(n−1), with base case fact(0) = 1 (or fact(1) = 1).
Explanation: Quick sort is often very fast in practice on general arrays, with average O(n log n) time, although its worst case is O(n²).
Explanation: Insertion sort is often excellent for small arrays because it has low overhead and performs well on small or nearly sorted inputs.
Explanation: Stability in sorting means equal-key elements retain their relative order; it does not mean every element stays at the same absolute index.
Explanation: Big-O notation provides an asymptotic upper bound and is commonly used to express worst-case time complexity.
Explanation: An array is a data structure that stores multiple elements of the same data type under a single variable name. Each element is stored at a specific index, allowing efficient access and retrieval. For example, an integer array can store values such as 10, 20, 30, 40, with each value accessible using its index.
Explanation: The pop operation removes and returns the item at the top of a stack. Push inserts a new item at the top.
Explanation: A circular queue wraps its front and rear indices around the array, allowing previously freed positions to be reused. Its capacity remains bounded unless it is designed to resize.
Explanation: Floyd's cycle-detection algorithm advances one pointer by one node and another by two nodes. If the list contains a cycle, the pointers eventually meet, using O(1) extra space.
Explanation: A balanced binary search tree has height O(log n). Search follows a single root-to-leaf path, so its time is O(log n). In an unbalanced tree, worst-case search can be O(n).
Explanation: Floyd–Warshall computes shortest paths between all pairs of vertices using dynamic programming. It runs in O(V³) time and supports negative edge weights, but not negative cycles.
Explanation: Longest common subsequence is commonly solved with dynamic programming by combining solutions for prefixes of the two sequences. The standard algorithm takes O(mn) time for lengths m and n.
Explanation: A topological ordering places each vertex before all vertices it points to. Such an ordering exists only for a directed acyclic graph and is useful for scheduling dependency-constrained tasks.
Explanation: KMP preprocesses the pattern to compute prefix information, allowing the search to avoid rechecking text characters unnecessarily. Its time complexity is O(n + m) for text length n and pattern length m.
Explanation: A stack follows LIFO: the most recently inserted item is the first one removed. Push adds an item to the top, and pop removes the top item.
Explanation: Preorder traversal processes the root first, then the left subtree, then the right subtree. It is useful for tasks such as serializing a tree.
Explanation: Postorder traversal processes the left subtree, then the right subtree, and finally the root. It is useful when children should be processed before their parent, such as deleting a tree.
Explanation: Because a singly linked list has no direct indexing and the list is unsorted, a search may need to inspect every node. The worst-case time complexity is O(n).
Explanation: A stable sort keeps equal-key records in the same relative order as in the input. Stability does not by itself guarantee a particular running time or memory usage.
Explanation: With an early-exit flag, bubble sort can detect that no swaps occurred during the first pass and stop. That pass still scans the array, so the best-case time is O(n).
Explanation: A queue organizes elements in a linear sequence with insertion at the rear and removal from the front. Trees, graphs, and heaps represent non-linear relationships.
Explanation: Time complexity models how the amount of computational work grows with input size, often using asymptotic notation. Actual elapsed time also depends on hardware, implementation, and other factors.
Explanation: Union-find maintains a partition of elements into disjoint sets. Find identifies an element's set, and union merges sets; path compression and union by rank/size make operations nearly constant amortized time.
Explanation: A queue follows FIFO: the earliest inserted item is removed first. Enqueue adds an item at the rear, while dequeue removes one from the front.
Explanation: Arrays support direct index-based access, so accessing a known position takes constant time, O(1), under the usual array model.
Explanation: In the worst case, linear search checks every element, such as when the target is absent or is the final element. Its running time grows linearly with n.
Explanation: Binary search compares the target with the middle element and discards about half of the remaining search range each step, giving O(log n) worst-case time.
Explanation: Binary search relies on the order of elements to decide which half can be discarded. Duplicate values and non-integer values are allowed if ordering and comparisons are well-defined.
Explanation: Function calls are managed using a call stack. Each call creates a stack frame containing information such as local variables and the return address; the frame is removed when the call returns.
Explanation: A tree represents hierarchical relationships through nodes connected by parent-child links. It has a root and can contain subtrees.
Explanation: Breadth-first search uses a queue to process vertices in the order they are discovered, exploring a graph level by level.
Explanation: Iterative depth-first search uses a stack to visit a recently discovered vertex before backtracking. Recursive DFS uses the program's call stack.
Explanation: A singly linked-list node stores its data and a link or reference to the next node. The last node's next reference is usually null.
Explanation: Inserting at the head requires creating a node, pointing it to the former head, and updating the head reference. These operations take constant time, O(1).
Explanation: A hash table can locate a bucket from a key's hash and typically performs lookup in expected O(1) time with a suitable hash function and controlled load factor. Worst-case lookup can be O(n).
Explanation: A collision occurs when different keys map to the same bucket or slot. Collision handling commonly uses separate chaining or open addressing.
Explanation: Inorder traversal visits the left subtree, then the node, then the right subtree. For a binary search tree with the usual ordering property, this visits keys in sorted non-decreasing order.
Explanation: A binary tree permits at most two children per node, conventionally called the left child and the right child.
Explanation: Kruskal's algorithm sorts edges by weight and adds an edge when it connects different components, avoiding cycles. For a connected weighted undirected graph, it produces a minimum spanning tree.
Explanation: Dijkstra's algorithm repeatedly finalizes the currently closest unsettled vertex and relaxes its outgoing edges. Its standard correctness guarantee requires non-negative edge weights.
Explanation: Merge sort divides the input, recursively sorts each half, and merges the sorted halves. Its worst-case time is O(n log n), and the standard merge procedure can preserve the relative order of equal keys.
Explanation: If each partition separates only one element from the rest, the recursion becomes highly unbalanced. The total work is then proportional to n + (n−1) + ... + 1, which is O(n²).
Explanation: In reverse-sorted input, each new element may need to move past all previously processed elements. The total number of shifts is quadratic, giving O(n²) worst-case time.
Explanation: Selection sort finds the minimum element in the unsorted portion and swaps it into the next sorted position. It performs O(n²) comparisons in its usual implementation.
Explanation: Insertion sort performs well on small or nearly sorted arrays because each element moves only a short distance. Its best-case running time is O(n), while its worst case is O(n²).
Explanation: Bottom-up heap construction is O(n), not O(n log n), because most nodes are near the leaves and require little or no sift-down work.
Explanation: A max-heap maintains the property that every parent is greater than or equal to its children. Therefore, the maximum element is at the root.
Explanation: Array-based merge sort typically uses O(n) auxiliary storage for merging. Its recursion stack is O(log n), but the additional array storage dominates, so total auxiliary space is O(n).
Explanation: The standard factorial definition uses 0! = 1 as its base case and n! = n × (n−1)! for positive integers n. The base case stops the recursion.
Explanation: Each Fibonacci term is the sum of the two preceding terms. The next term after 5 and 8 is 5 + 8 = 13.
Explanation: Divide and conquer breaks a problem into smaller subproblems, solves them recursively or independently, and combines their results. Merge sort and binary search are classic examples.
Explanation: Big-O notation describes an asymptotic upper bound on how an algorithm's resource use grows with input size. It does not directly specify wall-clock time in seconds.
Explanation: Space complexity describes how memory requirements grow with input size. Analyses may distinguish total space from auxiliary space used in addition to the input.
Explanation: Big-Omega notation expresses an asymptotic lower bound. Big-O gives an upper bound, while Big-Theta gives a tight asymptotic bound when both upper and lower bounds hold.
Explanation: An adjacency list stores each vertex and its existing neighbors, using O(V + E) space. An adjacency matrix uses O(V²) space, which can be wasteful when the graph has relatively few edges.
Explanation: In a simple undirected graph, each pair of distinct vertices can share at most one edge and self-loops are not allowed. There are n choose 2 possible pairs, or n(n−1)/2 edges.
Explanation: A binary heap supports efficient priority-queue operations: peek at the highest-priority item in O(1), and insert or remove the top item in O(log n). Other implementations may be appropriate for different workloads.