correct / clarify grammar (#34042)
added to article to help clarify some texts as well as added def. article as needed.
This commit is contained in:
parent
0b3415b2fa
commit
57492772fe
@ -4,8 +4,9 @@ title: Divide and Conquer Algorithms
|
||||
## Divide and Conquer Algorithms
|
||||
|
||||
|
||||
Divide and Conquer | (Introduction)
|
||||
Like Greedy and Dynamic Programming, Divide and Conquer is an algorithmic paradigm. A typical Divide and Conquer algorithm solves a problem using following three steps.
|
||||
Divide and Conquer
|
||||
|
||||
Divide and Conquer is an algorithmic paradigm, similar to Greedy and Dynamic Programming. A typical Divide and Conquer algorithm solves a problem using the following three steps.
|
||||
|
||||
1. **Divide**: Break the given problem into subproblems of same type. This step involves breaking the problem into smaller sub-problems. Sub-problems should represent a part of the original problem. This step generally takes a recursive approach to divide the problem until no sub-problem is further divisible. At this stage, sub-problems become atomic in nature but still represent some part of the actual problem.
|
||||
2. **Conquer**: Recursively solve these sub-problems. This step receives a lot of smaller sub-problems to be solved. Generally, at this level, the problems are considered 'solved' on their own.
|
||||
@ -15,13 +16,13 @@ This method usually allows us to reduce the time complexity by a large extent.
|
||||
|
||||
For example, Bubble Sort uses a complexity of O(n^2), whereas quicksort (an application Of Divide And Conquer) reduces the time complexity to O(nlog(n)). Linear Search has time complexity O(n), whereas Binary Search (an application Of Divide And Conquer) reduces time complexity to O(log(n)).
|
||||
|
||||
Following are some standard algorithms that are Divide and Conquer algorithms.
|
||||
Following are some standard algorithms that are of the Divide and Conquer algorithms variety.
|
||||
|
||||
1) **Binary Search** is a searching algorithm. In each step, the algorithm compares the input element x with the value of the middle element in array. If the values match, return the index of middle. Otherwise, if x is less than the middle element, then the algorithm recurs for left side of middle element, else recurs for right side of middle element.
|
||||
1) **Binary Search** is a searching algorithm. In each step, the algorithm compares the input element (x) with the value of the middle element in array. If the values match, return the index of middle. Otherwise, if x is less than the middle element, then the algorithm recurs to the left side of the middle element, else it recurs to the right side of the middle element.
|
||||
|
||||
2) **Quicksort** is a sorting algorithm. The algorithm picks a pivot element, rearranges the array elements in such a way that all elements smaller than the picked pivot element move to left side of pivot, and all greater elements move to right side. Finally, the algorithm recursively sorts the subarrays on left and right of pivot element.
|
||||
2) **Quicksort** is a sorting algorithm. The algorithm picks a pivot element, rearranges the array elements in such a way that all elements smaller than the picked pivot element move to the left side of the pivot, and all greater elements move to the right side. Finally, the algorithm recursively sorts the subarrays on left and right of pivot element.
|
||||
|
||||
3) **Merge Sort** is also a sorting algorithm. The algorithm divides the array in two halves, recursively sorts them and finally merges the two sorted halves. The time complexity of this algorithm is O(nLogn), be it best case, average case or worst case. It's time complexity can be easily understood from the recurrence eqaution :T(n) = 2T(n/2) + n.
|
||||
3) **Merge Sort** is also a sorting algorithm. The algorithm divides the array into two halves, recursively sorts them, and finally merges the two sorted halves. The time complexity of this algorithm is O(nLogn), be it best case, average case or worst case. It's time complexity can be easily understood from the recurrence equat :T(n) = 2T(n/2) + n.
|
||||
|
||||
4) **Closest Pair of Points** The problem is to find the closest pair of points in a set of points in x-y plane. The problem can be solved in O(n^2) time by calculating distances of every pair of points and comparing the distances to find the minimum. The Divide and Conquer algorithm solves the problem in O(nLogn) time.
|
||||
|
||||
@ -36,4 +37,4 @@ Following are some standard algorithms that are Divide and Conquer algorithms.
|
||||
|
||||
Both paradigms (D & C and DP) divide the given problem into subproblems and solve subproblems. How to choose one of them for a given problem? Divide and Conquer should be used when same subproblems are not evaluated many times. Otherwise Dynamic Programming or Memoization should be used.
|
||||
|
||||
For example, Binary Search is a Divide and Conquer algorithm, we never evaluate the same subproblems again. On the other hand, for calculating nth Fibonacci number, Dynamic Programming should be preferred.
|
||||
For example, Binary Search is a Divide and Conquer algorithm, we never evaluate the same subproblems again. On the other hand, for calculating the nth Fibonacci number, Dynamic Programming should be preferred.
|
||||
|
Loading…
x
Reference in New Issue
Block a user