Last active
February 19, 2024 11:53
-
-
Save ZapDos7/f5f33dd019ab15a772be7d03f47348c6 to your computer and use it in GitHub Desktop.
Big O, also known as Big O notation, represents an algorithm's worst-case complexity. It uses algebraic terms to describe the complexity of an algorithm.
In Big O, there are six major types of complexities (time and space):
- Constant: O(1)
- Linear time: O(n)
- Logarithmic time: O(n log n)
- Quadratic time: O(n^2)
- Exponential time: O(2^n)
- Factorial time: O(n!)
- In-place: modifies existing array while sorting its elements
- External: when all to-be-sorted data cannot be placed in-memory (best for big size of data - doesn't fit in RAM so we use hard drive)
- Stable: maintain the relative order of records with equal keys (i.e. values)
- Sequential: check all elements sequentially
- Interval: specifically designed for search in sorted data structures
-
- start from the leftmost element
- 1-1 compare with each element
- if x matches element, return index
- else, return -1
Binary Search | Linear Search |
---|---|
sorted input | any form input |
random data access | sequential access |
O(log[n]) |
O(n) |
ordering comparisons | equality comparisons |
> > > _ < < <
> > > < _ < <
> > _ < > < <
> _ > < > < <
> < > _ > < <
> < > < > _ <
> < > < > < _
> < > < _ < >
> < _ < > < >
_ < > < > < >
< _ > < > < >
< < > _ > < >
< < > < > _ >
< < > < _ > >
< < _ < > > >
< < < _ > > >
Minimum number of moves = (leftFacingFrogs + 1)(rightFacingFrogs + 1) - 1 = (3+1)(3+1) -1 = 16 - 1 = 15
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment