She was only half-listening as she prepared a list of things to do the next day,on Halloween.
VOA: special.2010.10.30
So in this case, one of the standard ways to do this, is to use what's called a linked list.
标准的处理方法是使用链表,我接下来也准备这么做。
So do reach out ultimately to your assigned teaching fellow, to me, to the help list, to the forums online.
所以务必联系到你们的研究生助教,到我这,到那个帮助栏,到在线论坛上。
"My friends and I have made a list of things we want to do over the summer. Different places to travel, to get away to, maybe a beach a few hours away.
VOA: special.2010.06.18
So it's certainly at least linear in the length of the list. For each starting point, what do I do?
它至少是线性的计算列表的长度,每次到了循环开始的点?
"We must do better." Republicans have put forward a list of principles that they think should drive the 2010 budget.
VOA: standard.2009.03.17
So, she is interested in how this molecule, gemcitabine, inhibits an enzyme. So, to do those studies, she needs to know a lot of the stuff on this list.
她对这个分子,二氟脱氧胞嘧啶核苷怎么抑制酶很感兴趣,要做这些研究。
In 2000,Russian President Vladimir Putin, signed off on an updated list of no-can-do jobs for women.
VOA: standard.2009.11.05
This is one of a long list of experiments that we can't do anymore.
这只是众多实验中的一个而已,我们没时间讲其他的了。
Now, what do you suppose was the most expensive item on that list?
你们觉得清单里的哪一项最贵?
Now this is actually a poor way to do it, because you might say, well, it's just the list.
它以这种形式显示出来了,现在这实际上是一种很差劲的方法,因为你可能会说,好吧。
So the first thing we'll do is, we'll print the element, in this case it will be a list right? Because it's a list with two lists in it.
因此这儿我们要做的第一件事,就是要显示元素,在这儿元素就是数组了对不对?,因为这个数组包含了两个数组。
If I do this, try and get the 10th element of a list that's only eight long. I get what looks like an error, but it's actually throwing an exception.
如果我来这么做,试着去取长度为8的列表的第十个元素,我貌似能得到一个错误。
But what you should be able to do is take a look at a list of answers for what we're saying z effective might be, and determining which ones are possible versus which ones are not possible.
但是你们应该能够做到的,是看一下这个可能的,有效电荷量的答案列表,并且确定哪些是可能的,哪些是不可能的。
So I'm first going to look for something that's not in the list, I'm going to see, is minus 1 in this list, so it's going to be at the far end, and if I do that in the basic case, bam.
如果我试试第一种最基本的方法,噢,一下就完成了对不对?,因为这种方法查了下第一个元素,然后发现目标数比较下,因为目标数小于第一个元素。
And what does that say? It says, let's assume I want to do k searches of a list. OK.
如果我们假定要在列表中做k次搜索,在线性的情况下,假定是一个未排序的情况。
How do I figure that out? Well I'm looping down the list, right? I'm walking down the list.
怎么算出来的呢?我在循环遍,历这个列表对吧?那要遍历这个列表。
OK? So the example I'm going to do, I'm going to search a sorted list.
来搜索目标元素,好,翻到课堂材料的第二页。
So an easy way to do this would be to say, let's just represent them as a list.
一个简单的方法就是,让我们用数组的形式。
So halfway is the right thing to do, because at each step, I'm guaranteed to throw away at least half the list. Right? And that's nice.
一半以上的元素,对不对?,这很棒,好,大家猜猜这个算法的增长率是多少?,为什么?太对了。
So it's going to look at the rest of the list, walking along, and what does it do?
所以它会查看列表剩下部分,遍历它们,那它要做什么呢?
The easy thing to do would be the following: start at the front end of the list, check the first element. If it's the thing I'm looking for, I'm done. It's there. If not, move on to the next element. And keep doing that.
从数组的第一个元素开始:,如果这是目标元素那么结束,如果不是的话就继续比较下面的元素,并一直这么比较下去,但如果,在某一点我发现我要寻找的数字。
This is sorted, this is sorted, how do I now make a list of size 2?
这个是有序的,这个也是有序的,我怎样才能组成一个有2个元素的列表?
I've got a list, walk you through it an element at a time, do I look at each element of the list more than once?
你一次只能得到他的一个元素,我是不是把数组里面的每个元素,都过了大于等于一次?,你不这样认为么?大家有什么建议?
As I keep moving down, that part gets smaller, it's not always the initial length of the list, and you're right. But if you do the sums, or if you want to think of it this way, if you think about this more generally, it's always on average at least the length of the list.
等等,随着移动,剩下的部分越来越小,并不是初始那么长了,如果你算一算,或者你这么想,你考虑更一般的情况,平均下来至少是列表的长度。
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.
我们之前做过了一次,但还是再做一次吧,我得小心的在列表中执行,例如在这个例子中。
Well let's see. My fall back is, I could just do linear search, walk down the list one at a time, just comparing those things. OK. So that's sort of my base. But what if I wanted, you know, how do I want to get to that sorted list? All right?
我只能做线性搜索了,一次遍历一遍列表,一个一个比较,但如果我想要,那怎样得到有序的列表呢?,现在的一个问题是,我们排序之前?
Takes in a list. What does it say to do?
这段代码要做什么?
Here's the problem. How do I get to the nth- er, the k'th element in the list, in this case?
如何找到第n个元素呢-,在这里,如何找到第k个元素呢?
You try to design actually I'm going to come back to that in a second. It's like you're trying to use a hash function that spread things out pretty evenly. But the places you store into in those lists may have to themselves have a small list in there, and when you go to check something, you may have to do a linear search through the elements in that list.
你尝试着去设计,实际上过会儿我会回头讲解这个问题,类似于你需要用一个哈希函数,非常平均的将物体分发出去,但是在列表中你数据,映射到的地方可能会有自己的一小段列表,当你回头查找数据的时候,你可能需要在那一小段列表中做线性查找。
应用推荐