Skip to content

Commit 30091ed

Browse files
committed
update readme
1 parent e1f0647 commit 30091ed

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

merge-sort/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## What It Is
66

7-
Like **[QuickSort](https://github.com/Dentrax/Data-Structures-with-Go/tree/master/quick-sort)**, Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The `merge()` function is used for merging two halves. The `merge(arr, l, m, r)` is key process that assumes that `arr[l..m]` and `arr[m+1..r]` are sorted and merges the two sorted sub-arrays into one. See following C implementation for details
7+
Like **[QuickSort](https://github.com/Dentrax/Data-Structures-with-Go/tree/master/quick-sort)**, `MergeSort` is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The `merge()` function is used for merging two halves. The `merge(arr, l, m, r)` is key process that assumes that `arr[l..m]` and `arr[m+1..r]` are sorted and merges the two sorted sub-arrays into one. See following C implementation for details
88

99
![Preview Thumbnail](https://upload.wikimedia.org/wikipedia/commons/c/cc/Merge-sort-example-300px.gif)
1010

quick-sort/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h1 align="center">Quick Sort Source</h1>
2+
3+
[What It Is](#what-it-is)
4+
5+
## What It Is
6+
7+
Like **[MergeSort](https://github.com/Dentrax/Data-Structures-with-Go/tree/master/merge-sort)**, `QuickSort` is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways.
8+
9+
* Always pick first element as pivot.
10+
* Always pick last element as pivot (implemented below)
11+
* Pick a random element as pivot.
12+
* Pick median as pivot.
13+
14+
The key process in quickSort is `partition()`. Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. All this should be done in linear time.
15+
16+
![Preview Thumbnail](https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif)
17+
18+
QuickSort(arr[], start, end)
19+
--------------------------
20+
21+
**Partition Algorithm**
22+
23+
There can be many ways to do partition, following pseudo code adopts the method given in CLRS book. The logic is simple, we start from the leftmost element and keep track of index of smaller (or equal to) elements as i. While traversing, if we find a smaller element, we swap current element with arr[i]. Otherwise we ignore current element.
24+
25+
![Preview Thumbnail](https://raw.githubusercontent.com/Dentrax/Data-Structures-with-Go/master/quick-sort/resources/quick-sort.png)
26+
27+
> * Input: {10, 7, 8, 9, 1, 5}
28+
> * Output: Sorted array is `1 5 7 8 9 10`
29+
30+
**Algorithm Complexity**
31+
32+
| Complexity | Notation |
33+
| ----------------- |:------------:|
34+
| `Time Complexity` | `O(n log n)` |
35+
| `Auxiliary Space` | `O(n)` |

quick-sort/resources/quick-sort.png

42.6 KB
Loading

0 commit comments

Comments
 (0)