Skip to content

Commit ea52ca8

Browse files
authored
Create normaldistribution_quicksort_README.md
1 parent f707513 commit ea52ca8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Algorithm implementing QuickSort Algorithm where the pivot element is chosen randomly between first and last elements of the array and the array elements are taken from a Standard Normal Distribution.
2+
3+
This is different from the ordinary quicksort in the sense, that it applies more to real life problems , where elements usually follow a normal distribution. Also the pivot is randomized to make it a more generic one.
4+
5+
6+
#Array Elements
7+
8+
The array elements are taken from a Standard Normal Distribution , having mean = 0 and standard deviation 1.
9+
10+
The code
11+
12+
```python
13+
14+
>>> import numpy as np
15+
>>> from tempfile import TemporaryFile
16+
>>> outfile = TemporaryFile()
17+
>>> p = 100 # 100 elements are to be sorted
18+
>>> mu, sigma = 0, 1 # mean and standard deviation
19+
>>> X = np.random.normal(mu, sigma, p)
20+
>>> np.save(outfile, X)
21+
>>> print('The array is')
22+
>>> print(X)
23+
24+
```
25+
26+
---------------------
27+
28+
#Plotting the function for Checking 'The Number of Swappings' taking place between Normal Distribution QuickSort and Ordinary QuickSort
29+
30+
```python
31+
>>>import matplotlib.pyplot as plt
32+
33+
# Normal Disrtibution is red
34+
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,6,15,43,136,340,800,2156,6821,16325],linewidth=2, color='r')
35+
#Simple QuickSort is green
36+
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,4,16,67,122,362,949,2131,5086,12866],linewidth=2, color='g')
37+
>>> plt.show()
38+
```

0 commit comments

Comments
 (0)