← 返回首页
Feat/ternary search by Sadam-jay · Pull Request #2156 · trekhleb/javascript-algorithms · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Feat/ternary search#2156

Open
Sadam-jay wants to merge 2 commits into
trekhleb:masterfrom
Sadam-jay:feat/ternary-search
Open

Feat/ternary search#2156
Sadam-jay wants to merge 2 commits into
trekhleb:masterfrom
Sadam-jay:feat/ternary-search

Conversation

Copy link
Copy Markdown

Ternary Search implementation

This PR adds a Ternary Search implementation to the search/ collection.

What it does

Ternary search is a divide-and-conquer algorithm for finding the position of a target value within a sorted array. It divides the search space into three equal parts instead of two, reducing the range by a third each iteration.

Complexity

  • Time Complexity: O(log₃ n)
  • Space Complexity: O(1)

Files added

  • src/algorithms/search/ternary-search/ternarySearch.js: The algorithm implementation.
  • src/algorithms/search/ternary-search/__test__/ternarySearch.test.js: Comprehensive test suite.
  • src/algorithms/search/ternary-search/README.md: Documentation with complexity table and explanation.

Checklist

  • Code follows the existing project style and patterns.
  • npm run lint passes with no errors.
  • npm test passes with 100% coverage for the new code.
  • README.md includes a clear explanation and complexity table.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

1 participant

Footer

© 2026 GitHub, Inc.