Nepedia
Back to Discover
Fluent Reader
💻

Time complexity

technology Maturity 11-13 Next article →

Computers follow sets of steps to finish a job. These steps are called algorithms. Scientists want to know how much time an algorithm takes to run. This idea is called time complexity.

comparison computational complexity
comparison computational complexity

It is hard to guess the exact seconds a computer uses. Instead, we count the number of elementary operations. These are the tiny, simple steps the computer performs. We assume every single step takes a fixed amount of time. This helps us see how the work grows as the task gets bigger.

Sometimes, one job can take different amounts of time. This happens because different inputs can be harder than others. To be safe, we often look at the worst-case time complexity. This tells us the maximum time needed for a certain input size. We can also look at the average-case complexity. This is the average time for all possible inputs of that size. Scientists focus on how time changes as the input size increases. This is called asymptotic behavior.

comparison computational complexity
comparison computational complexity

We use a special math tool called big O notation to describe this. It uses a letter, usually O, followed by a function. The variable n represents the size of the input. For example, n might be the number of bits used. This notation helps us group algorithms into different speed classes. Some jobs are very fast and use constant time. This means the time does not depend on the input size. An example is finding the first item in a sorted list.

comparison computational complexity
comparison computational complexity

Other algorithms take more time as the input grows. Linear time, or O(n), grows at a steady rate. If you double the input, the work also doubles. A linear search is a good example of this. Logarithmic time, or O(log n), is even faster and very efficient. You can see this in a binary search. In a binary search, you look at the middle of a sorted list. You then throw away the half you do not need. This makes the search space get smaller very quickly.

comparison computational complexity
comparison computational complexity

There are many other ways to classify these speeds. Some algorithms take quadratic time, written as O(n²). This includes simple sorting methods like bubble sort. Other tasks take polynomial time, which is written as O(nᵏ). Scientists often call these polynomial time tasks "tractable" or "feasible." This means they are practical to solve. Some very hard problems take exponential time, or O(2ⁿ). These take a huge amount of time as the input grows. Understanding these different speeds helps us choose the best way to solve a problem.

comparison computational complexity
comparison computational complexity
425 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (1)
File:comparison computational complexity.svg
comparison computational complexity.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.