Data Structure is about how data is organized. The organization of data can impact the efficiency of a program.
Algorithm is a set of instructions for completing a specific task. Even if we've decided on a particular data structure, proper selection of which algorithm to use is another factor that can affect the efficiency of a program.
Algorithm | Code |
---|---|
Linear Search on Regular Array | py, js |
Linear Search on Ordered Array | py, js |
Binary Search | py, js |
Bubble Sort | py, js |
Selection Sort | py, js |
Insertion Sort | py, js |
Time complexity is the amount of time taken by an algorithm to run. Time complexity is not an actual time required to execute an algorithm, but the number of steps an algorithm performs to complete its task.
Because the number of steps an algorithm takes can vary depending on the number of data, to help ease communication regarding time complexity or efficiency, we use a formalized expression called Big O Notation.
Big O Notation is a notation that tells how the number of steps changes as the data increases. Big O Notation generally refers to the worst-case scenario, because knowing how inefficient an algorithm can get in a worst-case scenario is more useful, it prepares us for the worst.
Following are several time complexities:
-
$O(1)$ , constant time -
$O(log N)$ , log time -
$O(N)$ , linear time -
$O(N^2)$ , quadratic time
Source: Big O Cheat Sheet
If you find a bug or have a way to improve this repo, please create an issue or pull request.
MIT © Annisa Nadia