Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a README.md in Searching and Sorting directories separately #112

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Competitive Coding/Search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Search Algorithms

### Linear
![alt text](https://camo.githubusercontent.com/c05ad3f2178af2f16ebe2c04eb122e1e0c6a055b/687474703a2f2f7777772e7475746f7269616c73706f696e742e636f6d2f646174615f737472756374757265735f616c676f726974686d732f696d616765732f6c696e6561725f7365617263682e676966)

From [Wikipedia](https://en.wikipedia.org/wiki/Linear_search): linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.
Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.

__Properties__
* Worst case performance O(n)
* Best case performance O(1)
* Average case performance O(n)
* Worst case space complexity O(1) iterative

### Binary
![alt text](https://camo.githubusercontent.com/1cd853b57885449a176810b3e967167fb9fbf3b3/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f662f66372f42696e6172795f7365617263685f696e746f5f61727261792e706e67)

From [Wikipedia](https://en.wikipedia.org/wiki/Binary_search_algorithm): Binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value within a sorted array. It compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful.

__Properties__
* Worst case performance O(log n)
* Best case performance O(1)
* Average case performance O(log n)
* Worst case space complexity O(1)

### Interpolation
Interpolation search is an improved version of binary search algorithm.

![alt text](https://qph.ec.quoracdn.net/main-qimg-02f1f050de01608b9b1f2f27155d1b17)

Even when the data is sorted, binary search does not take advantage of that to probe the position of desired data.
Position Probing in Interpolation
SearchInterpolation search search a particular item by computing the probe position. Initially probe position is the position of the middle most item of the collection.If middle item is greater than item then probe position is again calculated in the sub-array to the right of the middle item other wise item is search in sub-array to the left of the middle item. This process continues on sub-array as well until the size of subarray reduces to zero.


__Properties__
* Worst case performance O(n)
* Best case performance O(1)
* Average case performance O(log(logn))
* Worst case space cmplexity O(1)
84 changes: 84 additions & 0 deletions Competitive Coding/Sorting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
## Sort Algorithms


### Bubble
![alt text](https://camo.githubusercontent.com/40b8099e638526dce298f8dc91246173d56e389a/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f382f38332f427562626c65736f72742d6564697465642d636f6c6f722e7376672f32323070782d427562626c65736f72742d6564697465642d636f6c6f722e7376672e706e67)

From [Wikipedia](https://en.wikipedia.org/wiki/Bubble_sort): Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

__Properties__
* Worst case performance O(n^2)
* Best case performance O(n)
* Average case performance O(n^2)

###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/bubble-sort)



### Insertion
![alt text](https://camo.githubusercontent.com/a7657e625281b63ca552a40c099c9331ce79f6a1/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f372f37652f496e73657274696f6e736f72742d6564697465642e706e67)

From [Wikipedia](https://en.wikipedia.org/wiki/Insertion_sort): Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

__Properties__
* Worst case performance O(n^2)
* Best case performance O(n)
* Average case performance O(n^2)

###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/insertion-sort)


### Merge
![alt text](https://camo.githubusercontent.com/64ba2bcbd5c11779657e40a1d03d0ea691f6fa57/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f632f63632f4d657267652d736f72742d6578616d706c652d33303070782e676966)

From [Wikipedia](https://en.wikipedia.org/wiki/Merge_sort): In computer science, merge sort (also commonly spelled mergesort) is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. Mergesort is a divide and conquer algorithm that was invented by John von Neumann in 1945.

__Properties__
* Worst case performance O(n log n)
* Best case performance O(n)
* Average case performance O(n)


###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/merge-sort)

### Quick
![alt text](https://camo.githubusercontent.com/2499d89bbb30337a5d2d7770cc034b4b71fbfdc6/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f362f36612f536f7274696e675f717569636b736f72745f616e696d2e676966)

From [Wikipedia](https://en.wikipedia.org/wiki/Quicksort): Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order.

__Properties__
* Worst case performance O(n^2)
* Best case performance O(n log n) or O(n) with three-way partition
* Average case performance O(n log n)

###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/quick-sort)

### Selection
![alt text](https://camo.githubusercontent.com/3174db3ca6ed6da3159b4bbc18f73359f0ab33ae/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f622f62302f53656c656374696f6e5f736f72745f616e696d6174696f6e2e6769662f32353070782d53656c656374696f6e5f736f72745f616e696d6174696f6e2e676966)

From [Wikipedia](https://en.wikipedia.org/wiki/Selection_sort): The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

__Properties__
* Worst case performance O(n^2)
* Best case performance O(n^2)
* Average case performance O(n^2)

###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/selection-sort)

### Shell
![alt text](https://camo.githubusercontent.com/e80043bbd0ce86517a91198be315740504c6980e/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f642f64382f536f7274696e675f7368656c6c736f72745f616e696d2e676966)

From [Wikipedia](https://en.wikipedia.org/wiki/Shellsort): Shellsort is a generalization of insertion sort that allows the exchange of items that are far apart. The idea is to arrange the list of elements so that, starting anywherem considereing every nth element gives a sorted list. Such a list is said to be h-sorted. Equivanelty, it can be thought of as h intterleaved lists, each individually sorted.

__Properties__
* Worst case performance O(nlog2 2n)
* Best case performance O(n log n)
* Average case performance depends on gap sequence

###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/shell-sort)

### Time-Compexity Graphs

Comparing the complexity of sorting algorithms (Bubble Sort, Insertion Sort, Selection Sort)

[Complexity Graphs](https://github.com/prateekiiest/Python/blob/master/sorts/sortinggraphs.png)