You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/1500-1599/1595 - Minimum Cost to Connect Two Groups of Points.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ description: "This document provides a solution where we return the minimum cost
13
13
---
14
14
## Problem
15
15
16
-
You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.
16
+
You are given two groups of points where the first group has $size1$ points, the second group has $size2$ points, and $size1 >= size2$.
17
17
18
-
The cost of the connection between any two points are given in an size1 x size2 matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.
18
+
The cost of the connection between any two points are given in an $size1$ x $size2$ matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.
19
19
20
20
### Examples
21
21
@@ -94,7 +94,7 @@ There are four approaches discussed that helps to obtain the solution:
94
94
- Use memoization to store and reuse results of subproblems to improve efficiency.
95
95
96
96
4.**Base and Transition**:
97
-
-**Base Case:** If all points in the first group are processed (i == size1), calculate the cost to connect any remaining points in the second group that have not been connected.
97
+
-**Base Case:** If all points in the first group are processed (i == $size1$), calculate the cost to connect any remaining points in the second group that have not been connected.
98
98
99
99
-**Transition:** For each point in the second group, update the bitmask and recursively calculate the minimum cost.
100
100
@@ -158,13 +158,13 @@ This problem can be solved using dynamic programming. The problem requires conne
158
158
159
159
### Complexity Analysis
160
160
161
-
#### Time Complexity: O(size1 × 2^size2 x size2)
161
+
#### Time Complexity: O($size1$ × $2^size2$ x $size2$)
162
162
163
-
> **Reason**: There are 'size 1' points in the first group, and each point can potentially connect to any subset of the 'size2' points in the second group, leading to 2^size2 possible states for the bitmask. For each state, we iterate over all points in the second group, hence the additional factor of 'size2'.
163
+
> **Reason**: There are $'size 1'$ points in the first group, and each point can potentially connect to any subset of the $'size2'$ points in the second group, leading to $'2^size2'$ possible states for the bitmask. For each state, we iterate over all points in the second group, hence the additional factor of $'size2'$
164
164
165
-
#### Space Complexity: O(size1 × 2^size2)
165
+
#### Space Complexity: O($size1$ × $2^size2$)
166
166
167
-
> **Reason**: Additional space is used for the recursion stack, which is O(size1).
167
+
> **Reason**: Additional space is used for the recursion stack, which is O($size1$).
0 commit comments