An algorithm is a finite, ordered sequence of well-defined instructions or rules designed to solve a specific problem or accomplish a task. Algorithms are fundamental to computer science because they provide a systematic approach to computation, independent of any particular programming language or hardware. They are evaluated on correctness, efficiency, and clarity, and form the basis of every software program ever written.
| Property | Description | Example |
|---|---|---|
| Input | Zero or more inputs are accepted | A list of numbers to sort |
| Output | At least one output is produced | The sorted list |
| Definiteness | Each step is precisely defined | Swap elements if A > B |
| Finiteness | Terminates after a finite number of steps | Stops after n passes |
| Effectiveness | Each step is basic enough to be carried out | Simple comparisons and swaps |
Wikimedia Commons, CC BY-SA
Time complexity is a measure of the amount of time an algorithm takes to complete as a function of the size of its input, typically expressed using Big O notation. It describes how the running time grows relative to the input size, helping developers predict performance and compare algorithms. Understanding time complexity is essential for writing scalable software, especially when dealing with large datasets.
Binary search is a highly efficient search algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search interval in half. At each step, it compares the target to the middle element and discards the half in which the target cannot lie. With a time complexity of O(log n), binary search is dramatically faster than linear search for large sorted datasets.
Big O notation is a mathematical notation used to describe the upper bound of an algorithm's growth rate in terms of time or space, characterising its worst-case performance as the input size approaches infinity. It abstracts away constant factors and lower-order terms, focusing on the dominant factor that determines scalability. Big O is the industry standard language for comparing algorithm efficiency and is essential for technical interviews and software engineering.
Derived from the name of the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi. His Latinised name "Algoritmi" gave rise to the word "algorithm". The term was popularised in its modern computational sense in the 20th century.