Explain meet in the middle time complexity [closes #57]
This commit is contained in:
parent
c94cdf33f2
commit
3d8961e703
|
@ -749,10 +749,10 @@ because $S_A$ contains the sum $6$,
|
||||||
$S_B$ contains the sum $9$, and $6+9=15$.
|
$S_B$ contains the sum $9$, and $6+9=15$.
|
||||||
This corresponds to the solution $[2,4,9]$.
|
This corresponds to the solution $[2,4,9]$.
|
||||||
|
|
||||||
The time complexity of the algorithm is $O(2^{n/2})$,
|
We can implement the algorithm so that
|
||||||
because both lists $A$ and $B$ contain about $n/2$ numbers
|
its time complexity is $O(2^{n/2})$.
|
||||||
and it takes $O(2^{n/2})$ time to calculate the sums of
|
First, we generate \emph{sorted} lists $S_A$ and $S_B$,
|
||||||
their subsets to lists $S_A$ and $S_B$.
|
which can be done in $O(2^{n/2})$ time using a merge-like technique.
|
||||||
After this, it is possible to check in
|
After this, since the lists are sorted,
|
||||||
$O(2^{n/2})$ time if the sum $x$ can be created
|
we can check in $O(2^{n/2})$ time if
|
||||||
from $S_A$ and $S_B$.
|
the sum $x$ can be created from $S_A$ and $S_B$.
|
Loading…
Reference in New Issue