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

selection_sort.py: Add SelectionSort Algo #447

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This repository contains examples of various algorithms written on different pro
| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | | | | [:octocat:](heap_sort/python) |
| [Maximum Subarray Problem](https://en.wikipedia.org/wiki/Maximum_subarray_problem) | | | | [:octocat:](/maximum_subarray/Python)|
| [Knapsack Problem](https://en.wikipedia.org/wiki/Knapsack_problem) | | | | [:octocat:](knapsack_problem/Python)|
| [Selecton Sort](https://en.wikipedia.org/wiki/Selection_sort) | [:octocat:](selection_sort/C) | | | |
| [Selecton Sort](https://en.wikipedia.org/wiki/Selection_sort) | [:octocat:](selection_sort/C) | | | [:octocat:](selection_sort/Python) |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant change


## Implemented Data Structures
Expand All @@ -44,11 +44,11 @@ This repository contains examples of various algorithms written on different pro

| Language | Steps |
| --------------- | ---------------------------------------------------------------------- |
| JavaScript | <pre>node [filename.js]</pre> |
| Python | <pre>python [filename.py]</pre> |
| C | <pre>gcc [filename.c]<br>./a.out # unix<br>a.exe # windows</pre> |
| CPP | <pre>g++ [filename.cpp]<br>./a.out # unix<br>a.exe # windows</pre> |
| Java | <pre>javac [filename.java]<br>java [filename]</pre> |
| JavaScript | ```node [filename.js]``` |
de-sh marked this conversation as resolved.
Show resolved Hide resolved
| Python | ```python [filename.py]``` |
| C | ```gcc [filename.c]; ./a.out # in unix; a.exe # in windows``` |
| CPP | ```g++ [filename.cpp]; ./a.out # in unix; a.exe # in windows``` |
| Java | ```javac [filename.java]; java [filename]``` |


## Contributing
Expand Down
20 changes: 20 additions & 0 deletions selection_sort/python/selection_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Function to do selection sort of given array(Arr)
def selection_sort(Arr):
de-sh marked this conversation as resolved.
Show resolved Hide resolved
for i in range(len(Arr)):
low = i;
for j in range(i+1, len(Arr)):
if Arr[j] < Arr[low]:
low = j
Arr[i], Arr[low] = Arr[low], Arr[i]

# Given array
Arr = [4, 3, 42, 82, 5, 2, 33]
de-sh marked this conversation as resolved.
Show resolved Hide resolved

print("The unsorted array is:")
print(Arr)

# Calling selection sort algorithm
selection_sort(Arr)

print("The sorted array is:")
print(Arr)