• retagged by
2,914 views
1 1 vote
Brute force algorithm time complexity for subset sum problem

a) O(N logN) b)O(N^2) c) O(N^2 logN) d) O(2^N)

1 Answer

1 1 vote

Let isSubSetSum(int set[], int n, int sum) be the function to find whether there is a subset of set[] with sum equal to sum. n is the number of elements in set[].

The isSubsetSum problem can be divided into two subproblems
…a) Include the last element, recur for n = n-1, sum = sum – set[n-1]
…b) Exclude the last element, recur for n = n-1.
If any of the above the above subproblems return true, then return true.

and the amount of work done is O(2N)

so from that work done , i guess the brute force complexity will be D

Position:
Show:

Related questions

0 0 votes
1 1 answer
481
481 views
Mahesha999 asked Feb 2, 2017
481 views
Let $f(n)=\Omega(n)$ and $g(n)=\Omega\left(n^{2}\right)$. Then $f(n)+g(n)$ is$\Omega(n)$$\theta(n)$$\Omega\left(n^{2}\right)$$O(n)$
0 0 votes
1 1 answer
2.0k
2.0k views
akshayaK asked Dec 20, 2018
1,960 views
$L1 \subseteq L2$ decidable ? (for any of languages)i read No language is closed under subset operation Not even Regular Langauge ?I it TRUE ??
2 2 votes
1 answers 1 answer
2.4k
2.4k views
Lakshman Bhaiya asked Oct 5, 2018
2,414 views
Which of the following is not a subset of $P(P(P(\phi)))$?$A)$ {$\phi$}$B)$ { {$\phi$} }$C)$ { {$\phi$} , { {$\phi$} } }$D)$ { { { {$\phi$} } } }