1.ECS为何快? 要想知道ECS为和快,我们就需要去了解一下 CPU与缓存(Cache)
首先我们先来了解一下CPU读取数据时的操作,首先CPU会先从自己的缓存中去查找,如下图,若缓存中没有找到需要的数据,则会去内存中查找,CPU在内存中找到数据后就会将新数据存放在缓存(Cache)当中。但是CPU访问内存的速度会比访问Cache的速度慢100倍,因此提高缓存命中率,避免频繁去内存会大大提高性能。因此我们应该尽量使用数组,避免数据分散,尽量连续的进行处理。
最常见的例子就是在数据量小的情况下遍历数组会比遍历List快上很多,因为数组是有序的,而列表则是分散的,无序的。
分治 复杂问题分解成若干规模相同的子问题。 动态规划 类似于分治法。但具有最优子结构性质和重叠子问题性质。 贪心 不从整体考虑只求当前局部最优解。 回溯 达不到(最优)目标,就退回再走。
背包问题 0 若i=0或T=0 c[i][T]= c[i-1][T] 若T<w[i] max(c[i-1][T-w[i]]+v[i] , c[i-1][T]) 若i>0且T≥w[i]
字符串编辑距离(Edit Distance)是指两个字符串之间,由一个转变成另一个所需的最少编辑操作次数。 许可的编辑操作包括:
将一个字符替换成另一个字符 插入一个字符 删除一个字符
[][]数组相当于正常的一维数组,只不过数组的里的元素存的都是数组,而这些数组的长度各不相同 [,]是一个二维数组,数组的中的每一行都有相同列数,每一列都有相同的行数