Still quadratic, right? I'm looking for the worst case behavior, it's still quadratic, it's quadratic in the length of the list, so I'm sort of stuck with that.
还是平方,对吧,我在寻找最坏的情况,它还是平方,它是列表长度的平方,我对此有点无奈了。
How do I figure that out? Well I'm looping down the list, right? I'm walking down the list.
怎么算出来的呢?我在循环遍,历这个列表对吧?那要遍历这个列表。
And then, if I want to find out if something's there, I do the same thing. But notice now, hash is converting the input into an integer.
然后,我想查找出某些元素是否在列表中,我做同样的事,但是现在注意,哈希是将输入转化成一个整数,所以,其思想是什么?
So let me expand on that very slightly, and again we did this last time but I want to do one more time. I have to be careful about how I'm actually implementing a list.
我们之前做过了一次,但还是再做一次吧,我得小心的在列表中执行,例如在这个例子中。
The second question I want to ask is what's the base case? When do I get down to a problem that's small enough that it's basically trivial to solve? Here it was lists of size one. I could have stopped at lists of size two right. That's an easy comparison.
第二个问题是什么是基础条件?,我要将问题分解到何时才使得问题,小到可以解决的基本问题?,这里是当列表的长度为1有时候,我也可以在长度为2的时候停止分解,那是一个非常简单的对比。
I'm returning that as my set.
所以我在创建一个列表。
I'll let you just grok it but you can see it's basically doing what I did over there. Setting up two indices for the two sub-list,it's just walking down, finding the smallest element, putting it into a new list. When it gets to the end of one of the lists, it skips to the next part, and only one of these two pieces will get called because only one of them is going to have things leftovers.
你们可以大体的浏览一下,但是它们基本就是我在那里所做的事情,为两个子列表设置了两个指针,指针顺着列表走下去,找到最小的元素,把它放入到一个新的列表中去,当它走到一个列表的尾部时,它会跳到下部分去,两部分中只有一个会被执行,因为只有一个会有元素剩余。
应用推荐