DEV Community

Cover image for Sorting Algorithm Theory VS Implementation 🧐 ?

Sorting Algorithm Theory VS Implementation 🧐 ?

Peter Andrew on January 07, 2024

Why Sorting? I started learning Golang last week and to solidify my understanding of the syntax, I practiced using Leetcode. This led me...
Collapse
 
gowthamsagar310 profile image
GowthamSagar310 • Edited

so, the first thing here is the order of growth, bubble sort grows quadratically, where as merge sort has n*log(n). as n becomes large,
(taking limit), n^2 grows faster than n*log(n), but this is just an upperbound / asymptotic analysis, which is done after ignoring the lower order terms, constants and other external factors such as compiler optimizations, and hardware configs. intuitively it feels (atleast for me) that for smaller array sizes, the instrcutions needed for swapping elements are must faster than loading the recursive stack back and forth into memory.

Collapse
 
peterchu999 profile image
Peter Andrew

Yep, agree with ur thought 🙌.
Thanks for Commenting ❤️