DEV Community

Cover image for Merge Sort Quick Reference

Merge Sort Quick Reference

edA‑qa mort‑ora‑y on October 17, 2019

Merge sort is a useful algorithm for sorting a list of items. It's an efficient and predictable algorithm. Inevitably it'll come up during your int...
Collapse
 
theodesp profile image
Theofanis Despoudis

The merge part is useful in cases where you want to merge two sorted arrays, or find the kth element of two sorted arrays.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Yes, the merge part is useful as an independent algorithm. Knowing how these algorithms work are thus useful for constructing new algorithms.

Collapse
 
ovieokeh profile image
Ovie Okeh

I found the most difficult part of implementing it was actually the merge function. After that, it's almost ridiculously easy.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y • Edited

I admit my pseudo-code ignores some of the details, making it look easier than it is.

My front function has to deal with the end of a list and provider a proper comparison when no item is available. It can be done this way.