Metadata-Version: 2.1
Name: gopy
Version: 0.7.2
Summary: Python Data Structures and Algorithms
Home-page: https://github.com/strongSoda/gopy
Author: Imran Khan
Author-email: strongsoda2@gmail.com
License: MIT
Download-URL: https://github.com/strongSoda/gopy/archive/v0.7.0.tar.gz
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Description-Content-Type: text/markdown
Requires-Dist: snakeviz (>=2.0.1)
Requires-Dist: numpy (>=1.17.0)

## Python Data Structures and Algorithms

- [Installation](#install)
- [Usage](#usage)
- [For Education](#for-education)
- [For Analysis](#for-analysis)
- [List of Implementations](#list-of-implementations)
- [Contribute](#contribute)
- [Support](#support)

### Install

```bash
pip3 install gopy
```

or

```bash
pip install gopy
```

### Usage

You can test this by making a python file `test.py`

**Example:** Bubble Sort

```python
from gopy.sorting import bubble
print(bubble.sort([5,4,3,2,1]))
```

Output: 

```bash
[1,2,3,4,5]
```

**Example:** Linear Search

```python
from gopy.search import lsearch
print(lsearch.search(3,[5,4,3,2,1]))
```

Output: 

```bash
2
```

**Example:** Binary Search

```python
from gopy.search import bsearch
print(bsearch.search(30,[5,4,3,2,1]))
```

Output: 

```bash
Not Found
```

### For Education

This library can be used for production software as well as for educational purposes.

**Example:** Learn Quick Sort

```python
import gopy.sorting.quick as quick
print(quick.__doc__)
```

Output: 

```markdown
Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data 
into smaller arrays. A large array is partitioned into two arrays one of which holds values 
smaller than the specified value, say pivot, based on which the partition is made and another 
array holds values greater than the pivot value.

Quick sort partitions an array and then calls itself recursively twice to sort the two resulting 
subarrays. This algorithm is quite efficient for large-sized data sets as its average and worst 
case complexity are of Ο(n2), where n is the number of items.

### Quick Sort Pivot Algorithm

Based on our understanding of partitioning in quick sort, we will now try to write an algorithm for 
it, which is as follows.

Step 1 − Choose the highest index value has pivot
Step 2 − Take two variables to point left and right of the list excluding pivot
Step 3 − left points to the low index
Step 4 − right points to the high
Step 5 − while value at left is less than pivot move right
Step 6 − while value at right is greater than pivot move left
Step 7 − if both step 5 and step 6 does not match swap left and right
Step 8 − if left ≥ right, the point where they met is new pivot

### Quick Sort Pivot Pseudocode

The pseudocode for the above algorithm can be derived as −

```python
function partitionFunc(left, right, pivot)
   leftPointer = left
   rightPointer = right - 1

   while True do
      while A[++leftPointer] < pivot do
         //do-nothing            
      end while

      while rightPointer > 0 && A[--rightPointer] > pivot do
         //do-nothing         
      end while

      if leftPointer >= rightPointer
         break
      else                
         swap leftPointer,rightPointer
      end if

   end while 

   swap leftPointer,right
   return leftPointer

end function
```

### Quick Sort Algorithm

Using pivot algorithm recursively, we end up with smaller possible partitions. Each partition is 
then processed for quick sort. We define recursive algorithm for quicksort as follows −

Step 1 − Make the right-most index value pivot
Step 2 − partition the array using pivot value
Step 3 − quicksort left partition recursively
Step 4 − quicksort right partition recursively

### Quick Sort Pseudocode

To get more into it, let see the pseudocode for quick sort algorithm −

```python
procedure quickSort(left, right)

   if right-left <= 0
      return
   else     
      pivot = A[right]
      partition = partitionFunc(left, right, pivot)
      quickSort(left,partition-1)
      quickSort(partition+1,right)    
   end if		

end procedure
```
```

### For Analysis

You can see profiling of all algorithms


**Example:** Analyse ternary search

```python
from gopy.search.ternary import *
print(profile())
```

Output: 

```bash
7 function calls (6 primitive calls) in 0.000 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
      2/1    0.000    0.000    0.000    0.000 ternary.py:14(ternary_search)
        1    0.000    0.000    0.000    0.000 ternary.py:31(search)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 {built-in method builtins.len}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
```

*Check input data for profiling*

```python
from gopy.search.ternary import *
print(profile.__doc__)
```

Output: 

```bash
profiling input 
    search(10,[0,1,2,3,4,5,6,7,8,9,10])
```

### List of implementations

- [sorting](/gopy/sorting/)
    - [bubble](/gopy/sorting/bubble.py/)
- [searching](/gopy/search/)
    - [linear search](/gopy/search/lsearch.py/)
    - [binary search](/gopy/search/bsearch.py/)


### Contributing

Any form of contribution is welcome :smile:

### Support

If this project helps you, consider supporting


<a href="https://www.patreon.com/bePatron?u=17066721">
  <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
</a>

#### OR 

[Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=P3BP3APA22KEU&source=url)


