分而治之_分而治之范式(它是什么,其应用,优缺点)

分而治之

In the branch of Computer Science and Engineering, Information Technology and all the associated branches among these fields the term "Divide and Conquer" is an algorithm design paradigm based on the principle of recursion ( multi-branched). In this algorithmic approach, the algorithm designed works recursively by breaking down the problem in hand, into two or more sub-problems or parts based on the complexity of the problem. This sub-problems or parts are also called atomic or fractions. This atomics or fractions are recursively broken down into more and more atomic or fractions until they are broken down into a form that can be solved. After solving these fractions or atomics they are then again traversed back recursively but this time instead of breaking down the problem, the problems are merged back with their recursively broken counterparts then the required solution for that particular problem is generated.

在计算机科学与工程,信息技术以及所有这些领域的相关分支中,术语“分而治之”是一种基于递归原理(多分支)的算法设计范例。 在这种算法方法中,根据问题的复杂性,设计的算法通过将手头的问题分解为两个或更多子问题或部分来递归工作。 此子问题或部分也称为原子或分数。 将此原子或分数递归分解为越来越多的原子或分数,直到将其分解为可以求解的形式为止。 在解决了这些分数或原子之后,它们再次被递归地遍历,但是这次不是分解问题,而是将问题与它们的递归破坏的对等体合并回去,然后生成该特定问题所需的解决方案。

Divide and Conquer Approach is divided into three processes and these three processes form the basis of divide and conquer paradigm for problem-solving:

分而治之方法分为三个过程,这三个过程构成了解决问题的分而治之范式的基础:

1)除 (1) Divide)

The first and foremost process for solving any problem using Divide and Conquer paradigm. As suggested by the name it’s function is just to divide the problem into sub-problem which in turn if are more complex then are again divided into more sub-parts. Basically , if we consider for example binary search ( an example of Divide and Conquer approach ) the given list is broken ( under some specified consider defined by its algorithm and user input ) into single elements among which then the element to search is compared and the user gets a prompt whether the element is in the list.

使用分而治之范式解决任何问题的第一个也是最重要的过程。 顾名思义,它的功能只是将问题分解为子问题,如果问题更复杂,则又将其分解为更多的子部分。 基本上,如果我们考虑例如二进制搜索(分而治之方法的示例),则给定列表被分解(在其算法和用户输入定义的某些特定考虑下)成单个元素,然后在其中比较要搜索的元素,用户会收到提示,提示该元素是否在列表中。

2)征服 (2) Conquer)

This process is referred to as ‘ Conquer ’ because this process is what which performs the basic operation of a defined algorithm like sort in cases of various sorts, finds the element to be searched in case of binary search, multiplying of the numbers in Karatsuba Algorithm and etc. But almost among algorithms at least the most basic ones that we study mostly are considered to be solved in this part since the divide part breaks them into single elements which can be simply solved.

此过程称为“征服”,因为该过程将执行已定义算法的基本操作,例如在各种情况下进行排序,在二进制搜索情况下查找要搜索的元素,然后在Karatsuba算法中将数字相乘但是几乎在所有算法中,至少我们研究最多的最基本算法被认为是可以解决的,因为除法部分将它们分解为可以简单解决的单个元素。

3)合并 (3) Merge)

This is the last process of the 'Divide' and 'Conquer' approach whose function is to recursively rebuild the original problem but what we get now is the solution to that problem. In merge procedure, the solved elements of the ‘ Conquer ‘ are recursively merged together like the way they divided in the first step i.e. ‘ Divide’.

这是“划分”“征服”方法的最后一个过程,其功能是递归地重建原始问题,但是我们现在得到的是该问题的解决方案。 在合并过程中,“征服”的已解决元素被递归合并在一起,就像它们在第一步中划分的方式一样,即“除法”。

Divide and Conquer Paradigm

The steps 'Conquer' and 'Merge' work so close that sometimes they are treated as a single step. The Divide and Conquer can be implemented in two ways:

