feat: Add Median of Two Sorted Arrays to Divide and Conquer#13730
Closed
balaraj74 wants to merge 2 commits intoTheAlgorithms:masterfrom
Closed
feat: Add Median of Two Sorted Arrays to Divide and Conquer#13730balaraj74 wants to merge 2 commits intoTheAlgorithms:masterfrom
balaraj74 wants to merge 2 commits intoTheAlgorithms:masterfrom
Conversation
- 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
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:
NOTE: Only |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.