filmov
tv
Merge Sort Pseudocode | Merge Sort with example
Показать описание
👉Links for DAA Notes:
🧑🎓Contributed by: Junaid Gazi
🧑🎓Contributed by: Mannu Garg
Merge sort is one of the most efficient sorting techniques and it’s based on the “divide and conquer” paradigm.
In merge sort, the problem is divided into two subproblems in every iteration.
Hence efficiency is increased drastically.
Declare left and right var which will mark the extreme indices of the array
Left will be assigned to 0 and right will be assigned to n-1
Find mid = (left +right)/2
Call merge Sort on (left, mid) and (mid+1,rear)
Above will continue till left is less than right
Then we will call merge on the 2 subproblems.
Time Complexity of Merge sort
In the worst case, in every iteration, we are dividing the problem into further 2 subproblems. Hence this will perform log n operations and this has to be done for n iteration resulting in n log n operations total.
In the best case that is sorted array, we can do some modification by using a flag to check whether the lament is already sorted or not
Best Time Complexity: O(nlogn)
Average Time Complexity: O(nlogn)
Worst Time Complexity: O(nlogn)
►Design and Analysis of algorithms (DAA) (Complete Playlist):
Other subject-wise playlist Links:
--------------------------------------------------------------------------------------------------------------------------------------
► Operating System :
►Database Management System:
► Theory of Computation
►Artificial Intelligence:
►Computer Networks (Complete Playlist):
►Computer Architecture (Complete Playlist):
►Structured Query Language (SQL):
►Discrete Mathematics:
►Compiler Design:
►Number System:
►Cloud Computing & BIG Data:
►Software Engineering:
►Data Structure:
►Graph Theory:
►Programming in C:
►Digital Logic:
---------------------------------------------------------------------------------------------------------------------------------------
Our social media Links:
--------------------------------------------------------------------------------------------------------------------------------------
►For Any Query, Suggestion or notes contribution:
Комментарии