StudyFox
कीमतेंब्लॉगएक्सटेंशनमुफ़्त टूल
  • कीमतें
  • ब्लॉग
  • एक्सटेंशन
  • मुफ़्त टूल
  • शुरू करेंसाइन इन
StudyFox

अपने नोट्स, PDF और स्लाइड्स को फ़्लैशकार्ड, क्विज़, नोट्स और माइंड मैप में बदलें।

StudyFox खोलें

स्टडी टूल्स

  • होमवर्क हेल्पर
  • नोट मेकर
  • फ़्लैशकार्ड मेकर
  • क्विज़ मेकर
  • माइंड मैप मेकर

प्रोडक्ट

  • कीमतें
  • Chrome एक्सटेंशन
  • मुफ़्त एक्सटेंशन
  • स्टडी सेट देखें
  • ब्लॉग

सहायता

  • सहायता केंद्र
  • संपर्क करें
  • गोपनीयता नीति
  • सेवा की शर्तें

तुलना करें

  • Chegg का विकल्प
  • Course Hero का विकल्प
  • Coursology का विकल्प
  • Photomath का विकल्प
  • Gauthmath का विकल्प
  • PhotoSolve का विकल्प
  • CollegeTools का विकल्प
  • Transcript का विकल्प
  • SmartSolve का विकल्प
  • Homeworkify का विकल्प
  • AnswersAi का विकल्प
  • StudyX का विकल्प
  • Quizlet का विकल्प
  • Anki का विकल्प
  • Knowt का विकल्प
  • Brainscape का विकल्प
  • सभी तुलनाएँ

© 2026 StudyFox AI. सर्वाधिकार सुरक्षित।

  • X
  • Discord
  • Instagram
ExploreEngineering & TechComputer ScienceAlgorithms Quiz: Sorting, Searching and Graph Basics

Quiz · Medium

Algorithms Quiz: Sorting, Searching and Graph Basics

Twenty questions on sorting algorithms, binary search, BFS and DFS, shortest paths, spanning trees, Huffman coding and dynamic programming.

by Kill h.20 questionsCreated Nov 20, 2026, 08:26 PM
Computer Science· AlgorithmsTags#algorithms#sorting#graphs#quiz

