193k views
0 votes
a list of flowers is searched for poppy using binary search. flowers list: azalea, daisy, iris, magnolia, peony, poppy, rose, violetwhat is the first flower searched? what is the second flower searched?

User Trinth
by
8.5k points

1 Answer

6 votes

the first flower searched was "magnolia," and the second flower searched was "poppy."

How to find the flowers searched ?

In a binary search, you start by examining the middle element of the list, and based on the comparison of the target element with the middle element, you decide whether to search the left or right half of the list.

Start with the full list: azalea, daisy, iris, magnolia, peony, poppy, rose, violet The middle element is "magnolia."

Since "poppy" comes after "magnolia" in alphabetical order, you know it will be in the right half of the list. Discard the left half of the list and continue the search in the right half: peony, poppy, rose, violet

The middle element in this right half is "poppy."

User Shiva Saurabh
by
7.7k points