Write a program using mergesort technique.



Write a program using mergesort technique...

Answer / Saurabh Agarwal

Here's an implementation of Merge Sort in Python:n```pythonndef merge_sort(arr):n if len(arr) <= 1:n return arrn mid = len(arr) // 2n left = merge_sort(arr[:mid])n right = merge_sort(arr[mid:])n return merge(left, right)ndef merge(left, right):n result = []n i, j = 0, 0n while i < len(left) and j < len(right):n if left[i] <= right[j]:n result.append(left[i])n i += 1n else:n result.append(right[j])n j += 1n result += left[i:]n result += right[j:]n return result

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What is the Difference between sax and dom parser?

1 Answers  


List some applications of tree-data structure?

1 Answers  


Which is the fastest sorting?

1 Answers  


What is ascii sort order?

1 Answers  


What is data structure explain in detail?

1 Answers  


What is hashing in cyber security?

1 Answers  


What are the advantages of bubble sort?

1 Answers  


Can you distinguish between ArrayList and Array?

1 Answers   QuestPond,


How will you free the memory that is allocated at run time?

1 Answers  


What is meant by strongly connected in a graph?

1 Answers  


How many parts are there in a declaration statement using data structures?

1 Answers  


What is the difference between hashset and hashmap?

1 Answers  


Categories