Comments (12)
I think we could rename merge_sort_fastest.py to something else as it is not fast at all neither resembles merge sort. What do you think?
from python.
Yes! @tom5610 you are right. The usage of inbuilt functions is not right here to make program faster.
By the way the Python/sorts/merge_sort.py is more faster than this.
from python.
It's also not merge sort. It's some weird two-pronged version of selection sort.
from python.
# Merges two subarrays of arr[].
# First subarray is arr[l..m]
# Second subarray is arr[m+1..r]
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m
# create temp arrays
L = [0] * (n1)
R = [0] * (n2)
# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]
for j in range(0 , n2):
R[j] = arr[m + 1 + j]
# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second subarray
k = l # Initial index of merged subarray
while i < n1 and j < n2 :
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1
# Copy the remaining elements of L[], if there
# are any
while i < n1:
arr[k] = L[i]
i += 1
k += 1
# Copy the remaining elements of R[], if there
# are any
while j < n2:
arr[k] = R[j]
j += 1
k += 1
# l is for left index and r is right index of the
# sub-array of arr to be sorted
def mergeSort(arr,l,r):
if l < r:
# Same as (l+r)/2, but avoids overflow for
# large l and h
m = (l+(r-1))/2
# Sort first and second halves
mergeSort(arr, l, m)
mergeSort(arr, m+1, r)
merge(arr, l, m, r)
PLEASE CHECK THIS. i HOPE IT HELPS
from python.
@brunohadlich ,
I think we should have only one merge_sort file not merge_sort.py and merge_sort_fastest.py. I will inspect these two files and get back to you. What do you think?
from python.
I agree, it's been a long time since my last contribution to this project as I'm busy with other tasks. Feel free to discuss and apply the best solution.
from python.
It's ok, I just started on this project. I will spend more time on it and keep it posted here.
from python.
Hi @brunohadlich
I looked at these two files:
- merge_sort.py
- merge_sort_fastest.py
The one that I recommend to keep is merge_sort.py, the other one is NOT merge sort algorithm. It's something else that works fine but for the sake of algorithm education is misleading.
Let me know if there is any more work to be done on this issue, otherwise after deleting the file 'merge_sort_fastest.py' we can close this issue.
Note: @cclauss please look at this message.
from python.
Just raise a PR for the same
from python.
Please open a PR that renames merge_sort_fastest.py to unknown_sort.py.
from python.
OK sure, thank you.
from python.
PR is created: #1612.
from python.
Related Issues (20)
- Build Test Broken
- Learning Python HOT 1
- @Git~CDT Open Repo~Nomine'
- Adding Gaussian Error Linear Unit to neural network activation functions HOT 1
- Misformatted/linked wiki entry in python sorting
- Global variable should not using in class method HOT 3
- Broken Computer Vision README url
- attributeerror:'artistlist' object has no attribute 'remove' HOT 1
- Improve our test coverage HOT 1
- Adding Financial algorithms in Python HOT 3
- Haversine distance may be using the wrong phi1 and phi2 angle
- data_structures/trie/radix_tree.py wont really end up in 'case 1' for insert HOT 1
- TensorFlow in FINALLY compatible with Python 3.12
- Migrate to numpy 2.0 HOT 3
- Engineering HOT 5
- Failure when running pre-commit and try to fix errors.
- Import Issue in Gaussian naive bayes example HOT 3
- mimetypes can't get demo.js type HOT 4
- Implementation of the Knapsack Problem Solver
- aa
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python.