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

selection_sort.py: Add SelectionSort Algo #447

wants to merge 8 commits into from

Conversation

de-sh
Copy link

@de-sh de-sh commented Oct 25, 2018

This adds SelectionSort Algorithm, which sorts
the element in O(n^2) time complexity. This PR
has the Python implementation of this algo.

Fixes #446

By submitting this pull request I confirm I've read and complied with the
below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the commit guidelines for this project.
  • My code follows the standard code structure.
  • This pull request has a descriptive title. For example, {Tag}: Add {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
  • This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met.
  • I have mentioned the issue number correctly (with hyperlink) in this pull request description.

de-sh and others added 2 commits October 25, 2018 16:10
Made changes including denoting completion of selection sort implementation in Python as well as standardization of Markdown
@sangamcse

This comment has been minimized.

@sangamcse
Copy link
Member

Comment on cc39a18, file selection_sort/python/selection_sort.py, line 8.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp8sjn3jnu/selection_sort/python/selection_sort.py
+++ b/tmp/tmp8sjn3jnu/selection_sort/python/selection_sort.py
@@ -6,6 +6,7 @@
             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]

@sangamcse
Copy link
Member

Comment on cc39a18, file selection_sort/python/selection_sort.py, line 4.

E703 statement ends with a semicolon

Origin: PycodestyleBear (E703), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on cc39a18, file selection_sort/python/selection_sort.py, line 11.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on 93edc39, file selection_sort/python/selection_sort.py, line 4.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpgvi3mzjv/selection_sort/python/selection_sort.py
+++ b/tmp/tmpgvi3mzjv/selection_sort/python/selection_sort.py
@@ -1,7 +1,7 @@
 # Function to do selection sort of given array(Arr)
 def selection_sort(Arr):
     for i in range(len(Arr)):
-        low = i;
+        low = i
         for j in range(i+1, len(Arr)):
             if Arr[j] < Arr[low]:
                 low = j

@sangamcse
Copy link
Member

Comment on 93edc39, file selection_sort/python/selection_sort.py, line 8.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpgvi3mzjv/selection_sort/python/selection_sort.py
+++ b/tmp/tmpgvi3mzjv/selection_sort/python/selection_sort.py
@@ -6,6 +6,7 @@
             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]

@sangamcse
Copy link
Member

Comment on 93edc39, file selection_sort/python/selection_sort.py, line 4.

E703 statement ends with a semicolon

Origin: PycodestyleBear (E703), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on 93edc39, file selection_sort/python/selection_sort.py, line 11.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on f00d9de, file selection_sort/python/selection_sort.py, line 4.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpghornuhk/selection_sort/python/selection_sort.py
+++ b/tmp/tmpghornuhk/selection_sort/python/selection_sort.py
@@ -1,7 +1,7 @@
 # Function to do selection sort of given array(Arr)
 def selection_sort(Arr):
     for i in range(len(Arr)):
-        low = i;
+        low = i
         for j in range(i+1, len(Arr)):
             if Arr[j] < Arr[low]:
                 low = j

@sangamcse
Copy link
Member

Comment on f00d9de, file selection_sort/python/selection_sort.py, line 8.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpghornuhk/selection_sort/python/selection_sort.py
+++ b/tmp/tmpghornuhk/selection_sort/python/selection_sort.py
@@ -6,6 +6,7 @@
             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]

@sangamcse
Copy link
Member

Comment on f00d9de, file selection_sort/python/selection_sort.py, line 4.

E703 statement ends with a semicolon

Origin: PycodestyleBear (E703), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on f00d9de, file selection_sort/python/selection_sort.py, line 11.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on 1fbb1f5, file selection_sort/python/selection_sort.py, line 4.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp3lch9w2z/selection_sort/python/selection_sort.py
+++ b/tmp/tmp3lch9w2z/selection_sort/python/selection_sort.py
@@ -1,7 +1,7 @@
 # Function to do selection sort of given array(Arr)
 def selection_sort(Arr):
     for i in range(len(Arr)):
-        low = i;
+        low = i
         for j in range(i+1, len(Arr)):
             if Arr[j] < Arr[low]:
                 low = j

@sangamcse
Copy link
Member

Comment on 1fbb1f5, file selection_sort/python/selection_sort.py, line 8.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp3lch9w2z/selection_sort/python/selection_sort.py
+++ b/tmp/tmp3lch9w2z/selection_sort/python/selection_sort.py
@@ -6,6 +6,7 @@
             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]

@sangamcse
Copy link
Member

Comment on 1fbb1f5, file selection_sort/python/selection_sort.py, line 4.

E703 statement ends with a semicolon

Origin: PycodestyleBear (E703), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on 1fbb1f5, file selection_sort/python/selection_sort.py, line 11.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

