Cattle primary passenger screening algorithm fourth note 1

 oneNote algorithm notes format please forgive poor

O This is not a zero-Europe

As long as higher-order terms do not understand the low-order terms .. following:

It is converted from the arithmetic sequence

Here is this expression is not constant operation as long as the low-order terms and higher order terms ignored coefficient higher-order terms we only need n2 so the time complexity is o (n2)

The book is the use of thinking limits us to understand here is faster

   

   

The time complexity of the process is a process big O (M * N) need to traverse the M * N times

Binary lookup time complexity is log2 (N) time complexity

   

2 time complexity of the method is to process O (M * logN) Note A is ordered

   

Note 3 A process is not occurring in the cost of sequencing is not considered

End efflux and ba is both a and b are compared when both a time which is smaller when the comparison continues to move to the sides of one of the mobile to the end of the time

That when b <= a case where (b will move, but also the determination is not printed b = a, b <a print only) except in both cases a so called mobile will later merge sort efflux in speaking

Time Complexity: The two add up

Where O (N + M) A and B should be carried out because the movement is therefore N + M Complexity

   

 

   

   

   

If the number 0 positions than the number 1 position on the big exchange then see if the next number and so on before a number 1 position and 2 position on the exchange ratio after a large number of words such maximum number to finish the lap to the last position it now lined up a number we can reduce a number of sort of

   

What we said at the beginning that is 0-n-1 to find a minimum of 0 into position and then 1-N-1 to find a minimum of 1 into the position of this sort is to choose

i here is the beginning of our position

It introduced two priority above all on the project almost did not see the time just to help us understand the complexity

Insertion sort helpful

   

   

0-0 can not be 0-1 rows of small row of the left put the number between 0-2 and then compare the number 2 position on the first position and the number is relatively small if it is to continue to compare and exchange 0 1

It is equivalent to have got a good brand needs to have a chance to row a new insert cards one by one to compare

In fact, here it is this exchange swap two numbers

这里的情况 就要用到最好情况 最坏情况 还有平均情况 需要看具体的数据状况 我们一般用最差情况 来估计时间复杂度

   

对数器很重要

如果写出了一个排序 怎么来验证她对不对 还可以用在贪心策略 验证这个贪心策略对不对

需要实现一个随机样本的产生器 生成一个数组 长度和值都是随机的

再准备一个绝对正确的方法 时间复杂度高的算法容易写 我们这里验证的是时间复杂度低的算法

然后再大样本测试

参加比赛的时候或者笔试的时候 应该准备对数器模板 二叉树的 数组的 可以验证哪一个出错了

还有堆 排序等等这些都需要准备模板

   

1小时30分左右

一个简单的利用递归 查找数组中的最大值

递归函数就是系统帮我们压栈 函数是如何自己调用自己的 栈里记录方法的参数和方法里面的变量还有执行到哪一步 以及相应的所有信息都会压入栈中 相当于被归档 然后再跑子过程

任何递归行为都可以改为非递归 就是从递归变成迭代了

   

   

如何分析复杂度: 这是一个高深的话题 这里我们讲一个通例

样本量为N的情况下 时间复杂度为 T代表Time

   

只要满足这个公式 的复杂度就是为

所以这里的复杂度是 O(N)

   

2:03开始

这个就用到了master公式的求解 归并排序就是先左侧部分排好序 再右侧部分排好序 然后整体利用外排的方式排好 当左右两侧排好序后 准备一个辅助数组

谁小 谁就往这个辅助数组里面填充

当整体有序了 再拷贝回原数组

   

代码:

   

   

   

   

   

 

面试中特别常见的题型 小和问题和逆序对问题

小和问题 可以使用归并排序 先拆分成左右 两边 分治的思想

代码讲解:2:40 这里代码的意思是 左侧部分产生的小和 + 右侧部分产生的小和 +整体产生的小和

   

防止溢出 如果溢出的话 算出的下标是有可能是不对的 因为L+R可能会溢出 上面的写法不安全

位运算比算术运算快很多

   

   

   

   

   

   

   

   

   

   

   

   

Guess you like

Origin www.cnblogs.com/alalajijun/p/12335323.html