-1

I developed an algorithm but just not sure what is the complexity of the algorithm. I provide a brief description of it below:

"For $N$ user case, there are $B(N)$ Decision Variables. $B(N)$ is Bell Number, for those of you who are not familiar with Bell Numbers please be noted that $B(N)$ grows exponentially with $N$. In every turn, I have to choose the minimum Decision Variable among all of the Decision Variables and do a certain action accordingly."

I know that sorting problem is considered a Polynomial $(P)$ problem. But I am confused if my algorithm is considered $P$ or $NP$ or $NP-hard$ since the number of decision variables that are being sorted grows exponentially with $N$.

Nadi
  • 1
  • 1
  • An algorithm is claimed to run in time polynomial in the size of the input, so if your algorithm has to go through, say, $2^n$ cases, then it cannot run in polynomial time no matter how fast you solve these cases. (Side note: a problem is in NP or NP-hard, not an algorithm). – Anthony Labarre Jun 20 '17 at 08:08
  • Possible duplicate. Plus, you're confusing "this algorithm takes this long" with "every algorithm takes this long". – Raphael Jun 20 '17 at 13:03
  • @Raphael I don't think it's a duplicate but that question is super-relevant. – David Richerby Jun 20 '17 at 13:35

1 Answers1

3

Your question is somewhat malformed because P and NP are classes of problems, not algorithms. For example, as you state, the problem of sorting is in P. However, that doesn't mean that every sorting algorithm runs in polynomial time. For example, the well-known joke algorithm bogosort sorts lists by trying every possible permutation until it finds one that is sorted. It has running time approximately $n!$, which is far from polynomial. If a problem has polynomial time complexity, that means that there exists an algorithm that solves it in polynomial time, but it doesn't mean that all algorithms for the problem are that efficient.

It's not possible to say what the complexity of your problem is, or what the running time of your algorithm is, because you haven't given a precise description of either. The fact that it involves choosing a "best" set from some exponentially large set doesn't necessarily mean the problem has to have exponential time complexity: there could be a smart way of picking the best set without considering all the options. For example, there are polynomial-time algorithms for finding the shortest path between two points in a graph, even though there may be exponentially many paths.

David Richerby
  • 81,689
  • 26
  • 141
  • 235
  • Ok. Thanks. I call it a problem of sorting B(N) numbers. Bell numbers grow exponentially with $N$ and several asymptotic formulas for the Bell numbers are known. In one of the references, following bound is established:

    \begin{equation}\label{} B(N) < {\Bigg(\frac{0.792N}{ln(N+1)} \Bigg)}^N \end{equation} It is obvious that it grows exponetially. Can you figure out if sorting of that amount of numbers is considered $NP-hard$?

    – Nadi Jun 20 '17 at 08:43
  • 2
    @Nadi The question doesn't really make sense. NP relates to decision problems -- things with yes/no answers. Things that aren't decision problems can be NP-hard if they can be converted to decision problems: for example, the optimization problem "Find the largest thing" can be converted into the decision problem "Does the largest thing have size at least $x$?" But sorting can't really be converted into a hard decision problem: the answer to "Can it be sorted?" is always yes, whereas "Is it already sorted?" is too easy to be a hard problem. – David Richerby Jun 20 '17 at 09:06
  • So, essentially, duplicate? – Raphael Jun 20 '17 at 13:03
  • "even though there may be exponentially many paths. " -- super-exponentially, even! – Raphael Jun 20 '17 at 13:04
  • @DavidRicherby I'm no complexity expert but I wonder out of interest, suppose you consider "the sorting of Bell numbers" to be the base problem, then the decision problem might be "is this sequence of Bell numbers associated with n as B(n) sorted?". If you take n to be your input and you're guaranteed to end up with a number of elements exponential in n, wouldn't this make "sorting Bell numbers" NP-hard? That said, it feels like the OP's problem is a verbose reformulation of a NP-hard problem, enumerating all exponentially many possibilities and consider them as choices/decision variables. – Fasermaler Jun 20 '17 at 20:43
  • 1
    @Fasermaler Computational complexity is measured with respect to the length of the input in bits. You can tell if any list is sorted deterministically in time linear in the number of bits required to write out that list. It doesn't matter if the length of that list is exponential in some parameter you've chosen to call $n$: we measure complexity with respect to the length. (And, in any case, according to the inequality in the first comment, the $n$th Bell number can be written in about $n\log n$ bits anyway, so your list isn't even exponentially long in your $n$.) – David Richerby Jun 21 '17 at 10:36