From 3d8961e703705bb742890d71305e84570caaea87 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Sun, 10 Dec 2017 11:25:35 +0200 Subject: [PATCH] Explain meet in the middle time complexity [closes #57] --- chapter05.tex | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chapter05.tex b/chapter05.tex index 31fac4e..1376afa 100644 --- a/chapter05.tex +++ b/chapter05.tex @@ -749,10 +749,10 @@ because $S_A$ contains the sum $6$, $S_B$ contains the sum $9$, and $6+9=15$. This corresponds to the solution $[2,4,9]$. -The time complexity of the algorithm is $O(2^{n/2})$, -because both lists $A$ and $B$ contain about $n/2$ numbers -and it takes $O(2^{n/2})$ time to calculate the sums of -their subsets to lists $S_A$ and $S_B$. -After this, it is possible to check in -$O(2^{n/2})$ time if the sum $x$ can be created -from $S_A$ and $S_B$. \ No newline at end of file +We can implement the algorithm so that +its time complexity is $O(2^{n/2})$. +First, we generate \emph{sorted} lists $S_A$ and $S_B$, +which can be done in $O(2^{n/2})$ time using a merge-like technique. +After this, since the lists are sorted, +we can check in $O(2^{n/2})$ time if +the sum $x$ can be created from $S_A$ and $S_B$. \ No newline at end of file