Skip to content

Unhandled Edge Case in Binary Search Implementation #1095

Open
@ShadBalti

Description

@ShadBalti

The current implementation of the binary search algorithm in the JavaScript codebase does not handle a specific edge case where the target element is present multiple times in the sorted array. This issue is reported to address the potential misbehavior and propose a solution to handle scenarios where the binary search encounters duplicate elements.

Steps to Reproduce:

  1. Input a sorted array containing duplicate elements.
  2. Perform a binary search for a target element present multiple times in the array.
  3. Observe the behavior when the target element is found.

Expected Behavior:
The binary search algorithm should reliably locate and return any occurrence of the target element in the sorted array, providing accurate indices for all instances.

Current Behavior:
The current implementation may not consistently handle scenarios where duplicate elements exist in the sorted array, leading to unpredictable results when searching for the target element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions