Open to hybrid algorithms?

5
closed
skewballfox
skewballfox
Posted 1 year ago

Open to hybrid algorithms? #277

this is something we are covering in my algorithms course. it's possible to create algorithms that switch between different strategies based off the size of the input. for example this hybrid of selection sort and quick sort (using Hoare's partition scheme consistently outperforms a regular quick sort by a constant factor:

`
pub fn hybrid_quick_sort<T>(arr: &mut [T])
where
    T: Ord + Clone,
{
    let len = arr.len();
    if len > 17 {
        _hybrid_quick(arr, 0, len - 1)
    } else {
        selection_sort(arr)
    }
}

fn _hybrid_quick<T>(arr: &mut [T], lo: usize, hi: usize)
where
    T: Ord + Clone,
{
    if lo < hi {
        if hi - lo > 17 {
            let p = partition(arr, lo, hi);
            _hybrid_quick(arr, lo, p);
            _hybrid_quick(arr, p + 1, hi);
        } else {
            selection_sort(&mut arr[lo..hi + 1]) //from first element to include to first element to exclude
        }
    }
}

siriak
siriak
Created 1 year ago

We're open for such algorithms for sure, just please reuse existing quick and selection sorts instead of duplicating them!

github-actions[bot]
github-actions[bot]
Created 11 months ago

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

skewballfox
skewballfox
Created 11 months ago

with the quick sort, I did the asymptotic analysis with Hoare's partition scheme, so I don't know if Lomuto's would have the same pivot point (not even sure if the pivot point would vary based on hardware factors)

github-actions[bot]
github-actions[bot]
Created 10 months ago

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot]
github-actions[bot]
Created 10 months ago

Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our Gitter channel. Thank you for your contributions!