博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
arraymethodDivide and Conquer
阅读量:6272 次
发布时间:2019-06-22

本文共 3529 字,大约阅读时间需要 11 分钟。

PS:今天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘。目前又不当COO,还是得用心记代码哦!

    Divide and Conquer is an algorithmic paradigm 

    based on multi-branched recursion

    .

    1. Divide: Break the given problem into subproblems of same type.

2. Conquer: Recursively solve these subproblems
3. Combine: Appropriately combine the answers

    

    

The name "divide and conquer" is sometimes applied also to algorithms that reduce each problem to only one subproblem, such as the  algorithm.

    

Because it uses , so it can be converted into simple . Under this broad definition, however, every algorithm that uses recursion or loops could be regarded as a "divide and conquer algorithm". Therefore, some authors (I prefer this viewpoint too) consider that the name "divide and conquer" should be used only when each problem may generate two or more subproblems.The name decrease and conquer has been proposed instead for the single-subproblem class.

    

    

Divide and Conquer (D & C) vs Dynamic Programming (DP)

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, Quicksort 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.

    

    Following are some standard algorithms that are Divide and Conquer algorithms.

    

    1)  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)  is also a sorting algorithm. The algorithm divides the array in two halves, recursively sorts them and finally merges the two sorted halves.

    

    3)  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.

    

    5)  is an efficient algorithm to multiply two matrices. A simple method to multiply two matrices need 3 nested loops and is O(n^3). Strassen’s algorithm multiplies two matrices in O(n^2.8974) time.

    

    6)  is the most common algorithm for FFT. It is a divide and conquer algorithm which works in O(nlogn) time.

    

    5)  it does multiplication of two n-digit numbers in at most array和method single-digit multiplications in general (and exactly array和method when n is a power of 2). It is therefore faster than the classical algorithm, which requires n2 single-digit products. If n = 210 = 1024, in particular, the exact counts are 310 = 59,049 and (210)2 = 1,048,576, respectively.

    

    

    

    References

    

    

文章结束给大家分享下程序员的一些笑话语录: 火车

一个年轻的程序员和一个项目经理登上了一列在山里行驶的火车,他们发现 列车上几乎都坐满了,只有两个在一起的空位,这个空位的对面是一个老奶 奶和一个年轻漂亮的姑娘。两个上前坐了下来。程序员和那个姑娘他们比较 暧昧地相互看对方。这时,火车进入山洞,车厢里一片漆黑。此时,只听见 一个亲嘴的声音,随后就听到一个响亮的巴掌声。很快火车出了山洞,他们 四个人都不说话。
那个老奶奶在喃喃道, “这个年轻小伙怎么这么无礼, 不过我很高兴我的孙女 扇了一个巴掌”。
项目经理在想,“没想到这个程序员居然这么大胆,敢去亲那姑娘,只可惜那 姑娘打错了人,居然给打了我。”
漂亮的姑娘想,“他亲了我真好,希望我的祖母没有打疼他”。
程序员坐在那里露出了笑容, “生活真好啊。 这一辈子能有几次机会可以在亲 一个美女的同时打项目经理一巴掌啊”

--------------------------------- 原创文章 By

array和method
---------------------------------

转载地址:http://llopa.baihongyu.com/

你可能感兴趣的文章
linux防火墙相关 iptables
查看>>
最简单的单例模式
查看>>
JPopupMenu的使用以及JPopupMenu中子组件的事件处理
查看>>
从反汇编的角度看引用和指针的区别
查看>>
拓马长枪定乾坤
查看>>
UIProgressView的详细使用
查看>>
Silverlight实用窍门系列:70.Silverlight的视觉状态组VisualStateGroup
查看>>
照片筛选与上传功能
查看>>
Hello ZED
查看>>
常见web攻击方式
查看>>
hdu 4472
查看>>
oracle存储过程中is和as区别
查看>>
windows 2003 群集
查看>>
几个gcc的扩展功能
查看>>
Spark一个简单案例
查看>>
关于结构体占用空间大小总结(#pragma pack的使用)
查看>>
通过浏览器查看nginx服务器状态配置方法
查看>>
shell简介
查看>>
android 使用WebView 支持播放优酷视频,土豆视频
查看>>
怎么用secureCRT连接Linux
查看>>