menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Merge sort
Learn Merge sort in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.
12 min read
•
Advanced
data-structures-algorithms-074.py
python
def merge_sort(a):
if len(a)<2:return a
m=len(a)//2;l=merge_sort(a[:m]);r=merge_sort(a[m:]);out=[]
while l and r:out.append((l if l[0]<=r[0] else r).pop(0))
return out+l+r
print(merge_sort([8,3,6,2,7]))
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content