20 questions

  1. 1

    Which complexity class does the curve that rises most steeply in this chart belong to?

    • A

      O(n²)

    • B

      O(n log n)

    • O(2ⁿ)

    • D

      O(n)

    Exponential growth quickly overtakes every polynomial curve. The orange curve is n², which grows fast but more slowly than 2ⁿ.

  2. 2

    Which sorting algorithm is stable, always O(n log n), and needs O(n) extra space?

    • Merge sort

    • B

      Quicksort

    • C

      Heap sort

    • D

      Selection sort

    Merge sort splits in halves and merges with a temporary array. Quicksort and heap sort are not stable; selection sort is O(n²).

  3. 3

    Merge sort splits [38, 27, 43, 3, 9, 82, 10] as shown. How many times is the array split before every piece has one element (the number of levels of splitting)?

    • A

      2

    • B

      4

    • C

      7

    • 3

    7 → 4 and 3 → pieces of at most 2 → single elements: three levels of splitting, which is ceil(log₂ 7). Image: public domain, via Wikimedia Commons.

  4. 4

    In quicksort with the last element as pivot, what input causes the worst case?

    • A

      A random permutation

    • An already sorted array

    • C

      An array of all different values in random order

    • D

      An array with many duplicates only

    On sorted input the last element is the maximum, so each partition removes just one element: n + (n − 1) + … = O(n²). A random permutation gives an expected O(n log n). With many duplicates a naive partition can also degrade, but sorted input is the classic case.

  5. 5

    The picture shows binary search for 7 in a sorted array of 17 elements. How many elements are compared before 7 is found?

    • A

      3

    • B

      5

    • 4

    • D

      9

    It compares with 14 (7 < 14), 6 (7 > 6), 8 (7 < 8) and finally 7: four comparisons. Linear search from the start would need five. Image: AlwaysAngry, CC BY-SA 4.0, via Wikimedia Commons.

  6. 6

    What is the worst-case number of comparisons binary search needs on a sorted array of 1,000 elements?

    • 10

    • B

      1,000

    • C

      500

    • D

      100

    ceil(log₂ 1000) = 10 since 2¹⁰ = 1024. Each step halves the search range.

  7. 7

    Which algorithm finds the shortest path in an unweighted graph?

    • A

      Depth-first search

    • B

      Kruskal's algorithm

    • C

      Topological sort

    • Breadth-first search

    BFS explores vertices in order of distance from the source, so the first time it reaches a vertex is along a shortest path. DFS can reach a vertex by a long route first.

  8. 8

    Dijkstra's algorithm is run from A on the graph. What is the shortest distance to E?

    • A

      10

    • 11

    • C

      12

    • D

      13

    A→C (2) →B (3) →D (8) →E (11). The edge C–E gives 2 + 10 = 12, which is longer.

  9. 9

    Why can't Dijkstra's algorithm be used on graphs with negative edge weights?

    • A

      It runs out of memory

    • B

      It only works on trees

    • A settled vertex may later have a shorter path

    • D

      It cannot use a heap

    Dijkstra finalizes the closest unsettled vertex, assuming nothing can make it closer. A negative edge breaks that assumption. Use Bellman-Ford instead.

  10. 10

    Which algorithm builds a minimum spanning tree by sorting edges and rejecting those that form a cycle?

    • Kruskal's algorithm

    • B

      Prim's algorithm

    • C

      Dijkstra's algorithm

    • D

      Bellman-Ford

    Kruskal sorts edges by weight and uses union-find to skip cycle-forming edges. Prim grows a single tree from a start vertex.

  11. 11

    A graph has 8 vertices and is connected. How many edges does a minimum spanning tree of it have?

    • A

      8

    • B

      9

    • C

      28

    • 7

    A spanning tree has V − 1 edges: 7.

  12. 12

    A DFS visits the vertices of this tree in the order shown by the numbers. Which of the following describes DFS?

    • A

      It visits all neighbours of the start first

    • It explores as deep as possible, then backtracks

    • C

      It always finds the shortest path

    • D

      It uses a queue

    DFS goes 1 → 2 → 3 → 4 → backtracks to 5, 6 … It uses a stack or recursion. Image: Alexander Drichel, CC BY-SA 3.0, via Wikimedia Commons.

  13. 13

    What is the time complexity of building a Huffman code for n symbols using a min-heap?

    • A

      O(n)

    • B

      O(n²)

    • O(n log n)

    • D

      O(2ⁿ)

    There are n − 1 merges, each with O(log n) heap operations.

  14. 14

    Which of these symbols gets the longest code in the Huffman tree shown?

    • 'o' (frequency 1)

    • B

      The space character (frequency 7)

    • C

      'e' (frequency 4)

    • D

      'f' (frequency 3)

    Rare symbols end up deep in the tree: 'o' has a 5-bit code (00110), 'f' has 4 bits, while the space and 'e' have 3 bits each. Image: public domain, via Wikimedia Commons.

  15. 15

    Which statement about comparison-based sorting is true?

    • A

      Some algorithms sort in O(n) in the worst case

    • B

      Quicksort is always O(n log n)

    • C

      Merge sort needs O(1) space

    • Every comparison sort needs Ω(n log n) comparisons in the worst case

    A decision tree for n elements has at least n! leaves, so its height is at least log₂(n!) = Θ(n log n). Counting sort is O(n + k) but is not comparison based.

  16. 16

    Which technique solves the 0/1 knapsack problem correctly in O(nW) time?

    • A

      Greedy by value

    • Dynamic programming

    • C

      Greedy by value-to-weight ratio

    • D

      Binary search

    Greedy rules can fail for 0/1 knapsack. The DP table over items and capacities is correct and pseudo-polynomial. Image: VectorVoyager, CC BY-SA 4.0, via Wikimedia Commons.

  17. 17

    True or false: Python's built-in sorted() is stable.

    • True

    • B

      False

    Timsort is stable, so elements with equal keys keep their original relative order.

  18. 18

    What is the time complexity of naive recursive Fibonacci fib(n) = fib(n−1) + fib(n−2)?

    • A

      O(n)

    • B

      O(n log n)

    • Exponential, about O(1.618ⁿ)

    • D

      O(n²)

    The call tree roughly multiplies by φ ≈ 1.618 per level because of overlapping subproblems. Memoization reduces it to O(n).

  19. 19

    True or false: insertion sort runs in O(n) time on an already sorted array.

    • True

    • B

      False

    Each element is compared once with its predecessor and never moved. That is why it is used for nearly sorted data.

  20. 20

    Which sort should you choose to sort a million integers each between 0 and 999?

    • Counting sort

    • B

      Bubble sort

    • C

      Selection sort

    • D

      Binary search

    Counting sort runs in O(n + k) = O(10⁶ + 10³) and needs no comparisons. Bubble and selection sort are O(n²).