From ccfc980be0e71ef2617aa17ac0904c6d3ffb25fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20T=C3=BCrkal?= Date: Thu, 26 Oct 2017 14:04:30 +0300 Subject: [PATCH] update readme --- array-minimum-distance/README.md | 6 +++--- array-rotation/README.md | 12 ++++++------ array-smallest-missing-number/README.md | 19 +++++++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/array-minimum-distance/README.md b/array-minimum-distance/README.md index 0da6ec0..0eaba49 100644 --- a/array-minimum-distance/README.md +++ b/array-minimum-distance/README.md @@ -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 | | ----------------- |:---------:| diff --git a/array-rotation/README.md b/array-rotation/README.md index 585131d..b2e1d9f 100644 --- a/array-rotation/README.md +++ b/array-rotation/README.md @@ -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 | | ----------------- |:---------:| diff --git a/array-smallest-missing-number/README.md b/array-smallest-missing-number/README.md index ae159ca..2529f32 100644 --- a/array-smallest-missing-number/README.md +++ b/array-smallest-missing-number/README.md @@ -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 doesn’t work if there are duplicate elements in the array.` -Algorithm Complexity --------------------------- +**Algorithm Complexity** | Complexity | Notation | | ----------------- |:------------:|