Module: sorting()
Method : bubble_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it. Also this method prints out the array after each iteration, so that one can visualize how bubble sort works.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the bubble sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,9,8,7,6]
ping = al.sorting()
ping.bubble_sort(arr)
Output:
[9, 10, 8, 7, 6]
[9, 8, 10, 7, 6]
[9, 8, 7, 10, 6]
[9, 8, 7, 6, 10]
[8, 9, 7, 6, 10]
[8, 7, 9, 6, 10]
[8, 7, 6, 9, 10]
[7, 8, 6, 9, 10]
[7, 6, 8, 9, 10]
[6, 7, 8, 9, 10]
Bubble Sort Runtime = 0.0009982585906982422 seconds
[6, 7, 8, 9, 10]
For getting the hint just pass hint=True in the function like - bubble_sort(arr,True).
Module: sorting()
Method : selection_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it. Also this method prints out the array after each iteration, so that one can visualize how selection sort works.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the selection sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,9,8,7,6,5,4]
ping = al.sorting()
ping.selection_sort(arr)
Output:
[4, 9, 8, 7, 6, 5, 10]
[4, 5, 8, 7, 6, 9, 10]
[4, 5, 6, 7, 8, 9, 10]
[4, 5, 6, 7, 8, 9, 10]
[4, 5, 6, 7, 8, 9, 10]
[4, 5, 6, 7, 8, 9, 10]
Selection Sort Runtime = 0.0 seconds
[4, 5, 6, 7, 8, 9, 10]
Module: sorting()
Method : bogo_sort(arr,asc=True,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it.
Parameters : arr is an one dimensional array as python list,
asc is passed True by default, which determines the ascending or descending order, when passed as False, it sorts in the descending order,
hint is passed False by default, by declaring hint=True
a detailed description of the selection sort algorithm can be found.
#for sorting in ascending order
from edualgo import algorithms as al
arr = [10,8,6,7,9,5,1,4]
ping = al.sorting()
ping.bogo_sort(arr,True)
#for sorting in descending order
ping.bogo_sort(arr,False)
Output:
#for ascending order
Bogo Sort Runtime = 0.8378016948699951 seconds
array([ 1, 4, 5, 6, 7, 8, 9, 10])
#for descending order
Bogo Sort Runtime = 0.8386266231536865 seconds
array([10, 9, 8, 7, 6, 5, 4, 1])
Module: sorting()
Method : insertion_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it. Also this method prints out the array after each iteration, so that one can visualize how insertion sort works.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the selection sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,8,6,7,9,5,1,4]
ping = al.sorting()
ping.insertion_sort(arr)
Output:
[8, 10, 6, 7, 9, 5, 1, 4]
[6, 8, 10, 7, 9, 5, 1, 4]
[6, 7, 8, 10, 9, 5, 1, 4]
[6, 7, 8, 9, 10, 5, 1, 4]
[5, 6, 7, 8, 9, 10, 1, 4]
[1, 5, 6, 7, 8, 9, 10, 4]
[1, 4, 5, 6, 7, 8, 9, 10]
Insertion Sort Runtime = 0.0 seconds
[1, 4, 5, 6, 7, 8, 9, 10]
Module: sorting()
Method : merge_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the merge sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,8,6,7,9,5,1,4]
ping = al.sorting()
ping.merge_sort(arr)
Output:
Merge Sort Runtime = 0.0 seconds
[1, 4, 5, 6, 7, 8, 9, 10]
Module: sorting()
Method : heap_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the merge sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,8,6,7,9,5,1,4]
ping = al.sorting()
ping.heap_sort(arr)
Output:
[1, 4, 5, 6, 7, 8, 9, 10]
Heap Sort Runtime = 0.0 seconds
Module: sorting()
Method : quick_sort(arr,hint=False)
Uses : As the name suggests, this methods sorts the array as well as shows the time taken in seconds for sorting it.
Parameters : arr is an one dimensional array as python list,
hint is passed False by default, by declaring hint=True
a detailed description of the quick sort algorithm can be found.
from edualgo import algorithms as al
arr = [10,8,6,7,9,5,1,4]
ping = al.sorting()
ping.quick_sort(arr)
Output:
[1, 4, 5, 6, 7, 8, 9, 10]
Quick Sort Runtime = 0.0 seconds
Do you want to contribute to our project ? We welcome every python lover to come forwards and have some fun with our source code. Steps to contibute:
Keep coding, keep loving python