I'm currently read on this article - https://core.ac.uk/download/pdf/154419746.pdf and confused about how the O(n^2 * 2^n) time complexity of algorithm 1 is computed. Can someone explain it? I originally thought it was the Bellman-Held-Karp algorithm, but it seems to be slightly different from ordinary pseudo code.

- 45
- 6
-
I think you mean O(2^n * n^2), right? – Schottky Jun 14 '21 at 06:38
-
I don't think this is a programming question. You would do better asking this on either a Computer Science or Mathematics SE site. – Stephen C Jun 14 '21 at 07:02
1 Answers
The full algorithm is actually O(n^3 * 2^n). The complexity that you gave is the complexity needed to calculate n problems. But we can find out where that complexity comes from by directly looking at the code. The first loop that we have is this:
foreach w in V do
…
end do
This is done in exactly n steps.
We can ignore this since the second loop is way more complex (and if you add two complexities, the one that is more complex wins)
There are four nested loops which means that we need to multiply the single complexities. All of them but one are O(n):
for i=2,…|V|
clearly since we iterate over all elements in V minus one
foreach w in S
and foreach u in S
: both contain enough elements to qualify for O(n) (in the first iteration 1, then 2, then 4, e.t.c.)
And then finally we have the for each subset S of V where the size of S is i
. This is combinatorics, but there are 2^n elements where this is true.

- 1,549
- 1
- 4
- 19
-
Great explanation! btw do you know whether this is the Bellman-Held-Karp algorithm or TSP-D first pass algorithm? I'm quite confused about this part after reading the whole article – pew Jun 17 '21 at 13:55
-
I'm not really sure but I don't think 'TSP-D first pass' is an actual algorithm. What you are looking at is (I think) the Bellman-Held-Karp algorithm. TSP-D simply describes the problem (traveling salesman with drones) – Schottky Jun 18 '21 at 14:15