Skip to content

Commit 0b47bf6

Browse files
Update 0004-Median-of-two-Sorted-Array.md
1 parent e0b1f5e commit 0b47bf6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

dsa-solutions/lc-solutions/0000-0099/0004-Median-of-two-Sorted-Array.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tags:
66
- Array
77
- Binary Search
88
- Divide and Conquer
9-
description: Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
9+
description: Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be $O(log (m+n))$.
1010
---
1111

1212

@@ -20,7 +20,7 @@ description: Given two sorted arrays nums1 and nums2 of size m and n respectivel
2020

2121
Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return the median of the two sorted arrays.
2222

23-
The overall run time complexity should be `O(log (m+n))`.
23+
The overall run time complexity should be $O(log (m+n))$.
2424

2525
**Example 1:**
2626
```
@@ -46,7 +46,7 @@ Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
4646

4747
### Solution
4848

49-
#### Approach 1: Merge Sort (O(m + n))
49+
#### Approach 1: Merge Sort $(O(m + n))$
5050

5151
**Algorithm:**
5252
1. Merge `nums1` and `nums2` into a single sorted array.
@@ -79,7 +79,7 @@ def findMedianSortedArrays(nums1, nums2):
7979
#### Approach 2: Binary Search (O(log(min(m, n))))
8080

8181
**Intuition:**
82-
To achieve O(log(min(m, n))) complexity, use binary search on the smaller array. The goal is to find a partition where the left half of both arrays combined is less than or equal to the right half.
82+
To achieve $O(log(min(m, n)))$ complexity, use binary search on the smaller array. The goal is to find a partition where the left half of both arrays combined is less than or equal to the right half.
8383

8484
**Algorithm:**
8585
1. Ensure `nums1` is the smaller array.
@@ -125,13 +125,13 @@ def findMedianSortedArrays(nums1, nums2):
125125
### Complexity Analysis
126126

127127
- **Time Complexity:**
128-
- Approach 1: O(m + n) because it involves merging both arrays into one sorted array.
129-
- Approach 2: O(log(min(m, n))) because it performs binary search on the smaller array.
128+
- Approach 1:$O(m + n)$ because it involves merging both arrays into one sorted array.
129+
- Approach 2: $O(log(min(m, n)))$ because it performs binary search on the smaller array.
130130

131131
- **Space Complexity:**
132-
- Approach 1: O(m + n) due to the additional space needed for the merged array.
133-
- Approach 2: O(1) because it uses only a constant amount of additional space.
132+
- Approach 1: $O(m + n)$ due to the additional space needed for the merged array.
133+
- Approach 2: $O(1)$ because it uses only a constant amount of additional space.
134134

135135
### Summary
136136

137-
Approach 1 is straightforward but not optimal in terms of time complexity for large input sizes. Approach 2 leverages binary search to efficiently find the median with logarithmic time complexity, making it suitable for large arrays.
137+
Approach 1 is straightforward but not optimal in terms of time complexity for large input sizes. Approach 2 leverages binary search to efficiently find the median with logarithmic time complexity, making it suitable for large arrays.

0 commit comments

Comments
 (0)