NP-What? Complexity Types of Optimization Problems Explained | by Hennie de Harder | Aug, 2023


Complex building. Image created with Midjourney by the author.

An introduction to one of the central questions in computer science

How come the shortest path problem is easy to solve, but the traveling salesman problem is not? What are the mathematical ideas on this? How to determine if a problem will take an unmanageable number of steps if its size increases? In this post you will learn the basics on this topic. And if you want to get serious with this, I’ve included a short note on one of the millennium prize problems related to this topic at the end of the post.

Before we get started with NP hardness, you should know the basics of time complexity. If you are familiar with time complexity, Big O notation, and worst case analysis, you can skip the following section.

When we work with computers and write programs, we often deal with problems that can be solved in different ways. One important thing we need to consider is how efficient these solutions are. Time complexity helps us understand how fast an algorithm runs as the size of the problem it’s solving gets bigger.

Big O notation can be compared with labeling the algorithm with a simple sticker that tells us how long the algorithm takes to finish based on how many things we’re dealing with. It’s a way to describe how the number of steps of an algorithm grows relative to the input size of the problem.

Note: Time complexity essentially relates to the number of steps you take, instead of actual time, so it’s kind of bad naming. Otherwise you could use a faster computer and the same algorithm.

Labeling boxes (algorithms) with a sticker: how fast are you? Image by author.

We usually focus on the worst-case scenario because we want to be sure that no matter what input we give the algorithm, it won’t take longer than a certain amount of time. This helps us make sure our solution is reliable even when things get tough.



Source link

Leave a Comment