Code Monkey home page Code Monkey logo

Comments (12)

brunohadlich avatar brunohadlich commented on May 22, 2024 1

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.

sumitkumar22299 avatar sumitkumar22299 commented on May 22, 2024

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.

crazymerlyn avatar crazymerlyn commented on May 22, 2024

It's also not merge sort. It's some weird two-pronged version of selection sort.

from python.

pandyamarut avatar pandyamarut commented on May 22, 2024
# 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.

bardia52 avatar bardia52 commented on May 22, 2024

@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.

brunohadlich avatar brunohadlich commented on May 22, 2024

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.

bardia52 avatar bardia52 commented on May 22, 2024

It's ok, I just started on this project. I will spend more time on it and keep it posted here.

from python.

bardia52 avatar bardia52 commented on May 22, 2024

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.

onlinejudge95 avatar onlinejudge95 commented on May 22, 2024

Just raise a PR for the same

from python.

cclauss avatar cclauss commented on May 22, 2024

Please open a PR that renames merge_sort_fastest.py to unknown_sort.py.

from python.

bardia52 avatar bardia52 commented on May 22, 2024

OK sure, thank you.

from python.

bardia52 avatar bardia52 commented on May 22, 2024

PR is created: #1612.

from python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.