Safekipedia

Computational complexity

Adapted from Wikipedia · Discoverer experience

In computer science, computational complexity is about understanding how much time and memory an algorithm needs to solve a problem. When we talk about complexity, we look at how many steps a computer needs to take and how much space it needs to store information while running a program. This helps us know which programs work best for big jobs.

The complexity of a problem is tied to the best possible way to solve it. Even if we find one good method, there might be an even better one out there. Scientists study both the ways to solve problems and the problems themselves to find the most efficient solutions.

Because the size of the job can change, complexity is often shown as a rule that connects the job size to the time or space needed. For example, a small task might be quick, but a huge task could take much longer. This helps computer experts choose the right method for different kinds of work.

Resources

When we talk about how hard a computer task is, we often look at how much time and memory it needs.

We don't use real-time units like seconds because computers change over time. Instead, we count the basic steps a computer needs to finish a task. These steps are like tiny jobs the computer does one after another.

We also care about how much space in the computer's memory a task needs. Some tasks need a lot of space, while others can fit in just a little.

For tasks where many computers work together, we look at how much they need to talk to each other. This is called communication complexity.

There are many other ways to measure how hard a task is, like counting the number of math steps needed. Sometimes, these steps can take much longer if the numbers get really big!

Main article: circuit complexity

Main article: communication complexity

Complexity as a function of input size

Only the time it takes for a computer to solve a problem is looked at here, but this idea also works for other things a computer needs, like memory space.

Because it’s impossible to test every possible input for an algorithm, we usually talk about how hard a problem is based on the size of the input. This size is written as n (the number of bits in the input). But, even for inputs of the same size, some can be easier or harder to solve than others. So, there are a few ways to talk about complexity:

When people just say “complexity” without saying more, they usually mean the worst-case time complexity.

Asymptotic complexity

Main article: Asymptotic computational complexity

It can be hard to know exactly how much time or space an algorithm will need, especially for very large problems. Because of this, computer scientists often look at how the amount of time or space an algorithm needs grows when the problem gets bigger and bigger. They use something called "big O notation" to describe this growth.

For example, the usual way to multiply two big whole numbers takes about O(n2) time. This means that if you double the number of digits, the time it takes will go up by about four times. This helps us understand how well an algorithm will work when dealing with really large numbers.

Models of computation

The complexity of a problem depends on the model of computation used, which defines the basic operations done in a unit of time. When the model is not specified, it is usually assumed to be a multitape Turing machine, as many realistic models behave similarly for most problems.

Deterministic models, such as recursive functions, lambda calculus, and Turing machines, have steps that are fully determined by the previous state. Non-deterministic models, like non-deterministic Turing machines, allow some choices during computation and consider the best possible outcomes simultaneously. This concept relates to the important P = NP problem, which asks whether problems solvable in polynomial time on a non-deterministic machine can also be solved efficiently on a deterministic one.

Parallel and distributed computing split tasks across multiple processors, with parallel computing offering faster data transmission and distributed computing using networks. The goal is to design algorithms where the product of computation time and the number of processors is as close as possible to the time on a single processor.

Quantum computing, based on quantum mechanics, might solve some problems more efficiently, though building such computers remains theoretical. Quantum complexity theory studies problem complexity for quantum computers and helps develop post-quantum cryptography to protect against future quantum attacks.

Main articles: Parallel computing and Distributed computing

Problem complexity

The complexity of a problem is about how hard it is to solve using the best possible method. We usually compare this to how much time or memory a computer needs. For many problems, you need to look at all the information given, which takes time related to the amount of data.

Some problems are harder because the answers can be very big. For example, solving certain equations can sometimes need a lot of steps, growing very fast with more details. Sorting items, like putting numbers in order, also needs a certain amount of steps to make sure everything is in the right place.

Use in algorithm design

Evaluating how much work an algorithm needs is very important when designing it. This helps us know how fast it will run.

Some people think that as computers get faster, we don’t need to worry about this anymore. But this isn’t true. Faster computers let us work with much bigger amounts of data. For example, sorting a few hundred names can be done quickly by almost any method. But sorting a million names can take a long time if we use a slow method. Some smart methods, like quicksort and merge sort, can do this job much faster than simpler ones.

Checking how much work an algorithm needs helps us choose better ways to solve problems and improve complex methods without trying every option.

Related articles

This article is a child-friendly adaptation of the Wikipedia article on Computational complexity, available under CC BY-SA 4.0.