- Space Complexity: How much memory does the alogirthm require?
- Time Complexity: How mych time does it take to complete?
- What does the alogrithm accept, and what are the results?
- Serial / parallel
- Exact / approximate
- Deterministic / non-deterministic
- Find specific data in a structure ( for example, a substring within a string)
- Take a dataset and apply a sort order to it
- Given one set of data, derive another from it ( is a given number a prime?)
- Manipulating or navigating set of data that are stored within a particular structure (count specific items, navigate among data elements, filter out unwanted data, etc.)
Find the greatest common denomiator (GCD) of two integers.
Example: GCD of 20 and 8 is 4 (because 8 / 4 is 2; and 20 / 4 is 5)
- For two integers a and b, where a > b, divide a by b.
- If the remainder, r, is 0, then stop: GCD is b.
- Otherwise, set a to b, b ro r, and repeat at step 1 until r is 0.
- Measure how an algortithm responds to dataset size
- Big-O notation
- Classifies performance as the input size grows
- "O" indicates the order of operation: time scale to perform an operation
- Many alogorithms and data structures have more than one O (Inserting data, searching for data, deleting data, etc.)
Notation | Description | Example |
---|---|---|
O(1) | Constant time | Looking up a single element in an array |
O(log n) | Logarithmic | Finding an item in a sorted array with a binary search |
O(n) | Linear time | Searching an unsorted array for a specific value |
O(n log n) | Log-linear | Complex sorting alogorithms like heap sort and merge sort |
O(n2) | Quadratic | Simple sorting algorithms, such as bubble sort, selection sort, and insertion sort |
- Arrays
- Linked Lists
- Stacks and queues
- Trees
- Hash tables
- Calculate itms index: O(1)
- Insert or delete item at beginning: O(n)
- Insert or delete item in middle :O(n)
- Insert or delete item at end: O(1)
- Bubble Sort
- Merge Sort
- Quick sort
- One of the most basic sorting alogorithms
- Very simple to understand and implement
- Performance: O(n2)
- Other sorting alogorithms are generally much better
- Not considered to be a pratical solution
- Divide-and-congquer algorithm
- Breaks a dataset into individual pieces and merges them
- Uses recursion to operate on datasets
- Performs well on large set of data
- In general has a performance of O(n log n) time complexity
- Divide-and-conquer algorithm, like the merge sort
- Also uses recursion to perfomr sorting
- Generally performs better than merge sort, O(n log n)
- Operates in place on the data
- Worst case is O(n2) when data is mostly sorted already