Skip to content

Commit f374438

Browse files
authored
Sync binary-search docs with problem-specifications (#1651)
* Sync binary-search docs with problem-specifications There were a few follow-on tweaks to binary-search. For context, this is part of the project to overhaul all the practice exercises. You can read about that here: https://forum.exercism.org/t/new-project-making-practice-exercises-more-consistent-and-human-across-exercism/3943 ---- If you approve this pull request, I will eventually merge it. However, if you are happy with this change **please merge the pull request**, as it will get the changes into the hands of the students much more quickly. If this pull request contradicts the exercise on your track, **please add a review with _request changes_**. This will block the pull request from getting merged. Otherwise we aim to take an optimistic merging approach. If you wish to suggest tweaks to these changes, please open a pull request to the exercism/problem-specifications repository to discuss, so that everyone who has an interest in the shared exercise descriptions can participate. * Run configlet sync on binary-search
1 parent c7a89f4 commit f374438

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

exercises/practice/binary-search/.docs/instructions.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ Your task is to implement a binary search algorithm.
55
A binary search algorithm finds an item in a list by repeatedly splitting it in half, only keeping the half which contains the item we're looking for.
66
It allows us to quickly narrow down the possible locations of our item until we find it, or until we've eliminated all possible locations.
77

8-
```exercism/caution
8+
~~~~exercism/caution
99
Binary search only works when a list has been sorted.
10-
```
10+
~~~~
1111

1212
The algorithm looks like this:
1313

14-
- Divide the sorted list in half and compare the middle element with the item we're looking for.
15-
- If the middle element is our item, then we're done.
16-
- If the middle element is greater than our item, we can eliminate that number and all the numbers **after** it.
17-
- If the middle element is less than our item, we can eliminate that number and all the numbers **before** it.
18-
- Repeat the process on the part of the list that we kept.
14+
- Find the middle element of a *sorted* list and compare it with the item we're looking for.
15+
- If the middle element is our item, then we're done!
16+
- If the middle element is greater than our item, we can eliminate that element and all the elements **after** it.
17+
- If the middle element is less than our item, we can eliminate that element and all the elements **before** it.
18+
- If every element of the list has been eliminated then the item is not in the list.
19+
- Otherwise, repeat the process on the part of the list that has not been eliminated.
1920

2021
Here's an example:
2122

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Introduction
22

33
You have stumbled upon a group of mathematicians who are also singer-songwriters.
4-
They have written a song for each of their favorite numbers, and, as you can imagine, they have a lot of favorite numbers.
4+
They have written a song for each of their favorite numbers, and, as you can imagine, they have a lot of favorite numbers (like [0][zero] or [73][seventy-three] or [6174][kaprekars-constant]).
55

66
You are curious to hear the song for your favorite number, but with so many songs to wade through, finding the right song could take a while.
77
Fortunately, they have organized their songs in a playlist sorted by the title — which is simply the number that the song is about.
88

99
You realize that you can use a binary search algorithm to quickly find a song given the title.
10+
11+
[zero]: https://en.wikipedia.org/wiki/0
12+
[seventy-three]: https://en.wikipedia.org/wiki/73_(number)
13+
[kaprekars-constant]: https://en.wikipedia.org/wiki/6174_(number)

0 commit comments

Comments
 (0)