update readme

master
Furkan Türkal 7 years ago
parent d8127210b0
commit ccfc980be0

@ -21,12 +21,12 @@ Examples
> * Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2
> * Output: Minimum distance between 3 and 2 is 1.
**METHOD 1 (Simple)**
METHOD 1 (Simple)
--------------------------
Use two loops: The outer loop picks all the elements of arr[] one by one. The inner loop picks all the elements after the element picked by outer loop. If the elements picked by outer and inner loops have same values as x or y then if needed update the minimum distance calculated so far.
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:---------:|

@ -10,7 +10,8 @@
> * Input: Rotation of the above array by `2` will make array
> * Output: `3 4 5 6 7 1 2`
**METHOD 1 (Use temp array)**
METHOD 1 (Use temp array)
--------------------------
Input arr[] = [1, 2, 3, 4, 5, 6, 7], d = 2, n =7
@ -21,8 +22,7 @@ Input arr[] = [1, 2, 3, 4, 5, 6, 7], d = 2, n =7
* 3) Store back the `d` elements
arr[] = [3, 4, 5, 6, 7, 1, 2]
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:---------:|
@ -30,7 +30,8 @@ Algorithm Complexity
| `Auxiliary Space` | `O(d)` |
**METHOD 2 (Rotate one by one)**
METHOD 2 (Rotate one by one)
--------------------------
```go
leftRotate(arr[], d, n)
@ -45,8 +46,7 @@ Let us take the same example arr[] = [1, 2, 3, 4, 5, 6, 7], d = 2
Rotate arr[] by one 2 times
We get `[2, 3, 4, 5, 6, 7, 1]` after first rotation and `[3, 4, 5, 6, 7, 1, 2]` after second rotation.
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:---------:|

@ -21,30 +21,30 @@ Examples
> * Input: {0, 1, 2, 3, 4, 5, 6, 7, 10}, n = 9, m = 11
> * Output: `8`
**METHOD 1 (Use Binary Search)**
METHOD 1 (Use Binary Search)
--------------------------
`For i = 0 to m-1`, do binary search for i in the array. If i is not present in the array then `return i`.
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:------------:|
| `Time Complexity` | `O(m log n)` |
**METHOD 2 (Linear Search)**
METHOD 2 (Linear Search)
--------------------------
If `arr[0] is not 0`, `return 0`. Otherwise traverse the input array starting from index 0, and for each pair of elements a[i] and a[i+1], find the difference between them. if the difference is greater than 1 then `a[i] + 1` is the missing number.
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:------------:|
| `Time Complexity` | `O(n)` |
**METHOD 3 (Use Modified Binary Search)**
METHOD 3 (Use Modified Binary Search)
--------------------------
In the standard Binary Search process, the element to be searched is compared with the middle element and on the basis of comparison result, we decide whether to search is over or to go to left half or right half.
In this method, we modify the standard Binary Search algorithm to compare the middle element with its index and make decision on the basis of this comparison.
@ -56,8 +56,7 @@ In this method, we modify the standard Binary Search algorithm to compare the mi
`Note: This method doesnt work if there are duplicate elements in the array.`
Algorithm Complexity
--------------------------
**Algorithm Complexity**
| Complexity | Notation |
| ----------------- |:------------:|

Loading…
Cancel
Save