Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
46 views
in Computer by (20 points)
edited by

Apply binary search for the following sequence of numbers 10,20,30,40,50,60,70,80,90.search for item =30

Please log in or register to answer this question.

1 Answer

0 votes
by (38.0k points)
  1. Initialize: Set the lower bound (start) to index 0 and the upper bound (end) to the index of the last element in the sequence.

    • Start: 0
    • End: 8
  2. Calculate mid: Find the index of the middle element by averaging the start and end indices (round down if necessary).

    • Mid: (0 + 8) / 2 = 4
  3. Compare: Check if the middle element is equal to the item you're searching for (30). Since 50 ≠ 30:

    • Sequence: 10, 20, 30, 40, 50, 60, 70, 80, 90
    • Mid value: 50 ≠ 30
  4. Update bounds: Update the start or end index based on whether the item is greater or smaller than the middle element. Since 30 < 50, update the end index to mid - 1.

    • Start: 0
    • End: 3
  5. Repeat: Continue the process until the item is found or the bounds cross each other.

    • New Mid: (0 + 3) / 2 = 1
    • Sequence: 10, 20, 30, 40, 50, 60, 70, 80, 90
    • Mid value: 20 ≠ 30
    • New Start: 2
    • End: 3
  6. Repeat:

    • New Mid: (2 + 3) / 2 = 2
    • Sequence: 10, 20, 30, 40, 50, 60, 70, 80, 90
    • Mid value: 30 = 30
  7. Found: The item 30 is found at index 2.

So, the binary search algorithm successfully finds the item 30 at index 2 in the given sequence of numbers.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...