P and NP: Algorithms Part One
I know I keep on going for two months and then saying "I'm not going to do it again!", however at least I have a legitimate reason this time. My computer broke. Completely. So, I bought the amazingly awesome, beefy, and fast Lenovo Y500 for development. I'm opening it on Monday !
Now, I'm using a temporary laptop for small development, and I'm updating you:
Firstly, my (first) software product is being released soon. I haven't told you guys about it yet, however it is PyText! (That's not the real domain name, however the normal one is currently down so yeah !)
Secondly, I've been working on Jarvis.
Before I start, let me say how much I'm enjoying Python. Everything is so easy and simple. No linker problems or weird compiler bugs. Everything is a module away (from, maybe, PyPi ). Python is so simple yet powerful, it has everything I like about a programming language. The syntax really is just beautiful to look at.
I'm working my way through Code-Academy's Python track and Learn Python The Hard Way, after which I'm reading one of the books about PyGame development, after which I'm reading a Python Data Structures book. After which I'll probably tackle a functional programming language !
Jarvis is my personal voice-assistant. I've integrated him with the Wolfram-Alpha API and he's using PySpeech (on Windows) and CMU Sphinx (on Linux) for voice recognition. He is awesome. He can do everything Siri can do (wolfram-alpha), except he's on a desktop and tailored for me.
I'm currently getting a Raspberry PI and hooking up hidden microphones around my room. The PI will just be running the script (I also am going to be interfacing my script with a set of LCD lights which I'm also hooking up to show the status of Jarvis, what he's currently doing, etc.)!
I will be able to walk into my room and this will happen (with CMU Sphinx rather than PySpeech it's even better because of CMU Sphinx's grammar):
PI: "Yes sir?"
Me: "What temperature is it in Arizona? It's where my parents live"
(CMU Sphinx can filter out the "It's where my parents live part")
PI: "I'm not sure, let me check. Oh yes, here it is. It's 36 Degrees Celsius, sir"
I can't wait until it's hooked up! (I'm already testing on my temporary laptop)
Now onto P and NP.
When discussing algorithms, we find that P and NP constantly come up. A key part of understanding algorithms is understanding both how they scale and how hard they are to solve. P and NP help us answer both of these questions.
Multiplication is considered an P problem. Computers can perform multiplication rather quickly, and it is very easy for them to solve a multiplication problem. Multiplication is a P problem because no matter how much more complex it gets, the time it takes to solve only increases by little. It is considered to be upper-bounded by a polynomial expression.
What does this mean?
It means that:
Some polynomial is greater than the running time of the algorithm.
If we have a polynomial z and an equation f(x), z upper bounds f(x) if z >= f(x) for all possible values of x.
An NP problem would be finding factors of a number. As the number gets bigger the problem gets harder and harder to solve.
Finding the factors of 20 is trivial, however finding the factors of a 100 digit behemoth? It often takes at least twenty years to solve simple factoring problems like that. In retrospect, for a computer (not considering the size of values. This is considering that this computer is equipped to store numbers with any amount of digits and that there is enough RAM) 20 * 20 relatively the same as a one-hundred digit number squared.
Now that we understand P and NP, what is NP-Complete?
Take the clique problem:
Try to find the largest "clique" in this. That is, a group of dots all connected together in a polygon:
The green highlighted groups are cliques. They form polygons.
Finding a clique in a group of, say, 5 dots seems easy, however what about 1000 dots? It's basically impossible.
The clique problem is NP, however it has another interesting characteristic pushing it beyond NP:
We can put any NP problem through a "transformer" and turn it into a clique problem. This means we can turn a factoring problem into a clique problem and so forth.
This means the clique problem is NP - Complete. If we find a way to solve it fast enough to where it becomes an P problem, then we will have turned every NP (Hard to solve) problem into a P problem. This is a huge deal.
The even more interesting thing is that scientists believe that there's no way to turn an NP-Complete problem into a P problem, or that P != NP, however they can't figure out how to prove it. So, no one really knows if P = NP or not.