3

In my formal languages class, we discussed DIV, defined as following:

$\mathrm{DIV} = \{\langle a,b\rangle : \text{$a, b \in N$ and $a$ has a divisor $d$ for some $1 < d \leq b$ }\}$

($\langle\cdot\rangle$ means encoded, let's say as binary)

We were told that it isn't known whether DIV is in P and were tasked to prove it was in NP. I naively and mistakenly assumed that DIV was in P because of the following algorithm:

   On input <a,b>
   For all 1<d<=b
       check if d divides a.
       If so, accept.
   reject.

I thought that this algorithm would run in polynomial time because we do $b$ many divisions at worst. Division is polynomial time, therefore, $b$ many divisions is also polynomial time. (also note, $b < a$, or DIV is trivially true, where $d = a$).

However, i was told that this algorithm is not polynomial time with respect to the input. I don't really understand this part. Something along the lines of since $a$ and $b$ are encoded in binary, the input is of order $O(\log n)$. And that means our b many divisions is actually $O(b) \cdot O(\text{divisions})$, and that $O(b)$ is $O(2^{\log b})$. However, isn't $2^{\text{log base $2$ of $b$}}$ the same as $b$? How is that not polynomial time?

Discrete lizard
  • 8,248
  • 3
  • 24
  • 53
John_Titor
  • 33
  • 3

1 Answers1

4

When we say that an algorithm runs in polynomial time, we mean polynomial in the length of the input to the algorithm, i.e., the number of bits needed to represent the input. Suppose both $a$ and $b$ are at most $n$; then the pair $\langle a,b\rangle$ takes $\lg n$ bits to represent. So, an algorithm whose running time is $O(n)$ takes exponential time (exponential in $\lg n$). In particular, your algorithm is an exponential time algorithm.

The problem DIV is basically equivalent to the integer factoring problem. It is an open question whether there exists any polynomial-time algorithm for it, but many believe that there probably is no polynomial time algorithm for it.

D.W.
  • 159,275
  • 20
  • 227
  • 470
  • What exactly does it mean to be polynomial in the length of the input? Are you saying that because the input n is log(a) + log(b) that our algorithm is exponentially larger because for every n we input, we do 2^n divisions? For example, if i input <1,000,001, 1,000,000>, n would be 20 + 20, and we end up doing 2^20 steps in the worst case scenario? – John_Titor Apr 26 '19 at 00:43
  • @John_Titor, perhaps the following will be helpful: https://cs.stackexchange.com/q/13625/755, https://cs.stackexchange.com/q/9556/755, https://cs.stackexchange.com/q/60735/755, https://cs.stackexchange.com/q/91880/755, https://en.wikipedia.org/wiki/Time_complexity#Polynomial_time – D.W. Apr 26 '19 at 00:58
  • As a followup that is slightly unrelated, how can i prove DIV is in co-NP? If I use the following algorithm to prove DIV in NP: Given our input <a,b> Non-deterministically choose d, where 1<d<=b Check if d divides a. If not, reject Else, accept. I seem to cycle back to having to check every possible input, which would become exponential like above. – John_Titor Apr 26 '19 at 01:47
  • @John_Titor, we'd prefer that you use the 'Ask Question' button to ask follow-up questions. I suggest checking the definition of Co-NP before you ask. – D.W. Apr 26 '19 at 05:13
  • No offense, but your answers come off as slightly condescending. I'm already familiar with formal definitions for all of these things, the issues I'm having, and hence why I asked the questions to begin with, are because I didn't understand the how of it. Such as in the original post I understood what the definition of time-complexity was and that in order for something to be considered polynomial-time, it must be polynomial with respect to the input.The issue was with my understanding of what input is, being the size of the representation of the numbers rather than the numbers themselves. – John_Titor Apr 27 '19 at 08:16
  • And for future reference, simply telling others to look up the definition of something isn't very helpful. I think most people are capable of that on their own. If you think that the definition contains something relevant to answering their question, it'd be more helpful to point out what that might be, whether obvious or nuanced, rather than leaving them to figure it out on their own. – John_Titor Apr 27 '19 at 08:20
  • @John_Titor There is no way for D.W. to know how well you are acquainted with certain definitions. There are many people that ask questions about subjects for which they do not understand the definitions. As for your remark on referring to definitions, a simple 'just look at the definitions' can be more helpful than you think. (I mean, there was even a question where this apparently was all the asker needed to solve the question themselves) It also may be more educational to not point at the specifics of the definition, if you think that can be figured out on their own. – Discrete lizard Apr 27 '19 at 10:20
  • 1
    @John_Titor, sorry that it wasn't helpful! For what it's worth, I wasn't trying to be condescending; I had a limited amount of time to help, and I can't tell how much you already do and don't know, so I tried to do what I could within the time available to me. Sorry for leaving the impression that I was talking down to you. – D.W. Apr 27 '19 at 16:44