Merge Sort
Merge Sort
v=mB5HXBb_HY8
Merge sort is defined as a sorting algorithm that works by dividing an array
into smaller subarrays, sorting each subarray, and then merging the sorted
subarrays back together to form the final sorted array.
In simple terms, we can say that the process of merge sort is to divide the
array into two halves, sort each half, and then merge the sorted halves back
together. This process is repeated until the entire array is sorted.
Merge sort is a sorting algorithm that works by dividing the input array into two
halves, sorting each half recursively, and then merging the sorted halves.
● Divide: The algorithm starts by dividing the array into two halves, roughly
equal in size. If the array has only one element or is empty, it is already
considered sorted.
● Conquer: The algorithm recursively sorts the two halves of the array. This
process continues until each subarray contains only one element, which is
considered sorted.
● Merge: The sorted subarrays are then merged back together to create a single
sorted array. This is done by comparing the elements of the two subarrays
and selecting the smaller (or larger) element to place in the final sorted array.
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[mid:]
merged += left[left_index:]
merged += right[right_index:]
return merged
if mid_val == target:
return mid_index
elif mid_val > target:
return binary_search(sorted_list, left_pointer, mid_index, target)
else:
return binary_search(sorted_list, mid_index + 1, right_pointer, target)
MATRIX MULTIPLICATION
TIME COMPLEXCITY
For a 2D array, the space complexity is O(n*n).
QUICK SORT
https://www.youtube.com/watch?v=7h1s2SojIRw
3n , n factorial, n^2, log(n), root n, n log(n), 2^n, n^3, n^2 log(n) sort
them in increasing order
log(n) (logarithmic)
root n (√n) (square root)
n (linear)
n log(n) (linearithmic)
n^2 log(n) (n squared logarithmic)
n^2 (quadratic)
n^3 (cubic)
2^n (exponential)
n! (factorial)