diff --git a/README.md b/README.md index e89f793..ea6148a 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,18 @@ Coding examples: - print "hello"; +**O(log n)** + +O(log n) is slightly more difficult to explain. +One good example of a O(log n) problem is when searching up a phone book. Even if the phone book is thick, you would not need to search every name, but you just have to look for the name under the correct alphabet. + +Reducing the problem size with every iteration + +Coding examples: +- Binary search +- Finding largest/smallest number in a binary search tree + + **O(N)** Performance will grow linearly and in direct proportion to the size of the input data set. @@ -282,7 +294,18 @@ Coding examples: - Traversing a linked list - Linear Search -**O(N)^2** + +**O(n log n)** + +To better understand it, think of it as O(N) and O(log n). An example of such a notation is the Quick sort when we divide the array into two parts and each time it takes O(N) time to find a pivot element. + +Coding examples: +- Merge Sort +- Heap Sort +- Quick Sort + + +**O(N^2)** Performance is directly proportional to the square of the size of the input data set. This is common with nested iterations over the data set. @@ -294,32 +317,14 @@ Coding examples: - Insertion Sort - Selection Sort -**O(2N)** -Performance doubles with each additon to the input data set. The growth curve of an O(2N) function is exponential. +**O(2^N)** + +Performance doubles with each additon to the input data set. The growth curve of an O(2^N) function is exponential. Coding examples: - Recursive calculation of Fibonacci numbers -**O(log n)** - -O(log n) is slightly more difficult to explain. -One good example of a O(log n) problem is when searching up a phone book. Even if the phone book is thick, you would not need to search every name, but you just have to look for the name under the correct alphabet. - -Reducing the problem size with every iteration - -Coding examples: -- Binary search -- Finding largest/smallest number in a binary search tree - -**O(n log n)** - -To better understand it, think of it as O(N) and O(log n). An example of such a notation is the Quick sort when we divide the array into two parts and each time it takes O(N) time to find a pivot element. - -Coding examples: -- Merge Sort -- Heap Sort -- Quick Sort ## Big-Ω (Big-Omega) notation It describes: