divide and conquer and recursion

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:44:51

问题


I wonder if the technique of divide and conquer always divide a problem into subproblems of same type? By same type, I mean one can implement it using a function with recursion. Can divide and conquer always be implemented by recursion?

Thanks!


回答1:


"Always" is a scary word, but I can't think of a divide-and-conquer situation in which you couldn't use recursion. It is by definition that divide-and-conquer creates subproblems of the same form as the initial problem - these subproblems are continually broken down until some base case is reached, and the number of divisions correlates with the size of the input. Recursion is a natural choice for this kind of problem.

See the Wikipedia article for more good information.




回答2:


A Divide-and-conquer algorithm is by definition one that can be solved by recursion. So the answer is yes.




回答3:


Usually, yes! Merge sort is an example of the same. Here is an animated version of the same.




回答4:


Yes. In divide and conquer algorithmic technique we divide the given bigger problem into smaller sub-problems. These smaller sub-problems must be similar to the bigger problem except that these are smaller in size.

For example, the problem of sorting an array of size N is no different from the problem of sorting an array of size N/2. Except that the latter problem size is smaller than that of former one.

If the smaller sub-problem is not similar to the bigger one, then the divide and conquer technique can not be used to solve the bigger problem. In other words, a given problem can be solved using divide and conquer technique only iff the given bigger problem can be divided into smaller sub problems which are similar to the bigger problem.




回答5:


Examining merge sort algorithm will be enough for this question. After understanding implementation of merge sort algorithm with divide and conquer (also recursion) you will see how difficult it would be making it without recursion.

Actually the most important thing here is the complexity of the algorithm which is expressed with big-oh notation and nlogn for merge sort.

For mergesort exapmle there is another version which is called bottom-up merge sort. It is simple and non-recursive version of it.

it is about 10% slower than recursive, top-down mergesort on typical systems. You can refer to following link for more information. It is explained well in 3rd lecture.

https://www.coursera.org/learn/introduction-to-algorithms#




回答6:


Recursion is a programming method where you define a function in terms of itself. The function generally calls itself with slightly modified parameters (in order to converge).

  1. Divide the problem into two or more smaller subproblems.
  2. Conquer the subproblems by solving them (recursively).
  3. Combine the solutions to the subproblems into the solutions for the original problem.



回答7:


Yes All Divide and Conquer always be implemented using recursion .

A typical Divide and Conquer algorithm solves a problem using following three steps.

  1. Divide: Break the given problem into sub-problems of same type.
  2. Conquer: Recursively solve these sub-problems
  3. Combine: Appropriately combine the answers

Following are some standard algorithms that are Divide and Conquer algorithms. 1) Binary search, 2) Quick Sort, 3) Merge Sort, 4) Strassen’s Algorithm




回答8:


Imagine P is a problem with size of n and S is the solution. In this case, if P is large enough to be divided into sub problem, for example P1, P2, P3, P4, ... , Pk; let say k sub problems and also there would be k solutions for each of k sub problems, like S1, S2, S3, ... , Sk; Now if we combine each solutions of sub problem together we can get the S result. In divide and conquer strategy what ever is the main problem all sube problems must be same. For example if P is sort then the P1, P2 and Pn must be sort too. So this is how it is recursive in nature. So, divide and conqure will be recursive.



来源:https://stackoverflow.com/questions/2249767/divide-and-conquer-and-recursion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!