Skip to content

Comments

feat: Add Median of Two Sorted Arrays to Divide and Conquer#13730

Closed
balaraj74 wants to merge 2 commits intoTheAlgorithms:masterfrom
balaraj74:master
Closed

feat: Add Median of Two Sorted Arrays to Divide and Conquer#13730
balaraj74 wants to merge 2 commits intoTheAlgorithms:masterfrom
balaraj74:master

Conversation

@balaraj74
Copy link

Hey there! I've added the Median of Two Sorted Arrays algorithm to the divide and conquer section.

Quick Overview
This solves the classic problem of finding the median when you have two sorted arrays. Instead of merging them (which would be slow), I used a smart binary search approach that's super efficient.

The Algorithm:

Finds the median in O(log(min(m, n))) time - really fast!
Uses only O(1) extra space
Handles all the tricky cases: empty arrays, different sizes, negative numbers, floats, etc.
What's Included:

Clean, well-commented code with type hints
10 doctests that cover edge cases (all passing )
Detailed explanations in the docstring
Why This Matters
This is one of those interview classics that really shows off divide-and-conquer thinking. It's way better than the naive "merge everything" approach, and I think it'll be a great addition to the repo for people learning algorithms.

Closes #13717

Let me know if you'd like any changes! Happy to adjust based on feedback.

- Implement partition-based divide-and-conquer solution
- Time complexity: O(log(min(m, n)))
- Space complexity: O(1)
- Handles empty arrays, integers, floats, and negative numbers
- Includes comprehensive doctests for edge cases
- Fixes TheAlgorithms#13717
Add Median of Two Sorted Arrays Algorithm to Divide and Conquer Section
@algorithms-keeper
Copy link

Closing this pull request as invalid

@balaraj74, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines.

If you're facing any problem on how to mark a checkbox, please read the following instructions:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed invalid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Median of Two sorted arrays

1 participant