In computer science, the time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of the length of the input. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, where an elementary operation takes a fixed amount of time to perform. Thus, the amount of time taken by the algorithm is at most a constant multiple of the number of elementary operations.
The time complexity of an algorithm is often expressed as a function T(n), where n is the length of the input. For example, if the time complexity of an algorithm is T(n) = 2n^2 + 5n + 10, then, as the input size n increases, the time taken by the algorithm increases quadratically.
There are two common ways to express time complexity: asymptotic notation, and exact time complexity.
Asymptotic notation is a mathematical notation that describes the limiting behavior of a function as the argument tends to infinity. The most common types of asymptotic notation are Big O notation, Big Ω notation, and Big Θ notation.
Exact time complexity is a mathematical notation that describes the exact amount of time taken by an algorithm to run as a function of the length of the input.
Common time complexity functions are:
The time complexity of an algorithm can be affected by the choice of data structures. For example, the time complexity of a sorting algorithm can be different depending on whether the input is an array or a linked list.
The time complexity of an algorithm is also affected by the choice of algorithms. For example, the time complexity of a sorting algorithm can be different depending on whether the algorithm is a comparison sort or a non-comparison sort.
The time complexity of an algorithm is also affected by the choice of implementation. For example, the time complexity of a sorting algorithm can be different depending on whether the implementation is in a high-level language or a low-level language.
The time complexity of an algorithm is also affected by the choice of hardware. For example, the time complexity of a sorting algorithm can be different depending on whether the hardware is a general-purpose computer or a special-purpose computer.
The time complexity of an algorithm is also affected by the choice of operating system. For example, the time complexity of a sorting algorithm can be different depending on whether the operating system is a multitasking operating system or a single-tasking operating system.
The time complexity of an algorithm is also affected by the choice of compiler. For example, the time complexity of a sorting algorithm can be different depending on whether the compiler is a optimizing compiler or a non-optimizing compiler.
The time complexity of an algorithm is also affected by the choice of libraries. For example, the time complexity of a sorting algorithm can be different depending on whether the library is the Standard Template Library or the Boost library.
The time complexity of an algorithm is also affected by the choice of computer architecture. For example, the time complexity of a sorting algorithm can be different depending on whether the computer architecture is a von Neumann architecture or a Harvard architecture.
The time complexity of an algorithm is also affected by the choice of cache size. For example, the time complexity of a sorting algorithm can be different depending on whether the cache size is small or large.
The time complexity of an algorithm is also affected by the choice of main memory size. For example, the time complexity of a sorting algorithm can be different depending on whether the main memory size is small or large.
The time complexity of an algorithm is also affected by the choice of virtual memory size. For example, the time complexity of a sorting algorithm can be different depending on whether the virtual memory size is small or large.
The time complexity of an algorithm is also affected by the choice of disk size. For example, the time complexity of a sorting algorithm can be different depending on whether the disk size is small or large.
The time complexity of an algorithm is also affected by the choice of network size. For example, the time complexity of a sorting algorithm can be different depending on whether the network size is small or large.
The time complexity of an algorithm is also affected by the choice of input size. For example, the time complexity of a sorting algorithm can be different depending on whether the input size is small or large.
The time complexity of an algorithm is also affected by the choice of output size. For example, the time complexity of a sorting algorithm can be different depending on whether the output size is small or large.
The time complexity of an algorithm is also affected by the choice of number of processors. For example, the time complexity of a sorting algorithm can be different depending on whether the number of processors is small or large.
The time complexity of an algorithm is also affected by the choice of word size. For example, the time complexity of a sorting algorithm can be different depending on whether the word size is small or large.
The time complexity of an algorithm is also affected by the choice of clock speed. For example, the time complexity of a sorting algorithm can be different depending on whether the clock speed is slow or fast.
The time complexity of an algorithm is also affected by the choice of I/O devices. For example, the time complexity of a sorting algorithm can be different depending on whether the I/O devices are slow or fast.