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

Fixes wiki and doctest issues #11227

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions Python.wiki/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Python Algorithms
Copy link
Author

Choose a reason for hiding this comment

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

Yes, I suppose that is true. In fixing the wiki issue, the doctests issue was highlighted. Both are addressed here

- All the algorithms are implemented in **Python** for **education purpose** only.<br>
- These are just for **demonstration** purpose.<br>
- There are many implementations of different algorithms in the Python standard library that are much better for performance reasons.<br>

<a href="https://github.com/TheAlgorithms/Python/blob/master/DIRECTORY.md"><b>List of Algorithms</b></a>
93 changes: 93 additions & 0 deletions Python.wiki/Sorting-Algorithms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<h1>index</h1>

<br/>

<ol>
<li><a href="">Selection Sort</a></li>
Copy link
Member

@cclauss cclauss Jan 2, 2024

Choose a reason for hiding this comment

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

I am a bit uncomfortable with an unsorted list of sorting algorithms. Are these sorted alphabetically, sorted for speed, or other? DIRECTORY.md is machine-generated to keep algorithms up-to-date and sorted alphabetically.

Copy link
Author

Choose a reason for hiding this comment

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

This is a like for like drop-in except for the corrected markdown. The existing pages algorithms were already sorted like this. Ultimately, I was just trying to fix the issue highlighted in #11227 which also has the unsorted list. The wiki can be edited in the GUI by a repo admin in <30seconds

<li><a href="">Bubble Sort</a></li>
<li><a href="">Recursive Bubble Sort</a></li>
<li><a href="">Insertion Sort</a></li>
<li><a href="">Recursive Insertion Sort</a></li>
<li><a href="">Merge Sort</a></li>
<li><a href="">Iterative Merge Sort</a></li>
<li><a href="">Quick Sort</a></li>
<li><a href="">Iterative Quick Sort</a></li>
<li><a href="">Heap Sort</a></li>
<li><a href="">Counting Sort</a></li>
<li><a href="">Radix Sort</a></li>
<li><a href="">Bucket Sort</a></li>
<li><a href="">ShellSort</a></li>
<li><a href="">TimSort</a></li>
<li><a href="">Comb Sort</a></li>
<li><a href="">Pigeonhole Sort</a></li>
<li><a href="">Cycle Sort</a></li>
<li><a href="">Cocktail Sort</a></li>
<li><a href="">Strand Sort</a></li>
<li><a href="">Bitonic Sort</a></li>
<li><a href="">Pancake sorting</a></li>
<li><a href="">Binary Insertion Sort</a></li>
<li><a href="">BogoSort or Permutation Sort</a></li>
<li><a href="">Gnome Sort</a></li>
<li><a href="">Sleep Sort – The King of Laziness / Sorting while Sleeping</a></li>
Copy link
Member

Choose a reason for hiding this comment

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

I HATE this algorithm because it wastes time and compute power.

<li><a href="">Structure Sorting (By Multiple Rules) </a></li>
<li><a href="">Stooge Sort</a></li>
<li><a href="">Tag Sort (To get both sorted and original)</a></li>
<li><a href="">Tree Sort</a></li>
<li><a href="">Cartesian Tree Sorting</a></li>
<li><a href="">Odd-Even Sort / Brick Sort</a></li>
<li><a href="">QuickSort on Singly Linked List</a></li>
<li><a href="">QuickSort on Doubly Linked List</a></li>
<li><a href="">3-Way QuickSort (Dutch National Flag)</a></li>
<li><a href="">Merge Sort for Linked Lists</a></li>
<li><a href="">Merge Sort for Doubly Linked List</a></li>
<li><a href="">3-way Merge Sort</a></li>
</ol>

***

<h2>Selection sort</h2>

**Selection sort**, algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
<ol>
<li> The subarray which is already sorted.</li>
<li> Remaining subarray which is unsorted.</li>

In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.

#### Properties:
- Worst-case performance O(n^2)
- Best-case performance O(n)
- Average case performance O(n^2)

**read more at: [Wikipedia](https://en.wikipedia.org/wiki/Selection_sort)**<br>
**code: [Selection sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py)**

***


<h2>Bubble sort</h2>

**Bubble sort**, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. It can be practical if the input is usually in sorted order but may occasionally have some out-of-order elements nearly in position.

#### Properties:
- Worst-case performance O(n^2)
- Best-case performance O(n)
- Average case performance O(n^2)

**read more at: [Wikipedia](https://en.wikipedia.org/wiki/Bubble_sort)**<br>
**code: [Bubble sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py)**

***


<h2>Insertion sort</h2>

**Insertion sort** is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

#### Properties:
- Worst-case performance O(n^2)
- Best-case performance O(n)
- Average case performance O(n^2)

**read more at: [Wikipedia](https://en.wikipedia.org/wiki/Insertion_sort)**<br>
**code: [Insertion sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/insertion_sort.py)**
1 change: 1 addition & 0 deletions Python.wiki/_Footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p align="center"><a href="https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md">Contribution</a> | <a href="https://gitter.im/TheAlgorithms">join at Gitter!</a></p>
4 changes: 2 additions & 2 deletions web_programming/get_top_billionaires.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def calculate_age(unix_date: float) -> str:
>>> from datetime import datetime, UTC
>>> years_since_create = datetime.now(tz=UTC).year - 2022
>>> int(calculate_age(-657244800000)) - years_since_create
73
72
MarlieChiller marked this conversation as resolved.
Show resolved Hide resolved
>>> int(calculate_age(46915200000)) - years_since_create
51
50
"""
# Convert date from milliseconds to seconds
unix_date /= 1000
Expand Down