@sangamcse sangamcse added process/wip Work in Progress and removed process/pending_review labels Oct 25, 2018
Copy link
Member

@sangamcse sangamcse left a comment

Choose a reason for hiding this comment

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

Write good commit message which is given in the contributing guidelines

README.md Outdated Show resolved Hide resolved
selection_sort/python/selection_sort.py Outdated Show resolved Hide resolved
selection_sort/python/selection_sort.py Outdated Show resolved Hide resolved
Copy link
Member

@123vivekr 123vivekr left a comment

Choose a reason for hiding this comment

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

  1. Please fix your commit message. Do take a look at commit guidelines.
  2. Do squash your commits (Try rebasing ;))

@de-sh de-sh closed this Oct 26, 2018
@de-sh de-sh reopened this Oct 26, 2018
Copy link
Author

@de-sh de-sh left a comment

Choose a reason for hiding this comment

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

I believe all these changes are valid and agree to the application of the same to my code. I am still not an expert at GitHub and so I've made all changes as a separate branch for which I am ready to send a PR

Implementing best practices in writing markdown files I have complied with specification set by [markdownlint](https://github.com/DavidAnson/markdownlint/blob/v0.11.0/doc/Rules.md)
@sangamcse sangamcse added process/pending_review and removed process/wip Work in Progress labels Oct 26, 2018
@sangamcse
Copy link
Member

Comment on 98443df, file selection_sort/python/selection_sort.py, line 4.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp52dhoqv4/selection_sort/python/selection_sort.py
+++ b/tmp/tmp52dhoqv4/selection_sort/python/selection_sort.py
@@ -1,7 +1,7 @@
 # Function to do selection sort of given array(Arr)
 def selection_sort(Arr):
     for i in range(len(Arr)):
-        low = i;
+        low = i
         for j in range(i+1, len(Arr)):
             if Arr[j] < Arr[low]:
                 low = j

@sangamcse
Copy link
Member

Comment on 98443df, file selection_sort/python/selection_sort.py, line 8.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp52dhoqv4/selection_sort/python/selection_sort.py
+++ b/tmp/tmp52dhoqv4/selection_sort/python/selection_sort.py
@@ -6,6 +6,7 @@
             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]

@sangamcse
Copy link
Member

Comment on 98443df, file selection_sort/python/selection_sort.py, line 4.

E703 statement ends with a semicolon

Origin: PycodestyleBear (E703), Section: all.autopep8.

@sangamcse
Copy link
Member

Comment on 98443df, file selection_sort/python/selection_sort.py, line 11.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

Compliance to PEP8 standards was maintained in the above correction to code.
@de-sh de-sh changed the title Add selection sort.py selection_sort.py: Add SelectionSort Algo Oct 26, 2018
Copy link
Member

@sangamcse sangamcse left a comment

Choose a reason for hiding this comment

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

Fix the Travis checks as your PR is breaking that. See the comments on your code above; you need to fix those.

| Python | ```python [filename.py]``` |
| C | ```gcc [filename.c]```<br>```./a.out # unix```<br>```a.exe # windows```|
| CPP | ```g++ [filename.cpp]```<br>```./a.out # unix```<br>```a.exe # windows```|
| Java | ```javac [filename.java]```<br>```java [filename]``` |
Copy link
Member

Choose a reason for hiding this comment

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

These changes needs to be ignored as it is being used as HTML tags and then being used for the website https://nitskmos.github.io/Algorithms/.

Copy link
Author

Choose a reason for hiding this comment

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

capture
Is this what you want it to look like?

@@ -39,17 +37,15 @@ This repository contains examples of various algorithms written on different pro
| [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | [:octocat:](binary_search_tree/Cpp) | | |
| [Fenwick Tree](https://en.wikipedia.org/wiki/Fenwick_tree) | | | [:octocat:](fenwick_tree/java) | [:octocat:](fenwick_tree/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

@@ -24,9 +23,8 @@ This repository contains examples of various algorithms written on different pro
| [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | [:octocat:](shell_sort/C) | | | [:octocat:](shell_sort/Python) |
| [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) | | | |

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

| [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) | | | |

| [Knapsack Problem](https://en.wikipedia.org/wiki/Knapsack_problem) | | | | [:octocat:](knapsack_problem/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

@@ -6,7 +6,6 @@
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/NITSkmOS/Algorithms/blob/master/LICENSE)
[![OpenHub](https://www.openhub.net/p/NITSkmOS-algo/widgets/project_thin_badge?format=gif)](https://www.openhub.net/p/NITSkmOS-algo?ref=Thin+badge)


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

@sangamcse sangamcse added process/wip Work in Progress and removed process/pending_review labels Oct 26, 2018
@sangamcse sangamcse closed this Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Algo] Selection Sort [Python]
3 participants