Posts

Showing posts from January, 2023

2. Merge sort

 Merge sort Approach Divide      Divide the n-element sequence to be sorted  into two subsequences of n=2 elements each Conquer  Sort the two subsequences recursively using merge sort. Combine Merge the two sorted subsequences to produce the sorted answer. Merge MERGE(A,p,q,r) A - Array p,q and r - indices into array p <= q <= r A[ p .. q ] , A[ q .. r ] -->  A[ p .. r ] (venv) [velmuruganponnusamy@localhost merge-sort]$ cat merge-sort.py  def merge(A,p,q,r):     # pre-requisities in python     # array slicing and index and length function     L1 = A[ p:q ]     L2 = A[ q:r ]     print("Array - {0} ".format(A))     print( "*" * 80 )     # try without this step and identify why are we performing append stats     # depends on the ascending and descending, 999999999 needs to be changed     # if asc -> positive high value   ...