“征服”“合并”步骤是如此接近,以至于有时将它们视为一个步骤。 分而治之可以两种方式实现:

  1. Naturally i.e. by using recursion

    自然地,即通过使用递归

  2. Explicitly i.e. by using data structures like stack and queues etc

    明确地,即通过使用诸如堆栈和队列之类的数据结构

One of the major characteristics of Divide and Conquer is that the time complexity of its algorithms can be easily calculated by solving recurrence relations and its correctness can be evaluated via Mathematical Induction.

分而治之的主要特点之一是可以通过求解递归关系轻松计算其算法的时间复杂度,并可以通过数学归纳法评估其正确性。

分而治之策略的应用 (Applications of Divide and Conquer Strategy)

  1. Binary Search (C program for binary search)

    二进制搜索( 用于二进制搜索的C程序 )

  2. Merge Sort (Merge sort | C++ Example)

    合并排序( 合并排序| C ++示例)

  3. Quick Sort (Quick sort | C++ Example)

    快速排序( 快速排序| C ++示例)

  4. Closest Pair of Points

    最接近的点对

  5. Strassen’s Multiplication

    Strassen的乘法

  6. Karatsuba Algorithm

    唐津算法

  7. Cooley-Tukey Algorithm

    Cooley-Tukey算法

分而治之策略的优点 (Pros of Divide and Conquer Strategy)

  1. Solves difficult problems with ease.

    轻松解决难题。

  2. Algorithms designed with Divide and Conquer strategies are efficient when compared to its counterpart Brute-Force approach for e.g. if we compare time complexity of simple matrix multiplication i.e. O(n3) and that of Strassen's matrix multiplication i.e. O(n2.81).

    与除法相比,用分而治之策略设计的算法是高效的,例如,如果我们比较简单矩阵乘法(即O(n3))和Strassen矩阵乘法(即O(n2.81))的时间复杂度。

  3. Algorithms designed under Divide and Conquer strategy does not require any modification as they inhibit parallelism and can easily be processed by parallel processing systems.

    在分而治之策略下设计的算法不需要任何修改,因为它们抑制了并行性,并且可以轻松地由并行处理系统处理。

  4. It makes efficient use of memory cache this happens so because that problems when divided gets so small that they can be easily solved in the cache itself.

    它有效地利用了内存缓存,因为发生这种情况的原因是,分割后的问题变得很小,可以轻松地在缓存本身中解决。

  5. If we use floating numbers then the results may improve since round off control is very efficient in such algorithms.

    如果我们使用浮点数,则结果可能会有所改善,因为舍入控制在此类算法中非常有效。

分而治之的弊端 (Cons of Divide and Conquer Strategy)

  1. Divide and Conquer strategy uses recursion that makes it a little slower and if a little error occurs in the code the program may enter into an infinite loop.

    分而治之策略使用的递归机制会使其变慢,并且如果代码中发生了一些错误,程序可能会进入无限循环。

  2. Usage of explicit stacks may make use of extra space.

    使用显式堆栈可能会占用额外的空间。

  3. If performing a recursion for no. times greater than the stack in the CPU than the system may crash.

    如果不执行递归。 倍于CPU中堆栈的倍数,可能导致系统崩溃。

  4. Choosing base cases is also a limitation as picking small cases may work if the cases are taken much higher than the capacity of the system than problems may occur.

    选择基本案例也是一个限制,因为如果案例被认为比系统的容量大得多而无法解决问题,那么挑选小案例可能会起作用。

  5. Sometimes a case where the problem when broken down results in same subproblems which may needlessly increase the solving time and extra space may be consumed.

    有时,当问题分解时导致相同的子问题,可能会不必要地增加求解时间,并且可能会占用额外的空间。

翻译自: https://www.includehelp.com/algorithms/divide-and-conquer-paradigm.aspx

分而治之

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值