Unit I Design And Analysis of Algorithms continued
Unit I Design And Analysis of Algorithms continued
Definition
Algorithm:
Max: a [i]
Min: a [i]
For i= 2 to n do
If a[i]> max then
max = a[i]
if a[i] < min then
min: a[i]
return (max, min)
Merge Sort
● Merge sort is a sorting algorithm that follows the divide and conquer
approach.
● It works by recursively dividing the input array into smaller sub arrays and
sorting those sub arrays then merging them back together to obtain the sorted
array.
How merge sort works:
● Divide: Divide the list or array recursively into two halves until it can no more
be divided.
● Conquer: Each sub array is sorted individually using the merge sort
algorithm.
● Merge: The sorted sub arrays are merged back together in sorted order. The
process continues until all elements from both sub arrays have been merged.
Recurrence Relation of Merge Sort:
Convex Hull
Algorithm Steps:
1) Find the point with minimum x-coordinate lets say, min_x and similarly the
point with maximum x-coordinate, max_x.
2) Make a line joining these two points, say L. This line will divide the whole set
into two parts. Take both the parts one by one and proceed further.
3) For a part, find the point P with maximum distance from the line L. P forms a
triangle with the points min_x, max_x. It is clear that the points residing inside
this triangle can never be the part of convex hull.
4) The above step divides the problem into two sub-problems (solved
recursively). Now the line joining the points P and min_x and the line joining the
points P and max_x are new lines and the points residing outside the triangle is
the set of points. Repeat point no. 3 till there no point left with the line. Add the
end points of this point to the convex hull.
Thank you…..!!!