Question #17: What is the time complexity of the following algorithm?
Here, a graph of n nodes is assumed and the problem is to find an independent set of size k. The algorithm enumerates all k sized subsets and then checks if any one of them satisfies the independent set property. Independent set is a set of vertices such that no two vertices in the set have an edge between them.
Options:
- O(nk)
- O(kn)
- O(nn)
- O(kk)
Solution:
There are C(n,k) total sets of size k from n vertices. And each of this set is checked, so complexity is of the order O(nk). Hence, the correct answer is option 1.
