Skip to content

translation: update binary_search_recur.md #1663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

yanedie
Copy link
Contributor

@yanedie yanedie commented Feb 18, 2025

If this pull request (PR) pertains to Chinese-to-English translation, please confirm that you have read the contribution guidelines and complete the checklist below:

  • This PR represents the translation of a single, complete document, or contains only bug fixes.
  • The translation accurately conveys the original meaning and intent of the Chinese version. If deviations exist, I have provided explanatory comments to clarify the reasons.

If this pull request (PR) is associated with coding or code transpilation, please attach the relevant console outputs to the PR and complete the following checklist:

  • I have thoroughly reviewed the code, focusing on its formatting, comments, indentation, and file headers.
  • I have confirmed that the code execution outputs are consistent with those produced by the reference code (Python or Java).
  • The code is designed to be compatible on standard operating systems, including Windows, macOS, and Ubuntu.

@yanedie
Copy link
Contributor Author

yanedie commented Feb 18, 2025

@krahets I wonder how to eliminate those commit histories. Do you have any idea?

Copy link
Contributor

@yuelinxin yuelinxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! @yanedie please consider my suggestions.

@@ -1,40 +1,40 @@
# Divide and conquer search strategy

We have learned that search algorithms fall into two main categories.
We have learned from the [chapter 10.5](../chapter_searching/searching_algorithm_revisited.md) that search algorithms fall into two main categories.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this reference is necessary?


In fact, **search algorithms with a time complexity of $O(\log n)$ are usually based on the divide-and-conquer strategy**, such as binary search and trees.
In fact, **search algorithms with a time complexity of $O(\log n)$ are typically based on the divide-and-conquer strategy**, such as binary search and tree.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "trees" instead of "tree" because we are not referring to a specific one.

- **The problem can be divided**: Binary search recursively divides the original problem (searching in an array) into subproblems (searching in half of the array), achieved by comparing the middle element with the target element.
- **Subproblems are independent**: In binary search, each round handles one subproblem, unaffected by other subproblems.
- **The solutions of subproblems do not need to be merged**: Binary search aims to find a specific element, so there is no need to merge the solutions of subproblems. When a subproblem is solved, the original problem is also solved.
- **Dividing the problem**: Binary search recursively divides the original problem (searching in the full array) into subproblems (searching in half of the array) by comparing the middle element with the target element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Dividing the problem" -> "Dividable problem", this aligns better with the other headers


Divide-and-conquer can enhance search efficiency because brute-force search can only eliminate one option per round, **whereas divide-and-conquer can eliminate half of the options**.
Divide-and-conquer improves search efficiency. This is because, in brute-force search, only one option can be eliminated per round. In contrast, **divide-and-conquer search eliminates half of the options in each round**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is because, in brute-force search" -> "Since in brute-force search" might be more concise.

2. Recursively solve the subproblem reduced by half in size, which could be $f(i, m-1)$ or $f(m+1, j)$.
3. Repeat steps `1.` and `2.`, until `target` is found or the interval is empty and returns.
1. Calculate the midpoint $m$ of the search interval $[i, j]$ to eliminate half of the search space.
2. Recursively solve the subproblem on the reduced interval, either $f(i, m-1)$ or $f(m+1, j)$.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"reduced interval" -> "reduced search space" keep consistent with previous wording

3. Repeat steps `1.` and `2.`, until `target` is found or the interval is empty and returns.
1. Calculate the midpoint $m$ of the search interval $[i, j]$ to eliminate half of the search space.
2. Recursively solve the subproblem on the reduced interval, either $f(i, m-1)$ or $f(m+1, j)$.
3. Repeat steps `1.` and `2.`, until `target` is found or the interval becomes empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, replace interval with search space.

@yuelinxin
Copy link
Contributor

@krahets I wonder how to eliminate those commit histories. Do you have any idea?

If you don't want those commits to show up, a good way might be to fork a new branch from krahets:main for this PR and copy your changes into it. But you might need to create a new PR for this so it depends on you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants