chapter
    Searching Algorithms and Binary Search Short Notes for GATE DA

    Searching Algorithms and Binary Search short notes for GATE DA: 2 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice ques

    searching algorithms and binary search short notes

    Quick Recall: Binary Search Worst-Case

    Quick Recall: Worst-Case

    Concept Formula / Rule
    Recurrence Relation
    Exact Max Comparisons
    Found vs Not Found Worst-case depth is identical.
    Comparisons per Step Check if 1 (3-way) or 2 (if-else).

    Halve the size, add one step,
    take the floor of the log, and never forget the plus one.

    Quick Recall: Preconditions & Representation

    Quick Recall: Preconditions

    Requirement Reason Consequence if Missing
    Sorted Order Enables elimination principle. Cannot discard half
    Random Access Enables mid calculation. Cannot jump to mid collapse
    Contiguous Memory Arrays provide direct indexing. Linked lists require traversal

    Sorting allows elimination. Contiguous memory allows instant jumps. You need both for .

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    Level 1: Warm-up

    In a binary search implementation, each step checks if the middle element is equal to the target, and if not, checks if it is less than the target. For an array of size , which of the following statements is true regarding the maximum number of comparisons?

    Question 2
    Level 1: Warm-up

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 5?

    Question 3
    Level 1: Warm-up

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    Question 4
    Level 1: Warm-up

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 8?

    Question 5
    Level 1: Warm-up

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    Question 6
    Level 1: Warm-up

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 9?

    Question 7
    Level 1: Warm-up

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    Question 8
    Level 1: Warm-up

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 10?

    Question 9
    Level 1: Warm-up

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    Question 10
    Level 1: Warm-up

    For a standard binary search on a sorted array with duplicate elements, which of the following actions makes it impossible to guarantee finding the first occurrence of the target in time?

    Free preview ends here

    Login to view the complete short notes

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Searching Algorithms and Binary Search Short Notes for GATE DA

    Searching Algorithms and Binary Search short notes for GATE DA: 2 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    Quick Recall: Binary Search Worst-Case

    Quick Recall: Worst-Case

    Concept Formula / Rule
    Recurrence Relation
    Exact Max Comparisons
    Found vs Not Found Worst-case depth is identical.
    Comparisons per Step Check if 1 (3-way) or 2 (if-else).

    Halve the size, add one step,
    take the floor of the log, and never forget the plus one.

    Quick Recall: Preconditions & Representation

    Quick Recall: Preconditions

    Requirement Reason Consequence if Missing
    Sorted Order Enables elimination principle. Cannot discard half
    Random Access Enables mid calculation. Cannot jump to mid collapse
    Contiguous Memory Arrays provide direct indexing. Linked lists require traversal

    Sorting allows elimination. Contiguous memory allows instant jumps. You need both for .

    Searching Algorithms and Binary Search: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Programming, Data Structures and Algorithms MCQ

    In a binary search implementation, each step checks if the middle element is equal to the target, and if not, checks if it is less than the target. For an array of size , which of the following statements is true regarding the maximum number of comparisons?

    1. A.

      It is bounded by

    2. B.

      It is bounded by

    3. C.

      It is bounded by

    4. D.

      It is bounded by

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This tests the comparison counting trap based on code implementation.

    Step 1: Analyze the code logic. There are two comparisons per step: one for equality, one for less-than.

    Step 2: The depth of the tree is still .

    Step 3: Multiply the depth by the number of comparisons per step: .

    Answer: It is bounded by .

    Question 2 · Programming, Data Structures and Algorithms MCQ

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 5?

    1. A.

      16

    2. B.

      20

    3. C.

      15

    4. D.

      31

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This tests the boundary cases of the floor function in the formula.

    Step 1: Set the formula equal to 5: .

    Step 2: Solve for the floor: .

    Step 3: Convert to an inequality: , which means , or .

    Step 4: Check the options. 16, 20, and 31 are all in the range .

    Step 5: 15 is outside this range, making it impossible.

    Answer: 15

    Question 3 · Programming, Data Structures and Algorithms MCQ

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    1. A.

      is strictly less than 14

    2. B.

      is bounded above by 14

    3. C.

      is exactly 13

    4. D.

      is bounded above by 13

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question that tests the comparison counting trap with a specific array size.

    Step 1: Identify and the comparison type (separate checks = 2 comparisons per step).

    Step 2: Calculate the tree depth: . Since and , .

    Step 3: Depth = .

    Step 4: Calculate the worst-case comparisons: .

    Step 5: Evaluate the options. can be exactly 14 in the worst case. Therefore, " is bounded above by 14" is the only true statement.

    Answer: is bounded above by 14.

    Question 4 · Programming, Data Structures and Algorithms MCQ

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 8?

    1. A.

      128

    2. B.

      200

    3. C.

      255

    4. D.

      256

    Correct Answer:

    D

    Step-by-Step Solution

    Key idea: This tests the boundary cases of the floor function in the formula.

    Step 1: Set the formula equal to 8: .

    Step 2: Solve for the floor: .

    Step 3: Convert to an inequality: , which means , or .

    Step 4: Check the options. 128, 200, and 255 are all in the range .

    Step 5: 256 is outside this range, making it impossible.

    Answer: 256

    Question 5 · Programming, Data Structures and Algorithms MCQ

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    1. A.

      is strictly less than 16

    2. B.

      is bounded above by 16

    3. C.

      is exactly 15

    4. D.

      is bounded above by 15

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question that tests the comparison counting trap with a specific array size.

    Step 1: Identify and the comparison type (separate checks = 2 comparisons per step).

    Step 2: Calculate the tree depth: . Since and , .

    Step 3: Depth = .

    Step 4: Calculate the worst-case comparisons: .

    Step 5: Evaluate the options. can be exactly 16 in the worst case. Therefore, " is bounded above by 16" is the only true statement.

    Answer: is bounded above by 16.

    Question 6 · Programming, Data Structures and Algorithms MCQ

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 9?

    1. A.

      256

    2. B.

      300

    3. C.

      511

    4. D.

      512

    Correct Answer:

    D

    Step-by-Step Solution

    Key idea: This tests the boundary cases of the floor function in the formula.

    Step 1: Set the formula equal to 9: .

    Step 2: Solve for the floor: .

    Step 3: Convert to an inequality: , which means , or .

    Step 4: Check the options. 256, 300, and 511 are all in the range .

    Step 5: 512 is outside this range, making it impossible.

    Answer: 512

    Question 7 · Programming, Data Structures and Algorithms MCQ

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    1. A.

      is strictly less than 12

    2. B.

      is bounded above by 12

    3. C.

      is exactly 11

    4. D.

      is bounded above by 11

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question that tests the comparison counting trap with a specific array size.

    Step 1: Identify and the comparison type (separate checks = 2 comparisons per step).

    Step 2: Calculate the tree depth: . Since and , .

    Step 3: Depth = .

    Step 4: Calculate the worst-case comparisons: .

    Step 5: Evaluate the options. can be exactly 12 in the worst case. Therefore, " is bounded above by 12" is the only true statement.

    Answer: is bounded above by 12.

    Question 8 · Programming, Data Structures and Algorithms MCQ

    For a standard binary search, which of the following array sizes makes it impossible for the maximum number of comparisons to be exactly 10?

    1. A.

      512

    2. B.

      750

    3. C.

      1023

    4. D.

      1024

    Correct Answer:

    D

    Step-by-Step Solution

    Key idea: This tests the boundary cases of the floor function in the formula.

    Step 1: Set the formula equal to 10: .

    Step 2: Solve for the floor: .

    Step 3: Convert to an inequality: , which means , or .

    Step 4: Check the options. 512, 750, and 1023 are all in the range .

    Step 5: 1024 is outside this range, making it impossible.

    Answer: 1024.

    Question 9 · Programming, Data Structures and Algorithms MCQ

    Consider a recursive binary search on an array of size . The implementation uses separate checks for equality and inequality at each step. Which of the following statements correctly describes the worst-case number of comparisons ?

    1. A.

      is strictly less than 16

    2. B.

      is bounded above by 16

    3. C.

      is exactly 15

    4. D.

      is bounded above by 15

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question that tests the comparison counting trap with a specific array size.

    Step 1: Identify and the comparison type (separate checks = 2 comparisons per step).

    Step 2: Calculate the tree depth: . Since and , .

    Step 3: Depth = .

    Step 4: Calculate the worst-case comparisons: .

    Step 5: Evaluate the options. can be exactly 16 in the worst case. Therefore, " is bounded above by 16" is the only true statement.

    Answer: is bounded above by 16.

    Question 10 · Programming, Data Structures and Algorithms MCQ

    For a standard binary search on a sorted array with duplicate elements, which of the following actions makes it impossible to guarantee finding the first occurrence of the target in time?

    1. A.

      Continuing the search in the left half after a match

    2. B.

      Returning the index immediately upon finding a match

    3. C.

      Using linear search from the beginning of the array

    4. D.

      Sorting the array in descending order before searching

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This tests the boundary case of handling duplicates and the modification required to find the first occurrence.

    Step 1: Understand the goal. We want the first occurrence of the target in time.

    Step 2: Evaluate Option A. Continuing the search in the left half after a match is the correct modification to push the search towards the first occurrence. It maintains .

    Step 3: Evaluate Option B. Returning the index immediately upon finding a match stops the search at an arbitrary occurrence. It makes it impossible to guarantee finding the first occurrence.

    Step 4: Evaluate Option C. Using linear search degrades the time complexity to , violating the constraint, but the question asks what makes it impossible to guarantee finding the first occurrence in time via the binary search logic itself. Wait, returning immediately is the fundamental flaw in the standard algorithm for this specific goal.

    Step 5: Evaluate Option D. Sorting in descending order just flips the comparison logic; it doesn't solve the duplicate boundary issue.

    Step 6: The action that breaks the guarantee of finding the first occurrence while attempting to maintain the search logic is returning immediately.

    Answer: Returning the index immediately upon finding a match.

    More short notes in this unit