Figure out what I'm trying to walk through What's the collection of things I'm trying to walk through. Figure out what I want to do at each stage. Figure out what the end test is.
弄清楚需要遍历的东西,弄清楚我需要遍历的东西的集合,弄清楚我在每一步该做什么,弄清楚终结测试。
So this looks like it's doing a little bit of extra work, but you can see, if you look at that how it cuts it down at each stage.
它就做了很多多余的工作,如果你认真看,你能看到每个阶段,它是如果缩减查找空间的,我要告诉你。
At each stage, no matter which branch, here or here, I take, I'm cutting down the length of the list that I'm searching in half. All right?
选的是这里还是那里,我总是把列表分成两半,对吧?,所以如果我处理一个长度为n的列表?
Log n Log n, because at each stage I'm cutting the problem in half. So I start off with n then it's n n/2 n/4 n/8 over two n over four n over eight.
因为总共有多少层?,因为在每一层,我都是把问题分解成两半,因此以n开始,然后是。
应用推荐