# transcripts

session: F05-01
timestamp: 00:02:02.00
speaker: JAC
utterance:
so if we think about it as a family tree um this could be the great grand +// this would be the great grandparent of this child here.


session: F05-01
timestamp: 00:02:18.10
speaker: JAC
utterance:
so  if we look at it this way # we have a parent # and then we check the left child and the left child is less than the parent.


session: F05-01
timestamp: 00:02:28.07
speaker: JAC
utterance:
and if we check the child of this parent +// this parent +// this left child  +// we check its right child um and we find that it's greater so it's correct.


session: F05-01
timestamp: 00:02:41.28
speaker: JAC
utterance:
now if we come here # and we go to the right child we find out that +// eleven # which eleven is greater than seven so that's correct.


session: F05-01
timestamp: 00:04:36.07
speaker: JAC
utterance:
but right now the way it's drawn it's +// this is the +// this part +// portion here points to the right child # this part here points to the left child.


session: F05-01
timestamp: 00:05:20.01
speaker: JAC
utterance:
we check its right child # there's no right child so we come back and check its left child and find out it's eight.


session: F05-01
timestamp: 00:05:41.15
speaker: JAC
utterance:
we check five's right child which is null so we come back up # and then we check five's left child which is four which is less.


session: F05-01
timestamp: 00:06:21.20
speaker: JAC
utterance:
the standard format is # right child is always greater than the parent # left child is always less than the parent.


session: F05-01
timestamp: 00:07:02.24
speaker: JAC
utterance:
so # um by convention the right child is always greater than its parent and the left child is always less than its parent.


session: F05-01
timestamp: 00:07:10.29
speaker: JAC
utterance:
now if we go about and start switching those like we have here # someone who's using the structure and you haven't setup where the left child is greater than the parent # is not going to be getting the results that they're expecting.


session: F05-01
timestamp: 00:07:27.10
speaker: JAC
utterance:
so if I try and search +// if you try and search a tree and you want +// you know that the left child should be less # and you grab everything from the left because you need to do some sorting out or whatever.


session: F05-01
timestamp: 00:09:00.35
speaker: JAC
utterance:
we need to find out +// we need to make a new connection # right between the parent of nine # and nine's child.


session: F05-01
timestamp: 00:10:55.09
speaker: JAC
utterance:
then we would compare # six to the right child which is seven # and we would find that seven +// err six is less than seven so we would go check seven's left child.


session: F05-01
timestamp: 00:11:15.29
speaker: 101
utterance:
so if it doesn't have a child and it's less than or say like that number is greater than it you could pop it right in there?


session: F05-01
timestamp: 00:12:38.22
speaker: JAC
utterance:
now if we were to move nine +// if we were to make nine the new head +// the new parent what happens is eight and seven are both less than nine and then we'd have to +// we'd have to put them here


session: F05-01
timestamp: 00:13:02.23
speaker: JAC
utterance:
so we wouldn't want to do +// we wouldn't want to go about and delete nine +// or I'm sorry make nine the head because nine +// doing that would mean we'd have to insert eight and seven here and we'd have a lopsided tree.


session: F05-01
timestamp: 00:13:24.04
speaker: JAC
utterance:
want to +// we really don't +// we want to try to and keep # the tree somewhat balanced you can see here the tree is not completely balanced but it's not +// everything is not all on one side like that.


session: F05-01
timestamp: 00:15:37.13
speaker: JAC
utterance:
so we did the minimal +// minimal amount of +// minimal amount of work that we had to do because now we didn't have to +// seven didn't have to go reestablish connections with anyone else.


session: F05-01
timestamp: 00:15:52.13
speaker: 101
utterance:
how come you couldn't keep the nine and the eight the way they were # because it would still be like+...


session: F05-01
timestamp: 00:15:57.19
speaker: JAC
utterance:
if we were to change +// if we were to do that # it would have +// I'm just going to draw this side that you're talking about.


session: F05-01
timestamp: 00:16:22.15
speaker: JAC
utterance:
for that to happen you would have to delete this connection # make a connection between nine and seven now.


session: F05-01
timestamp: 00:16:37.05
speaker: JAC
utterance:
think of the +// think of the structure +// these data structures as we're trying to be as efficient as possible they're made +// in +// for some type of data structures there may be ways to be more efficient # but also it may be less efficient in other ways.


session: F05-01
timestamp: 00:16:56.26
speaker: JAC
utterance:
there's ways to +// there is a way to keep these trees very balanced # so that they keep rotating but every time you insert something you have to go back and rotate it.


session: F05-01
timestamp: 00:17:08.09
speaker: JAC
utterance:
so if you're not doing something so it would keep it balanced but at the cost of having to do several rotations so it's expensive.


session: F05-01
timestamp: 00:17:17.06
speaker: JAC
utterance:
so if you have a huge tree and you do a couple inserts and you do rotations it might be rotated several times.


session: F05-01
timestamp: 00:17:26.26
speaker: JAC
utterance:
um there's one where you do a search # on a tree say we search for +// let's come here and say we searched for nine.


session: F05-01
timestamp: 00:17:53.01
speaker: JAC
utterance:
nine is equal to nine so what would happen is this nine now would move all the way up here +// would rotate it all the way up to five.


session: F05-01
timestamp: 00:18:17.28
speaker: JAC
utterance:
but now if you do a search on something you've searched on before you'll find it faster # so if I had a huge tree with uh a thousand # data +// a thousand nodes # uh I could find the +// I could find ones that I look for all the time faster.


session: F05-01
timestamp: 00:19:28.09
speaker: JAC
utterance:
so since it's greater we have to check the right child because the right child is always greater than the left child.


session: F05-01
timestamp: 00:19:36.06
speaker: JAC
utterance:
so we're coming in here and we'll compare xxx xxx xxx xxx xxx # we'll compare nine to eight and we find nine is greater than eight so we go to the left child.


session: F05-01
timestamp: 00:20:07.16
speaker: JAC
utterance:
so we would +// if we were looking +// since we're doing a search we would return # return to that +// return eight.


session: F05-01
timestamp: 00:20:15.17
speaker: JAC
utterance:
it depends on your function um you might want +// it might be a xxx and it would turn true or it might be +// you might want to have a function that actually returns the node for you.


session: F05-01
timestamp: 00:20:30.00
speaker: JAC
utterance:
typically you probably return the xxx +// return the node # or possibly one of the others you usually find.


session: F05-01
timestamp: 00:22:14.05
speaker: JAC
utterance:
so what we would do in case of finding null would be to return here # false or we return +// we might return null.


session: F05-01
timestamp: 00:22:27.29
speaker: JAC
utterance:
depends on your +// depends on your function and how you're implementing this um we might return null because you want to know that it's not there and you might say okay since four is not there I'm going to add four or you might return false only because you just want to find out if it's a new xxx or not.


session: F05-01
timestamp: 00:23:53.21
speaker: JAC
utterance:
we found +// we just did the search on four and we found out we didn't have it so we want to insert four.


session: F05-01
timestamp: 00:24:06.06
speaker: JAC
utterance:
you might want to a search # um to find out if four is in there if four is not in there then you might want to insert it.


session: F05-01
timestamp: 00:24:23.19
speaker: JAC
utterance:
um basically if you were to write the search # you'd want to just do a search and either return the node or return the pointer to the node or return true or false.


session: F05-01
timestamp: 00:24:38.05
speaker: JAC
utterance:
uh you might have search, return the node because you want to delete that node or you might have um search, return the null pointer to the null because it's in our case # three is pointing to null there isn't a four.


session: F05-01
timestamp: 00:24:53.26
speaker: JAC
utterance:
you might be like okay well now I'm going to insert # right there and instead of going through and saying okay now I'm going to insert four # you go in five, insert +// you'd basically be searching again for the appropriate place.


session: F05-01
timestamp: 00:25:10.24
speaker: JAC
utterance:
when you did the search already you already found the appropriate place (be)cause that's what you did to find it.


session: F05-01
timestamp: 00:25:28.02
speaker: JAC
utterance:
and # that way if we wanted to add four we could just add it straight instead of going through and doing all the expensive costs of trying to find it because if we had a tree and we think of each of these as levels on a tree this is our root.


session: F05-01
timestamp: 00:26:14.24
speaker: JAC
utterance:
so once you find the appropriate place # where a number should go or whatever data item you're putting in we're going to want to go back and search through all hundred leaves or go down a hundred leaves assuming let's say it's in the very bottom # the worst case scenario.


session: F05-01
timestamp: 00:26:35.08
speaker: JAC
utterance:
there's no point so that's why you'd want to xxx xxx but let's say whoever wrote this # didn't think like that or they don't care so we're going to insert four.


session: F05-01
timestamp: 00:27:36.26
speaker: JAC
utterance:
since the right child of three is null # we're going to insert the right child +// we're going to insert four there okay?


session: F05-01
timestamp: 00:27:47.27
speaker: JAC
utterance:
so basically # what we're doing is finding the first part +// the first instance to where the child +// the child +// this leaf +// we'll call them leaves # is not pointing to anything.


session: F05-01
timestamp: 00:28:11.18
speaker: JAC
utterance:
so in this case we're going to put four in the right child of three # because it's the first possible instance where it's available # there's something available.


session: F05-01
timestamp: 00:28:21.00
speaker: JAC
utterance:
now if two +// if three wasn't here # and we wanted to put a right +// we wanted to insert four we'd insert four here.


session: F05-01
timestamp: 00:28:31.17
speaker: JAC
utterance:
um now if we come back through here using this new tree # the problem of xxx tree is you never know how much space you need.


session: F05-01
timestamp: 00:29:09.22
speaker: JAC
utterance:
um so now if we were to insert # say # let's say we can insert decimals just to +// (be)cause I really don't have anything to xxx between four and five other than decimals.


session: F05-01
timestamp: 00:29:29.12
speaker: JAC
utterance:
so we compare four point five # and we compare +// we compare four point five to five and we find out that four point five is less than five so we check the left child.


session: F05-01
timestamp: 00:29:42.08
speaker: JAC
utterance:
and we would find that two is less than four point five so we go to the right child and we'd find out that three is less than four point five so we go to the right child and find out four is less than four point five.


session: F05-01
timestamp: 00:30:25.23
speaker: JAC
utterance:
all right # depending on the order we add these to the tree # it makes a difference in the way the tree looks.


session: F05-01
timestamp: 00:30:35.28
speaker: JAC
utterance:
this is our list of numbers that we can add and I'm going to say we're going to add them in this order: seven, three, five, eight, nine, two, and one okay?


session: F05-01
timestamp: 00:31:11.16
speaker: JAC
utterance:
we'll have +// we have a +// there is a head kind of like in linked lists # there's a head that's always pointing to the first +// the head is pointing to nothing so we make it seven.


session: F05-01
timestamp: 00:31:32.24
speaker: JAC
utterance:
we come and look at seven and three is less than seven so we check its left child and we find that it's null so we insert three to its left child.


session: F05-01
timestamp: 00:31:52.16
speaker: JAC
utterance:
compare five to seven # five is greater than seven so we insert five +// check the right child and the right child is null +// I'm sorry you're right.


session: F05-01
timestamp: 00:32:17.17
speaker: JAC
utterance:
compare five and three and we find five is greater than three so we add to its right child +// we check its right child we find its right child is null so insert five.


session: F05-01
timestamp: 00:32:32.06
speaker: JAC
utterance:
yeah basically you can say if +// if null you would insert +// you'd create a new node and insert it here and create the link between the two # if not +// if not compare it +// keep going # keep going until +// basically keep going until you find a place to insert it.


session: F05-01
timestamp: 00:32:51.23
speaker: JAC
utterance:
so now we want to insert the eight so we come here and compare seven and eight # eight is greater than seven.


session: F05-01
timestamp: 00:33:28.25
speaker: JAC
utterance:
so we check eight's right child # eight doesn't have a right child so we can insert nine as eight's right child.


session: F05-01
timestamp: 00:34:29.24
speaker: JAC
utterance:
so now we made a completely different tree # but it's still a binary search tree by changing the order we inserted them, right?


session: F05-01
timestamp: 00:34:39.01
speaker: JAC
utterance:
so if we wanted +// so we pretty much rearranged the given binary search tree and created another tree # which satisfies still the same properties.


session: F05-01
timestamp: 00:34:47.08
speaker: JAC
utterance:
so # you can see we have +// you'll get a different tree each time depending on the order of insertion.


session: F05-01
timestamp: 00:35:09.18
speaker: JAC
utterance:
is there anything that you're not +// you're having trouble with +// you don't have understanding for?


session: F05-01
timestamp: 00:35:53.06
speaker: JAC
utterance:
three is gone # so # since we're on the left side # we're going to check for +// we're going to check its left child first.


session: F05-01
timestamp: 00:37:02.04
speaker: %exp
utterance:
starting at the [00:36:35.14] mark, both Jack and the student are speaking at a volume that is often inaudible.


session: F05-01
timestamp: 00:38:02.09
speaker: JAC
utterance:
okay # if we were to delete eight # we'd just check seven and we'd find seven has no children and just nine # xxx xxx to draw just this batch and delete eight.


session: F05-01
timestamp: 00:38:24.19
speaker: JAC
utterance:
if we delete +// if we were to do the same thing +// if we were to just delete seven then # seven would just go away.


session: F05-01
timestamp: 00:39:01.25
speaker: JAC
utterance:
we don't want to write +// if we were to write this program we wouldn't want to write it +// two different deletion methods, right?


session: F05-01
timestamp: 00:39:16.12
speaker: JAC
utterance:
we don't want to write two different ones depending on whether it's on the left side or the right side.


session: F05-01
timestamp: 00:39:29.17
speaker: JAC
utterance:
so then the same thing should go here if we delete two # we should go down to the left and make a xxx.


session: F05-01
timestamp: 00:39:56.19
speaker: JAC
utterance:
(be)cause otherwise now you're writing multiple deletion methods and you're trying to reinsert this you're going to xxx xxx.


session: F05-02
timestamp: 00:00:22.05
speaker: LOW
utterance:
[^ makes same clicking noise] uh ok # so it's a list ## which is # you know # like ## buy Cheerios buy you know your [/] sugar [//] grocery [/] [^ the word was incomplete before the correction] list.


session: F05-02
timestamp: 00:00:30.18
speaker: LOW
utterance:
[^ makes same clicking noise] uh # oh, information [///] so here # just to keep it simple # the information is just a single letter ## but in a real example of course this would be maybe an employee record ## you know # it's got a name and a phone number an i@l d@l # all kinds of stuff ## here we just have a single letter.


session: F05-02
timestamp: 00:00:55.12
speaker: LOW
utterance:
and we need some way to indicate the end of the list [^ grunt] # so many textbooks # made it simpler I've just drawn a # slash.


session: F05-02
timestamp: 00:01:07.08
speaker: LOW
utterance:
[^ makes same clicking noise] so uh ## you have to keep track of the list with something # so you have a header pointer it's called which is why it's called h@l.


session: F05-02
timestamp: 00:01:21.20
speaker: LOW
utterance:
what the # value of the first node is which is c@l # we call that the info [>] # and then where the second node is # okay?


session: F05-02
timestamp: 00:01:28.16
speaker: LOW
utterance:
and then # that tells you k@l and so ## I draw them out like that but in computer and memory # they are not consecutive # so c@l may be a certain address # and k@l is a much greater address # and b@l is an even smaller address.


session: F05-02
timestamp: 00:01:49.15
speaker: LOW
utterance:
k@l [: okay] so an array is a list # but the things live consecutively and they live in memory together.


session: F05-02
timestamp: 00:01:54.21
speaker: LOW
utterance:
+^ here they don't live together # so instead of # living together each one tells you where the next one is.


session: F05-02
timestamp: 00:02:00.15
speaker: LOW
utterance:
[^ makes same clicking noise] but the thing is [^ grunt] # you really ## just sort of view it like this.


session: F05-02
timestamp: 00:02:23.03
speaker: LOW
utterance:
so if you want to know if there's a # x@l in the list # you have to say # uh # okay what's the first one?


session: F05-02
timestamp: 00:02:44.20
speaker: LOW
utterance:
we'll just do a couple of the linked lists # a couple of the binary search trees so you know what that is etcetera ## and watch the clock here.


session: F05-02
timestamp: 00:02:50.29
speaker: LOW
utterance:
so describe sequence of operations to insert a new node # which contains g@l # in the first list # after the node contains b@l.


session: F05-02
timestamp: 00:03:26.04
speaker: LOW
utterance:
now ## sort of somebody who doesn't know any computer science xxx that's the answer you know but # what we want to do is write in some sort of code +/.


session: F05-02
timestamp: 00:04:27.15
speaker: LOW
utterance:
+^ so in this case # uh we're gonna traverse the list # uh so # we're gonna # describe a sequence of operations # that after xxx b@l.


session: F05-02
timestamp: 00:05:23.19
speaker: LOW
utterance:
and now # obviously we're gonna use a # looping structure # cause [: because] what we wanna do is +//.


session: F05-02
timestamp: 00:05:33.28
speaker: LOW
utterance:
oh <I think we get to assume here in this> [//] # since you're really just getting into linked lists # in this problem we get to assume there is a b@l in the list.


session: F05-02
timestamp: 00:06:10.25
speaker: LOW
utterance:
so I've got the info field that tells me # the contents # and I've got the next field that tells me where the next one is # okay?


session: F05-02
timestamp: 00:07:20.26
speaker: LOW
utterance:
well # <we have> [/-] if we had broken this down into segments <we sorta did> [^ this was a tangent] # +/.


session: F05-02
timestamp: 00:07:48.16
speaker: LOW
utterance:
+^ let's imagine that there is a # new node # procedure at this a constructor that would return a new node and we'd be able to say what the info is # k [: okay] ?


session: F05-02
timestamp: 00:07:58.12
speaker: LOW
utterance:
+^ so we call them constructor for the nodes # and we'd say put g@l in there and <return node #> [//] return the xxx.


session: F05-02
timestamp: 00:08:11.12
speaker: LOW
utterance:
## and now # <all we have to> [/-] oh # and here's the other thing about linked lists and trees and stacks.


session: F05-02
timestamp: 00:08:42.12
speaker: LOW
utterance:
alright so # I've sorta written in the notation and now # <what would you say here> [//] what is that?


session: F05-02
timestamp: 00:09:25.23
speaker: LOW
utterance:
well yeah <this is> [///] we were just supposed to be assume doin uh # pseudo because you understand what it's about # but yeah.


session: F05-02
timestamp: 00:09:37.17
speaker: LOW
utterance:
+^ we have # copied the address that was in here # which was the node after b@l intuh [: into] that.


session: F05-02
timestamp: 00:09:46.29
speaker: LOW
utterance:
<uh # that field right there is the> [//] ### on the left hand side it moves assignment negative one.


session: F05-02
timestamp: 00:12:02.04
speaker: LOW
utterance:
so backing up one # this was a simple problem cause we were inserting a node after the node that contained b@l.


session: F05-02
timestamp: 00:12:28.01
speaker: LOW
utterance:
you know if # so xxx we put t@l here and <if t@l is next> [//] if the info of the next of t@l # is a@l +/.


session: F05-02
timestamp: 00:12:37.19
speaker: LOW
utterance:
but that used to be a problem # if you're over here at the end because the [//]there is no info of the next # okay?


session: F05-02
timestamp: 00:13:32.11
speaker: LOW
utterance:
so if we were looking for e@l ## s@l being null would tell us # that it is the very first node # okay?


session: F05-02
timestamp: 00:14:01.25
speaker: LOW
utterance:
+^ so let's just xxx [>] <look at> [///] <b@l is> [///] just go back and just change that pointer [?] into a null.


session: F05-02
timestamp: 00:14:34.20
speaker: LOW
utterance:
so always check # does it work if it's the first does it work if it's the last does it work if it's in the middle.


session: F05-02
timestamp: 00:14:47.15
speaker: LOW
utterance:
we're gonna use two pointers to traverse this list because we need to know # about two nodes in sequence # okay?


session: F05-02
timestamp: 00:15:58.05
speaker: LOW
utterance:
but hopefully you see that in [?] a hundred elements # it would still march across # and s@l would be right behind t@l.


session: F05-02
timestamp: 00:16:04.26
speaker: LOW
utterance:
okay # and in many many many operations you need two # sometimes even three pointers to get it done.


session: F05-02
timestamp: 00:16:17.11
speaker: LOW
utterance:
um # we should talk if we had time about what we'd do if <it wasn't> [?] xxx but suppose there was an a@l in the list.]


session: F05-02
timestamp: 00:17:48.06
speaker: LOW
utterance:
# uh you could have tertinary trees or whatever where uh xxx have three four seven kids or whatever.


session: F05-02
timestamp: 00:17:58.13
speaker: LOW
utterance:
+^ this guy has only one child # this one has one child # this one has zero # this one has zero kids zero.


session: F05-02
timestamp: 00:18:04.03
speaker: LOW
utterance:
okay so that makes it a binary tree ## uh # by the way this is called the root # and there's always a pointer # I didn't put it in this picture this is xxx a pointer to the root.


session: F05-02
timestamp: 00:18:31.00
speaker: LOW
utterance:
all of the nodes to the left are less than that node # and all of those to the right are bigger # okay?


session: F05-02
timestamp: 00:18:42.00
speaker: LOW
utterance:
left always gets you to smaller stuff # so left of seven is smaller stuff right of seven is bigger than seven.


session: F05-02
timestamp: 00:20:13.21
speaker: LOW
utterance:
alright so this [//] these are questions basically about using ## uh # yeah the first couple are about search.


session: F05-02
timestamp: 00:21:16.06
speaker: LOW
utterance:
now # not going to spend much time but this thing is much more efficient than looking at an array # alright?


session: F05-02
timestamp: 00:23:41.06
speaker: LOW
utterance:
technically <you would have to find> [//] kinda like we did in the list # you would have to find the parent of one # cause it's this pointer that changes.


session: F05-02
timestamp: 00:26:25.29
speaker: LOW
utterance:
I'm looking for somebody we could bring up here to the five ## and not do anything else to the tree really.


session: F05-02
timestamp: 00:27:13.06
speaker: LOW
utterance:
it'll be okay because # we just said it's the biggest of these so all of these guys are smaller than it # so it can be in the left subtree.


session: F05-02
timestamp: 00:27:20.05
speaker: LOW
utterance:
and # it's # already smaller than that # so three is less than five and five is less than all these guys.


session: F05-02
timestamp: 00:27:33.04
speaker: LOW
utterance:
we could find the smallest on this side # and you bring it up because it would be smaller than all these # cause it's the smallest of these guys.


session: F05-02
timestamp: 00:29:06.09
speaker: 102
utterance:
+, I thought we were just gonna like take this whole chunk # and put it like right there # so then two would be here # the one was there # the three was here # <and the nine was> [>] here.


session: F05-02
timestamp: 00:29:15.19
speaker: LOW
utterance:
okay so we [/] were looking for just one node to put on top of the five and not do anything else to the tree.


session: F05-02
timestamp: 00:29:40.16
speaker: LOW
utterance:
but real quickly I'll [/] say no # because you said go <find three> [>] go [x 3] and then go as far as you can.


session: F05-02
timestamp: 00:29:51.11
speaker: LOW
utterance:
for example # you could # the six xxx over here you could have the six <in the half> [?] of the tree.


session: F05-02
timestamp: 00:30:32.22
speaker: LOW
utterance:
in fact ## I often tell students # uh <what do you think> [///] I don't know what the cafeteria is like here but # many places when you walk into a cafeteria they have a stack of trays ## and let's suppose we have a very expensive container here with a # very very good spring.


session: F05-02
timestamp: 00:30:53.27
speaker: LOW
utterance:
now you [/] think there are many trays in there but you can't tell if there's one tray or a hundred trays in there because there's a container around # and it just shows you this one tray.


session: F05-02
timestamp: 00:31:04.16
speaker: LOW
utterance:
so you can't # look down in there and find a perfect red clean tray # you just have to take the ugly green ones on top.


session: F05-02
timestamp: 00:32:20.27
speaker: LOW
utterance:
and then # the other thing you can do # is to always take them off # the other thing you can do is put them on.


session: F05-02
timestamp: 00:33:12.24
speaker: LOW
utterance:
um ### oh and # the other thing about a stack is # it's # often called a # last in first out # you know?


session: F05-02
timestamp: 00:33:23.13
speaker: LOW
utterance:
so three was the # first # number that was pushed on the stack # then seven then two then five then four.


session: F05-02
timestamp: 00:33:37.04
speaker: LOW
utterance:
<let's just # figure out> [//] let's write the pseudocode to count how many elements there are in a stack # and not destroy the stack # okay?


session: F05-02
timestamp: 00:34:12.02
speaker: LOW
utterance:
<so rather than> [//] I like your idea # since you know arrays # but since we're talking about stacks let's put them in a stack.


session: F05-02
timestamp: 00:34:28.16
speaker: LOW
utterance:
so # uh we +// lets assume that we have a # you know # an s@l dot empty or something like that or +...


session: F05-02
timestamp: 00:34:54.28
speaker: LOW
utterance:
top # uh could throw the exception or it could return null and tell you that it's empty or something like that.


session: F05-02
timestamp: 00:35:18.05
speaker: 102
utterance:
you grab the +// first you're going to have to top it and we have to push into t@l what we just found.


session: F05-02
timestamp: 00:36:19.09
speaker: LOW
utterance:
pop the three, put it there and the counter, of course, is going one, two, three, four, five, six, okay?


session: F05-03
timestamp: 00:00:47.15
speaker: LOW
utterance:
and the only way you can keep track of a link list or way you do keep track of a link list is with a pointer to the first node.


session: F05-03
timestamp: 00:04:07.08
speaker: LOW
utterance:
uh because all you've got is this pointer for this first node so we're going to travel across the list until we find b@l.


session: F05-03
timestamp: 00:04:30.24
speaker: LOW
utterance:
and now we are on the loop because we don't know where b@l is and we don't know how many xxx there are on this list and et cetera.


session: F05-03
timestamp: 00:04:53.25
speaker: LOW
utterance:
because if there isn't a b@l in the list well I'm going to write it doesn't make sense because what we're going to do is we are going to say is remember there are two things here there is the info and there is a next.


session: F05-03
timestamp: 00:05:53.20
speaker: LOW
utterance:
so that is just that simple we're assuming there is a b@l in the list so xxx xxx so we'll exit the loop okay?


session: F05-03
timestamp: 00:06:14.00
speaker: LOW
utterance:
alright well t@l equals b@l and h@l one yeah all the info is not b@l yeah so it loops zero times we'll just leave it right there.


session: F05-03
timestamp: 00:06:29.18
speaker: LOW
utterance:
now we need to get a new node so let's +... how do you feel about constructors? do you think you can draw them?


session: F05-03
timestamp: 00:07:12.19
speaker: LOW
utterance:
so once we have found this guy we just get a new node so it is called a constructor xxx and we note the g@l in there.


session: F05-03
timestamp: 00:08:04.19
speaker: LOW
utterance:
is anybody else +... now don't put f@l +... it would be mistyped because this is supposed to be an address it's supposed to be the address for this whole node.


session: F05-03
timestamp: 00:08:28.22
speaker: LOW
utterance:
so what are we +... we're changing is this thing right here which is # next of t@l and we want to make a point here which is #


session: F05-03
timestamp: 00:08:47.12
speaker: LOW
utterance:
ok so it +... it was asymmetric here you are using the n@l next fields but here we have a pointer n@l and it is the right type next of t@l.


session: F05-03
timestamp: 00:08:56.07
speaker: LOW
utterance:
alright so that +... we made that a pointer the same thing as xxx xxx at first when we had this one xxx okay?


session: F05-03
timestamp: 00:09:09.01
speaker: LOW
utterance:
so we traveled the list until we found b@l and we did our surgery and we were careful about the ordering of the xxx.


session: F05-03
timestamp: 00:09:18.27
speaker: LOW
utterance:
you should always look for special cases +... well this would work if b@l was the last one on the list.


session: F05-03
timestamp: 00:09:32.29
speaker: LOW
utterance:
the next of n@l we copied over next of t@l this is the last one this will be the null holder you just copy it over.


session: F05-03
timestamp: 00:10:01.10
speaker: LOW
utterance:
some of these later ones have us do something with both lists one and two which is why we got two lists.


session: F05-03
timestamp: 00:10:17.00
speaker: LOW
utterance:
and see what you want to do +... you want to delete the node that contains a@l so what it is going to look like after you delete the a@l?


session: F05-03
timestamp: 00:10:31.12
speaker: LOW
utterance:
so just like heh this one the final picture is easy to draw, here the final picture is easy to draw now xxx xxx is how you can do it.


session: F05-03
timestamp: 00:10:40.01
speaker: LOW
utterance:
okay it is the same sort of +...oh by the way we get to assume there is an a@l in the list and if there isn't an a@l we can't delete the xxx xxx xxx xxx.


session: F05-03
timestamp: 00:12:09.02
speaker: LOW
utterance:
but this is easy to find I know what # you know, this is but the link +... to put +... I got to put one before which I've now passed by.


session: F05-03
timestamp: 00:12:18.17
speaker: LOW
utterance:
there is something called doubly linked lists where I store a pointer from this one to that one and I store a pointer back.


session: F05-03
timestamp: 00:12:28.19
speaker: LOW
utterance:
so we need to know what the node before a@l needs that is often the case when you're doing something with a linked list.


session: F05-03
timestamp: 00:12:36.19
speaker: LOW
utterance:
this was a simple one we just had to use one pointer we used to find d@l but here we need really a xxx is two pointers and we need to find a@l in order to find the ones before.


session: F05-03
timestamp: 00:12:48.01
speaker: LOW
utterance:
that is why less space so I'll have you use s@l is equal to null that would be our convention for initialization


session: F05-03
timestamp: 00:13:08.28
speaker: LOW
utterance:
this s@l is empty to begin with our null and if this is the a@l we can tell this is null by xxx xxx xxx implies this one #.


session: F05-03
timestamp: 00:13:28.10
speaker: LOW
utterance:
it is oh +... the picture is going to be +... suppose a long list s@l is going to follow behind t@l until t@l gets to a@l.


session: F05-03
timestamp: 00:14:07.03
speaker: LOW
utterance:
and now it is such a simple one we found it already but imagine there is a lot of xxx in here and just put an s@l where t@l was and then move the t@l forward so s@l is always right in front of t@l.


session: F05-03
timestamp: 00:14:55.09
speaker: LOW
utterance:
and then this +... nobody is pointing at this anymore that got destroyed so this is a piece of garbage.


session: F05-03
timestamp: 00:16:07.27
speaker: LOW
utterance:
uh by the way I'm putting in here just like with the link list you keep track of the list with a pointer to the first node.


session: F05-03
timestamp: 00:22:38.24
speaker: LOW
utterance:
so technically we have to find nine' s parent and then just have that parent point to his or her grandchild on this side.


session: F05-03
timestamp: 00:26:14.20
speaker: LOW
utterance:
likewise the smallest one over here wouldn't work (be)cause it is the smallest one so it could be the parent of these guys in the right tree.


session: F05-03
timestamp: 00:36:25.20
speaker: LOW
utterance:
so all they're saying is they don't want you to think this is the only binary search tree in the nodes.


session: F05-04
timestamp: 00:00:44.07
speaker: LOW
utterance:
in a linked list we lose the fact that they're physically together but we have a link that tells us what comes next.


session: F05-04
timestamp: 00:01:08.23
speaker: LOW
utterance:
which in this simple example is just a letter but it would be an employee's whole record or something like that or something really big.


session: F05-04
timestamp: 00:01:58.09
speaker: LOW
utterance:
we sort of draw (th)em like they're next to each other but in fact this one is the middle of memory.


session: F05-04
timestamp: 00:02:09.26
speaker: LOW
utterance:
and just to make, make the picture not be so wild but realize they don't need to be next to each other.


session: F05-04
timestamp: 00:02:28.23
speaker: LOW
utterance:
so the term we use for linked lists we use it for trees as well so you can use it for binary search trees maybe you've talked about.


session: F05-04
timestamp: 00:02:39.09
speaker: LOW
utterance:
+, you see the word travel in there or the root of travel in there so basically we're going to traverse or travel across the tree and do something as we go.


session: F05-04
timestamp: 00:03:25.13
speaker: LOW
utterance:
+, then nobody anywhere knows where this node is.[00:03:29.09]:*LOW: the only place to put the address of that node is stored right here.


session: F05-04
timestamp: 00:05:28.22
speaker: LOW
utterance:
alright so now we have found b@l now we are ready to do this surgery we'll cut a link here and put it up one.


session: F05-04
timestamp: 00:06:43.02
speaker: LOW
utterance:
what we're going to put there is not f@l that doesn't work because it is the wrong kind of thing # it is supposed to be a pointer.


session: F05-04
timestamp: 00:07:03.00
speaker: LOW
utterance:
that is one way yeah we said next of n@l so it +// because we want to put it there next of n@l is here next of t@l.


session: F05-04
timestamp: 00:07:25.21
speaker: LOW
utterance:
we've got a new node and put in after the one with b@l xxx xxx and we made a remark that those two are critical.


session: F05-04
timestamp: 00:07:31.17
speaker: LOW
utterance:
if we do this first what does the picture look like if we do this first and then make this guy point here.


session: F05-04
timestamp: 00:07:46.14
speaker: LOW
utterance:
and I can get me an infinite loop because now I can never find the end of the list because it is g@l, g@l, g@l.


session: F05-04
timestamp: 00:08:01.15
speaker: LOW
utterance:
number two # describe the sequence of operations to delete the node that contains a@l in this two [?].


session: F05-04
timestamp: 00:08:12.16
speaker: LOW
utterance:
well delete the node +// in the final picture +// always draw pictures for all these things when you're making lists or trees and so on.


session: F05-04
timestamp: 00:09:34.07
speaker: LOW
utterance:
if this was the a@l # the t@l would point there and s@l  would be null and if from that we could tell the xxx xxx xxx xx.


session: F05-04
timestamp: 00:09:50.02
speaker: LOW
utterance:
+< yeah before t@l advances so this becomes s@l and this becomes t@l ahem ahem and it is such a trivial example over there but in general if there is lots of things


session: F05-04
timestamp: 00:11:08.26
speaker: LOW
utterance:
let us +... number three # describe the sequence of operations to add list two to begin with list one.


session: F05-04
timestamp: 00:11:21.24
speaker: LOW
utterance:
+, well we know we have four in one list and three in the list and we know if we xxx there are seven in the list.


session: F05-04
timestamp: 00:11:38.04
speaker: LOW
utterance:
and maybe # you don't +// we're not worried about it but maybe h@l two is equal to null and there is only one list now and h@l two shouldn't point to the middle of the list anyway.


session: F05-04
timestamp: 00:11:46.10
speaker: 104
utterance:
so would you just set it +// when you actually get there will you set it equal to h@l two or would you set it equal +...


session: F05-04
timestamp: 00:11:59.06
speaker: LOW
utterance:
what I mean sort of won't +// it won't point to h@l two which will then point to this because you're h@l two is an address and it will have that address so yeah +...


session: F05-04
timestamp: 00:12:10.26
speaker: LOW
utterance:
so you see the you know +... in some sense it is trivial but, but, but, but how do we do this because all we have is h@l one we don't know where it fits.


session: F05-04
timestamp: 00:12:36.25
speaker: 104
utterance:
well you do something similar uh where you have uh a temporary pointer and a while loop that cycles through until it equals null and then you have +...


session: F05-04
timestamp: 00:12:47.23
speaker: LOW
utterance:
and that is what students often +// it is exactly what they do but when +// so I'm going to say t@l equals h@l one is started to here is a t@l.


session: F05-04
timestamp: 00:13:14.26
speaker: LOW
utterance:
we've got null so we move t@l over here, that is not null so we move t@l over so what is the problem with that?


session: F05-04
timestamp: 00:13:19.20
speaker: 104
utterance:
once +// if you don't have something else, another temporary pointer when t@l equals null # t@l equals null and not +...


session: F05-04
timestamp: 00:14:34.01
speaker: LOW
utterance:
just write or change that to an e@l if you wanted to and the t@l would point to the e@l and this would be null.


session: F05-04
timestamp: 00:15:27.15
speaker: LOW
utterance:
you want +// you want to +// you want to delete the first element +// you want to xxx xxx xxx just xxx h@l two is a list a@l followed by something, followed by something, followed by something, followed by something.


session: F05-04
timestamp: 00:16:07.23
speaker: LOW
utterance:
because we would find the a@l right away and s@l would still be null so we would be over here and so we set h@l two to next of t@l.


session: F05-04
timestamp: 00:16:22.15
speaker: LOW
utterance:
and those are the kind of special cases where a@l is first or a@l is the only element or a@l is last, would that be a problem?


session: F05-04
timestamp: 00:16:29.18
speaker: LOW
utterance:
if a@l is last # suppose we're suddenly deleting m@l # then our t@l would be here and our s@l would be here right?


session: F05-04
timestamp: 00:17:06.17
speaker: LOW
utterance:
s@l starts null and s@l takes this position and t@l goes there and then eventually # a step before the end this is there and t@l goes here.


session: F05-04
timestamp: 00:17:24.23
speaker: LOW
utterance:
we found # an easy way to find the last one is to use these two pointers # let t@l drop off and s@l is right behind it.


session: F05-04
timestamp: 00:17:47.22
speaker: LOW
utterance:
and then probably but I don't think they care we should say h@l two is equal to null just so it doesn't point to the middle of the list.


session: F05-04
timestamp: 00:18:11.20
speaker: LOW
utterance:
alright so uh # I'll help you if you need help but a couple of these are and a couple of these aren't binary search trees.


session: F05-04
timestamp: 00:19:14.07
speaker: LOW
utterance:
I don't know why they got a list over here because the simplest thing is the search and this list just puts it backwards.


session: F05-04
timestamp: 00:19:27.06
speaker: LOW
utterance:
now they don't even bother to point it out but just like a linked list the way you keep track of this tree is with a pointer to what you call the root.


session: F05-04
timestamp: 00:19:36.10
speaker: 104
utterance:
uh you check if it is +// if the next one +// if it's greater or equal to that one and then if it is less then you # use that pointer.


session: F05-04
timestamp: 00:21:20.05
speaker: LOW
utterance:
alright so that is basically +// that is the standard way to insert into a binary search tree and keep it in mind your search tree you do the search and if the search fails you put it there.


session: F05-04
timestamp: 00:21:29.25
speaker: LOW
utterance:
umm is there anything you +... question where it would go +// can you think of another that might bother you as to where it went?


session: F05-04
timestamp: 00:22:38.10
speaker: LOW
utterance:
so technically you're going to have to find the parent of that leaf and make this have a pointer going here.


session: F05-04
timestamp: 00:23:09.16
speaker: LOW
utterance:
anyway I can delete the nine and make this thing real easy if they say you know +` moving as few nodes as possible +`.


session: F05-04
timestamp: 00:23:24.28
speaker: LOW
utterance:
and that is the parent of your +// where it just points to his or her grandchild and there's only +// there's only +// nine only has one kid so there's only one grandchild.


session: F05-04
timestamp: 00:23:35.07
speaker: LOW
utterance:
and that +// that is very very simple surgery and # yeah it's still a binary search tree because all of these nodes were bigger than five to begin with they're still xxx.


session: F05-04
timestamp: 00:23:48.25
speaker: LOW
utterance:
alright and so you know # deleting eight would xxx if nine were still there and xxx to seven and there is five and xxx xxx xxx and deleting seven would xxx xxx.


session: F05-04
timestamp: 00:24:22.23
speaker: LOW
utterance:
uh the first thing probably you think of is well five has two kids could either of those kids move up and take five's place?


session: F05-04
timestamp: 00:24:36.05
speaker: LOW
utterance:
and uh it can't be two # I'm not quite sure # I mean it does the same problem over here # two has two kids


session: F05-04
timestamp: 00:24:48.18
speaker: LOW
utterance:
I can't move nine up because these guys are smaller than nine and they shouldn't be in the right subtree.


session: F05-04
timestamp: 00:24:53.08
speaker: LOW
utterance:
alright there's something on the left that could move up and there is something on the right that can move up # in order to take five's place.


session: F05-04
timestamp: 00:25:08.27
speaker: LOW
utterance:
the six could move up because +// well what +// what why +// you found (th)em +// what is the property of the six over here?


session: F05-04
timestamp: 00:25:13.29
speaker: 104
utterance:
it is less than all of these so these would stay on the right and it's also easy to move because it's a leaf.


session: F05-04
timestamp: 00:25:28.02
speaker: LOW
utterance:
and three is the biggest one on this side so it +// it is happy with them in this left subtree because it is bigger than them.


session: F05-04
timestamp: 00:25:37.12
speaker: LOW
utterance:
so in fact the biggest one on the right +// I'm sorry the smallest one on the right or the biggest one on the left.


session: F05-04
timestamp: 00:25:47.11
speaker: LOW
utterance:
I could have six and a half here and six and a quarter # and uh # six and three quarters and so on and so on and so on.


session: F05-04
timestamp: 00:26:03.02
speaker: LOW
utterance:
it can't be a tree on the left because if there were a tree on the left there would be something smaller.


session: F05-04
timestamp: 00:26:08.21
speaker: LOW
utterance:
so if we set six is the smallest on the right or three is the biggest on the left how do I find six in general?


session: F05-04
timestamp: 00:26:44.05
speaker: 104
utterance:
now I just have a quick question # the way the linked list had a next these have a left and a right?


session: F05-04
timestamp: 00:27:06.22
speaker: LOW
utterance:
so we are either +// if we're going to promote three or six in this case we're bringing up a leaf or we're bringing up a node with one kid.


session: F05-04
timestamp: 00:27:13.21
speaker: LOW
utterance:
and in general we have to write code xxx xxx for a pick up if we brought the six up of course, you just have to do this grandfather to grandson thing.


session: F05-04
timestamp: 00:27:34.11
speaker: LOW
utterance:
you found # the three and the six and xx from smallest to biggest and from biggest to smallest here and how to find most xxx in general which is once to the left and while is not null to the right as many times as possible.


session: F05-04
timestamp: 00:27:51.02
speaker: 104
utterance:
when you're actually writing the code for +// to do something like this # would you # have it find +// the one on the left and the one on the right and then have it choose which one is shorter?


session: F05-04
timestamp: 00:28:09.02
speaker: LOW
utterance:
this is called the info predecessor I look at these nodes in order it's one, two, three, five just to be there.


session: F05-04
timestamp: 00:28:26.29
speaker: LOW
utterance:
uh # yeah most people don't find both of them and then study which one is the easier to move because it's the fact that it's real simple to move +// if I haul this this way I'd have to do that surgery before I bring that up and it's probably faster to do than xxx xxx.


session: F05-04
timestamp: 00:28:48.07
speaker: LOW
utterance:
uh let's talk quickly about stacks they didn't give us any problems but uh we can make up our own that's real simple.


session: F05-04
timestamp: 00:29:01.13
speaker: LOW
utterance:
the name comes from a stack of trays in a cafeteria where all you're politely supposed to do is take the top one off.


session: F05-04
timestamp: 00:29:17.21
speaker: LOW
utterance:
so there's a spring down here that uh +// as these things +// located +// so you can't see if there are five elements in the stack all you can see is this top element.


session: F05-04
timestamp: 00:29:27.27
speaker: LOW
utterance:
and of course if you # pop it off +// the spring pops off it pushes the p@l to the top and xxx xxx xxx xxx.


session: F05-04
timestamp: 00:29:51.11
speaker: LOW
utterance:
uh the insert is called a push # and these come from the spring popping this thing up and the spring pushing down and you push on the stack some value n@l.


session: F05-04
timestamp: 00:30:03.13
speaker: LOW
utterance:
so this is a function that returns what popped off and that's a void function that takes the thing to make it come off.


session: F05-04
timestamp: 00:30:18.16
speaker: LOW
utterance:
which returns the q@l # but doesn't take it off this way so this is destructive and this is not destructive.


session: F05-04
timestamp: 00:30:34.01
speaker: LOW
utterance:
um so there's a quick example let's count +// write a function that counts the number of xxx make sure it's all in the xxx list.


session: F05-04
timestamp: 00:30:58.06
speaker: LOW
utterance:
alrighty so I guess we better set a counter equal to zero and then we'll use some sort of while loop.


session: F05-04
timestamp: 00:31:12.26
speaker: LOW
utterance:
+< yeah well s@l is not empty we assume there's some way which there is to tell if the stack is empty or not.


session: F05-04
timestamp: 00:31:40.05
speaker: LOW
utterance:
and I guess in some sense # now way out here we can return xxx xxx xxx xxx a function that returns xxx.


session: F05-04
timestamp: 00:31:50.08
speaker: LOW
utterance:
and # I guess that's technically +// based on what I said that is all we need but we'll change that in a second so while this isn't empty we pop it and count it so one, two, three, four, five.


session: F05-04
timestamp: 00:33:46.28
speaker: LOW
utterance:
once that whole while loop is done we just do a while loop that's popping through t@l and pushing on s@l.


session: F05-04
timestamp: 00:34:00.18
speaker: LOW
utterance:
uh # let's check with Davide because I forgot to check what time we actually started okay I think we're at about time.


session: F05-04
timestamp: 00:34:42.27
speaker: LOW
utterance:
rearrange the nodes on the binary search tree to create another tree which is also a binary search tree so they want a different binary search tree for those nodes.


session: F05-04
timestamp: 00:34:51.00
speaker: LOW
utterance:
uh I think the point they're trying to make here is that you know that isn't the only tree you could have with those uh nodes.


session: F05-04
timestamp: 00:36:05.14
speaker: LOW
utterance:
now it's not the case # that +// look at the numbers here it's not a seven factorial difference +// trees because uh # it doesn't really matter where the one comes in this order after two.


session: F05-04
timestamp: 00:36:45.24
speaker: LOW
utterance:
usually when we talk about stacks you're also talking about queues and it's easy to just uh you know +// a printer queue is a real obvious example.


session: F05-04
timestamp: 00:36:55.16
speaker: LOW
utterance:
uh but use stacks for example if you're evaluating expressions so uh # have you heard of the verse xxx notation or anything?


session: F05-04
timestamp: 00:37:12.28
speaker: LOW
utterance:
you enter the three then you enter the five you hit the plus button it gives you eight and then you uh suppose you multiply four times that thing and then somehow you got thirty-two I hope, right?


session: F05-04
timestamp: 00:37:33.19
speaker: LOW
utterance:
when you see a number +// so we're going +// we're going to evaluate this thing in one path across here okay?


session: F05-04
timestamp: 00:38:08.22
speaker: LOW
utterance:
so we get the five and the three and you add three and five so we pop these two off # we add # push the result back on okay?


session: F05-04
timestamp: 00:38:27.20
speaker: LOW
utterance:
we pop off the subtraction which is thirty-two minus seven yeah so we # we have evaluated that expression just by going through there but uh let me do one more where we got two and three and five and then we got plus then we got times.


session: F05-05
timestamp: 00:00:02.23
speaker: LOW
utterance:
let's move the desk # so basically we got some linked lists, and binary search tree, and some stack problems to discuss.


session: F05-05
timestamp: 00:00:16.05
speaker: LOW
utterance:
a quick review # all you have is a pointer to the first node right so each one # and you can't +// you don't know how many there are really and all right so the first node has two fields the info field which is in this case just c@l and the next there's the second one and then the third one and the fourth one and we mark the last one with a null point.


session: F05-05
timestamp: 00:00:46.20
speaker: LOW
utterance:
uh describe the sequence of operations to insert a new node after the node which contains +// a new node with g@l after the node which contains b@l okay?


session: F05-05
timestamp: 00:01:02.03
speaker: LOW
utterance:
let's take a new node with g@l in it # and uh let's change this link so you know there's the done picture # right there's the completed picture?


session: F05-05
timestamp: 00:01:11.20
speaker: LOW
utterance:
now but I wanted to show you +// it's a little bit subtle because I intentionally did this first I scratched this off and if I do that # change this pointer so it points to my new node and nobody knows where this node is.


session: F05-05
timestamp: 00:01:31.02
speaker: LOW
utterance:
so let's talk about +// well so that's the final picture but how do we get there so let's describe the operations to get there.


session: F05-05
timestamp: 00:01:51.04
speaker: LOW
utterance:
um and they say we use a temporary pointer t@l so here's how we set our traversal up we set uh t@l equal to h@l one # that's how you know anything about the list so in the picture t@l looks like this.


session: F05-05
timestamp: 00:02:37.26
speaker: LOW
utterance:
and what do we want to do +// okay so let's you know t@l # info t@l is not b@l so what do we want to do in the root?


session: F05-05
timestamp: 00:03:07.06
speaker: LOW
utterance:
exactly and that's +// we're not going to bother with the beginning, ends, the braces, or the while it's just xxx but that's all that goes in there, alright?


session: F05-05
timestamp: 00:03:18.22
speaker: LOW
utterance:
okay so that's the first part of this problem is to find the node that contains b@l and now we get a new node with g@l in it so let's suppose that's outside the loop so let's call the constructor the new node # with a g@l in it and return this address uh let's call it n@l.


session: F05-05
timestamp: 00:03:41.16
speaker: LOW
utterance:
new node # okay so we're going to picture like this +// I guess that's preferably null but they didn't specify so we can change it later.


session: F05-05
timestamp: 00:03:52.22
speaker: LOW
utterance:
okay # so now we have found the node b@l and now we're doing this little surgery so we just have to change a couple pointers but we discussed in the beginning we don't want to do this first so this is the one we're going to do first # not this one.


session: F05-05
timestamp: 00:04:30.18
speaker: LOW
utterance:
yeah great because uh sometimes dudes want to say f@l but no it's the wrong type it's the whole node yeah so it's t@l dot next.


session: F05-05
timestamp: 00:04:41.12
speaker: LOW
utterance:
okay and that's step number one and then we do step number two # which is make b@l point to g@l # make this node point to that node.


session: F05-05
timestamp: 00:05:05.12
speaker: LOW
utterance:
that's +// you're going to change this field right here # you know that's not t@l you don't want t@l pointing to that # this next portion right here.


session: F05-05
timestamp: 00:06:12.29
speaker: LOW
utterance:
so we'll start the same way # t@l here at equal h@l two # leave a space, while t@l info is not equal to a@l.


session: F05-05
timestamp: 00:06:31.07
speaker: LOW
utterance:
we'll do a t@l is t@l dot next # all right so that's not the a@l so move t@l over here, that is the a@l so just like we did up here we found b@l and we just found a@l.


session: F05-05
timestamp: 00:07:39.27
speaker: LOW
utterance:
so in my picture I'll put s@l over here # so I'm going to initialize t@l to h@l two and s@l equal to null # and we'll talk about it in a minute but hey that might be the a@l.


session: F05-05
timestamp: 00:07:54.11
speaker: LOW
utterance:
here's the idea as I move +// I move across # like this so whenever t@l gets here, s@l will be right behind it.


session: F05-05
timestamp: 00:08:24.28
speaker: LOW
utterance:
that's a very simple list so we're there already but you can see how if it was going to be a long list s@l would follow right behind t@l and now it's real easy to do the surgery because what changes it is this guy right here which is +...


session: F05-05
timestamp: 00:09:05.17
speaker: LOW
utterance:
here we found a@l but we needed the node before +// oh here's a problem # we should always look for special cases let's go back here.


session: F05-05
timestamp: 00:09:20.01
speaker: LOW
utterance:
if this was null to begin with # well we would still find b@l in the same way # and now we still get a new node and here's the question would this work g@l next equal t@l next?


session: F05-05
timestamp: 00:09:48.04
speaker: LOW
utterance:
the t@l is equal to h@l one it's already equal to b@l so it just comes up yeah so there's really no special cases there.


session: F05-05
timestamp: 00:10:01.04
speaker: LOW
utterance:
if a@l was the last element then this would be null but that's what we just copied in t@l next would be null.


session: F05-05
timestamp: 00:10:10.20
speaker: LOW
utterance:
so let's +// maybe you'll change you mind but we're trying to delete the e@l so the picture +// let me get a pencil here +// the picture would be t@l would stop here and this would be null.


session: F05-05
timestamp: 00:10:42.06
speaker: LOW
utterance:
yeah # right so h@l two would point at the a@l so we need a little if here um # if s@l is not null # then we can do that.


session: F05-05
timestamp: 00:12:03.22
speaker: LOW
utterance:
a list of four elements and a list of three elements # they want us to have a list of seven elements, right?


session: F05-05
timestamp: 00:12:29.23
speaker: LOW
utterance:
all we got is this pointer here # we got to find the last node so let's start off and see if we need how many pointers do we need # let's start off with temporary t@l.


session: F05-05
timestamp: 00:13:27.05
speaker: LOW
utterance:
so t@l falls off # the edge of the earth or whatever and this +// because you say while t@l is not null you keep +...


session: F05-05
timestamp: 00:13:39.20
speaker: LOW
utterance:
yeah alright # so students often want to look at t@l dot next but if you look at t@l dot next it doesn't work for an empty list because t@l is +// if the list is empty then t@l is null and you can't say t@l dot next # you get into +// you get into problems.


session: F05-05
timestamp: 00:13:54.28
speaker: LOW
utterance:
so that would work but you have to watch for special care so let's use two pointers again # let's do the same thing we did before # let's put t@l one equal h@l # h@l two, h@l one and s@l equal to null.


session: F05-05
timestamp: 00:14:09.29
speaker: LOW
utterance:
and now same thing as before while t@l is not null # we'll just move the pair forward # s@l behind t@l again so what do I say here?


session: F05-05
timestamp: 00:14:22.28
speaker: LOW
utterance:
okay so # that's not null so +// that's s@l +// t@l # then this moves here and t@l moves here # and s@l moves here and t@l moves here # s@l moves here and t@l dies.


session: F05-05
timestamp: 00:14:38.29
speaker: LOW
utterance:
that's # a very safe way to uh find the last one # you can say while t@l dot next ain't null but it won't work on an empty list.


session: F05-05
timestamp: 00:14:50.26
speaker: LOW
utterance:
alright so on all these things we have done some sort of traversal # and then we do some sort of surgery like the surgery for the xx right here.


session: F05-05
timestamp: 00:15:10.00
speaker: LOW
utterance:
right # and they don't mention it or anything but we should probably say h@l two equals null because we don't know a pointer to the middle of the list # we had two lists now we've xxx them together and only have one list +// they don't care about that xxx but uh for purity's sake.


session: F05-05
timestamp: 00:15:28.15
speaker: LOW
utterance:
okay # this is good we don't have any special cases we have to worry about uh if # we found the last element +// suppose this list is empty.


session: F05-05
timestamp: 00:15:56.07
speaker: LOW
utterance:
uh if the first list is empty what do you get when you # could xxx xxx +// we should have some kind of if here.


session: F05-05
timestamp: 00:16:04.19
speaker: LOW
utterance:
if s@l isn't null # then we can do that # and this we really don't need inside we should pull it out of the whole thing and put it down here at the bottom.


session: F05-05
timestamp: 00:16:19.07
speaker: LOW
utterance:
else if s@l is emtpy # if s@l is null # uh well actually there's two cases we're dealing with here # I guess if s@l is empty +// that's actually if t@l is empty +// (be)cause if the list is empty +...


session: F05-05
timestamp: 00:16:40.28
speaker: LOW
utterance:
um alright # if s@l is null # we know +// t@l is null xxx t@l is xxx xxx +// I guess we need another if that's xxx.


session: F05-05
timestamp: 00:16:57.05
speaker: LOW
utterance:
alright let me see if I can explain this to you # if s@l is null that means one of two things:  t@l is also null because there's no list or +// or t@l is # it's either while or no while # h@l one is empty or h@l one points to a single element.


session: F05-05
timestamp: 00:17:19.16
speaker: LOW
utterance:
in either of those cases s@l is null right # uh in this case t@l is also null +// s@l and t@l are both null # in this case t@l points to a single element.


session: F05-05
timestamp: 00:17:32.03
speaker: LOW
utterance:
if um +// in this case that h@l one is empty # what do I get if I glue h@l two to the end of h@l one?


session: F05-05
timestamp: 00:17:48.24
speaker: LOW
utterance:
if this has just one element +// if s@l is empty but t@l is not and of course we can go ahead and do what we did +// oh I'm sorry +// no there isn't a special case.


session: F05-05
timestamp: 00:18:05.16
speaker: LOW
utterance:
if there's one element s@l is going to be here and t@l is going to be empty so that's not what you want so there is another special case so if s@l is null and the list was empty # well what we should do is just say h@l one equals xxx xxx xxx, okay?


session: F05-05
timestamp: 00:18:21.05
speaker: LOW
utterance:
because then I would have had an empty list and this list +// I messed it up again # sorry about that.


session: F05-05
timestamp: 00:18:39.12
speaker: LOW
utterance:
okay alright well we'll get there so I guess two of these are and two of these aren't binary search trees # can you spot the ones that aren't?


session: F05-05
timestamp: 00:19:04.28
speaker: LOW
utterance:
right in fact this one is totally reversed so starting with this one which is uh # the property is everything to the left has to be less and everything right has to be greater # at every node.


session: F05-05
timestamp: 00:19:16.02
speaker: LOW
utterance:
so eleven +// this is less # that's bigger so uh about one of these is, one of these isn't # you see the +// I wish there were a symbol here uh a xxx or xx.


session: F05-05
timestamp: 00:19:40.24
speaker: LOW
utterance:
but this one is okay # eleven is less than twelve # eleven is bigger than all these guys # seven is less +// bigger than these guys and less than this guy # this one is okay.


session: F05-05
timestamp: 00:19:55.01
speaker: LOW
utterance:
&=cough okay # then they give us this binary search tree # which I have drawn over and they +// basically they ask us to do insertions and deletions and uh searches # well how +// why the heck is the questions in this order (be)cause search is easiest and insertion is next easiest and deletion is the hardest so let's sort of do (th)em backwards.


session: F05-05
timestamp: 00:20:20.07
speaker: LOW
utterance:
so all you're given +// they don't show it in the picture by the way, but all you're given is a pointer to the root, okay?


session: F05-05
timestamp: 00:20:54.02
speaker: LOW
utterance:
we didn't even do anything with the left subtree (be)cause we threw it all away # we went this way, alright.


session: F05-05
timestamp: 00:21:20.08
speaker: LOW
utterance:
alright # and then backing up they have us insert six +// they have us insert three different ways it's crazy let's just insert in a standard way.


session: F05-05
timestamp: 00:21:49.25
speaker: LOW
utterance:
and go left again and this is empty so it's right here so put it right there and that's the standard way to insert.


session: F05-05
timestamp: 00:21:57.29
speaker: LOW
utterance:
uh # do you feel good about that or do you think +// do you think of a number that you aren't sure where it would go?


session: F05-05
timestamp: 00:22:09.19
speaker: LOW
utterance:
we already have eight # so that's +// let's use a +// let's avoid duplicates just to keep out of things.


session: F05-05
timestamp: 00:22:37.23
speaker: LOW
utterance:
okay I think you get that idea uh alright so search is really simple we throw away half the tree each time which is what makes it efficient.


session: F05-05
timestamp: 00:22:57.14
speaker: LOW
utterance:
the trivial case they ask about is uh a node with no kids # they call that a leaf so deleting a leaf is really easy.


session: F05-05
timestamp: 00:23:18.13
speaker: LOW
utterance:
a leaf is really easy # deleting a node with only one kid # is pretty easy but not quite as easy and then the tough one is deleting a node with two kids.


session: F05-05
timestamp: 00:23:28.27
speaker: LOW
utterance:
so how do we complete +// well we want to delete nine and keep this thing to be a binary search tree and move as few things around as possible.


session: F05-05
timestamp: 00:23:44.13
speaker: LOW
utterance:
obviously you're going to take one node out # we've got seven nodes +// one, two, three, four, five, six, seven, eight nodes right now and we're going to lose a node.


session: F05-05
timestamp: 00:24:03.26
speaker: 105
utterance:
then # and then +// so this will point to # wait +// I started +// start going right and go over here and # should go to that?


session: F05-05
timestamp: 00:24:22.21
speaker: LOW
utterance:
so you've got sort of two pointers # this is your target or wherever you found your nine and you know its parent.


session: F05-05
timestamp: 00:24:43.07
speaker: LOW
utterance:
its only got one kid # so they're not really concerned here as much about xxx as understanding how to do it # picture wise let's think about the picture.


session: F05-05
timestamp: 00:24:54.08
speaker: LOW
utterance:
do you see a way to redraw the tree without nine in it that's real easy so it's still a binary search tree?


session: F05-05
timestamp: 00:25:04.07
speaker: LOW
utterance:
+< well okay we're assuming right now +// we're assuming that it doesn't have a xxx subtree # it only has one kid.


session: F05-05
timestamp: 00:25:10.09
speaker: LOW
utterance:
so this case +// this case zero let's call it # the trivial case which is a leaf which we've already talked about is a case one kid okay # case one and so something like nine has only one kid.


session: F05-05
timestamp: 00:25:25.18
speaker: LOW
utterance:
yeah sort of s@l its got left and right so s@l dot right is s@l dot left (be)cause its got only one tree here so yeah we just skip that # generation here.


session: F05-05
timestamp: 00:25:35.19
speaker: LOW
utterance:
so basically in terms of family tree sort of things this is the parent of that node and this guy # this points to his or her grandchild since this has only one kid there's only one grandchild on that side so it's easy to do.


session: F05-05
timestamp: 00:25:49.04
speaker: LOW
utterance:
yeah so it's minimal fuss we just change one pointer here and make it go to the grandchild and skip that generation and it's still a binary search tree (be)cause all of these things are bigger than five and +// so that's easy.


session: F05-05
timestamp: 00:26:32.26
speaker: LOW
utterance:
alright now let's look at a tough one # they say +// they say delete the node that contains five which has two kids.


session: F05-05
timestamp: 00:26:56.01
speaker: LOW
utterance:
it's not really hard because it's the root # it's hard because it's got two subtrees # two would be just as hard.


session: F05-05
timestamp: 00:27:02.01
speaker: LOW
utterance:
okay # well the +// so what I'm going to try to do is with as little muss and fuss as possible is I'm going to delete the five # we're going to try and find something else to put in here that could be the root of this tree.


session: F05-05
timestamp: 00:27:21.09
speaker: LOW
utterance:
uh # yeah I don't quite know what it means to +// I'm going to try to move two up there but two also has two kids and nine might have two kids # it would be a real mess.


session: F05-05
timestamp: 00:27:38.23
speaker: LOW
utterance:
and nine can't go up there (be)cause these guys are smaller than nine and they can't be in the right subtree.


session: F05-05
timestamp: 00:27:43.23
speaker: LOW
utterance:
but here's the cool thing there is something in this left tree that could go up there and there's one node in the left tree and there's one node in the right tree.


session: F05-05
timestamp: 00:28:30.05
speaker: LOW
utterance:
alright so by moving three up # it would work because it's the biggest one on this side so it's bigger than all these guys so they'd be in the left tree.


session: F05-05
timestamp: 00:28:38.29
speaker: LOW
utterance:
three is already in the left tree of five # three is already smaller than five so of course it's smaller than all those guys okay?


session: F05-05
timestamp: 00:28:44.16
speaker: LOW
utterance:
likewise six could come up and these guys would be happy (be)cause they're all bigger than six and these guys would be happy (be)cause they're all less than five therefore they're less than six okay?


session: F05-05
timestamp: 00:28:53.24
speaker: LOW
utterance:
so those are the two candidates to come up # the biggest one on the left or the smallest one on the right.


session: F05-05
timestamp: 00:29:05.01
speaker: LOW
utterance:
how could you find +// this is pretty deep down in there uh by the way they're both leaves as we have them.


session: F05-05
timestamp: 00:29:19.00
speaker: LOW
utterance:
it's bigger than five, less, less, less, bigger # but six is still the smallest but this guy can't have two kids # because if it had a left kid that kid would be smaller than this right and this is the smallest one so this has to be null and this one can't have a right kid (be)cause if it did have a right kid it would be four or whatever # it would be bigger right?


session: F05-05
timestamp: 00:30:13.19
speaker: LOW
utterance:
so now you sort of know how to find these guys and it doesn't matter which one you move up uh if you choose to move the six up you'd have to do this grandchild type of surgery here and then you could put the six to this spot okay but that would be pretty simple.


session: F05-05
timestamp: 00:30:34.12
speaker: LOW
utterance:
you find either the biggest one on the left or the smallest one on the right and bring it up and that doesn't cause another node with two kids to be deleted # the thing you're bringing up is either a leaf or a node with one kid because once again it can't +// this one can't have a right child because you went as far right as you could.


session: F05-05
timestamp: 00:31:06.12
speaker: LOW
utterance:
so we did it in this order # we searched (be)cause that was easy then we inserted (be)cause that was search and then insert when we find the spot then we talked about deletion and a hard one.


session: F05-05
timestamp: 00:31:15.11
speaker: LOW
utterance:
uh so here I think they just want you to see that there are many other binary search trees you can make up with those nodes # that's not the only one and here's the easiest way to do that I guess # is just give me those numbers in any order you want # just what's your favorite number among those number?


session: F05-05
timestamp: 00:31:44.10
speaker: LOW
utterance:
nine okay so let's just build a binary search tree with those values in that order so I'll make two the root and we'll insert three # where does it go?


session: F05-05
timestamp: 00:32:13.09
speaker: LOW
utterance:
okay # and then one is going over here and then nine is over there okay so there's another tree +// did I leave something out?


session: F05-05
timestamp: 00:32:30.26
speaker: LOW
utterance:
now not every arrangement makes up a different tree # if you invert the order of these two for example it won't make any difference.


session: F05-05
timestamp: 00:33:20.15
speaker: LOW
utterance:
the way I like to describe it is you get this very very fancy stack of trays and the only thing you can see is the one tray at the top.


session: F05-05
timestamp: 00:33:29.08
speaker: LOW
utterance:
so this container only let's you see the red tray you want is down in there and you got to take that stained purple one on the top of it.


session: F05-05
timestamp: 00:33:35.20
speaker: LOW
utterance:
and when you take a tray off the spring down here is so carefully loaded +// it's so precisely loaded that it pops one more tray up.


session: F05-05
timestamp: 00:33:43.16
speaker: LOW
utterance:
when you look at this you can't tell how many trays are in there you can just see there's one tray on top.


session: F05-05
timestamp: 00:33:50.18
speaker: LOW
utterance:
when you take a tray off it it might suddenly be empty but normally it pops up another of course somebody one at at time pushes so the operations here are pop.


session: F05-05
timestamp: 00:34:12.21
speaker: LOW
utterance:
there's two operations: you can pop the stack s@l and that will return the value that's on top +// it'll take it off.


session: F05-05
timestamp: 00:34:23.01
speaker: LOW
utterance:
and I +// it's called pop the spring pops up alright and the other operation you can use is push # I guess that's a procedure or function # you tell it what you want to put on here and you say s@l and xxx so that would push something on that stack.


session: F05-05
timestamp: 00:34:39.04
speaker: LOW
utterance:
uh and then they give you another one # they give you the top of the stack and this is what I often call peak.


session: F05-05
timestamp: 00:34:53.13
speaker: LOW
utterance:
it doesn't destroy the stack okay so if I top the stack I just keep getting ping ping ping ping okay it doesn't +// if I pop the stack I get p@l.


session: F05-05
timestamp: 00:35:52.04
speaker: LOW
utterance:
value equals pop s@l and of course I will increment the counter and from what I've said that technically works right I guess I said that was a function so I should return counter to bottom (be)cause that's going to be pop one, pop two, pop three, pop four, pop five, return five but what's the problem with like that?


session: F05-05
timestamp: 00:36:31.22
speaker: LOW
utterance:
right so you destroyed the stack so it counts the number of elements in s@l and if you mess with it restore the stack back to what it was okay so we've got to keep these things on.


session: F05-05
timestamp: 00:37:58.24
speaker: LOW
utterance:
now p@l is on the bottom so that really +// we shouldn't do that but we did save (th)em in a stack so how can +...


session: F05-05
timestamp: 00:38:23.10
speaker: LOW
utterance:
+, yeah we destroyed s@l to get the value then we had to restore it and we couldn't restore it just by assigning it the map we had to pop it back xxx.


session: F05-05
timestamp: 00:38:44.04
speaker: LOW
utterance:
yeah whatever you have an element type here so it's a stack of element types # anything you want it to be but here there's no pointer.


session: F05-06
timestamp: 00:00:05.14
speaker: JAC
utterance:
start a big list and basically each  <if you consider> [//]  call each of these a node, okay, each node only knows about the next node.


session: F05-06
timestamp: 00:00:54.14
speaker: JAC
utterance:
um so <if we want to insert something such as here> [//] if we want to insert a new node containing g@1, and we want to insert after b@1, we need to be careful how we insert it.


session: F05-06
timestamp: 00:01:23.02
speaker: JAC
utterance:
it would just +// you wouldn't have anything that points to f@l, so there's no way for you to find f@1 xxx.


session: F05-06
timestamp: 00:01:30.00
speaker: JAC
utterance:
so if we were to insert g@l, and we want to insert f@l to b@l, the first thing that we do is draw it in here.


session: F05-06
timestamp: 00:01:48.15
speaker: JAC
utterance:
first thing we would do is we would <check the> [//] find what it's pointing to, which is f@1, and we would set that equal to this.


session: F05-06
timestamp: 00:02:48.06
speaker: JAC
utterance:
let's see which points to # *uh k@l, k@l which points to # b@l, and I'm just going to xx the original, okay.


session: F05-06
timestamp: 00:03:24.08
speaker: JAC
utterance:
we want to delete f@l but what we'll come through and do is we'll go through and we'll <find out> [//] xxx keep going through, we'll eventually find f@l.


session: F05-06
timestamp: 00:03:54.13
speaker: JAC
utterance:
so <we set> [//] we would set # <we would set, we would set # b@l> [//] we would point b@l to null and delete f@l.


session: F05-06
timestamp: 00:04:13.24
speaker: JAC
utterance:
okay so we don't' know it's position until we get xxx, and we set, and we point here first and then delete f@l.


session: F05-06
timestamp: 00:04:23.27
speaker: JAC
utterance:
um depending on how you do this problematically you might make a copy of b@l and have b@l pointing to null and then +...


session: F05-06
timestamp: 00:04:41.02
speaker: JAC
utterance:
so it's better [///] theres a couple different ways to do it the best way is just basically point it to null and delete f@l.


session: F05-06
timestamp: 00:05:26.02
speaker: JAC
utterance:
okay if we delete a@l what we would do is we'd find e@l points to a@l okay and then we'd find a@l points to f@l.


session: F05-06
timestamp: 00:06:23.26
speaker: JAC
utterance:
a list of the two classes and your putting the class of students from one class and a class of students from another class or xxx from c@l programming and you want to merge the two together then lets say those three names are in this list and you want to merge this list because of whatever reason.


session: F05-06
timestamp: 00:07:23.23
speaker: JAC
utterance:
okay and <what we want> [/] what we want to do is we're going to add list two, which is this one here into list one after the node k@l.


session: F05-06
timestamp: 00:07:53.05
speaker: JAC
utterance:
so the first thing we're going to do is 0 [=writes letters] h@l two, b@l, a@l, f@l, and it points to null okay so we want to insert after k@l.


session: F05-06
timestamp: 00:09:57.13
speaker: JAC
utterance:
so then the result would be this h@l one, which was the head of the first list points to c@l which points to k@l which now points to e@l.


session: F05-06
timestamp: 00:10:17.20
speaker: JAC
utterance:
it's always pointing to a@l which points to f@l, which m@l now points to e@l, and b@l points to f@l, and f@l points to null.


session: F05-06
timestamp: 00:11:14.25
speaker: JAC
utterance:
so what we would do is we come in make the new node, and we would make m@l point to our new node, lets call it z@l.


session: F05-06
timestamp: 00:12:26.17
speaker: JAC
utterance:
okay so why don't we take our list and it's currently in the order e@l a@l m@l and we want to make it m@l e@l a@l.


session: F05-06
timestamp: 00:13:02.29
speaker: JAC
utterance:
so <we go back> [/] we go back to the head, and we find out what the head is pointing to, cause we can always reference the head.


session: F05-06
timestamp: 00:13:46.24
speaker: JAC
utterance:
um so then we have <e@l pointing to m@l> [//] Im sorry m@l pointing to e@l, and we need to get [///] um, we have e@l already pointing to a@l.


session: F05-06
timestamp: 00:14:07.18
speaker: JAC
utterance:
so we'll start at the head and we go and we find e@l and we find a@l and now a@l is pointing to m@l.


session: F05-06
timestamp: 00:15:06.04
speaker: JAC
utterance:
so now if we go through we find e@l points to a@l and then a@l points to m@l +// or a@l rather xxx pointing to m@l.


session: F05-06
timestamp: 00:15:15.14
speaker: JAC
utterance:
so right now we have the head which points to m@l, m@l which points to e@l, which points to a@l, which right now points back to m@l.


session: F05-06
timestamp: 00:20:12.12
speaker: JAC
utterance:
now what we're going to do is <we're going to take> [//] we're going to see what c@l is pointing at.


session: F05-06
timestamp: 00:20:19.24
speaker: JAC
utterance:
we know c@l is going to be pointing at a@l, because <we're always> [/] we're always inserting it in front of what we're going to switch.


session: F05-06
timestamp: 00:20:48.09
speaker: JAC
utterance:
we're looking to see what a@l points to and then we look to see what or we look at what c@l points to, c@l is pointing to a@l so we know what a@l is pointing to a@l is pointing to m@l.


session: F05-06
timestamp: 00:23:29.10
speaker: JAC
utterance:
it's <kind of like a link> [//] kind of like the same thing like a link list except we can only [//] we'll only be able to call of what the top is.


session: F05-06
timestamp: 00:24:22.25
speaker: JAC
utterance:
and there is a method called pop, which is the opposite of push and pulls whatever is currently on top of the stack.


session: F05-06
timestamp: 00:25:39.01
speaker: JAC
utterance:
a lot of different computer operations are based on the whole premise of the stack, memory, allocation, xxx.


session: F05-06
timestamp: 00:26:25.29
speaker: JAC
utterance:
usually if your using numbers or if your using strings you'd have to compare and see which one is less than your node, and which one is greater than your node.


session: F05-06
timestamp: 00:27:01.06
speaker: JAC
utterance:
okay, we have a standard format so that anytime we use a tree anywhere, everyone knows exactly how it works.


session: F05-06
timestamp: 00:27:19.02
speaker: JAC
utterance:
so, we call this the top of the tree, but if you think about it, lets consider this the root and this the branched of the tree spreading out, right?


session: F05-06
timestamp: 00:28:03.05
speaker: JAC
utterance:
the right child is always greater than it's parent, and the left child is always less than it's parent. JAC:	okay?


session: F05-06
timestamp: 00:28:11.07
speaker: JAC
utterance:
so now if we come down here to four, which is seven's left child, now four, if we think of it like a family tree, four can have children too.


session: F05-06
timestamp: 00:28:33.00
speaker: JAC
utterance:
if we come here and look at seven's right child, it's eleven, which is greater than seven, we look at twelve, it's xxx, we look at eleven's right child, it's twelve.


session: F05-06
timestamp: 00:28:53.04
speaker: JAC
utterance:
so based on the premise, based on the original question asked, <which leaves> [//] which of the following of our binary search tress?


session: F05-06
timestamp: 00:32:13.25
speaker: 106
utterance:
would that be the same general idea as if we want to go over here and find out where nines pointing to and then point to five?


session: F05-06
timestamp: 00:33:20.05
speaker: JAC
utterance:
<we consider this if we look at this is> [//] if we were to ignore everything else, this looks like it could just xxx.


session: F05-06
timestamp: 00:33:29.24
speaker: JAC
utterance:
okay, because as far as it's concerned right now nothing else xxx [///] it's being pointed to by something the head.


session: F05-06
timestamp: 00:33:42.11
speaker: JAC
utterance:
so we always look at the right child and then we find the left most child after we find the right child.


session: F05-06
timestamp: 00:35:05.09
speaker: JAC
utterance:
so it becomes [///] we delete five, seven comes here, <seven points> [//] we make seven point to <whatever five is pointing to> [//] whichever five is pointing to, so make it point to two.


session: F05-06
timestamp: 00:36:39.27
speaker: JAC
utterance:
if we want to insert six in here, # there's a couple different types of inserts but I'm going to focus on the typical one # and seven, okay.


session: F05-06
timestamp: 00:38:33.20
speaker: JAC
utterance:
*uh lets go if we want to do search [///] searching for eight is almost the same thing as when you insert and compare eight to five.


session: F05-06
timestamp: 00:40:10.20
speaker: JAC
utterance:
it says rearrange the nodes in a given binary search tree to create another tree which also says xxx.


session: F05-06
timestamp: 00:40:16.07
speaker: JAC
utterance:
so if we just start by reordering the list and make seven five is less then seven three is less than seven.


session: F05-06
timestamp: 00:40:43.29
speaker: JAC
utterance:
one [///] now this is an xxx tree cause you don't ever want to have something like this where it's all straight down you want to have +...


session: F05-06
timestamp: 00:41:43.15
speaker: JAC
utterance:
if we consider this depth zero, this depth one, this depth two, I never have to go further than depth two to find something.


session: F05-06
timestamp: 00:42:04.24
speaker: JAC
utterance:
always two decisions so either go to eight, or two more decisions, and we find everything within two attempts.


session: F05-07
timestamp: 00:00:03.16
speaker: JAC
utterance:
okay um now basically what a stack is +// you think of it as a physical item # it's like a +// it's like a stack of Legos.


session: F05-07
timestamp: 00:00:32.20
speaker: JAC
utterance:
then we want to push or put on another Lego or another item onto the stack so we put +// we push b@l onto the stack or we put our b@l Lego right?


session: F05-07
timestamp: 00:01:03.25
speaker: JAC
utterance:
this is the +// this is +// like in a stack of Legos whatever is the last piece you put is always the top.


session: F05-07
timestamp: 00:01:12.25
speaker: JAC
utterance:
so if I want to get a piece out I can only take the top piece off without ruining everything so we can only take the top so if I want to know what's at the top we have a method that's called top # and top just tells me what's at the top of the stack so right now top will give me f@l.


session: F05-07
timestamp: 00:01:31.06
speaker: JAC
utterance:
if I want to remove f@l from the stack uh we have a method called pop # which removes +// so like popping off the top Lego right?


session: F05-07
timestamp: 00:02:37.24
speaker: JAC
utterance:
so whatever goes in first in our case a@l was the one that went in first because we pushed it first.


session: F05-07
timestamp: 00:02:56.00
speaker: JAC
utterance:
there's another one called FIFO but that's not for stacks # it's first in first out um kind of like what they use at grocery stores.


session: F05-07
timestamp: 00:03:08.09
speaker: JAC
utterance:
you know the first set of stuff they get in +// fresh vegetables you want to put out first before you get more fresh vegetables because the fresh ones are going to start going bad.


session: F05-07
timestamp: 00:03:30.04
speaker: JAC
utterance:
um so if we +// if anytime you want to know what's currently at the top +// what's currently the last letter we inserted we call top to tell us if it's on there or we pop something off and we want to know what's on the +// what's on the +// like if I pop now g@l and if I call top I'll get e@l and if I pop and get rid of e@l and I call top I'll get d@l # and so on and so forth.


session: F05-07
timestamp: 00:03:57.10
speaker: JAC
utterance:
um and then if we ever want to add anything we push and whatever +// whatever you want to +// f@l, g@l, h@l, q@l.


session: F05-07
timestamp: 00:04:11.24
speaker: JAC
utterance:
it just keeps +// just like you stack Legos from the bottom up so you keep stacking on top xxx okay?


session: F05-07
timestamp: 00:06:38.20
speaker: JAC
utterance:
now each child which of course can have its own children so it has its parents so it can have its own left child and it can have its own right child.


session: F05-07
timestamp: 00:07:11.12
speaker: JAC
utterance:
uh so the reason why we have lower +// the uh left child be less than the parent and the right child being greater than the parent is so that +// it's a basic data structure so that it's consistent throughout.


session: F05-07
timestamp: 00:07:26.24
speaker: JAC
utterance:
you don't want to have someone else making a data structure and the left child is greater than the parent (be)cause it's not standard.


session: F05-07
timestamp: 00:07:33.08
speaker: JAC
utterance:
we need something standard so that when someone knows you're using a binary tree they know exactly what you mean alright?


session: F05-07
timestamp: 00:07:41.07
speaker: JAC
utterance:
so with that in mind if we look at this we can try and figure out which of these are binary trees and which ones are not binary trees.


session: F05-07
timestamp: 00:08:26.22
speaker: JAC
utterance:
we check its left child and it doesn't have a left child so we come back up to eleven and then we come back up to seven and then seven checks its left child # four which is less than seven.


session: F05-07
timestamp: 00:09:22.13
speaker: JAC
utterance:
if we really want to look at +// if we want to think of it in another way # right now what four really points to is null.


session: F05-07
timestamp: 00:09:44.15
speaker: JAC
utterance:
null can't point to null because you could have them +// they could be just be pointing infinitely, right and you don't want to do that # just one pointer to null.


session: F05-07
timestamp: 00:09:51.25
speaker: JAC
utterance:
so now if we look at this one here # we can move a little faster because we kind of know where we're going so we look at seven.


session: F05-07
timestamp: 00:11:01.00
speaker: 107
utterance:
could this still be a binary search tree if this ten were a thirteen because thirteen is greater than seven but it's not less than eleven?


session: F05-07
timestamp: 00:11:18.24
speaker: JAC
utterance:
so if it was thirteen we'd come here and we'd look and say thirteen is greater than eleven so I have to go to the right child okay then you compare yourself against the right child.


session: F05-07
timestamp: 00:11:59.10
speaker: JAC
utterance:
okay we're going to concentrate on this binary search tree and xxx going to be drawn here using beautiful circles (be)cause they're a lot easier to draw than squares.


session: F05-07
timestamp: 00:12:26.19
speaker: JAC
utterance:
now if you look at the tree you just +// now if you look at the tree everything +// assuming I draw it correctly is that it's um everything is on the same level so we have +// if this +// if we give assigned depths this is a depth of zero.


session: F05-07
timestamp: 00:12:55.28
speaker: JAC
utterance:
whereas if we search for five we don't go anywhere we're right at the root # it's the first line okay?


session: F05-07
timestamp: 00:13:00.26
speaker: JAC
utterance:
so # if we delete the node containing nine # so basically we're going to get rid of this here right?


session: F05-07
timestamp: 00:15:51.03
speaker: JAC
utterance:
so if we were to come here and delete two # the way we look at this is we'll look at two as +// we look at it relative to everything.


session: F05-07
timestamp: 00:16:08.15
speaker: JAC
utterance:
we say we pretend that two is the root (be)cause as far as two knows it's the root compared to this child here.


session: F05-07
timestamp: 00:16:21.23
speaker: JAC
utterance:
we look at its right child and then we look at its left most child # it has no left child so we just use three.


session: F05-07
timestamp: 00:16:52.28
speaker: 107
utterance:
so just +// and if like nine had another one +// ten +// you search ten and you go down this xxx or you only go one over when you're +...


session: F05-07
timestamp: 00:17:07.10
speaker: JAC
utterance:
+< if you're deleting five you look +// no you look just once +// you look at your child and then you look at all its left +// you look at its right +// your right child.


session: F05-07
timestamp: 00:17:29.25
speaker: JAC
utterance:
(be)cause if we put +// if we were for example to put nine instead of five let's say we were to just rotate this up now we get eight and seven which are both less than nine and we have to move everything over.


session: F05-07
timestamp: 00:17:41.28
speaker: JAC
utterance:
so it's a lot of extra work if we look at it from a proficiency standpoint so that's why we come and look for the lowest possible number in the first +// on the first right child so the left child is always less so eventually you're going to get to a point where you find the lowest left child which should be at the bottom.


session: F05-07
timestamp: 00:18:12.09
speaker: JAC
utterance:
so if we want to insert uh into this tree there are actually a few different ways to do insertion and # I can actually xxx xxx xxx xxx.


session: F05-07
timestamp: 00:19:28.03
speaker: JAC
utterance:
seven has no left child # so we're going to make six its new left child so # just add six there okay?


session: F05-07
timestamp: 00:19:42.22
speaker: JAC
utterance:
now there's another way to insert where instead of +// instead of going down the tree and inserting which takes +// obviously takes quite a bit of time if I have a huge tree.


session: F05-07
timestamp: 00:19:58.22
speaker: JAC
utterance:
if I have a tree with +// that has a hundred levels I have to possibly transverse that +// worse case a hundred levels to insert something.


session: F05-07
timestamp: 00:20:48.26
speaker: JAC
utterance:
so now instead of transversing the whole +// almost the whole tree to insert something I just insert it at the top and make it the new root and work all the way down.


session: F05-07
timestamp: 00:21:36.18
speaker: JAC
utterance:
if we want to find a four which is not obviously in the tree what we do is we would compare four against five and we find four is less than five so we check its left child.


session: F05-07
timestamp: 00:22:03.13
speaker: JAC
utterance:
four must not be in the tree then # so we return depending on what kind of +// type of function we have we might return false because we didn't find it or it might return null because it is pointing to null.


session: F05-07
timestamp: 00:24:37.24
speaker: JAC
utterance:
a little more +// a little more +// a little better distributed at least we have more xxx xxx xxx we just +// the left tree is one more level down than the right tree.


session: F05-07
timestamp: 00:26:03.00
speaker: JAC
utterance:
so whoever's in front # whoever's in front of me I know who's +// I know that person but I don't know who's behind me.


session: F05-07
timestamp: 00:26:09.26
speaker: JAC
utterance:
so we have this list here # and f@l which is +// f@l is the xxx xxx the front or +// if we think of this as a line he's at the front because there's nobody in front of him alright?


session: F05-07
timestamp: 00:27:19.07
speaker: JAC
utterance:
so we've transversed and we're here and we know b@l points +// we know +// b@l knows that he's in front +// he's in front of f@l or behind f@l rather.


session: F05-07
timestamp: 00:28:34.28
speaker: JAC
utterance:
we want to delete a@l so let's pretend we use our line +// or line thing and say a@l oh this line is too long I don't want to wait in line I'm going to leave okay?


session: F05-07
timestamp: 00:28:50.08
speaker: JAC
utterance:
so a@l won't know +// a@l is going to leave the line and we need to make sure that e@l knows m@l okay?


session: F05-07
timestamp: 00:29:24.19
speaker: JAC
utterance:
so e@l goes okay I'm going to go and point to m@l and a@l is going to go okay now that you're pointing to m@l I'm going to leave the line.


session: F05-07
timestamp: 00:29:44.07
speaker: JAC
utterance:
now let's say we have two lines # we have these two lines and we're in a movie theater and they say okay well we had the lines separated but now we're going to merge them together.


session: F05-07
timestamp: 00:30:01.01
speaker: JAC
utterance:
this was the +// this was the front of the line so it's saying +// question xx says insert list two into list one after +// add list two to the end of list one.


session: F05-07
timestamp: 00:31:02.03
speaker: JAC
utterance:
so we want to insert e@l after f@l so what we do is we come and check the line # we come and check this list first # we look at the line.


session: F05-07
timestamp: 00:31:19.15
speaker: JAC
utterance:
great so we want to make f@l point to this list so we check the head of this list # heads +// because the head is always points to the end of the line.


session: F05-07
timestamp: 00:31:40.05
speaker: JAC
utterance:
you don't know # you don't know what's at the end so we have something called the head which always points to the first or last depending on the way you look at it.


session: F05-07
timestamp: 00:32:04.16
speaker: JAC
utterance:
and s@l says okay well I'm to get in behind e@l so f@l is going to come in and point to e@l instead of pointing to null.


session: F05-07
timestamp: 00:32:13.09
speaker: JAC
utterance:
so head is like okay well h@l one is pointing +// head one is pointing to the front of the list I don't need to point to e@l (be)cause e@l is not the front of the list anymore so I'm going to away.


session: F05-07
timestamp: 00:32:30.18
speaker: JAC
utterance:
suppose # in um k@l's infinite wisdom that he wants to add his big group of buddies e@l, a@l and m@l # in front.


session: F05-07
timestamp: 00:33:27.13
speaker: JAC
utterance:
we come and k@l goes alright k@l I know b@l is in front of me and b@l goes okay # h@l two or head # I know b@l is in front of me.


session: F05-07
timestamp: 00:33:40.16
speaker: JAC
utterance:
okay # h@l two goes okay e@l +// b@l is in front of k@l and he's just like okay is anyone in front of me?


session: F05-07
timestamp: 00:34:32.06
speaker: JAC
utterance:
m@l tells k@l I'm in front of +// b@l is in front of me now so k@l says alright I'm going to check the head h@l two and be like who's +// who's at the end of the line?


session: F05-07
timestamp: 00:34:57.00
speaker: JAC
utterance:
kind of similar to this except the fact that we have to go through and find +// we have to find who's the last err the first person in the line.


session: F05-07
timestamp: 00:35:23.18
speaker: JAC
utterance:
um describe the sequence of operations to switch the nodes that contain c@l and the node that contains a@l.


session: F05-07
timestamp: 00:36:26.21
speaker: JAC
utterance:
so # what we're going to do is we have our +// we have something to count by called t@l # he is temporary.


session: F05-07
timestamp: 00:36:47.19
speaker: JAC
utterance:
I need you to hold my +// hold the place for me so we're going to do exactly the same thing we do when we insert.


session: F05-07
timestamp: 00:38:10.06
speaker: JAC
utterance:
so we +// t@l tells a@l that the head is pointing or the head says I was pointing to t@l so we come here and point to a@l.


session: F05-07
timestamp: 00:38:20.05
speaker: JAC
utterance:
so now this garbled mess we have a@l in place of c@l and t@l somewhere off in its own +// having a party while +...


session: F05-07
timestamp: 00:38:40.04
speaker: JAC
utterance:
um but basically # you're going to use this general concepts in case you're going to do anything +// any type of manipulation with the lists.


session: F05-07
timestamp: 00:38:50.06
speaker: JAC
utterance:
um if you need to insert, if you need to switch places with something you use a temporary um you always need to know who's in front of you and then you're going to insert something tell whoever's being inserted what's in front of you and then point to the one you're being inserted to.


session: F05-08
timestamp: 00:00:43.16
speaker: JAC
utterance:
<always> at the bottom. so we have a method which is called push ##. and let's, I'm going to use the letters xxx, push @a. ok? what push does is puts the first, is going to put next brick.


session: F05-08
timestamp: 00:01:08.19
speaker: JAC
utterance:
ok. if we push b@l now ##f@l. it would be just like building on top of Legos. we're going to put it right on top. ok. so we keep, every time we push we add on top of our previous label.


session: F05-08
timestamp: 00:01:56.08
speaker: JAC
utterance:
it's not like we're in an array. what it's it's like a *uh, if you stack up, if you stack up quarters, you're <stack>


session: F05-08
timestamp: 00:02:10.03
speaker: JAC
utterance:
ok. so it's the same, it's kind of the same principle with the stack. if i want, if i want something i can only get what is on <top>


session: F05-08
timestamp: 00:02:19.20
speaker: JAC
utterance:
so we actually have a method called top. the method does is tell me what's currently in the top position.


session: F05-08
timestamp: 00:03:43.24
speaker: JAC
utterance:
i call pop again, i get @b. if i call top, i got @a. now the whole concept behind this is what's called filo. first in last out.


session: F05-08
timestamp: 00:04:12.19
speaker: JAC
utterance:
has to be the last one to come out. ok. cuz we're always taking, we're always taking from the top. ok. and anytime, every whoever goes in first is on the bottom.


session: F05-08
timestamp: 00:04:58.18
speaker: JAC
utterance:
you can't call oh give me the third, give me the third element. give me the fifth element in the linklist. give me give me the last, give me element zero or one. um, what's actually in linklist is what we'll say we'll call the head. anytime you refer to the linklist you always go to the head first.


session: F05-08
timestamp: 00:06:05.11
speaker: JAC
utterance:
and the same for @k. @k may be the end of the line but doesn't know who, it doesn't know @c. but @k does know that @b is in front. and @b knows that @f's in front. and @f, the lucky son of a gun, knows he's the front of the line.


session: F05-08
timestamp: 00:06:27.28
speaker: JAC
utterance:
<cuz> he points to nothing. only time we point to nothing is something. if we're not pointing to anything then nothing will point to. we point to null.


session: F05-08
timestamp: 00:07:21.25
speaker: JAC
utterance:
ok. and @b's buddy, his good buddy @g comes up and he's just like hey what what we're doing is we're doing an insertion.


session: F05-08
timestamp: 00:07:46.00
speaker: JAC
utterance:
and he's just like yeah sure. @b says looks and sees who's in front of him. @f's in front of him. well, @b has to tell @g who's in front who's in front of him.


session: F05-08
timestamp: 00:08:15.14
speaker: JAC
utterance:
ok? so now here, if you're to go through the list we call the head. we would be here at the head. and then you xxx next, you'd find the next that points to @c, which points to @k, which points to @b, which now points to.


session: F05-08
timestamp: 00:08:32.17
speaker: JAC
utterance:
which points to @f. ok? if we have a line, our second line with @e @a @m it's a little shorter line@fp, and @m is the front of the line, right? ok. and let's say since @a doesn't know @a doesn't know how many people are in front of him, we're to think of this stalls the line.


session: F05-08
timestamp: 00:09:09.26
speaker: JAC
utterance:
@a doesn't know how many people are in front of him, he's been like i've been waiting here too long.


session: F05-08
timestamp: 00:09:24.02
speaker: JAC
utterance:
@m. ok? now if we come back if we go back to the list and we find out who's pointing to @a. he's pointing to @a.


session: F05-08
timestamp: 00:10:06.13
speaker: JAC
utterance:
now he can check that and still be here. but if we think of it, we can have like two pointers. one here where i am and where i'm, one where i'm looking.


session: F05-08
timestamp: 00:10:15.28
speaker: JAC
utterance:
ok. it, the head looks and sees xxx pointing to @e. now the head can also check to see who @e is pointing to. @e's pointing to @a.


session: F05-08
timestamp: 00:10:34.18
speaker: JAC
utterance:
<and> who they're pointing to. ok. i can look, i can find out who i'm who someone else is pointing to.


session: F05-08
timestamp: 00:10:43.03
speaker: JAC
utterance:
ok. cuz i know, i know that, i know that and i can find out who they're pointing to. who < i can ask them xxx>.


session: F05-08
timestamp: 00:11:03.17
speaker: JAC
utterance:
now @a, so this connection to @a goes away. i'm still at @a. @a says i'm pointing to @m xxxx and then i can get rid of myself and go away.


session: F05-08
timestamp: 00:11:16.07
speaker: JAC
utterance:
i go, i go to a different movie theater, whatever, i go to the bathroom. ok? i don't  really have to go to the bathroom. ok?


session: F05-08
timestamp: 00:11:25.19
speaker: JAC
utterance:
so@fp let's say we want to, let's say we have these two lines again. one of these days i'm actually gonna have all of these prewritten for myself@fp. we always refer back to the original.


session: F05-08
timestamp: 00:12:04.26
speaker: 108
utterance:
so it's more complicated than to move this out cuz you have a lot more by to go back and forth with. and it's just easier to just like from going to here right?.


session: F05-08
timestamp: 00:12:15.00
speaker: JAC
utterance:
yeah insertion is easier than a deletion. @e @a @m @n @o. ok. well let's say that's buddies where actually let's say that we had two separate we had what we thought was two separate lines.


session: F05-08
timestamp: 00:12:49.00
speaker: JAC
utterance:
ok? so *uh @f's not happy, he's not at the front of the line. so @f, @f finds out what the head, where the head is for the next line.


session: F05-08
timestamp: 00:13:06.04
speaker: JAC
utterance:
that's just error i am now pointing to null anymore i'm gonna point to @e. ok. so now @f's in front of @e. we delete this head come to one point in the middle.


session: F05-08
timestamp: 00:13:29.28
speaker: JAC
utterance:
ok. now if same, if we were in a similar situation@fp. i'd save myself so much time if i had it predrawn@fp. no, there's two, there's xxx @e which points to @a which points to @m which points to good old fashion null. ok. well let's say @k, @k is in line, he's hanging out and he sees his buddy @e. @e @a and @m.


session: F05-08
timestamp: 00:15:00.22
speaker: JAC
utterance:
i need to point to whoever's the head is pointing to. so i go to the head and i go ok head, <who are you pointing to>.


session: F05-08
timestamp: 00:15:26.25
speaker: JAC
utterance:
yeah, it just  xxx. i mean we think of it, head as something that points to the end of the line. you, you know how you could always see who's really last in the line?


session: F05-08
timestamp: 00:15:47.04
speaker: JAC
utterance:
and why in the linklist. ok? *uh@fp. i'm gonna go to try something xxx switch over to binary trees. now, a binary search tree has two choices.


session: F05-08
timestamp: 00:16:34.13
speaker: JAC
utterance:
however in this case, we're using numbers. we can't have yes and no. so we say are you greater than me or are you less than me?


session: F05-08
timestamp: 00:16:59.18
speaker: JAC
utterance:
yeah, exactly like the family tree. ok? now, the way we always do it is we have the right child *uh as.


session: F05-08
timestamp: 00:17:13.06
speaker: JAC
utterance:
greater and the left child is lesser. now the reason why we want to do that is because if i have, if someone else makes a tree.


session: F05-08
timestamp: 00:17:22.27
speaker: JAC
utterance:
if i, if if joe blow makes a tree and makes a tree for you and you're gonna use it in one of your classes, you need to know that it the way it's going to work.


session: F05-08
timestamp: 00:17:32.22
speaker: JAC
utterance:
so if we, if he was to make it the left child was greater than the parent then and you're expecting the right child to xxx.


session: F05-08
timestamp: 00:17:45.13
speaker: JAC
utterance:
and anything to the left is lesser. ok? so now if we come here we always look at the right child first. ok so this is this is going this way is going to the right child. right child. ok? so we look at seven's right child what we're trying to do is basically figure out are these binary search trees, right?


session: F05-08
timestamp: 00:18:06.26
speaker: JAC
utterance:
we look at its right child and we find eleven. eleven's greater than seven. we check its right child, it's twelve.


session: F05-08
timestamp: 00:18:21.28
speaker: JAC
utterance:
<ok>. so we come back up and which of twelve's left child. twelve doesn't have a left child so we come back up. we go to eleven, we check eleven's left child which is eight.


session: F05-08
timestamp: 00:18:41.01
speaker: JAC
utterance:
ok. we check its right child, it's null. we check its left child, it's null. we come back up to eight, check its left child, it's null.


session: F05-08
timestamp: 00:18:49.03
speaker: JAC
utterance:
go back up to eleven, we go back up to seven and then check its left child. four, four is less than seven. check its right child. five, greater than four. we check its right child, it's null. we check its left child, it's null. we go back up to four, we check its left child it's null. this is a binary search tree.


session: F05-08
timestamp: 00:19:42.10
speaker: JAC
utterance:
ok. so now if we come here, eleven is xxx compared to twelve. twelve is greater than eleven. twelve doesn't point to anything, come back up here to eleven, check its left child. seven is less than eleven.


session: F05-08
timestamp: 00:19:58.19
speaker: JAC
utterance:
<ten> is greater than seven, has no right child so check its left child. eight is less than ten. come back up, check seven's left child which is five, which is less. check its right child, it doesn't have one. check its left child, it's four. so this is a binary search tree.


session: F05-08
timestamp: 00:20:15.22
speaker: JAC
utterance:
ok. finally xxx. look at eight. look at it. right off the bat you can tell not a binary search tree.


session: F05-08
timestamp: 00:20:36.24
speaker: JAC
utterance:
ok. now five connected to xxx the way you draw it. i hate drawing boxes. xxx draw circles@fp. ok. when i can draw right it actually looks like this. you can see this is the root, right?


session: F05-08
timestamp: 00:21:05.20
speaker: JAC
utterance:
and if we say this is level zero and this is level one, level two and level three. so that's a depth.


session: F05-08
timestamp: 00:21:30.17
speaker: JAC
utterance:
ok? so there's no [x3] it's not more expensive to check the left child than it is to check the right child.


session: F05-08
timestamp: 00:22:01.07
speaker: JAC
utterance:
cuz i have to keep going further down the tree. now let's say that we want to get rid of nine from the tree.


session: F05-08
timestamp: 00:22:42.19
speaker: JAC
utterance:
ok? so what will happen is one of five, eight and seven and this stays the same. two, three, and one. alright?


session: F05-08
timestamp: 00:22:58.25
speaker: JAC
utterance:
uh huh. now if we delete five, kind of the same thing. actually exactly the same thing pretty much. three, then nine, and eight, and seven. ok. now we're gonna delete five.


session: F05-08
timestamp: 00:23:29.27
speaker: JAC
utterance:
now five actually has a right child, so we're gonna look at its left most child. the left most left child.


session: F05-08
timestamp: 00:23:36.24
speaker: JAC
utterance:
ok. so basically we're gonna go nine, what's your child? eight. eight, do you have any children? yes. seven. seven's my left child. who's my who's your left child? seven, do you have a left child? no, i point to null.


session: F05-08
timestamp: 00:24:09.09
speaker: JAC
utterance:
on this side of the tree stays the same. now seven keeps, gets eight as a child. eight has nine as its child.


session: F05-08
timestamp: 00:24:28.23
speaker: JAC
utterance:
out of here. what we do is look at its right child and then we look at its left left most child. cuz it doesn't have one, we'll use three.


session: F05-08
timestamp: 00:24:48.18
speaker: JAC
utterance:
ok? now, if we look at our tree and say we want to find out. if we want to find out if this tree contains eight.


session: F05-08
timestamp: 00:25:13.14
speaker: JAC
utterance:
ok. so we have to search through the tree. ok. like you have a deck of cards, you have to search through your deck of cards and find your ace of spades. right?


session: F05-08
timestamp: 00:25:21.28
speaker: JAC
utterance:
so we look through our tree and we compare eight, which is what we're searching for. to the first, the root, which is five.


session: F05-08
timestamp: 00:25:40.09
speaker: JAC
utterance:
ok. so we check its right child. and we check eight against nine. eight is less than nine. so if eight is in the tree it should be in its left, it should be left. so we compare eight and eight and they're equal.


session: F05-08
timestamp: 00:26:08.12
speaker: JAC
utterance:
so if you're there, you should be on the right. and four is greater than three, if you're in the tree, you should be on the right. so we check and three doesn't point to anybody. so if three doesn't point to anyone, four can't be


session: F05-08
timestamp: 00:26:23.15
speaker: JAC
utterance:
in the tree. so, um, we might return fa. we might say false, it's not in the tree. or we might return, we might return null. it depends on [x3] the the function or math. it depends on how it's written. we could return null because if you want to, you might go, oh check to see if this is in there.


session: F05-08
timestamp: 00:26:58.06
speaker: JAC
utterance:
so depends on depends on function. depends on how you [x3] want to write. if you want to write it efficiently or you want to write it simple.


session: F05-08
timestamp: 00:27:07.11
speaker: JAC
utterance:
you know, there's simple and there's different things. *uh. now let's say i want to insert@fp eight, seven, two, three, and one. say we want to insert, um, six.


session: F05-08
timestamp: 00:27:36.06
speaker: JAC
utterance:
into this tree. ok? one way that we can do it is that we insert six into the first spot that's available for it. so what we'll do is we'll come here first and compare six and five and six is greater than five. so we look at its right child. so second, we come here and compare six and nine.


session: F05-08
timestamp: 00:28:11.05
speaker: JAC
utterance:
it's still last. we compare full step, we compare seven and its, six is less than seven so we go to its left child. it's pointing to null.


session: F05-08
timestamp: 00:28:37.19
speaker: JAC
utterance:
ok? so next time, if someone tries to insert something six is still is still pointing to a null. so it knows that ok you're the end.


session: F05-08
timestamp: 00:28:47.22
speaker: JAC
utterance:
right. so now if we were to, cuz if we were to insert um five and a half, cuz i can't insert. i can't .


session: F05-08
timestamp: 00:29:07.09
speaker: JAC
utterance:
you might compare what, like where length. or you might compare alphabetically which ones and then move here.


session: F05-08
timestamp: 00:29:16.13
speaker: JAC
utterance:
you can do that, or you might have letters, you know. who knows? i mean either or whichever anything you can compare.


session: F05-08
timestamp: 00:29:29.22
speaker: JAC
utterance:
it's simple, it's easy, and then once you think about it you can realize ok, if i can do this with numbers, i can do this with anything that i can compare.


session: F05-08
timestamp: 00:29:40.09
speaker: JAC
utterance:
i can, if you can compare words. um, if you have, you can compare, if you have a structure, something a data of thing of cars.


session: F05-08
timestamp: 00:29:51.19
speaker: JAC
utterance:
ok. you had a way to compare one car versus the other and determine which one was greater. so if i had a ford and i had the dodge, and you were able to find out that by comparing them dodge is greater than <ford>.


session: F05-08
timestamp: 00:30:17.28
speaker: JAC
utterance:
then you can use this structure in order to add them. because there is a way to compare and see what's greater than, what's less than, what's equal. ok. as long as you can do those three things


session: F05-08
timestamp: 00:30:29.10
speaker: JAC
utterance:
you can have a data structure like this for binary search tree for anything. ok? we use numbers because everyone uses numbers in math and.


session: F05-08
timestamp: 00:30:53.24
speaker: JAC
utterance:
and you might, now you might say oh all three of these equal but i might say these aren't lists. since this is capital.


session: F05-08
timestamp: 00:31:16.15
speaker: JAC
utterance:
another way we could insert is basically a fallen premise that well what if my tree had a hundred levels.


session: F05-08
timestamp: 00:31:30.26
speaker: JAC
utterance:
and worst case scenario, i have to insert go all the way to the hundredth level before i can insert six.


session: F05-08
timestamp: 00:31:59.29
speaker: JAC
utterance:
five as its child and then keep everything else the same. left child one and three. and make nine its new child. eight and seven. ok?


session: F05-08
timestamp: 00:32:40.05
speaker: JAC
utterance:
because if i do it this way, six is already in the tree. i'm trying to insert six, i can find six and say oh, six is already in the tree. i don't need to insert it. or i might have the function that says find six in the tree, if six is in the tree to lead, six is now in the tree to insert.


session: F05-08
timestamp: 00:33:00.05
speaker: JAC
utterance:
ok? um, well i think that's time. are we done or. i got a couple more minutes, ok. xxx, ok, great, cool. *uh, let's see. alright so let's see xxx trying to xxx


session: F05-08
timestamp: 00:33:45.15
speaker: JAC
utterance:
top and xxx. top is a , element on top is a stack@fp. pop moves, top stack and push, push it on, puts onto


session: F05-08
timestamp: 00:35:05.18
speaker: JAC
utterance:
but the head can, the head can ask, the head can ask the person at the end of the line who's in front of that, in front of you.


session: F05-08
timestamp: 00:35:32.12
speaker: JAC
utterance:
ok? well i go, head next, next this returns @a. if i go head next [x3] this returns @m. and if i go one more next this would give me null.


session: F05-08
timestamp: 00:36:01.13
speaker: JAC
utterance:
ok? um, and binary trees. we have a left child and a right child, and right is greater than parents, and left is less than parents. and we always


session: F05-08
timestamp: 00:36:55.15
speaker: JAC
utterance:
ok? that was one minute of those five minutes that we have. but um@fp let's see if we can do, xxx if we can do this. um, if we want to make, invert this in the list we can find out, we go throught the list, find out if @m is pointing to the null.


session: F05-08
timestamp: 00:37:34.16
speaker: JAC
utterance:
um, we'll call head and we say head what do you point to. says i'm pointing to @e. so we say ok. so head is going to point to @e. well we're still at @m, we're gonna call the head again.


session: F05-08
timestamp: 00:37:52.10
speaker: JAC
utterance:
we're gonna go head what are you pointing to. head i'm pointing to @e. ok @e, where are you pointing to? @a. @a where are you pointing to? @m. ok, @m is not, i don't want you pointing to me anymore.


session: F05-08
timestamp: 00:38:06.10
speaker: JAC
utterance:
i want you pointing to. i want you pointing to null. but i also didn't change the head to point to me.


session: F05-09
timestamp: 00:00:00.14
speaker: LOW
utterance:
first of all, it's a linked list, there's some binary search trees, and then there's some stack questions.


session: F05-09
timestamp: 00:00:48.22
speaker: LOW
utterance:
but this thing is we can see it's a four on the list, but when it turns on the computer, we don't know how long it is, because all you have is a pointer to the first node.


session: F05-09
timestamp: 00:01:00.23
speaker: LOW
utterance:
and then you have to go there to find out *ahhah, that's not null, so there is a second node, so you have to go there to find out there is a third, and you have to go there to find out there is a fourth.


session: F05-09
timestamp: 00:01:18.26
speaker: LOW
utterance:
so the difference is the array is a list, first, second, third, xxx/xx to zero xxx/xx, but they're stored sequencially in memory.


session: F05-09
timestamp: 00:01:38.05
speaker: LOW
utterance:
so in fact my picture is just for simplicity, but this may be in the middle of everything and this is way ahead at the end of memory, the next one's back at the beginning of memory.


session: F05-09
timestamp: 00:02:00.23
speaker: LOW
utterance:
describe a sequence of operations to insert a new node that contains g@l in this list after the node that contains b@l.


session: F05-09
timestamp: 00:02:50.22
speaker: LOW
utterance:
that's what the after picture looks like but we have to write the operations that the computer could use to do that.


session: F05-09
timestamp: 00:02:55.26
speaker: LOW
utterance:
and even though it looks simple it's got something, I wouldn't say tricky, but it's got something you have to be careful about.


session: F05-09
timestamp: 00:03:17.28
speaker: LOW
utterance:
<but if I select basically this is just and address here> [//] I change this address in here and made it like the address of that one.


session: F05-09
timestamp: 00:04:15.25
speaker: LOW
utterance:
like one very simple thing we would do is we would travel across this list one, two, three, counting the nodes or something.


session: F05-09
timestamp: 00:04:24.04
speaker: LOW
utterance:
um in this case <we're going to assume> [//] I think they want us to assume, that there is a node b@l in the list.


session: F05-09
timestamp: 00:04:48.04
speaker: LOW
utterance:
<so here's our> [//] here's how we'll do this, we'll find the b@l by traversing or traveling across the list until we get to it, and then we'll get a new node with g@l in it after we get a couple of links.


session: F05-09
timestamp: 00:05:31.09
speaker: LOW
utterance:
so while and look we're just writing kind of <pseudo here> [//] pseudo code here, so we want to write while the info of node t@l is not equal to b@l.


session: F05-09
timestamp: 00:05:50.15
speaker: LOW
utterance:
there is what I just called the info, which is the c@l k@l b@l f@l u@l, make sure it's in there +...


session: F05-09
timestamp: 00:05:55.27
speaker: LOW
utterance:
and of course in a real world example it wouldn't be a single letter it would be a whole xxx record or something like that.


session: F05-09
timestamp: 00:06:44.26
speaker: LOW
utterance:
so it's the next of t@l in pseudo code, or if you would prefer I could write more Java-like, t@l dot next.


session: F05-09
timestamp: 00:07:33.06
speaker: LOW
utterance:
okay so now we'll just get a new node so in pseudo code write something like new node and it will with information g@l


session: F05-09
timestamp: 00:08:07.03
speaker: LOW
utterance:
so I've got the new node and now it's basically just two assignment statements to fix these two, *uh +...


session: F05-09
timestamp: 00:09:51.26
speaker: LOW
utterance:
<so most of +// well> [///] so these are addresses so next of n@l is an address, and what I put in there is what was in the next of t@l.


session: F05-09
timestamp: 00:13:26.19
speaker: LOW
utterance:
alright so it's going to go from three elements to two elements so the after picture is really simple here.


session: F05-09
timestamp: 00:13:42.02
speaker: LOW
utterance:
*uh so it's the same deal again, we're going to use a traversal, that's a new word so I will repeat it, because we got to find a@l.


session: F05-09
timestamp: 00:13:55.22
speaker: LOW
utterance:
all your given is h@l two might be way at the end or at the beginning or in special cases a@l at the beginning and whatever.


session: F05-09
timestamp: 00:15:16.25
speaker: LOW
utterance:
well the exact thing you said right there I think more explicitly the link I'm trying to change is two a@l.


session: F05-09
timestamp: 00:15:45.05
speaker: LOW
utterance:
often when you traverse a list you want to take two pointers across the list together so that when one comes to a certain situation, the other xxx/xx.


session: F05-09
timestamp: 00:16:22.03
speaker: LOW
utterance:
well, that's why we set it equal to null, because the t@l is pointing to the first node what the heck is behind that?


session: F05-09
timestamp: 00:19:17.22
speaker: LOW
utterance:
<and then um then that has> [/] when you did that you broke that link right here, so this is garbage and it will be collected by the garbage collector of Java.


session: F05-09
timestamp: 00:23:24.29
speaker: LOW
utterance:
which is if I go to eleven than eight ten is smaller than eleven so everywhere eight doesn't have any smaller things in the tree which is xxx/xx.


session: F05-09
timestamp: 00:25:25.12
speaker: LOW
utterance:
now they don't point it out but just like with a linked list you have a pointer to what we call the root.


session: F05-09
timestamp: 00:26:29.27
speaker: 109
utterance:
and you see where it's like that half's greater or less than four and then your gonna go to the left.


session: F05-09
timestamp: 00:28:33.02
speaker: LOW
utterance:
actually what they say is delete the node that contains nine from the given the binary search tree moving as few nodes as possible.


session: F05-09
timestamp: 00:30:19.22
speaker: LOW
utterance:
alright, so two would be another example of xxx/xx but in general it doesn't really matter that it's the root.


session: F05-09
timestamp: 00:30:28.10
speaker: LOW
utterance:
alright so they'd like us to do this moving as few nodes as possible and keeping it a binary search tree.


session: F05-09
timestamp: 00:30:49.25
speaker: LOW
utterance:
you know basically I don't know quite what that means xxx/xx two up there because also xxx going to cause us any problem.


session: F05-09
timestamp: 00:31:31.15
speaker: LOW
utterance:
there is one node on the left, and one node on the right, that could be moved up into that place and it would xxx the whole work out.


session: F05-09
timestamp: 00:33:15.12
speaker: LOW
utterance:
so I don't really have to check this side because all these guys are less than five so they're all less than six.


session: F05-09
timestamp: 00:35:35.29
speaker: LOW
utterance:
and there's this very special container that has a spring down in there that shows you just one tray on top.


session: F05-09
timestamp: 00:37:15.04
speaker: LOW
utterance:
so besides these we have a Boolean function, and tells us whether +// you know about Booleans, right?.


session: F05-09
timestamp: 00:37:55.12
speaker: LOW
utterance:
okay so then I can return count, I guess if the function that returns the number of things in the stack and it returns four.


session: F05-09
timestamp: 00:38:10.07
speaker: LOW
utterance:
four used to be the count but in finding out what the number of things in the stack was I destroyed the stack.


session: F05-09
timestamp: 00:38:59.18
speaker: LOW
utterance:
it's backwards # so what will I have to do- im not going to bother writing because I don't have the time.


session: F05-10
timestamp: 00:00:19.20
speaker: LOW
utterance:
and why it's called link list because what you all you're given all you're given is a pointer to the first item on the list.


session: F05-10
timestamp: 00:00:31.10
speaker: LOW
utterance:
uh, you can't see the rest of them and the only guy that knows where the second one lives is this first one and there's an address right here of the next one.


session: F05-10
timestamp: 00:00:41.20
speaker: LOW
utterance:
and then once you're there there's an address of the next one and once you're there there's an address to the next one.


session: F05-10
timestamp: 00:00:50.07
speaker: LOW
utterance:
and once you're there there's a special null pointer I just put a slash there which means the end of the list.


session: F05-10
timestamp: 00:01:24.00
speaker: LOW
utterance:
here all we know is the address of the first one and it might be the middle of memory and even though I've sort of drawn it next door you should imagine that the next one is way over here at the end of memory and the next one b@l would be here in the <beginning>.


session: F05-10
timestamp: 00:01:48.01
speaker: LOW
utterance:
there's the info which is here just a single letter and there is the next field and that's an address.


session: F05-10
timestamp: 00:01:56.01
speaker: LOW
utterance:
what's stored there is the address of that node and what you store there is the address of that node, ok?


session: F05-10
timestamp: 00:03:12.09
speaker: LOW
utterance:
but that's one important thing with dealing with link list and binary search trees and stacks is always draw yourself a picture, ok?


session: F05-10
timestamp: 00:03:22.10
speaker: LOW
utterance:
now the reason I want um +// I drew this picture is I also want to show you there's something subtle here.


session: F05-10
timestamp: 00:03:29.01
speaker: LOW
utterance:
mainly if we do it the way I suggested, if we do this first, if we break this pointer and make b@l point to the new g@l we have a problem.


session: F05-10
timestamp: 00:03:49.24
speaker: LOW
utterance:
ok so I have to do this one first while I still have this pointer to this node I need to copy it over here and then I could do this second, ok?


session: F05-10
timestamp: 00:04:07.00
speaker: LOW
utterance:
ok so here's how you do a traversal +// well, ok what we're going to do we're going to  put this node in after the node contains b@l.


session: F05-10
timestamp: 00:05:18.03
speaker: LOW
utterance:
which is in the next field that we're pointing at so t@l is its own next you take the next of the node t@l points to.


session: F05-10
timestamp: 00:05:37.00
speaker: LOW
utterance:
we're not worried about this is just pseudo code so don't worry about braces and stuff like that, ok?


session: F05-10
timestamp: 00:05:43.08
speaker: LOW
utterance:
alright, so remember we're trying to put the new node after the one b@l points to so we got to find b@l so we did it it's just that simple.


session: F05-10
timestamp: 00:07:15.01
speaker: LOW
utterance:
and that's why it's important we haven't done that yet because that address is stored right here, ok?


session: F05-10
timestamp: 00:08:53.02
speaker: LOW
utterance:
um, alright, so always draw pictures, watch out for order, and another thing we should quickly do is watch out for special cases.


session: F05-10
timestamp: 00:10:56.22
speaker: LOW
utterance:
so the list had three elements, we want to delete the node that contains a@l so now the list has two elements e@l and m@l.


session: F05-10
timestamp: 00:11:09.12
speaker: LOW
utterance:
it had three elements e@l was first and then that e@l told you to go to a@l and a@l told you to go to m@l but the point is you want to delete a@l.


session: F05-10
timestamp: 00:11:44.13
speaker: LOW
utterance:
give myself some space while +// well, first of all, if you want to delete a@l you have to find a@l, ok?


session: F05-10
timestamp: 00:12:36.01
speaker: LOW
utterance:
we're ready to do this surgery, by that I mean change some links links, cut some links and add some links.


session: F05-10
timestamp: 00:12:41.20
speaker: LOW
utterance:
but do you see a problem if I've got a pointer to a@l and I want to change the pointers while I put this pencil link in here.


session: F05-10
timestamp: 00:13:20.07
speaker: LOW
utterance:
well that makes sense, if you wanted to delete a@l, you got to do something to the one before the a@l.


session: F05-10
timestamp: 00:13:54.05
speaker: LOW
utterance:
*uh that way if we're looking for e@l we what t@l is the first one on the list and what's the one before that?


session: F05-10
timestamp: 00:14:24.03
speaker: LOW
utterance:
we also need to move s@l forward of course because the idea is s@l is going to always be behind t@l.


session: F05-10
timestamp: 00:15:46.04
speaker: LOW
utterance:
and now when I get out, t@l points to a@l, the node that contains a@l but s@l points to the one before.


session: F05-10
timestamp: 00:16:13.17
speaker: LOW
utterance:
yeah but I can't put m@l (be)cause that's the wrong type that's a +// that's a value this is an address.


session: F05-10
timestamp: 00:16:26.01
speaker: LOW
utterance:
yeah it's in the node that has a@l in it, but the node is the whole node of t@l so it's next of t@l, ok?


session: F05-10
timestamp: 00:17:24.00
speaker: LOW
utterance:
if you delete an m@l, you deleted the last element then suddenly the one before it becomes the last element.


session: F05-10
timestamp: 00:17:36.00
speaker: LOW
utterance:
I could tell this ain't going to work because I say next of s@l is something and s@l is null if you did that the first time.


session: F05-10
timestamp: 00:18:51.18
speaker: LOW
utterance:
sure, if you delete the first element on the list, then the pointer of the first element has to change.


session: F05-10
timestamp: 00:18:57.03
speaker: LOW
utterance:
h@l two points to this node that contains e@l, if you want to delete e@l, h@l two has to point to what used to be the second one, right?


session: F05-10
timestamp: 00:19:14.04
speaker: LOW
utterance:
summing that up, if we wanted to delete the node that contains a@l we have to find a@l and we really have to find the one before it and make this little change.


session: F05-10
timestamp: 00:19:29.17
speaker: LOW
utterance:
sometimes you move across a list with three, sometimes with four and that really really complicated problems.


session: F05-10
timestamp: 00:19:46.00
speaker: LOW
utterance:
first of all, a binary tree is a two-dimensional thing where the link list is a one dimensional thing.


session: F05-10
timestamp: 00:20:06.08
speaker: LOW
utterance:
at most two kids (be)cause four only has one, on the right and *uh somewhere down in here I'll find somebody that has an unknown left.


session: F05-10
timestamp: 00:21:41.16
speaker: LOW
utterance:
this one is totally reversed (be)cause these are supposed to be bigger than eight but they're all smaller than eight.


session: F05-10
timestamp: 00:22:28.08
speaker: LOW
utterance:
alright, they don't show you this but the way I keep track of the tree is with a pointer to the root.


session: F05-10
timestamp: 00:22:49.14
speaker: LOW
utterance:
*uh, I don't know why they put the problems in this order because deletion is the hardest, insertion the next hardest, searches the easiest.


session: F05-10
timestamp: 00:25:36.01
speaker: LOW
utterance:
if you know search then you just search,if you can't find it you put it right where you should've found it.


session: F05-10
timestamp: 00:25:42.04
speaker: LOW
utterance:
we really got three cases that they only ask us about two up here, (be)cause they don't ask us about the trivial one.


session: F05-10
timestamp: 00:26:05.14
speaker: LOW
utterance:
this actually, of course, when you really want you can change the pointer in the parent but we're just drawing pictures.


session: F05-10
timestamp: 00:27:07.04
speaker: LOW
utterance:
he has some other grandkids over here but he only has one on that side (be)cause nine only has one kid.


session: F05-10
timestamp: 00:27:23.05
speaker: LOW
utterance:
and it's still a binary search tree because all of these things are bigger than five, so they're still bigger than five.


session: F05-10
timestamp: 00:27:50.01
speaker: LOW
utterance:
well, what people usually try is to move two +// ok, so I'm going to do it just as painlessly as I can.


session: F05-10
timestamp: 00:28:06.03
speaker: LOW
utterance:
well, I try and move two up there but that doesn't work +//, I don't know what that means exactly anyway, (be)cause two's got two kids and I have another problem down here.


session: F05-10
timestamp: 00:28:29.25
speaker: LOW
utterance:
but it turns out, see if you can find it, there is one number on the left and there is one number on the right that could come up and take five's place and it would be alright.


session: F05-10
timestamp: 00:29:08.00
speaker: LOW
utterance:
and likewise, if you bring the eight up, some of this stuff's smaller than eight, but you could bring up the +...


session: F05-10
timestamp: 00:29:33.00
speaker: LOW
utterance:
if I pencil in the six up here, I'm going to just bring the six up here and of course take it out of the tree.


session: F05-10
timestamp: 00:29:40.08
speaker: LOW
utterance:
so it's ok over here, (be)cause these guys are smaller than five, so they're clearly smaller than six.


session: F05-10
timestamp: 00:30:26.16
speaker: LOW
utterance:
I could put six and a half on the tree, I could put two and a half on the tree and they would have kids.


session: F05-10
timestamp: 00:31:34.01
speaker: LOW
utterance:
well we start at the root, you go right once (be)cause you want to find the one smallest on the right side.


session: F05-10
timestamp: 00:31:43.01
speaker: LOW
utterance:
we'll find it five and a quarter are in the tree it has to be bigger than five to be over here but ok.


session: F05-10
timestamp: 00:31:56.16
speaker: LOW
utterance:
and four and a half would be here or whatever and these need to be four and a half in the tree that would leave the guy able to move up.


session: F05-10
timestamp: 00:32:22.08
speaker: LOW
utterance:
you can either have a no kid thing or a one kid thing because six can't have two kids (be)cause if we had a left kid you'd go down in there and have a small one.


session: F05-10
timestamp: 00:32:36.16
speaker: LOW
utterance:
and it's still a binary search tree, because, let's again, six is bigger than five so six works on these guys.


session: F05-10
timestamp: 00:32:49.03
speaker: LOW
utterance:
so you either find the smallest one on the right or you find the biggest one on the left and put him up there.


session: F05-10
timestamp: 00:33:21.13
speaker: LOW
utterance:
and this is a very fancy *uh container for the trays and all it does is present you with one tray at the top.


session: F05-10
timestamp: 00:33:36.01
speaker: LOW
utterance:
we're actually going to deal with a stack of letters or something like that so k@l, x@l, b@l, f@l, b@l that's good.


session: F05-10
timestamp: 00:33:46.12
speaker: LOW
utterance:
alright, so you have three operations, you are going to need two to give you three operations on a stack.


session: F05-10
timestamp: 00:34:02.17
speaker: LOW
utterance:
and it's destructive in that it, you know, if there were four of them, and you pop it, now there are only three of them.


session: F05-10
timestamp: 00:35:01.12
speaker: LOW
utterance:
now you don't really need top because if you want to know what's on top you can pop it and then push it right back on, right?


session: F05-10
timestamp: 00:35:32.19
speaker: LOW
utterance:
oh, we also assume that we have some sort of function, Boolean function that tells us whether the stack is empty or not.


session: F05-10
timestamp: 00:35:49.01
speaker: LOW
utterance:
now what we're going to do is we're going to pop the stack and for a minute, I'm going to throw the value away.


session: F05-10
timestamp: 00:36:46.00
speaker: LOW
utterance:
ok, so we're going to count the number of the stack and be sure to restore the stack when we're done.


session: F05-10
timestamp: 00:37:04.17
speaker: LOW
utterance:
*uh well, if we keep topping it, it'll just keep saying f@l [x4], (be)cause it's non destructive so we got to really, the only way we get to the b@l is get that f@l off of there.


session: F05-10
timestamp: 00:37:16.02
speaker: LOW
utterance:
*uh yeah, so top would not be destructive but it would never, you'd think there's an infinite number of things in there (be)cause it just keeps saying f@l [x4].


session: F05-10
timestamp: 00:37:30.00
speaker: LOW
utterance:
we pop it and put it here, the counter goes to three, pop it and put it here, the counter goes to four.


session: F05-10
timestamp: 00:38:21.23
speaker: LOW
utterance:
pop and push, pop and push, pop and push, you don't have to count (th)em (be)cause I know they're xxx.


session: F05-11
timestamp: 00:00:16.25
speaker: LOW
utterance:
um, the thing is, the reason it's called linked is the only one who knows where the second element is the first one.


session: F05-11
timestamp: 00:00:41.00
speaker: LOW
utterance:
*uh, this first one we call info and this silly example is just a single letter but the real example would be a employ employee record or something like that, ok?


session: F05-11
timestamp: 00:00:53.00
speaker: LOW
utterance:
and that has a second field which is called the next field which is basically an address and it tells us where the second node is, ok?


session: F05-11
timestamp: 00:01:01.05
speaker: LOW
utterance:
and the second node is content or info, it tells us where the third one is and that has a link or information about where the fourth one is.


session: F05-11
timestamp: 00:01:24.17
speaker: LOW
utterance:
but the point is, you can't tell that it's four elements without searching through them because the only person who knows where the first one is this pointer to each one and then you have to go there to find this one {x3} you have to go there you find out that that's empty, ok?


session: F05-11
timestamp: 00:01:51.01
speaker: LOW
utterance:
first, second, third, fourth but I mean, not in physical order (be)cause this might actually be *uh say in the middle of memory.


session: F05-11
timestamp: 00:01:59.04
speaker: LOW
utterance:
and this is reallly here at the end of memory and the next one's at the beginning of memory and the next one's, you know.


session: F05-11
timestamp: 00:02:19.12
speaker: LOW
utterance:
the first one, then right next to it, the second one, right next to it's the third one, right next to it's the fourth <one>.


session: F05-11
timestamp: 00:02:32.20
speaker: LOW
utterance:
this first one here they want us to describe a sequence of operations to insert a new node with g@l in it after the node that contains b@l.


session: F05-11
timestamp: 00:02:57.05
speaker: LOW
utterance:
so we're just going to get a new node somewhere with g@l in it and then we're going to insert it to this link list.


session: F05-11
timestamp: 00:03:38.12
speaker: LOW
utterance:
*uh the subtlety is if I get this new node g@l and make this node point at it, do this first then *uh oh how can I set this pointer to this node here because nobody, once I break that nobody knows where that node is, ok?


session: F05-11
timestamp: 00:04:10.07
speaker: LOW
utterance:
*uh a word if you haven't talked about heard a lot like this where you probably haven't heard but is not a strange word but not that strange.


session: F05-11
timestamp: 00:04:23.00
speaker: LOW
utterance:
what we're going to do in almost all of these exercises is traverse or travel down this list doing something.


session: F05-11
timestamp: 00:04:29.12
speaker: LOW
utterance:
for example, if we wanted to count how many elements are in here we would simply traverse it one, two, three, four, until we get to the end.


session: F05-11
timestamp: 00:04:53.02
speaker: LOW
utterance:
so what we have to do is we have to find the node b@l and then we have to insert this node after it.


session: F05-11
timestamp: 00:05:46.10
speaker: LOW
utterance:
well, we want to move t@l, so we set t@l equal to, in the picture, I want t@l to go from there to here, ok?


session: F05-11
timestamp: 00:06:10.15
speaker: LOW
utterance:
so t@l starts here, no it's info isn't b@l, so t@l becomes, t@l follow its own link, a link in that node over here.


session: F05-11
timestamp: 00:07:08.27
speaker: LOW
utterance:
t@l which I traversed the list with t@l until I go to b@l and N@l which is this pointer to this new node.


session: F05-11
timestamp: 00:07:18.02
speaker: LOW
utterance:
and now I just need to set a couple of links here but I +// what we said earlier we need to be careful and didn't do this one first.


session: F05-11
timestamp: 00:08:54.29
speaker: LOW
utterance:
and then step number two is we want to locate +// change this so that's the next of +// we know what t@l points to.


session: F05-11
timestamp: 00:11:05.00
speaker: LOW
utterance:
ok, so again, always draw pictures look what the before is and what the after is and then we just have to write stuff down to it.


session: F05-11
timestamp: 00:11:18.01
speaker: LOW
utterance:
I'll take t@l which is h@l two, that's the way we initialize except something's going to be different, so we'll leave a little space.


session: F05-11
timestamp: 00:11:50.05
speaker: LOW
utterance:
ok, if that weren't a@l then we keep marching until we found it, but we found it and get out of the loop.


session: F05-11
timestamp: 00:12:43.07
speaker: LOW
utterance:
the trouble is the address that needs to change, and the link that needs to change, is in the one prior to a@l, right?


session: F05-11
timestamp: 00:13:39.25
speaker: LOW
utterance:
and if if we're looking for m@l, t@l would go there, s@l would go here so s@l should always be one node behind t@l.


session: F05-11
timestamp: 00:15:47.03
speaker: LOW
utterance:
(be)cause now, when we get out of this loop t@l points to a@l, which is pretty useless, and s@l points to the one before a@l.


session: F05-11
timestamp: 00:16:23.22
speaker: LOW
utterance:
yeah, the node that has a@l in it, mainly the node that t@l points at and so, what we're going to do is we want to copy this address into here.


session: F05-11
timestamp: 00:17:39.07
speaker: LOW
utterance:
well, this while loop would still find t@l would point to a@l, s@l would point to here and then what we said was next of s@l is next of t@l.


session: F05-11
timestamp: 00:17:57.05
speaker: LOW
utterance:
alright, that's alright, if I take the last one off and then the one before it becomes the last one. ok?


session: F05-11
timestamp: 00:18:08.15
speaker: LOW
utterance:
ouch, I can see it isn't going to work because in that case, t@l stops right here and s@l is null, right?


session: F05-11
timestamp: 00:18:20.06
speaker: LOW
utterance:
(be)cause the info of t@l is e@l, and then you can't say next of s@l is next of t@l because s@l is null.


session: F05-11
timestamp: 00:19:43.04
speaker: LOW
utterance:
*um, so basically we changed a link but if we're actually deleting the first node, we change the header.


session: F05-11
timestamp: 00:20:26.02
speaker: LOW
utterance:
*uh, you can talk about ternary trees and how a left, a middle and a right tree or whatever, but a simple case is just the left or the right.


session: F05-11
timestamp: 00:24:30.15
speaker: LOW
utterance:
because the easiest way to insert six is to search for it and if we don't find it put it right where it should've been, ok?


session: F05-11
timestamp: 00:25:08.01
speaker: LOW
utterance:
and I think you understand insertion (be)cause you just search, ok, found and put it where you know, was, would have been.


session: F05-11
timestamp: 00:25:44.07
speaker: LOW
utterance:
alright, so the last thing we talk about is delete a node from a binary seach tree and keep it a binary search tree.


session: F05-11
timestamp: 00:26:31.04
speaker: LOW
utterance:
delete the node that contains nine, moving as few nodes as possible, could draw a resulting tree and also keep it a binary search tree.


session: F05-11
timestamp: 00:26:57.15
speaker: LOW
utterance:
and to talk about that in general, if we're in this case with one kid, doesn't really matter if it's a left kid or a right kid.


session: F05-11
timestamp: 00:27:45.10
speaker: LOW
utterance:
it modified this one address right here and it still stayed a binary search tree we should argue that but we didn't do anything over here.


session: F05-11
timestamp: 00:28:11.25
speaker: LOW
utterance:
hmm, well, what people normally try is to you to promote so I'm going to +// I'm going to delete this five.


session: F05-11
timestamp: 00:29:01.15
speaker: LOW
utterance:
there's one number on the left and there's one number on the right that I can bring right up here and replace, put in the five spot and it'll still be a binary search tree.


session: F05-11
timestamp: 00:29:56.02
speaker: LOW
utterance:
and three works (be)cause three's smaller than five and therefore if three's smaller than all these guys (be)cause five is smaller than all these guys, ok?


session: F05-11
timestamp: 00:30:15.00
speaker: LOW
utterance:
*uh. see I can't bring nine up (be)cause some of these are smaller, in fact they're all smaller than nine.


session: F05-11
timestamp: 00:30:26.24
speaker: LOW
utterance:
great, because if I bring up the six then it's ok on the right (be)cause these guys are bigger than six.


session: F05-11
timestamp: 00:31:45.25
speaker: LOW
utterance:
if you want the biggest over here, well, you gotta go left to get into this tree and then you go +...


session: F05-11
timestamp: 00:32:59.20
speaker: LOW
utterance:
(be)cause six is bigger than all these guys (be)cause it's bigger than five and it was bigger than these guys.


session: F05-11
timestamp: 00:33:09.00
speaker: LOW
utterance:
so that's a very +// it looked like it was a killer type thing but it turned out that if you pick one of these two numbers, the biggest over here or the smallest over there, it's pretty simple.


session: F05-11
timestamp: 00:34:23.25
speaker: LOW
utterance:
*uh, you got this container here that these trays are in and it does look like there's only one tray.


session: F05-11
timestamp: 00:34:29.02
speaker: LOW
utterance:
but as soon as you take that tray off, the spring pops up a little bit and next tray is presented, ok?


session: F05-11
timestamp: 00:34:44.03
speaker: LOW
utterance:
so two major operations you can use are called pop and you pop a stack and that takes the top thing off the stack and it gives it to you.


session: F05-11
timestamp: 00:36:55.23
speaker: LOW
utterance:
yeah, five was the count of the number in the stack but now it's zero (be)cause I destroyed the stack so that's not good.


session: F05-11
timestamp: 00:38:10.02
speaker: LOW
utterance:
and I couldn't +// it wouldn't work where I use top here (be)cause I'd say top is p@l one, top is p@l two, top is p@l three.


session: F05-12
timestamp: 00:00:19.11
speaker: LOW
utterance:
a list, there's a first element, second element, third element, third element # so that's an easy idea.


session: F05-12
timestamp: 00:00:26.07
speaker: LOW
utterance:
why it's called a link list is, the only # way you can get to the list is through what's called a header, which is just the address of the first node.


session: F05-12
timestamp: 00:00:38.00
speaker: LOW
utterance:
and that contains two things of information, called info, and a link or what we call a next field which contains the address of a second node.


session: F05-12
timestamp: 00:00:48.22
speaker: LOW
utterance:
the only way to get to that second one is through the first one, you can't go straight to the second one.


session: F05-12
timestamp: 00:00:52.23
speaker: LOW
utterance:
and then that has a link to the third one, that has a link to the fourth one, that's called a link list.


session: F05-12
timestamp: 00:01:11.02
speaker: LOW
utterance:
so if c@l is stored under a@l, k@l would be stored in the next cell, b@l in the next cell, f@l on the next cell.


session: F05-12
timestamp: 00:01:19.15
speaker: LOW
utterance:
and here, <they're not> [//] they're in logical order, first second, third, fourth, but they're not in physical order.


session: F05-12
timestamp: 00:01:25.11
speaker: LOW
utterance:
so actually c@l might be here in the middle of the memory, and then k@l is some big address at the end of the memory, and b@l is in some cell, over here at a lower memory.


session: F05-12
timestamp: 00:02:07.15
speaker: LOW
utterance:
of course the after picture is, we do know the g@l end, and it comes in after the one, the b@l, that had b@l in it.


session: F05-12
timestamp: 00:02:13.29
speaker: LOW
utterance:
<so we just change a couple of links here> [//] actually change one link and add another link, so that's the afterpicture.


session: F05-12
timestamp: 00:02:27.06
speaker: LOW
utterance:
unfortunately the computer doesn't understand the after picture, so I have to describe the sequence of operations that do this.


session: F05-12
timestamp: 00:02:46.05
speaker: LOW
utterance:
I did this first, you know I got a new node g@l, I changed this to point to it, I destroyed this pointer.


session: F05-12
timestamp: 00:03:08.01
speaker: LOW
utterance:
<so I have to do this first lets see if I can write the pseudo-code here in a second> [//] I have to do this first and this second.


session: F05-12
timestamp: 00:03:18.07
speaker: LOW
utterance:
again the reason I have to do that is if I change this then nobody knows the address of this node and I can't xx that.


session: F05-12
timestamp: 00:03:32.16
speaker: LOW
utterance:
<this is +// yeah, so I have to> [//] so I want this guy to point to the new node g@l but if I do that too early I wont be able to set this one to point to the node f@l.


session: F05-12
timestamp: 00:03:40.27
speaker: LOW
utterance:
<because this is the only guy that has the address of f@l> [>] the only place the address of f@l node is stored is right there, before we make the change.


session: F05-12
timestamp: 00:03:55.03
speaker: LOW
utterance:
since you haven't talked about linklist [/] you probably haven't heard this word, traversal # but there is the same root as travel.


session: F05-12
timestamp: 00:04:06.16
speaker: LOW
utterance:
so if I was counting the nodes of this list I'd go one, move over here two, over here three, over here four, xxx/xx.


session: F05-12
timestamp: 00:05:25.11
speaker: LOW
utterance:
while +// you know t@l is pointing at info that's not b@l, so what we want to do is we just want to traverse the list.


session: F05-12
timestamp: 00:05:51.03
speaker: LOW
utterance:
so that's if that's the info of t@l that's the c@l lets just call this the next of the new t@l points.


session: F05-12
timestamp: 00:06:11.13
speaker: LOW
utterance:
*uh okay t@l equals h1@l , t@l is the address to this node, <so it doesn't matter if I put t over here, you know> [//] anywhere I point this node it is the address to this node.


session: F05-12
timestamp: 00:06:23.08
speaker: 112
utterance:
<so you> [>] <you won't get the same> [//] would you get the same point out of writing t@l close to c@l at the top?


session: F05-12
timestamp: 00:06:43.13
speaker: LOW
utterance:
well, I don't know where the node that has c@l in it is in general, <and this is> [//] and if I write c@l here that's my info record or whatever, and this is a pointer here, and the same thing.


session: F05-12
timestamp: 00:07:12.09
speaker: LOW
utterance:
and this is another pointer assignment. t@l is a pointer <so t@l has to be> [//] well it doesn't have to be but this is the way we do it.


session: F05-12
timestamp: 00:07:23.23
speaker: LOW
utterance:
so to move t@l forward the way we do that is we say t@l is assigned the value that in this next node <k@l>.


session: F05-12
timestamp: 00:07:45.25
speaker: LOW
utterance:
Ok so the first thing we had to do is find b@l and basically took these three lines, the psuedo code, and these three lines, a real code, to find b@l.


session: F05-12
timestamp: 00:07:55.16
speaker: LOW
utterance:
and now we're not worried about +// this is pseudo code, we're not worried about curly braces and stuff.


session: F05-12
timestamp: 00:08:05.04
speaker: LOW
utterance:
so lets suppose we have a constructor here, say *uh new, give me a new node, course I'll pass the info g@l to the node with g@l in it, and *uh that will return into a node and *uh you'll give me back it's address, so lets use another temporary, lets call it n@l for new.


session: F05-12
timestamp: 00:08:25.23
speaker: LOW
utterance:
so that's my simple code for creating a new node with g@l in it, and remembering it, it's address and n@l.


session: F05-12
timestamp: 00:09:36.20
speaker: LOW
utterance:
and now we can do this one, we'll just change <this one right here> [//] which is the next field the node t@l points to, is +...


session: F05-12
timestamp: 00:09:50.05
speaker: LOW
utterance:
I need the address to this node g@l that's what g@l and <it's address> [/] it's address is stored in.


session: F05-12
timestamp: 00:09:56.25
speaker: LOW
utterance:
and +// this one was the next point, next equals next, but this one is m@l, but that's a pointer, this is pointer assignment, pointer assignment, and here is a content comparison.


session: F05-12
timestamp: 00:10:10.14
speaker: 112
utterance:
[<] <so that's> like um in Fortran <when um> [//] when we set a dimension variable for a one dimension array we have to allocate it.


session: F05-12
timestamp: 00:10:18.23
speaker: 112
utterance:
and if the allocated status doesn't equal zero we have to stop the program, we have not enough memory.


session: F05-12
timestamp: 00:10:40.05
speaker: LOW
utterance:
alright, void the problems of Fortran or Java because I was assuming you studied Java so I wrote in pseudo-code.


session: F05-12
timestamp: 00:11:05.06
speaker: LOW
utterance:
(be)cause if I reverse these, which is what this stuff is supposed to be# an xx, <if I do this first, lets see,> [//] I set this pointer to point to n@l, okay?


session: F05-12
timestamp: 00:11:48.21
speaker: LOW
utterance:
[<] <right back to itself> here it messes up the list, now it goes c@l, k@l, b@l, g@l, g@l, g@l, g@l, g@l, g@l, alright?


session: F05-12
timestamp: 00:12:15.25
speaker: LOW
utterance:
so three on the list, there's got to be a two on the list, so obviously, hopefully, that's the after picture.


session: F05-12
timestamp: 00:12:38.16
speaker: LOW
utterance:
except this time t@l is h@l two so this means t@l is pointing to this first node and now we gotta find it which is awhile +...


session: F05-12
timestamp: 00:13:06.07
speaker: LOW
utterance:
it's the same three lines that we had to start with earlier, but we got a problem and we'll see what that is in just a second.


session: F05-12
timestamp: 00:13:59.23
speaker: 112
utterance:
so <it you> [/] okay, if you need to delete a@l, and you can't go past it and you can't go to it, then how do you find it?


session: F05-12
timestamp: 00:14:08.20
speaker: LOW
utterance:
so one way is to look forward, but that's, you know is to stop here because the next info is a@l but that's not.


session: F05-12
timestamp: 00:14:36.15
speaker: LOW
utterance:
and the reason I set s@l equal to null so I'm going to go back and t@l is initially here, and s@l is initially null.


session: F05-12
timestamp: 00:16:50.28
speaker: LOW
utterance:
okay # well, when the t@l is the one that's going to be equal to a@l, so t@l's marching first and s@l is behind it.


session: F05-12
timestamp: 00:17:06.28
speaker: LOW
utterance:
because t@l isn't a@l, and when we get out a loop, from the loop the post condition I guess is, t@l points to the node with a@l, and here's whats important, and s@l points to the one in front of it.


session: F05-12
timestamp: 00:17:28.23
speaker: LOW
utterance:
so now, s@l is here, and t@l is here, and what we have to do, we have to change this pointer right here, so we use +...


session: F05-12
timestamp: 00:18:01.24
speaker: LOW
utterance:
and we can say the next node s@l, that's what you wanted to change, not to point there, you want to make it point over here.


session: F05-12
timestamp: 00:18:14.25
speaker: LOW
utterance:
++ is the address of this thing here, how I find the address of m@l, now this guy right here is storing it, so quick before you delete that guy, set this address equal to # next of +...


session: F05-12
timestamp: 00:19:01.26
speaker: LOW
utterance:
alright? okay we have time we'll come back and we won't probably have time we got to talk about *uh binary search trees a little bit and *uh stacks and queues.


session: F05-12
timestamp: 00:19:14.20
speaker: LOW
utterance:
so I guess the thing that you need to remember there is draw the pic[ture] so much you still have to draw the picture and watch out, sometimes the order is very critical.


session: F05-12
timestamp: 00:19:48.14
speaker: LOW
utterance:
and the way you keep track of the tree is through a pointer to the first node which is called the root.


session: F05-12
timestamp: 00:20:17.29
speaker: LOW
utterance:
of course you can have a ternary tree a 3-ary tree with left, middle, and right kids or a 10-ary tree with you know.


session: F05-12
timestamp: 00:20:36.23
speaker: LOW
utterance:
for every node, I'm pointing to the root but this is true everywhere, the nodes on the left are smaller, and the nodes on the right are larger.


session: F05-12
timestamp: 00:21:21.08
speaker: LOW
utterance:
alright, so the question was, which of these four are binary search trees, and I have already done that for you


session: F05-12
timestamp: 00:21:57.06
speaker: LOW
utterance:
but five has no left tree <so that's> [/] that's okay, I mean these are smaller then eleven, these are smaller than seven, that's smaller than five, and ten is bigger than seven +...


session: F05-12
timestamp: 00:22:17.02
speaker: LOW
utterance:
nope it's bigger than seven, so it's not drawn very well, eight is in the left subtree [?] of seven.


session: F05-12
timestamp: 00:23:11.13
speaker: LOW
utterance:
I don't know why they put the problems in that order because the searches are the easiest, then the insertions, then the deletions.


session: F05-12
timestamp: 00:24:20.02
speaker: LOW
utterance:
okay so we go right because we're looking for something bigger then five and we come to nine so we # do what?


session: F05-12
timestamp: 00:24:32.25
speaker: LOW
utterance:
so the problem was to describe the search procedures for eight and say we start at five and you go right to nine and you go left to eight and stop because you found it.


session: F05-12
timestamp: 00:25:13.10
speaker: LOW
utterance:
well a search could fail, I mean eight was in this tree and we found it, four isn't in that tree so of course we fail.


session: F05-12
timestamp: 00:25:58.19
speaker: LOW
utterance:
well alright so that's why I want to do them in this order, search, and then if it fails, put it in there.


session: F05-12
timestamp: 00:26:09.05
speaker: LOW
utterance:
we just search, it's called binary tree search and you discovered the algorithm for doing the insertion, that's simple. Deletion is trickier.


session: F05-12
timestamp: 00:26:20.14
speaker: LOW
utterance:
there are actually three cases they only look at two here in my notes, but quickly, lets suppose we want to delete a node with no kids.


session: F05-12
timestamp: 00:26:45.18
speaker: LOW
utterance:
basically I can just come here and change that to null. Case one if the one your trying to delete has one kid.


session: F05-12
timestamp: 00:27:06.04
speaker: LOW
utterance:
yeah, so it could be an immense tree below nine on the left side, what we're saying is nine only has one kid, either left or right.


session: F05-12
timestamp: 00:27:14.19
speaker: LOW
utterance:
so we want to delete nine, move as few nodes as possible without messing the whole tree around, and they don't say it but they want you to keep it a binary search tree.


session: F05-12
timestamp: 00:27:24.24
speaker: LOW
utterance:
so do you see a way of deleting nine <and not doing much surgery> [//] not doing much cutting and pruning?


session: F05-12
timestamp: 00:28:01.17
speaker: LOW
utterance:
now five has a couple of grandchildren over on this side, but on this side since five has only one kid nine has only one grandparent on the right side.


session: F05-12
timestamp: 00:28:15.13
speaker: LOW
utterance:
exactly as you drew it, basically you changed that one address right there and of course you would delete this node


session: F05-12
timestamp: 00:28:50.12
speaker: LOW
utterance:
alright so we're back to our original tree and what they want us to do is they want us to delete five.


session: F05-12
timestamp: 00:29:04.02
speaker: LOW
utterance:
so what people try to do is move two up, (be)cause two has two kids, and by the way two can't come up because <three and four can't be on the left side> [>]


session: F05-12
timestamp: 00:29:14.22
speaker: LOW
utterance:
and nine can't come up because these guys are smaller then nine and if they're smaller than nine they can't be in the +...


session: F05-12
timestamp: 00:29:18.17
speaker: LOW
utterance:
<but it turns out> [/] it turns out that if you look in the left tree, there is one node that can move up and take fives place and not be much of a problem.


session: F05-12
timestamp: 00:29:28.16
speaker: LOW
utterance:
or if you look on the right tree there is one node that can move up and take five's place and just by playing around and you know it can't be two.


session: F05-12
timestamp: 00:30:00.22
speaker: 112
utterance:
I picked since this side of the tree seems greater because it starts with numbers five I picked the <smallest number> [>].


session: F05-12
timestamp: 00:30:18.14
speaker: LOW
utterance:
the four, then it'll be bigger than these, so that's alright, and since it's less than five it'll be less than these guys.


session: F05-12
timestamp: 00:30:29.11
speaker: LOW
utterance:
it'll be greater than five, since we entered all these guys automatically, and it's the smallest of these so it's less than these guys.


session: F05-12
timestamp: 00:31:07.04
speaker: LOW
utterance:
alright, now it doesn't matter which one you pick, oh by the way, four and six are both leaves, *uh that doesn't have to be the case, if we put six and a half in this tree right here it bigger than five smaller smaller smaller the bigger is six.


session: F05-12
timestamp: 00:31:31.09
speaker: LOW
utterance:
because if six has a left child, that would be smaller than six, and we would keep going down that left branch, right?


session: F05-12
timestamp: 00:31:39.03
speaker: LOW
utterance:
if it has a right kid we'll just do this one kid, grandparent grandchild surgery that we did before.


session: F05-12
timestamp: 00:31:55.03
speaker: LOW
utterance:
and then we'll put six up here and it's still a binary search tree without doing much moving around.


session: F05-12
timestamp: 00:32:01.20
speaker: LOW
utterance:
(be)cause once again six is bigger than all these because it was bigger than the five and it was bigger than all these.


session: F05-12
timestamp: 00:32:09.11
speaker: LOW
utterance:
or, we could have brought the four up, and once again the four wouldn't necessarily be a leaf if I put the three and a half right here xxx right here.


session: F05-12
timestamp: 00:32:44.15
speaker: LOW
utterance:
I think of a bunch of trays in a cafeteria where they have this special really very elegant *uh dispenser the trays are in and all you can see is the trays on top.


session: F05-12
timestamp: 00:32:55.24
speaker: LOW
utterance:
there's a spring down here, and you take that try off the spring and it' loaded so that the next tray pops up.


session: F05-12
timestamp: 00:33:06.17
speaker: LOW
utterance:
so the only thing you can do is pop something off instead of trays we're going to have this thing on letters a@l x@l b@l.


session: F05-12
timestamp: 00:33:27.03
speaker: LOW
utterance:
you can pop a stack it's called s@l and that gives you the thing that's on top of the stack # it gives you a value.


session: F05-12
timestamp: 00:34:59.18
speaker: LOW
utterance:
well, I'm simply going to pop them off, because I've got to get them, I've got to tell them how many there are.


session: F05-12
timestamp: 00:35:53.21
speaker: LOW
utterance:
okay, since I'm running out of time, five is what +// there used to be in the stack, but since I popped him it's just four.


session: F05-12
timestamp: 00:36:17.19
speaker: LOW
utterance:
so, let me put this for you, let me show you, we should count the number out and then if we mess it, we should restore the stack.


session: F05-12
timestamp: 00:36:51.03
speaker: 112
utterance:
(be)cause you would have to pop it off, you would have to create another auxiliary to get it pushed back on.


session: F05-12
timestamp: 00:36:55.05
speaker: LOW
utterance:
so what we do is we do another element right (be)cause we're running out of time, we'll do another while loop, while t@l is empty.


session: F05-12
timestamp: 00:37:13.22
speaker: LOW
utterance:
*uh, you can ask them, but my guess is no but you can have them afterwards umm +// xx have those questions.


session: F05-13
timestamp: 00:00:21.26
speaker: JAC
utterance:
so if we think of our our stack, the stack is Legos, every time you want to put on something onto the stack you put a new Lego, right?


session: F05-13
timestamp: 00:02:03.14
speaker: JAC
utterance:
so basically like the whole idea premise you can't take you can never take anything from the bottom or the middle of your Legos.


session: F05-13
timestamp: 00:04:38.17
speaker: JAC
utterance:
um, obviously these are binary search trees and each node, preferably this as a node, each node has its +// has a child.


session: F05-13
timestamp: 00:05:05.27
speaker: JAC
utterance:
so, if we were to look at that and assume that each child is also it's a parent of some other children.


session: F05-13
timestamp: 00:05:21.14
speaker: JAC
utterance:
so just looking at this, we can look, go to the right, you see that the right child is greater than the parent.


session: F05-13
timestamp: 00:07:01.00
speaker: JAC
utterance:
um, so let's +// if we want to delete a node of this tree, with five, and eight, and seven, two, three, and two of the xx.


session: F05-13
timestamp: 00:11:33.25
speaker: JAC
utterance:
so whenever we find null, we've found, when we're doing a search we found out that we do not have the number that we're looking for whenever we're looking for in any tree.


session: F05-13
timestamp: 00:11:54.03
speaker: JAC
utterance:
or we might return the null pointer so that ok, I didn't find it, let me insert four into the tree, right?


session: F05-13
timestamp: 00:12:04.12
speaker: JAC
utterance:
so if I wanted to insert +// now I know where this is instead of me doing another adding and having go ok, I'm going to add four and have to go and compare five and four.


session: F05-13
timestamp: 00:12:14.20
speaker: JAC
utterance:
two, four, and three and four, and then five and find null and add it, doing basically another search, I could just add it right away. alright?


session: F05-13
timestamp: 00:12:52.03
speaker: JAC
utterance:
so the obvious way is to just transverse, I'm just going to draw the one side (be)cause obviously, the typical way it's going to come down here.


session: F05-13
timestamp: 00:14:06.07
speaker: JAC
utterance:
um, a second way is instead of adding every +// go down the entire tree, searching and then inserting.


session: F05-13
timestamp: 00:15:03.00
speaker: JAC
utterance:
so what =// some +// some algorithms do is they insert, instead of inserting six all the way down at the first available spot, they assume that the first available spot is the root, ok?


session: F05-13
timestamp: 00:15:57.05
speaker: JAC
utterance:
so we don't want +// we actually want to say put five is pointing to the right side and make six point to that, assuming that that's also greater than nine.


session: F05-13
timestamp: 00:16:40.10
speaker: JAC
utterance:
this way now, I want to insert at zero level and then we have to move everything else around, in order to shape it.


session: F05-13
timestamp: 00:18:40.27
speaker: JAC
utterance:
so if we wanted +// if we wanted to rearrange the nodes to create another tree, that that would be one way to do it.


session: F05-13
timestamp: 00:19:02.06
speaker: JAC
utterance:
it's probably the simplest way just to rearrange them otherwise, just to make xxx, just to change the order.


session: F05-13
timestamp: 00:19:40.01
speaker: JAC
utterance:
xxx the first off the stack, seven, three, seven, got the next one, nine, eight, two, one, and five.


session: F05-13
timestamp: 00:20:45.15
speaker: JAC
utterance:
so going +// doing a search down the left side or the right side and doing a search down the left side, both take the same amount of time.


session: F05-13
timestamp: 00:20:55.00
speaker: JAC
utterance:
so that searches on the right don't take twice as long, three times as long or N@l times as long, ok?


session: F05-13
timestamp: 00:21:39.00
speaker: JAC
utterance:
*uh, assume that this contains g@l, so if we wanted to insert a node, um, we find out we have where it's supposed to be inserted, right?


session: F05-13
timestamp: 00:26:14.07
speaker: JAC
utterance:
so we come through here and we delete this pointer, we delete a@l, and we delete we change what these point to.


session: F05-13
timestamp: 00:26:53.04
speaker: JAC
utterance:
um, # should you um # +// if you delete # +// if you delete a@l, delete +// delete a@l after you've reached the pointer # xxx.


session: F05-13
timestamp: 00:27:55.00
speaker: JAC
utterance:
you would call +// you would actually either de-allocate it from memory usually by calling delete which would call depending on which what language you're programming in.


session: F05-13
timestamp: 00:28:18.10
speaker: JAC
utterance:
if you were working C@l, you can call delete on a@l and it would call a descriptive delete and destroy this so xxx, ok?


session: F05-13
timestamp: 00:28:33.10
speaker: JAC
utterance:
if we wanted to add +// about five minutes +// want to add list two to this at the end of list one it's almost exactly the same as adding your node, right?


session: F05-13
timestamp: 00:32:10.25
speaker: JAC
utterance:
we actually want k@l to point to, not what the head two is pointing to, not what head two, what head two is pointing to.


session: F05-13
timestamp: 00:32:50.24
speaker: JAC
utterance:
now it's easier, sometimes it's easier to think of this list as just one big node and just think of it one xxx pointing to the head.


session: F05-13
timestamp: 00:33:27.04
speaker: JAC
utterance:
think of it +// a node can hold +// a node could hold *uh say you can have it as a structure, a name, a I@l D@l number, a phone number, right?


session: F05-13
timestamp: 00:34:03.12
speaker: JAC
utterance:
so what's the whole +// what's the key from me having one variable just to hold, and one data structure that holds all the other data structures together?


session: F05-13
timestamp: 00:34:35.05
speaker: JAC
utterance:
everything's still maintained in here and now I have a link list with just one element so you just add it.


session: F05-13
timestamp: 00:34:49.16
speaker: JAC
utterance:
xxx +// sometimes it's easier to obviously to simplify something that's going to make one big thing into a little thing.


session: F05-14
timestamp: 00:00:21.22
speaker: JAC
utterance:
what we could do is we can take an object, *uh, a number for example and we use a function called push, ok?


session: F05-14
timestamp: 00:00:47.03
speaker: JAC
utterance:
so now if i'm go again and do push b@l what it's going to do is take the next available spot and put it on top.


session: F05-14
timestamp: 00:00:58.12
speaker: JAC
utterance:
kind of like [x2] Legos you put [x2] your bottom piece first and you start stacking up on top right?


session: F05-14
timestamp: 00:01:17.26
speaker: JAC
utterance:
so now if we wanted to get something out of the stack, what we do is we have two different, we have two similar functions that do slightly different things.


session: F05-14
timestamp: 00:01:48.03
speaker: JAC
utterance:
now we have another function, kind of the opposite of push, um and kind of like top which is called pop #.


session: F05-14
timestamp: 00:03:22.09
speaker: JAC
utterance:
this is again you're pushing, this is just a *uh # a data, a structure to hold different elements such as characters, letters.


session: F05-14
timestamp: 00:04:09.16
speaker: JAC
utterance:
they're not actually there's some in here that aren't binary search trees and there are some that are.


session: F05-14
timestamp: 00:04:14.08
speaker: JAC
utterance:
what a binary search tree is [x2] you have what we call the, this would be called the root or parent ##, ok?


session: F05-14
timestamp: 00:05:25.19
speaker: JAC
utterance:
go check all the right children, come back up one, check the left child and go back and forth and xxx do that.


session: F05-14
timestamp: 00:05:46.15
speaker: JAC
utterance:
and what would actually do, what a computer program would do would be check it, check twelve's right child.


session: F05-14
timestamp: 00:06:59.26
speaker: JAC
utterance:
so if binary search tree, the right child should always be greater than the parent and left child should always be less than the parent.


session: F05-14
timestamp: 00:09:00.24
speaker: JAC
utterance:
now, you could +// I mean there's no reason why you couldn't have a binary search tree set up where you have the right child less than the parent and the left child greater than the parent like we have the set up here.


session: F05-14
timestamp: 00:09:17.02
speaker: JAC
utterance:
however, what happens is, if somebody's expecting you to have the right child greater and the left child less than.


session: F05-14
timestamp: 00:09:25.01
speaker: JAC
utterance:
and you write it the other way, they're going to be expecting something that isn't going to be happening, right?


session: F05-14
timestamp: 00:10:39.24
speaker: JAC
utterance:
there is +// if you create +// if you were to create some totally new thing, as long as you could compare it from one item to another, you can create a binary search tree, ok?


session: F05-14
timestamp: 00:13:02.00
speaker: JAC
utterance:
now, the reason we're doing this is we're finding the lowest number that is greater than five right?


session: F05-14
timestamp: 00:13:21.17
speaker: JAC
utterance:
ok? so we found seven is the lowest value so we're going to take seven and we're going to make it take the place of five.


session: F05-14
timestamp: 00:13:30.27
speaker: JAC
utterance:
now if we were to do, if we were to take nine for example and make it the new five or +// let's say we take eight, now you have eight here, but you have seven.


session: F05-14
timestamp: 00:13:41.15
speaker: JAC
utterance:
and now seven has to go over on this side and that's currently on this side of the tree right, and we break this up down the middle, alright?


session: F05-14
timestamp: 00:15:37.23
speaker: JAC
utterance:
seven, even though it's really  doesn't look like it's pointing to anything, it's actually pointing at null, ok?


session: F05-14
timestamp: 00:15:50.08
speaker: JAC
utterance:
that's how we know that we've reached a point where it's pointing to, it's pointing to null so that we know if we, if we ever find anything pointing to null, we can insert something there.


session: F05-14
timestamp: 00:16:08.01
speaker: JAC
utterance:
so since seven is left child is null, where we're going to do is set six equal to the position that seven is pointing to null.


session: F05-14
timestamp: 00:16:30.00
speaker: JAC
utterance:
um, if we do a search, actually rewrite this thing here. so getting that completely, eight, seven, two, one, and three.


session: F05-14
timestamp: 00:17:20.19
speaker: JAC
utterance:
um, depending on how we're writing, we might return in this spot on the tree so that we know exactly where it is.


session: F05-14
timestamp: 00:18:49.24
speaker: JAC
utterance:
or someone might return either the null pointer, the null node, so that ok i didn't find four i'm going to insert four here.


session: F05-14
timestamp: 00:20:30.06
speaker: JAC
utterance:
so, theoretically we could have, we could have a tree that's a hundred levels deep, a thousand levels deep, million levels deep, you keep going up to N@l, right?


session: F05-14
timestamp: 00:27:06.10
speaker: JAC
utterance:
so what g@l does is, is ok i'm going to point, I know b@l is in front of f@l, or f@l is in front of b@l #.


session: F05-14
timestamp: 00:27:22.27
speaker: JAC
utterance:
g@l is just like alright, I know f@l's in front of you, but now I know f@l's going to be in front of me.


session: F05-14
timestamp: 00:28:30.08
speaker: JAC
utterance:
so the comparison i'm going to make is same movie line, but a@l got bored and doesn't want to wait in line anymore.


session: F05-14
timestamp: 00:30:25.14
speaker: JAC
utterance:
say we want to insert #, we want to insert this second list here into the end of one or three here #.


session: F05-14
timestamp: 00:30:58.17
speaker: JAC
utterance:
so what we're going to do is we're going to find, we're going to go look through this first list and find where it points to null.


session: F05-14
timestamp: 00:31:48.15
speaker: JAC
utterance:
(be)cause we don't want something, we don't want to to think that h@l two is pointing to the head of [x2] the line.


session: F05-14
timestamp: 00:32:30.27
speaker: JAC
utterance:
instead what we're going to do is we're going to go look through the list and find where it's pointing to null.


session: F05-14
timestamp: 00:33:30.15
speaker: JAC
utterance:
so it's just the same thing as pointing through but we have to transverse whatever's inside in the first person ##.


session: F05-14
timestamp: 00:35:48.25
speaker: JAC
utterance:
a@l's going to be like ok temp i'm going to point to m@l # and i know e@l's pointing to you now so i'm going to have e@l point to me and you can just go away.


session: F05-15
timestamp: 00:00:42.27
speaker: JAC
utterance:
and we want to insert +// we want to create +// we're going to create a new node # g@l and we're going to insert it after b@l right?


session: F05-15
timestamp: 00:01:05.03
speaker: JAC
utterance:
(be)cause we don't necessarily +// we don't automatically know where it is so we go start here at the head and start going through one at a time until we find b@l right?


session: F05-15
timestamp: 00:01:34.25
speaker: JAC
utterance:
so we're going to +// so b@l is going to point +// we're going to end up wanting b@l to point to g@l and g@l to be pointing to whatever b@l is currently pointing to right?


session: F05-15
timestamp: 00:02:16.16
speaker: JAC
utterance:
we want g@l to point to f@l so what we do is +// we've gone through the entire list we found that +// who b@l points # it points to f@l so we're going to set +// we're going to have g@l point to whatever b@l is currently pointing to.


session: F05-15
timestamp: 00:02:33.00
speaker: JAC
utterance:
so right now we know +// we're at b@l # we create g@l and we set it equal to whatever b@l is pointing to, alright?


session: F05-15
timestamp: 00:03:54.29
speaker: JAC
utterance:
so we need to find a +// we need to go through the list and first find a@l so we go through h@l 2 and find e@l +// we find e@l is pointing to a@l.


session: F05-15
timestamp: 00:04:53.23
speaker: JAC
utterance:
well if we were to +// if we were coding +// if we were coding this we could say node +// assuming we're at e@l +// node, node, next, next # right?


session: F05-15
timestamp: 00:05:15.09
speaker: JAC
utterance:
um # so then this would tell me if I'm at +// if this is currently at e@l this would give me a@l +// this would be a@l.


session: F05-15
timestamp: 00:06:03.18
speaker: JAC
utterance:
so we know now that a@l is pointing to m@l so instead of e@l pointing to a@l we tell e@l to point to m@l okay.


session: F05-15
timestamp: 00:06:21.07
speaker: JAC
utterance:
so we take a@l we set its +// we delete its pointers we set it to null okay so right now it points to null.


session: F05-15
timestamp: 00:06:38.19
speaker: JAC
utterance:
then you're going to delete +// say # say for example for whatever reason and say something tries to access a@l before you delete it okay and it's going to have a@l and it's pointing to m@l.


session: F05-15
timestamp: 00:06:55.02
speaker: JAC
utterance:
you could have +// you could have +// you could have some problem so having it set it to null first and then deleting it so something +// process comes in and tries to access a@l and sees what's a@l is pointing to before you delete this it's not going to be pointing to anything else okay?


session: F05-15
timestamp: 00:07:12.12
speaker: JAC
utterance:
because if you were to just delete this +// there is a possibility that something could come in before you delete it.


session: F05-15
timestamp: 00:07:34.28
speaker: JAC
utterance:
it's the way +// it's the way I normally do it and most +// some of the professors I know usually do it that way okay?


session: F05-15
timestamp: 00:07:44.23
speaker: JAC
utterance:
um if we want to combine these two lists # we can actually think about this almost as one big node right?


session: F05-15
timestamp: 00:09:06.03
speaker: JAC
utterance:
so it's simple enough we just set it +// we set +// if we would set this equal to h@l two +// what it's pointing to so we create a link that way, right?


session: F05-15
timestamp: 00:09:19.21
speaker: JAC
utterance:
so now this is pointing here and we know the end of the list is pointing to null so we have a null here.


session: F05-15
timestamp: 00:09:28.24
speaker: JAC
utterance:
that +// you don't have to check for it but I'm just pointing out that if for some reason this wasn't pointing to anything we'd want to go through and make sure it was pointing to null.


session: F05-15
timestamp: 00:09:48.11
speaker: JAC
utterance:
we have +// the problem is though head two is not pointing to the beginning of the list # it's pointing to the middle of the list, right?


session: F05-15
timestamp: 00:10:08.29
speaker: JAC
utterance:
I mean you might want to +// you might want h@l two to also point to the same place h@l one is pointing to so that h@l two and h@l one point to each other +// point to the same spot.


session: F05-15
timestamp: 00:10:27.25
speaker: JAC
utterance:
because if it's pointing to the middle of your list you might be thinking it's beginning and then there's no way for you to go back to check to see if there was something in front of it right?


session: F05-15
timestamp: 00:10:43.03
speaker: JAC
utterance:
so we can either set it equal to whatever h@l one is pointing to or we can delete it completely # or if we were to copy +// or if for whatever reason if you wanted to have these two copies exist in memory # you could have +// you could have copied all these and create an entire new linked list and then added it like this.


session: F05-15
timestamp: 00:11:05.06
speaker: JAC
utterance:
more likely than not you would want to do that because this may have uh take up a lot of memory, right?


session: F05-15
timestamp: 00:11:13.29
speaker: JAC
utterance:
see each one of these nodes may represent something that's ten megabytes and you have a list +// you have a linked list of a thousand units.


session: F05-15
timestamp: 00:11:23.10
speaker: JAC
utterance:
you don't necessarily want to make copies of these because eventually you're going to run out of memory right?


session: F05-15
timestamp: 00:11:55.21
speaker: JAC
utterance:
so what we're going to do is insert this into after k@l so we do this almost the same way as last time but what we're going to do is find out what this node is pointing to +// I'm sorry find out what k@l is pointing to and set this node to point to that and then set k@l to point to that +// this part and of the xxx, right?


session: F05-15
timestamp: 00:12:30.22
speaker: JAC
utterance:
now the only difference is when we get inside the node we have to keep going and finding the point where it points to null.


session: F05-15
timestamp: 00:12:42.11
speaker: JAC
utterance:
well # not +// not trying to have you create +// you want to create a temporary +// you're saying you want to create a temporary node?


session: F05-15
timestamp: 00:12:55.09
speaker: JAC
utterance:
well we have +// I think writing on that wasn't the best +// we still have this is a +// we're doing it the same way as +// we're not editing so we have a@l and m@l xxx right?


session: F05-15
timestamp: 00:13:27.12
speaker: JAC
utterance:
I can think of it as one big +// I'm not saying let's make it +// let's make it a node # a one node.


session: F05-15
timestamp: 00:13:33.24
speaker: JAC
utterance:
I'm saying let's think of it as a single node maybe that makes it a little easier maybe I'm wrong or maybe this is complicated but if I think of this as one big node I know where it is, I know what's pointing to this end.


session: F05-15
timestamp: 00:13:50.14
speaker: JAC
utterance:
just like a regular node so I can +// I can just come in here and say I'm inserting after k@l and here's b@l so k@l points to b@l right now.


session: F05-15
timestamp: 00:14:14.19
speaker: JAC
utterance:
so here's the head # there's null but actually what I'm really doing is here's the head # here's e@l.


session: F05-15
timestamp: 00:15:03.04
speaker: JAC
utterance:
and I'm just finding out where it's null +// I'm in both lists +// I'm in both lists +// I'm in this list right now.


session: F05-15
timestamp: 00:15:20.01
speaker: JAC
utterance:
I store off something temporary what +// where this +// store this +// I want to know what it's pointing to, right?


session: F05-15
timestamp: 00:15:49.10
speaker: JAC
utterance:
(be)cause I know +// and I know where I'm going to insert it so what I do is I say +// I set m@l equal to +// m@l's +// whatever m@l is pointing to +// where it's pointing to next equals +// set it to whatever k@l is currently pointing to which I've already found out.


session: F05-15
timestamp: 00:16:29.24
speaker: JAC
utterance:
if I wanted to create +// if you wanted to create a temporary node what you would do is create a temp and set its pointer equal to b@l, right?


session: F05-15
timestamp: 00:16:43.19
speaker: JAC
utterance:
now I can reference +// I can reference this (be)cause I just +// I just created it and I know where it is, right?


session: F05-15
timestamp: 00:16:48.11
speaker: JAC
utterance:
I know I can call it so I could say +// I could check the temp and find out what it's pointing to right?


session: F05-15
timestamp: 00:17:20.19
speaker: JAC
utterance:
we're +// what I'm doing is I'm pointing +// I'm going through the list +// if we're looping +// we're doing a loop, right?


session: F05-15
timestamp: 00:17:32.04
speaker: JAC
utterance:
and we're at +// we start at the head and we loop through and we find out what the head is pointing to.


session: F05-15
timestamp: 00:18:07.29
speaker: JAC
utterance:
so now I have t@l +// I have t@l it's off of memory I know it's pointing +// I know it's pointing to b@l, right?


session: F05-15
timestamp: 00:18:36.16
speaker: JAC
utterance:
(be)cause I create the +// the point of creating the temp of the node t@l is so that I know where it is +// I know +// I know where it exists and I access it.


session: F05-15
timestamp: 00:19:04.22
speaker: JAC
utterance:
when you're here you want to create a temporary pointer to what it's +// you would create a temporary pointer to what it's pointing to.


session: F05-15
timestamp: 00:19:18.11
speaker: JAC
utterance:
well you're +// yeah you can create another +// you can create either +// there's a couple different ways you can probably do it.


session: F05-15
timestamp: 00:19:26.17
speaker: JAC
utterance:
um efficiently +// efficiently with the least amount of memory you want to find out what's pointing to k@l and then create a temporary there, right?


session: F05-15
timestamp: 00:19:45.11
speaker: JAC
utterance:
and you can create +// you can create another +// you can call it +// you can create another temporary called t@l two, right?


session: F05-15
timestamp: 00:19:53.17
speaker: JAC
utterance:
or you can do +// or you can be at k@l +// you can be at k@l and +// you can go through this list and find out what its null and set that equal to and have a function that returns what k@l is pointing to, right?


session: F05-15
timestamp: 00:20:14.21
speaker: JAC
utterance:
yeah if we wanted we could create a function that would have just returned this value so we could set this equal to b@l.


session: F05-15
timestamp: 00:20:41.10
speaker: JAC
utterance:
we're at k@l +// we don't even +// I don't even think we were +// we already had something pointing +// we already have the rest of the list pointing to k@l, right?


session: F05-15
timestamp: 00:21:24.18
speaker: JAC
utterance:
so if we were at k@l and we set +// we go through this list and find out what points to null and we set this equal to what k@l is pointing to, okay?


session: F05-15
timestamp: 00:21:35.07
speaker: JAC
utterance:
now I need to set k@l equal to this list and +// I'm going to insert the rest of this list here, right?


session: F05-15
timestamp: 00:22:11.08
speaker: JAC
utterance:
so if I call h@l +// if I call h@l two I say k@l next equals h@l two # next something like that right?


session: F05-15
timestamp: 00:22:35.06
speaker: JAC
utterance:
even think it's xxx xxx xxx xxx it's just +// whatever k@l is pointing +// if I say +// you see each of these have next on top of them, right?


session: F05-15
timestamp: 00:22:54.15
speaker: JAC
utterance:
so if I can reference it through this way, right and the same thing with the head h@l two point +// some next value.


session: F05-15
timestamp: 00:23:07.11
speaker: JAC
utterance:
so if I set this equal to this then what this is going to be pointing to now is it's going to be pointing to uh e@l right?


session: F05-15
timestamp: 00:23:22.15
speaker: JAC
utterance:
after this line k@l next equal +// well if I +// well if I was to check what its value is it's going to give me +// I'm sorry e@l, right?


session: F05-15
timestamp: 00:23:38.00
speaker: JAC
utterance:
I set it +// I set k@l next equal +// k@l next was b@l # and then I'm setting it equal to h@l two next.


session: F05-15
timestamp: 00:24:22.27
speaker: JAC
utterance:
now we have h@l two which is pointing to e@l which is pointing to a@l # which is pointing to m@l and we agree that we have m@l now pointing to b@l, right?


session: F05-15
timestamp: 00:24:57.29
speaker: JAC
utterance:
we want k@l to point to the first node in this list that we just added in front +// that we're trying to add at the same point.


session: F05-15
timestamp: 00:25:07.08
speaker: JAC
utterance:
both of these pointing to b@l is fine # it doesn't create any error or anything but we don't want +// we don't want this situation (be)cause right now I have two +// right now if you think about it we have two linked lists that eventually end at b@l and b@l points to f@l, right?


session: F05-15
timestamp: 00:25:28.20
speaker: JAC
utterance:
so this is what +// if we look at it this is exactly what we have +// I have two lists that merge at one point and then end at the same spot.


session: F05-15
timestamp: 00:25:58.03
speaker: JAC
utterance:
so in order to do that I need to set what k@l is pointing to equal to whatever h@l two +// whatever the head is pointing to.


session: F05-15
timestamp: 00:26:10.21
speaker: JAC
utterance:
I can transverse +// I can go here # call the head and find out what it's pointing to # it's pointing to c@l.


session: F05-15
timestamp: 00:26:23.09
speaker: JAC
utterance:
+, I find what k@l +// I have the +// I can reference what k@l is pointing to by +// let's say by calling k@l next, okay?


session: F05-15
timestamp: 00:27:07.29
speaker: JAC
utterance:
so I need to set whatever k@l is pointing to to whatever h@l two is +// the first thing h@l two is pointing to, right?


session: F05-15
timestamp: 00:27:16.19
speaker: JAC
utterance:
so I find out it's pointing to e@l so I want to set this to point to e@l instead of pointing to b@l.


session: F05-15
timestamp: 00:27:30.18
speaker: JAC
utterance:
(be)cause I had +// h@l two told me where it is and I currently know how to point +// I'm pointing to b@l and I can access this so I can say don't point to b@l anymore # point +...


session: F05-15
timestamp: 00:28:17.26
speaker: JAC
utterance:
so we find +// we first went through this list +// go through h@l two # find who points to null, right?


session: F05-15
timestamp: 00:28:43.18
speaker: JAC
utterance:
we need to go +// and then we go +// we go through h@l one and find # who points +// who +// I'm sorry +// who k@l points to.


session: F05-15
timestamp: 00:29:11.29
speaker: JAC
utterance:
okay so we find that value out and we want to set m@l to point to the same node k@l is pointing to, right?


session: F05-15
timestamp: 00:29:37.07
speaker: JAC
utterance:
so that's +// that's easy I can just instead of this pointing to null I set it pointing to b@l # and now it points to b@l.


session: F05-15
timestamp: 00:29:53.04
speaker: JAC
utterance:
we can have +// we can have +// we can have more and more +// we can have +// b@l can be pointed by more than one item, right?


session: F05-15
timestamp: 00:30:16.12
speaker: JAC
utterance:
we can create it if +// we can create a temporary node t@l and we know what it's pointing to # it points to b@l # xxx say it points to b@l.


session: F05-15
timestamp: 00:30:28.00
speaker: JAC
utterance:
and we can reference t@l and we can say m@l I want you to point to whatever t@l is pointing to, right?


session: F05-15
timestamp: 00:31:09.22
speaker: JAC
utterance:
I haven't done anything yet # now I also need to set this +// I need to set this equal to whatever h@l two is pointing to # whatever the other list is pointing to.


session: F05-15
timestamp: 00:31:26.19
speaker: JAC
utterance:
I know exactly where h@l two is and I know I'm going to set k@l equal to the first thing that h@l two is pointing to.


session: F05-15
timestamp: 00:31:38.13
speaker: JAC
utterance:
so I reference h@l two and I say h@l two what are you pointing to and it tells k@l it's pointing to e@l, right?


session: F05-15
timestamp: 00:32:01.17
speaker: JAC
utterance:
so we can either we could delete h@l two so it doesn't point to anything anymore or we can have h@l two if we wanted, depending on our situation, # we would have h@l two point to the same place as h@l one.


session: F05-15
timestamp: 00:34:29.24
speaker: JAC
utterance:
we need to find out what c@l is pointing to # it's pointing to k@l so we're going to put that in the temporary node, okay?


session: F05-15
timestamp: 00:34:39.05
speaker: JAC
utterance:
we're going to have it called t@l and t@l is going to be the same thing as c@l and it's going to be pointing to k@l, okay?


session: F05-15
timestamp: 00:35:38.12
speaker: JAC
utterance:
so if we xx reference the next next we know a@l is pointing +// we find out that a@l is pointing to m@l, right?


session: F05-15
timestamp: 00:35:51.01
speaker: JAC
utterance:
so what we want to do is we want to make a@l point to whatever +// whatever uh c@l is pointing to, right?


session: F05-15
timestamp: 00:37:07.23
speaker: JAC
utterance:
so we come through transverse this and find out what +// what's +// find c@l +// find what c@l is pointing to # it's pointing to k@l, right?


session: F05-15
timestamp: 00:37:45.16
speaker: JAC
utterance:
we're at c@l +// we have to find out +// we're at c@l we have to find out what's pointing +// what's pointing to a@l which is e@l, right?


session: F05-15
timestamp: 00:37:55.17
speaker: JAC
utterance:
so +// and we also +// we need to also make sure we lose a@l so we have to set +// we want h@l one to point to a@l.


session: F05-15
timestamp: 00:39:38.16
speaker: JAC
utterance:
so we want to set a@l equal to whatever c@l is pointing to but we want to have a@l point to the same thing as c@l.


session: F05-15
timestamp: 00:40:08.28
speaker: JAC
utterance:
we can transverse the list and find out +// transverse the list find out what a@l +// find out what c@l points to and have that point +// a@l point to that, right?


session: F05-16
timestamp: 00:00:25.29
speaker: JAC
utterance:
we build up +// we build up on them so like every time we put something in +// say I want to add a@l, b@l, c@l, and d@l.


session: F05-16
timestamp: 00:00:58.01
speaker: JAC
utterance:
now if I want to take anything out I can't just take out the middle (be)cause it destroys everything, right?


session: F05-16
timestamp: 00:01:03.03
speaker: JAC
utterance:
I can't take out b@l so I always take from the top so if the first time I have to take something out I take d@l out.


session: F05-16
timestamp: 00:01:22.28
speaker: JAC
utterance:
there's a uh method called push which pushes something out of the stack so if I was to push a@l # I'd put a@l in the bottom of the stack, right?


session: F05-16
timestamp: 00:01:38.04
speaker: JAC
utterance:
now if I push b@l I come and I put b@l on top of a@l just like I was doing here and now I have a special +// I have a special +// if I'm programming I have a special method that does this for me.


session: F05-16
timestamp: 00:02:06.02
speaker: JAC
utterance:
yeah if I wanted to do +// if I wanted to create a structure where I could push a@l and then push c@l then I +...


session: F05-16
timestamp: 00:02:45.23
speaker: JAC
utterance:
what top does is gets whatever is currently at the top position so if I call top right now I get +// it would give me b@l or tell me that b@l is here on the top.


session: F05-16
timestamp: 00:03:05.29
speaker: JAC
utterance:
if we do it in this case +// if we were to do it in this case before we removed everything we'd get d@l.


session: F05-16
timestamp: 00:03:44.25
speaker: JAC
utterance:
now if I call pop which is the opposite of push # now pop doesn't take anything because I don't know what's on here on top, okay?


session: F05-16
timestamp: 00:03:52.19
speaker: JAC
utterance:
but what it's going to do is take the value that's currently on top so here in this case would be d@l or d@l is on top.


session: F05-16
timestamp: 00:04:07.06
speaker: JAC
utterance:
so now if I was to call top # the value it would give me off this list would be c@l # because now c@l is the one on top.


session: F05-16
timestamp: 00:05:22.04
speaker: JAC
utterance:
in alphabetical order from a@l to z@l and then I'd start taking everything off and I'd get z@l and then y@l and then x@l # we'd get the alphabet.


session: F05-16
timestamp: 00:06:25.01
speaker: JAC
utterance:
we call this node all the way at the top +// we call it the parent or we can call it the root if we look at this whole thing like a tree.


session: F05-16
timestamp: 00:06:55.23
speaker: JAC
utterance:
now a parent has a right child and a left child so this would be its left child and this would be its right child, right?


session: F05-16
timestamp: 00:07:05.25
speaker: JAC
utterance:
now the way we structure is that our right child +// the right child's value is always greater than the parent so if we look at this we have seven is the parent value and its right child value is eleven.


session: F05-16
timestamp: 00:07:28.27
speaker: JAC
utterance:
that if we were to do +// if we were to call t@l +// if we call this p@l, l@l c@l and r@l c@l # p@l is greater than the left child and p@l is less than the right child.


session: F05-16
timestamp: 00:07:45.12
speaker: JAC
utterance:
so we look at the parent +// we look at the right child and it's greater than eleven and the left child is +// I'm sorry +// we look at the right child, it's greater than seven.


session: F05-16
timestamp: 00:08:09.17
speaker: JAC
utterance:
what we do is we always check +// if we want to make sure something is a binary search tree we go check all the right children first and then we check the left child +// left children so I'm going to show you.


session: F05-16
timestamp: 00:08:43.29
speaker: JAC
utterance:
it doesn't have a left child so we'd come back to twelve and then go back to eleven then we would check eleven's left child.


session: F05-16
timestamp: 00:09:10.17
speaker: JAC
utterance:
I couldn't have five because it wouldn't +// five isn't greater than seven # it would never come to the right.


session: F05-16
timestamp: 00:09:14.25
speaker: 116
utterance:
but eleven is greater than seven and eleven could have +// smaller than eleven could be five, right?


session: F05-16
timestamp: 00:09:21.02
speaker: JAC
utterance:
right but if I was to come here and do an insert +// if I wanted to add something to the tree I would come here and the first thing I would do is compare five and seven and I'd say five is less than seven, right?


session: F05-16
timestamp: 00:09:32.27
speaker: JAC
utterance:
so it would go to the left and then I'd compare five and four and I'd find five is greater than four so I'd go to the right of four and there's five.


session: F05-16
timestamp: 00:10:20.04
speaker: JAC
utterance:
so looking at this, based on what I told you, that the right child is always greater than the left child +// err I'm sorry +// the right child is always greater than the parent and the left child is always less than the parent # this would be a binary search tree.


session: F05-16
timestamp: 00:11:02.28
speaker: JAC
utterance:
this eight +// eight is the right child of ten # it's not greater than ten so this is not a binary search tree, okay?


session: F05-16
timestamp: 00:12:51.08
speaker: JAC
utterance:
now I'm going to make +// I'm going to come here and the first thing I'm going to do is compare six and five.


session: F05-16
timestamp: 00:13:58.23
speaker: JAC
utterance:
now this is important because if it was just seven and there was nothing else pointing I'd have difficulty inserting six.


session: F05-16
timestamp: 00:14:56.06
speaker: JAC
utterance:
assume that you +// assume that we could have it in such a way that you could have something greater than right, alright?


session: F05-16
timestamp: 00:15:02.15
speaker: JAC
utterance:
there is +// just because it looks like we can't doesn't mean we don't # we could restructure this whole tree and such a way where we could allow for something to go on the right child.


session: F05-16
timestamp: 00:15:41.06
speaker: JAC
utterance:
now one of the reasons why we don't necessarily want to insert by keep going down the list and find where to insert six +// look at this and do another comparison here, right?


session: F05-16
timestamp: 00:16:00.10
speaker: JAC
utterance:
now if I have a tree +// if we say +// if we consider each one of these a level the root is at level zero.


session: F05-16
timestamp: 00:16:18.09
speaker: JAC
utterance:
so I had to do all these +// I had to get this far down the tree before I found where to insert six, right?


session: F05-16
timestamp: 00:17:24.00
speaker: JAC
utterance:
and what I'm going to do instead of going down the whole tree is I'm going to insert six as the new root.


session: F05-16
timestamp: 00:17:35.02
speaker: JAC
utterance:
so what six will do is it will take +//  it will make +// it will compare it and find out that five is less than six so six will become the new parent and make five its left child.


session: F05-16
timestamp: 00:18:13.28
speaker: JAC
utterance:
now I had to restructure somewhat +// the tree somewhat and now I only have to do the one comparison on top.


session: F05-16
timestamp: 00:18:22.09
speaker: JAC
utterance:
I think two or three +// I might have to do two or three or four or maybe even ten changes to restructure the tree correctly, right?


session: F05-16
timestamp: 00:19:48.12
speaker: JAC
utterance:
however now, if I want to delete five instead of nine what I do is I check its right child # this time we have a right child.


session: F05-16
timestamp: 00:20:00.23
speaker: JAC
utterance:
we check its right child since nine has +// five has a right child what we're going to do is find the last +// the most left child.


session: F05-16
timestamp: 00:20:11.28
speaker: JAC
utterance:
when I say most left I'm just going to keep going down on the list and find out who's the most left, right?


session: F05-16
timestamp: 00:20:34.26
speaker: JAC
utterance:
now the reason behind that is there is +// this is +// this value here it going to be the lowest value.


session: F05-16
timestamp: 00:20:43.29
speaker: JAC
utterance:
now if I put nine +// if I was to promote nine here now I'd have to restructure the whole +// the entire tree because now eight and seven don't belong on the right side # they belong on the left side now.


session: F05-16
timestamp: 00:20:57.23
speaker: JAC
utterance:
by finding the lowest value now I'm going to do the least amount of change here on the right side of the tree.


session: F05-16
timestamp: 00:21:04.08
speaker: JAC
utterance:
so what happens is seven now becomes the new root and inherits all its +// all five's left children # two, three, one.


session: F05-16
timestamp: 00:21:44.14
speaker: JAC
utterance:
now another thing +// so we notice that the most left child on the right side if I go all the way over one and as far left as I can is the lowest of all the values on the right.


session: F05-16
timestamp: 00:22:07.08
speaker: JAC
utterance:
so it's +// it could be an easy way to find +// if I wanted to find the greatest +// if I wanted to find the greatest value, right?


session: F05-16
timestamp: 00:22:15.04
speaker: JAC
utterance:
just go all the way to the most right or all the way to the most left on whichever side depending on the value I'm trying to find, greatest or lowest.


session: F05-16
timestamp: 00:22:55.04
speaker: JAC
utterance:
but if we're looking for a data structure we don't necessarily know +// if we're looking in this structure we don't know +// we don't +// it's not just mapped out, right?


session: F05-16
timestamp: 00:24:13.03
speaker: JAC
utterance:
if someone's name was eight and in there could be someone's phone number +// a whole bunch of information so it might be if I'm trying to find it that might be the reason it no longer turns up.


session: F05-16
timestamp: 00:24:24.19
speaker: JAC
utterance:
now if I want to find four +// I'm just going to work on drawing this but we really don't need it +// I'm going to compare four and five.


session: F05-16
timestamp: 00:25:22.00
speaker: JAC
utterance:
as long as this tree +//  as long as the structure of the tree is maintained correctly four can't be anywhere else.


session: F05-16
timestamp: 00:26:02.10
speaker: JAC
utterance:
now instead of doing an insert and searching the entire tree to find four # which would be stupid because now I've already found it and I know exactly where it's going to go I can just insert it there.


session: F05-16
timestamp: 00:26:15.01
speaker: JAC
utterance:
um # we can rearrange this tree just by changing the order in which we insert it if were to start say seven, eight, five, nine, um three, two, one.


session: F05-16
timestamp: 00:27:14.08
speaker: JAC
utterance:
and then +// not a pretty tree obviously it's very unbalanced (be)cause we were very deep on this side and not as deep on this side but that would be one way we could change the tree.


session: F05-16
timestamp: 00:27:27.20
speaker: JAC
utterance:
you could just change the first numbers and insert everything else pretty much the same but just go through the tree that way between your inserts.


session: F05-16
timestamp: 00:27:51.23
speaker: JAC
utterance:
each node +// we refer to these as nodes +// points to someone else just like we had in a tree, right?


session: F05-16
timestamp: 00:28:23.01
speaker: JAC
utterance:
each person in the line knows who is in front of him so if Person c@l knows Person k@l # he knows that Person k@l +...


session: F05-16
timestamp: 00:28:59.29
speaker: JAC
utterance:
now if we wanted to insert a new node let's say g@l and we want to insert it after the node that contains b@l so we want to insert it here.


session: F05-16
timestamp: 00:29:19.24
speaker: JAC
utterance:
we would come searching through, we'd call the head first (be)cause the head knows where the line is.


session: F05-16
timestamp: 00:29:33.23
speaker: JAC
utterance:
so we would go through and we would check/compare b@l and c@l # b@l is not c@l so we would go and find k@l.


session: F05-16
timestamp: 00:30:18.20
speaker: JAC
utterance:
we don't have to go to f@l we just have to ask b@l who's in front of him and he'll tell us it'll be f@l.


session: F05-16
timestamp: 00:30:50.06
speaker: JAC
utterance:
now b@l is still pointing to f@l but we don't want b@l to point to f@l anymore we want b@l to point to g@l, okay?


session: F05-16
timestamp: 00:31:12.02
speaker: JAC
utterance:
so what we're going to do now is Bob or b@l is no longer going to have f@l in front of him, he has g@l.


session: F05-16
timestamp: 00:32:12.03
speaker: JAC
utterance:
e@l +// yeah +// or we have some function +// we say well we create some temporary storage and we call it t@l and we say t@l wants to know and says, if we say um if we call any node that we're at say we're at this node right here and we say next +// if I'm at e@l and I say node next and that returns a@l.


session: F05-16
timestamp: 00:32:57.00
speaker: JAC
utterance:
basically saying I am e@l, give me what I'm pointing to which is a@l and then this whole thing now is giving +// this is giving me a@l.


session: F05-16
timestamp: 00:33:16.09
speaker: JAC
utterance:
if I ask +// since it's giving me a@l I can also ask a@l what it's giving next and that will tell me m@l.


session: F05-16
timestamp: 00:33:45.27
speaker: JAC
utterance:
move to a@l +// move to a@l so now we know where a@l is and we can tell e@l to point to m@l then we can have a@l no longer point to m@l and then delete a@l.


session: F05-16
timestamp: 00:34:10.00
speaker: JAC
utterance:
we could insert the entire +// an entire other list into here if we think about it exactly the same way as inserting one node.


session: F05-16
timestamp: 00:34:26.05
speaker: JAC
utterance:
however, this +//  if I think of this as my one big node I still have to transverse and find out which node inside this big node is pointing to null.


session: F05-16
timestamp: 00:34:40.06
speaker: JAC
utterance:
and then since I can always reference the head I can come back to the head and find out what the head is pointing to, set b@l to point to e@l.


session: F05-16
timestamp: 00:34:52.19
speaker: JAC
utterance:
now last thing I would want to do is delete this head because I don't want it to point anymore to the middle # it would be pointing to the middle of the list now, right?


session: F05-16
timestamp: 00:36:03.27
speaker: JAC
utterance:
I don't want to be able to +// I don't want people reference to the back of the line and be adding people here where I can ruin everything.


session: F05-16
timestamp: 00:36:49.23
speaker: JAC
utterance:
here, I could have +// if I was to add this to the head h@l two this is h@l two and this is the rest of the line and then h@l one, right?


session: F05-16
timestamp: 00:36:59.12
speaker: JAC
utterance:
so I could be adding stuff on this portion of the list, adding more people here and h@l one could be adding more people here and that's not really a linked list any more, is it?


session: F05-16
timestamp: 00:37:30.28
speaker: JAC
utterance:
uh if we were to switch nodes we would create a temporary node # have it take the place +// you know the swap function?


session: F05-16
timestamp: 00:38:05.15
speaker: JAC
utterance:
I insert # I set t@l equal to +// I set it equal to all the values +// everything that a@l is doing # make it point to m@l and I have e@l point to t@l now.


session: F05-16
timestamp: 00:38:41.22
speaker: JAC
utterance:
except instead of getting rid of c@l completely I take c@l out and I replace +// I find t@l which is in the place of a@l and I do the same thing I did with um with t@l, right?


session: F05-16
timestamp: 00:38:56.09
speaker: JAC
utterance:
I could set everything equal to it and have t@l point to m@l +// I'm sorry, c@l point to m@l and e@l point to c@l.


session: F05-16
timestamp: 00:39:12.20
speaker: JAC
utterance:
and basically everything that's +// everything that a@l is pointing to +// is pointing to a@l +// everything that a@l is pointing to I store those values of into a temporary.


session: F05-16
timestamp: 00:39:25.07
speaker: JAC
utterance:
I get everything that pertains to a@l and I store that in a temp and I set +// and I make temp +// I make temp take the place of a@l.


session: F05-16
timestamp: 00:40:00.12
speaker: JAC
utterance:
a@l comes out and find c@l and does the same thing that t@l did with c@l +// with a@l which is find out who's in front of c@l, we find out who's in back of c@l and takes c@l's place.


session: F05-16
timestamp: 00:40:20.12
speaker: JAC
utterance:
t@l +// c@l finds t@l and finds out who t@l is pointing to and who is pointing to t@l # gets that information and has everyone point to c@l and c@l points to whoever t@l was pointing to and takes the place of t@l and then we delete t@l.


session: F05-17
timestamp: 00:03:16.16
speaker: JAC
utterance:
so we're going to keep going down the list until we find the child that has no child of its own or that points to null, right?


session: F05-17
timestamp: 00:06:37.13
speaker: JAC
utterance:
we check three which is currently pointing to null so it doesn't have a right child so now three gets four as its right child.


session: F05-17
timestamp: 00:07:05.04
speaker: JAC
utterance:
if we look at the binary search tree and we consider the stack # we can look at this and say # uh we can say five, eight, seven, two, one, and three, right?


session: F05-17
timestamp: 00:07:31.14
speaker: JAC
utterance:
if this is my stack, I can think every time I take the top I grab top and then insert into a binary tree which I haven't created yet.


session: F05-17
timestamp: 00:08:39.10
speaker: JAC
utterance:
so if we rearrange the numbers in the stack we'll end up with a different binary search tree, right?


session: F05-17
timestamp: 00:09:35.00
speaker: JAC
utterance:
we just keep following that pattern we get a binary search tree seven, five +// seven, five, nine, eight, three.


session: F05-17
timestamp: 00:10:18.00
speaker: JAC
utterance:
ugly tree but pretty unbalanced	# but that would xxx just rearrange the numbers and just do xxx xxx.


session: F05-17
timestamp: 00:10:59.05
speaker: JAC
utterance:
say you want to insert six but we don't want to insert it +// we don't want to search the entire binary search tree to insert it, right?


session: F05-17
timestamp: 00:11:43.10
speaker: JAC
utterance:
so take six and make it the new root and it inherits five as its child and we find out five is less than six so it becomes its left child.


session: F05-17
timestamp: 00:11:56.15
speaker: JAC
utterance:
we look +// so it inherits +// five will inherit all its left children # or keep all its left children.


session: F05-17
timestamp: 00:12:29.14
speaker: JAC
utterance:
this way instead of doing N@l comparisons we're actually doing +// we just insert at the top # and re-sort everything.


session: F05-17
timestamp: 00:12:48.21
speaker: JAC
utterance:
especially if we were to search something that's recently inserted and we're not going to far down the tree, right?


session: F05-17
timestamp: 00:12:58.08
speaker: JAC
utterance:
if I just recently inserted eight into the tree I'm only going to come one, two, three comparisons versus if I insert +// if I inserted in the bottom here I'd be doing one, two, three, four, five comparisons.


session: F05-17
timestamp: 00:14:09.08
speaker: 117
utterance:
um yeah is +// I mean, is it possible +// I mean it's possible that there's more than one correct way to build a binary tree?


session: F05-17
timestamp: 00:14:37.08
speaker: JAC
utterance:
yeah, you would have +// typically we have what is usually some kind of root which points to the actual +// if we're building it using code.


session: F05-17
timestamp: 00:14:57.00
speaker: JAC
utterance:
if it's pointing to null then we insert the first node # right there so building this exact tree we actually call the root.


session: F05-17
timestamp: 00:15:28.15
speaker: JAC
utterance:
and then we would call the root again and we find it's got a null and we check for its left child +// if we're inserting nine it's going to follow the premise of the tree.


session: F05-17
timestamp: 00:16:28.04
speaker: JAC
utterance:
compare eight and seven # eight is greater than seven so eight becomes seven's right child since seven doesn't have any right children, right?


session: F05-17
timestamp: 00:17:24.21
speaker: JAC
utterance:
now if I was to do +// this is usually the insertion that is most common is to search the entire tree and then xx.


session: F05-17
timestamp: 00:17:35.01
speaker: JAC
utterance:
now if I'm inserting +// but I'm using the insert-as-the-new-parent method then I'm going to get a totally different tree even if I use the same ordering.


session: F05-17
timestamp: 00:17:54.02
speaker: JAC
utterance:
however, if I insert every new node on the top and push everything else down accordingly then I'll have everything on the bottom as the old nodes and everything on top is the new nodes, in that case.


session: F05-17
timestamp: 00:18:26.12
speaker: JAC
utterance:
it's not usual but you might want to make a database using trees or um this is the simplest search +// binary tree structure.


session: F05-17
timestamp: 00:18:49.22
speaker: JAC
utterance:
um, so it depends on what you want to do if we're referencing +// if you insert something new and then you keep referencing the same new item or if you reference newer items frequently then you want to insert at the top first all the time.


session: F05-17
timestamp: 00:19:08.27
speaker: JAC
utterance:
if you're inserting +// if you're referencing older items first  more often you'd want to have the bottom insertion.


session: F05-17
timestamp: 00:19:19.10
speaker: JAC
utterance:
there's other trees where you can rotate to get things balanced so that a search to the left and a search to the right are about the same depth so that I don't do fifteen searches on the left and three searches on the right, I mean, if I had to do searches you'd want to keep everything somewhat balanced.


session: F05-17
timestamp: 00:20:00.20
speaker: JAC
utterance:
in order so that it's thought +// anything that you do a search for you're probably going to try and find it again and instead of searching through the entire tree now to find it you just find it at the top next time you do a search.


session: F05-17
timestamp: 00:20:19.03
speaker: JAC
utterance:
there are a lot of +// like I said, there are a lot of different trees but they all stem from binary search tree of the same concept of the right child being greater than the parent and the left child being less than the parent.


session: F05-17
timestamp: 00:20:48.20
speaker: JAC
utterance:
you can check this for equality and check to see if it's less than (be)cause if you can do +// if you can check this one then you can check this (be)cause it's the same thing, right, it's just the other way.


session: F05-17
timestamp: 00:21:25.02
speaker: JAC
utterance:
I honestly don't know what else to go over (be)cause I know I don't need to go over linked lists with you that much.


session: F05-17
timestamp: 00:21:52.24
speaker: JAC
utterance:
um you could do an invert like this where they take e@l, a@l, m@l +// this list here and rearrange it so it's e@l, a@l instead.


session: F05-17
timestamp: 00:22:22.10
speaker: JAC
utterance:
I mean if I want to insert +// if you want to insert a node, right, you just call the node +// call the root and then find out if its left child or right child, recall the same function.


session: F05-17
timestamp: 00:22:37.09
speaker: JAC
utterance:
(be)cause I mean this is the root while this is the root of this, this is the root of this, this is the root of this.


session: F05-17
timestamp: 00:22:59.10
speaker: JAC
utterance:
yeah though sometimes thinking recursively is not so easy especially for freshman so that's why I follow this.


session: F05-17
timestamp: 00:23:19.15
speaker: JAC
utterance:
so I'm going to do this:  describe the sequence of operations to add list two to the end of list one.


session: F05-17
timestamp: 00:23:28.14
speaker: JAC
utterance:
yeah, well, if you know how to insert +// the way I look at this if you can insert b@l after g@l +// g@l after b@l, right?


session: F05-17
timestamp: 00:23:51.25
speaker: JAC
utterance:
granted, we have to transverse everything in the node to find out who's pointing to null and what it's +// you know.


session: F05-17
timestamp: 00:23:58.18
speaker: JAC
utterance:
but conceptually, one big node and you can add it almost the same way except you can search through it.


session: F05-17
timestamp: 00:24:13.18
speaker: JAC
utterance:
and of course, every time you do an insertion if you insert a list into another list you have to get rid of the head pointer, right?


session: F05-17
timestamp: 00:24:47.22
speaker: JAC
utterance:
take a node, create a temporary node, set its pointers all the same to a@l, liberate a@l set a@l and its pointers to c@l then get c@l back and set your pointers.


session: F05-17
timestamp: 00:25:20.20
speaker: JAC
utterance:
delete the node nine so if we delete nine +// five, eight +// we look at its right children, it doesn't have any right children.


session: F05-17
timestamp: 00:25:48.16
speaker: JAC
utterance:
the idea behind doing it +// looking at the +// when we deleted five we looked for our right child and then looked for the leftmost child because this number here +// whatever is the most left will be the lowest value.


session: F05-17
timestamp: 00:26:03.10
speaker: JAC
utterance:
and if we go to the left child and look for the right most child then that would be the greatest value on this side of the tree, right?


session: F05-17
timestamp: 00:26:15.24
speaker: JAC
utterance:
this would be the greatest value on this side of the tree the value on this side is the lowest value on this side of the tree.


session: F05-17
timestamp: 00:26:22.00
speaker: JAC
utterance:
(be)cause if you were to promote nine to the root now we have to +// these guys are on the wrong side now and now we got to bring them over here.


session: F05-17
timestamp: 00:26:32.14
speaker: JAC
utterance:
and if we have a tree and depth we might, you know, have a big problem having to switch everything over and a tree that might be 2N@l depth on one side and zero on the other which is almost pointless.


session: F05-17
timestamp: 00:26:51.00
speaker: JAC
utterance:
I mean, it's not a binary search tree anymore it's almost a link list at that point (be)cause it would just be all down like that and maybe little branches like that.


session: F05-17
timestamp: 00:27:32.22
speaker: JAC
utterance:
see what value you'll get because you don't want to do +// we obviously want +// efficiency is important in memory, right?


session: F05-17
timestamp: 00:28:10.22
speaker: JAC
utterance:
so yeah, worst case +// worst case scenario N@l and there's a different data +// binary search tree data structures like A@l V@l L@l.


session: F05-17
timestamp: 00:28:27.20
speaker: JAC
utterance:
there's tri trees which you probably won't go over in any of your classes unless you have a professor Reid.


session: F05-17
timestamp: 00:28:33.01
speaker: JAC
utterance:
um, yeah that was what we had to use for a dictionary so you could have all the words +// all the letters.


session: F05-17
timestamp: 00:28:47.10
speaker: JAC
utterance:
we'd find one letter and check the next letter and find multiple words without doing several searches.


session: F05-17
timestamp: 00:28:55.27
speaker: JAC
utterance:
um yeah, so I mean everything +// every tree that you'll come across will be based off, well, binary search tree structure.


session: F05-17
timestamp: 00:29:08.27
speaker: JAC
utterance:
and obviously we do different type of insertions and everything just to try and improve efficiency like I said, if we did a search for eight, eight would get rotated up to be more efficient so if we have to do multiple searches for eight or anything else, it's always at the top.


session: F05-17
timestamp: 00:29:32.15
speaker: JAC
utterance:
but for that the cost of doing it is we're always, every time, we're rotating everything to find it so now this becomes inefficient if every time I'm looking for something N@l deep and rotating it up so now my efficiency is gone.


session: F05-17
timestamp: 00:29:51.03
speaker: JAC
utterance:
it's pointless, we might as well stick with a regular binary search tree (be)cause I'm doing +// you're doing N@l deep so you're doing N@l comparisons.


session: F05-17
timestamp: 00:30:12.15
speaker: 117
utterance:
any kind of tree that would link back to its parent node or, I mean, there are different kinds of trees +...


session: F05-17
timestamp: 00:30:37.27
speaker: JAC
utterance:
you might build a structure that knows who its +// you might build it so it knows five is its child +// that it's child of five but typically there aren't any trees that keep track.


session: F05-17
timestamp: 00:31:02.20
speaker: JAC
utterance:
so there's real point usually but you might find +// you might build a structure and say I'm at seven and I need to know who my parent was.


session: F05-17
timestamp: 00:31:17.25
speaker: JAC
utterance:
you might say +// you might say I'm at seven and I need to know +// I need to get my parent because I need to know who's my sibling, right?


session: F05-17
timestamp: 00:31:52.00
speaker: JAC
utterance:
because it would be crazy to keep track of +// for the seven to keep track of all its siblings, right?


session: F05-17
timestamp: 00:32:06.04
speaker: JAC
utterance:
I don't have to keep track +// seven doesn't have to go, 'these are my brothers, these are my sisters.'


session: F05-17
timestamp: 00:32:15.12
speaker: JAC
utterance:
if you really want to know who are the siblings then you ask the parents and the parent will know all of them.


session: M05-01
timestamp: 00:00:04.19
speaker: LOW
utterance:
uh and you've studied that in class then they tricked you and gave you some questions about binary search trees.


session: M05-01
timestamp: 00:01:28.18
speaker: LOW
utterance:
here for the +// in both cases for the root these guys on the left are smaller than seven and these guys on the right are all bigger than seven.


session: M05-01
timestamp: 00:01:39.27
speaker: LOW
utterance:
so every node in the tree has to have smaller nodes or children to the left and larger ones to the right.


session: M05-01
timestamp: 00:01:50.02
speaker: LOW
utterance:
uh so of course this is a node and ten is a node that has only one kid though it's supposed to be on this side.


session: M05-01
timestamp: 00:02:57.24
speaker: LOW
utterance:
now # since the noun is binary search tree the algorithm would probably be, 'binary search tree search.'


session: M05-01
timestamp: 00:05:10.28
speaker: LOW
utterance:
like you said, it was at seven but it couldn't move left so it says, 'okay, this guy is the new left son of seven.'


session: M05-01
timestamp: 00:06:32.07
speaker: 001
utterance:
well since this has no right node it makes it kind of easy because you can just move the eight up and just change five's object.


session: M05-01
timestamp: 00:06:38.08
speaker: 001
utterance:
to nine's left but if you had both of them you'd probably have to compare both of them so see which one.


session: M05-01
timestamp: 00:06:50.24
speaker: LOW
utterance:
and +// alright so the first thing you did of course is you had to find nine so you searched for it.


session: M05-01
timestamp: 00:09:31.06
speaker: LOW
utterance:
if you pick the smallest over here it can replace the n@l because it is both larger than all of these and (be)cause it's larger than n@l.


session: M05-01
timestamp: 00:09:40.04
speaker: LOW
utterance:
and yet it would be the smallest in here and smaller than all the rest of those therefore reserves the tree property.


session: M05-01
timestamp: 00:09:55.17
speaker: LOW
utterance:
it's going to be smaller than n@l and therefore smaller than all of those and it's going to be bigger than all of these.


session: M05-01
timestamp: 00:10:16.01
speaker: 001
utterance:
probably first off if you're trying to find the seven move to the right one and pretty much move as far to the left as you can.


session: M05-01
timestamp: 00:10:24.03
speaker: LOW
utterance:
so in fact you move to the right once because you need to get into the right subtree and the bigger ones.


session: M05-01
timestamp: 00:10:28.28
speaker: LOW
utterance:
then you run a while loop and while you got to come to the end and just keep going left, left, left, left, left.


session: M05-01
timestamp: 00:10:40.07
speaker: LOW
utterance:
I mean, this tree is a very simple tree what if you wanted to move seven up and it had other subtrees below it?


session: M05-01
timestamp: 00:10:48.12
speaker: LOW
utterance:
could it be possible that this is a recursive sort of problem that in bringing seven up you're causing the same problem to occur lower in the tree that you would just solve by bringing five up?


session: M05-01
timestamp: 00:11:47.16
speaker: LOW
utterance:
we can't put any whole numbers in here but if there was +// what number would be in the tree right here?


session: M05-01
timestamp: 00:11:54.17
speaker: LOW
utterance:
it would have to be bigger than five, smaller than nine and smaller than eight but bigger than seven and so that's a half?


session: M05-01
timestamp: 00:12:02.20
speaker: LOW
utterance:
okay so it's possible but you would still want to move seven up because seven is still the smallest.


session: M05-01
timestamp: 00:13:34.25
speaker: LOW
utterance:
uh describe the sequence of operations to delete the node that contains a@l so we can get rid of a@l here in list two.


session: M05-01
timestamp: 00:13:52.02
speaker: LOW
utterance:
alright so we have h@l two is a pointer to a node that contains e@l which is a pointer to a node that contains a@l which is a pointer to a node that contains m@l which is xx.


session: M05-01
timestamp: 00:14:17.14
speaker: 001
utterance:
and kind of just traverse the list using a while loop until t@l one's object is next +// object value equals a@l.


session: M05-01
timestamp: 00:14:27.04
speaker: LOW
utterance:
so I guess I better +// the beginner's most common error here is to traverse t@l one until it gets to a@l.


session: M05-01
timestamp: 00:15:05.08
speaker: LOW
utterance:
we can talk about that in a minute if we want to but um I think in the pre-test they were having you assume there was an a@l in there.


session: M05-01
timestamp: 00:15:17.28
speaker: 001
utterance:
and then you set t@l one's object +// wait, I would probably do is set another pointer t@l two to a@l and then um t@l one's object next equals t@l two's object next so you move this here and then you can just set this to null.


session: M05-01
timestamp: 00:15:47.00
speaker: LOW
utterance:
yeah so I think in the pre-test they would be very happy if you would just set t@l one to the one prior to a@l and then did t@l one's next is t@l two's next but you're on to something here # if you remove this from the list what are you going to do with it?


session: M05-01
timestamp: 00:16:52.22
speaker: LOW
utterance:
alright so what you had before is something like, while t@l one's dot next +// t@l one's dot next, yeah +// I'm sorry that's correct +// dot content wasn't equal to a@l, right?


session: M05-01
timestamp: 00:17:11.01
speaker: LOW
utterance:
and that got us in trouble because it's never going to happen because there never was an a@l in there.


session: M05-01
timestamp: 00:17:18.06
speaker: 001
utterance:
we could probably do this while object next does not equal null then you can do if t@l one dot next dot value equals a@l else t@l equals t@l object next.


session: M05-01
timestamp: 00:17:32.03
speaker: LOW
utterance:
uh here is a common way that often works maybe just a little slightly easier notation is to use two pointers.


session: M05-01
timestamp: 00:17:43.14
speaker: LOW
utterance:
we'll set p@l to point to the head of the list and we'll set q@l to point to null and the idea is that q@l is behind p@l and we'll do that +// we get in a while loop here um so we're going to have a while p@l isn't null.


session: M05-01
timestamp: 00:18:06.11
speaker: LOW
utterance:
uh we could check and then we could move (th)em both forward so in the while loop we'll move p@l forward and we'll move q@l forward so p@l will point and p@l will be p@l's next and q@l will be +// q@l will be p@l first so in the while loop q@l would be where p@l is and p@l would be p@l's next.


session: M05-01
timestamp: 00:18:23.05
speaker: LOW
utterance:
um and then we got two progressing across the list and then what we're checking for is if p@l's content is a@l and q@l is you're t@l one.


session: M05-01
timestamp: 00:18:36.06
speaker: LOW
utterance:
ahem before that we can always check to see if p@l is null because if we're looking for a@l and well looking for x@l no that's not it we'll go forward, no that's not it we'll move forward.


session: M05-01
timestamp: 00:18:51.08
speaker: LOW
utterance:
well with my two pairs of +// my pair of pointers traversing the list will reach the end when p@l drops off the edge of the earth.


session: M05-01
timestamp: 00:19:24.25
speaker: 001
utterance:
um we could probably use the same method of finding the end of the list you just talked about and then just set the last node's object next to h@l two.


session: M05-01
timestamp: 00:19:46.29
speaker: LOW
utterance:
probably null, but yeah h@l one works (be)cause if you don't what you have is a linked list with another pointer in the middle of the linked list which is pretty weird.


session: M05-01
timestamp: 00:19:52.27
speaker: LOW
utterance:
they don't say that here # I don't think they're worried about that on the pre- or post-test, but it would be a nice extra bonus.


session: M05-01
timestamp: 00:20:29.26
speaker: 001
utterance:
yeah, again you just find uh +// this time you could actually point t@l one to b@l itself and then t@l +// well you'd have a pointer to g@l so g@l's object next becomes b@l's object next and b@l's object next becomes g@l.


session: M05-01
timestamp: 00:20:43.06
speaker: LOW
utterance:
um # I'm sure you can do it if we make +// if we put this new node before the node that contains b@l.


session: M05-01
timestamp: 00:21:00.01
speaker: LOW
utterance:
uh and of course we're assuming there is a b@l in the list (be)cause we'd have to be a little careful if we didn't know that.


session: M05-01
timestamp: 00:21:16.02
speaker: LOW
utterance:
so go to list two and see it there and you see the final picture and the xxx and you're right there.


session: M05-01
timestamp: 00:21:26.08
speaker: 001
utterance:
okay so you'd have to use pointer t@l two to find the end of list two so that you're pointing to the last node and then you could use t@l one uh to find k@l and then once you got that +...


session: M05-02
timestamp: 00:00:09.28
speaker: LOW
utterance:
um so they gave a little pretest that has some linked list problems and some binary search tree problems.


session: M05-02
timestamp: 00:00:24.05
speaker: LOW
utterance:
they gave us two linked lists uh this one of course has got four nodes and this has got three nodes is um but is all you really know so how do you keep track of a linked list?


session: M05-02
timestamp: 00:00:37.19
speaker: LOW
utterance:
so all you really can see is the header node and of course you go to that you could see that the next one and so on and so on, okay.


session: M05-02
timestamp: 00:00:46.16
speaker: LOW
utterance:
well, uh people do it in different ways but essentially, haha, I guess the answer to that is yes, but how are you going to keep track of it?


session: M05-02
timestamp: 00:00:56.11
speaker: 002
utterance:
yeah that's the thing (be)cause I know we have +// I've seen some exercises where they ask us to create a linked list but without using any sentinels or any header nodes and I'm thinking how would one keep track of where the linked list is located?


session: M05-02
timestamp: 00:01:11.10
speaker: LOW
utterance:
you need some kind of external pointer now what we're dealing with here are called linear linked lists they're just lined up on a straight line.


session: M05-02
timestamp: 00:01:19.01
speaker: LOW
utterance:
there is something called a circular linked list where we say, hey this last node which is now pointing to nothing or null, it's kind of wasteful so you make if point back to the first node.


session: M05-02
timestamp: 00:01:30.00
speaker: LOW
utterance:
but still you need a pointer or it becomes a circular thing so it needs an external pointer to something.


session: M05-02
timestamp: 00:01:36.07
speaker: LOW
utterance:
so yeah in our case we have a pointer to h@l one in fact it's the pointer to the header node which is in fact the only way to get into the list.


session: M05-02
timestamp: 00:01:46.10
speaker: LOW
utterance:
uh so this first one says describe the sequence of operations to insert a new node which contains g@l into list one after the node that contains b@l.


session: M05-02
timestamp: 00:01:57.18
speaker: LOW
utterance:
well, the after picture is real simple you just put in a new node in here after the one b@l points to but how do we do that I guess the question is?


session: M05-02
timestamp: 00:02:09.08
speaker: 002
utterance:
well, you would have to start at the header node then you'd have to test to see if this is equal to b@l so if the, let's say that the element +// the element is equal to b@l then you would +// well, let's say is this equal to b@l?


session: M05-02
timestamp: 00:02:33.21
speaker: 002
utterance:
well, then you would have to say if this is equal to +// is not equal to b@l then you have to do node dot next so whatever this points to +...


session: M05-02
timestamp: 00:02:45.14
speaker: 002
utterance:
oh actually no I'm just iterating through the list but we can change h@l one if you wanted to but then you would lose the head of the list.


session: M05-02
timestamp: 00:03:35.05
speaker: LOW
utterance:
now I guess we get to assume there's a b@l in the list so while we haven't found b@l we just keep moving forward.


session: M05-02
timestamp: 00:03:58.21
speaker: 002
utterance:
so then  t@l one is here and you want to create or not create +// just kind of +// you create a new node and you have the key or the element equal to g@l but then you have to +...


session: M05-02
timestamp: 00:04:18.21
speaker: 002
utterance:
okay so then whatever +// so you want this +// first you have to, in order to keep track of b@l, you want this to point to whatever this is pointing to.


session: M05-02
timestamp: 00:04:40.13
speaker: 002
utterance:
++ is pointing here which is pointing to what this g@l dot next is going to point to, whatever b@l dot next is pointing to.


session: M05-02
timestamp: 00:05:03.26
speaker: 002
utterance:
yeah, (be)cause you don't want to lose track of the b@l or you actually don't want to lose track of this node.


session: M05-02
timestamp: 00:05:14.17
speaker: LOW
utterance:
uh so it said describe the the sequence of operations to insert this new node after the node that contains b@l.


session: M05-02
timestamp: 00:05:46.02
speaker: 002
utterance:
so unless you wanted +// unless it's a circular linked list you'd have to iterate all the way through there.


session: M05-02
timestamp: 00:05:51.15
speaker: LOW
utterance:
okay so in fact it is harder and we can come back to that later if we want to but # but basically we can make it pretty simple if, in yours you found the node that contained b@l and then of course, let's say you just did the surgery.


session: M05-02
timestamp: 00:06:14.10
speaker: 002
utterance:
you have to find # uh take b@l then the pointer is already pointing to b@l but then there's really no way to point back to k@l.


session: M05-02
timestamp: 00:06:28.23
speaker: LOW
utterance:
that's right so we could use two +// we could move across this list with a pair # p@l and q@l behind it, alright?


session: M05-02
timestamp: 00:06:40.01
speaker: LOW
utterance:
and so we could move it (un)til p@l which is you're t@l one was pointing at b@l okay so we can do it with xxx.


session: M05-02
timestamp: 00:06:50.10
speaker: LOW
utterance:
um # well in fact, number two # describe the sequence of operations to delete the node that contains a@l in list two so I happened to already have drawn on here.


session: M05-02
timestamp: 00:07:04.09
speaker: 002
utterance:
so you had your temporary nodes # t@l one is equal to h@l two and then if t@l one dot +// if t@l one is not equal to e@l or t@l one is not equal to a@l then you go to the next.


session: M05-02
timestamp: 00:07:23.21
speaker: 002
utterance:
so once you find a@l in order to delete this +// you would have to delete this by getting this xxx over here and then this would +// then what you could do is set this equal to null and have this one pointing to this one.


session: M05-02
timestamp: 00:07:46.03
speaker: LOW
utterance:
okay, once you found +// you basically described the sequence of operations a minute ago to find this node a@l so you have t@l one pointing here.


session: M05-02
timestamp: 00:08:04.28
speaker: LOW
utterance:
there are a couple different ways to do it uh one idea I was going to suggest is use two pointers but uh the way to do it with one pointer +// we talked about one pointer first.


session: M05-02
timestamp: 00:08:15.07
speaker: LOW
utterance:
uh we are assuming there's an a@l in the list # we may come back and take that away in a minute, right now we're assuming there's an a@l in the list.


session: M05-02
timestamp: 00:08:40.03
speaker: LOW
utterance:
so basically you would set uh t@l one equal to this and of course that could be the a@l so we'd have to check and see if that was it.


session: M05-02
timestamp: 00:08:59.22
speaker: 002
utterance:
++ yeah, by looking ahead and if you +// once you find +// if you find that once you're looking ahead you could do like a t@l one +// t@l one dot next equals t@l one dot next dot next.


session: M05-02
timestamp: 00:09:19.14
speaker: LOW
utterance:
suppose there is no a@l in the list and you're looking ahead and t@l one gets here and you start looking ahead and you get done with all the pointers to reference.


session: M05-02
timestamp: 00:09:27.13
speaker: LOW
utterance:
so uh let me show how you can do it with two pointers uh let's call (th)em    t@l one and t@l two, that's what it usually is # t@l one in front and t@l two behind.


session: M05-02
timestamp: 00:10:08.03
speaker: LOW
utterance:
we move these things forward so we +// t@l one is the going forwards so we'd better set t@l two first because t@l two is t@l one's old position so t@l two is now here, right?


session: M05-02
timestamp: 00:10:36.15
speaker: LOW
utterance:
get info or whatever it's called # t@l one dot get the info is not equal to a@l keep moving forward but stop when it is equal to a@l, right?


session: M05-02
timestamp: 00:10:50.04
speaker: LOW
utterance:
well, you finish it off for me, why don't we +// if you want to get rid of this node we simple change +...


session: M05-02
timestamp: 00:10:53.10
speaker: 002
utterance:
++ so then you do t@l one, t@l one dot next so then t@l two dot next, t@l two dot next is equal to t@l one or t@l one dot next or t@l two dot next equal to t@l one dot next.


session: M05-02
timestamp: 00:11:21.23
speaker: LOW
utterance:
and then you have a pointer t@l one to this node if you can give it up or whatever free it or dispose of it, you know, xxx okay.


session: M05-02
timestamp: 00:11:30.06
speaker: LOW
utterance:
but that's a nice way to do it with uh two pointers and look ahead works but it's a little more maybe um, you know, it's got t@l one dot next dot next dot get info and it's got more dots in it so it's got more danger that you're wandering off into the list.


session: M05-02
timestamp: 00:12:14.02
speaker: LOW
utterance:
alright, so here's h@l one # xx points to c@l which points to k@l which points to the b@l which points to the f@l.


session: M05-02
timestamp: 00:12:46.00
speaker: 002
utterance:
well, you first want to start at the header of one and you have to go through all these until you find a null to a like a h@l one dot next dot whatever points to null.


session: M05-02
timestamp: 00:12:59.07
speaker: 002
utterance:
and when you find the null value then you want to +// then you want to point this null value to the header of this list over here.


session: M05-02
timestamp: 00:13:13.06
speaker: LOW
utterance:
so basically you're sort of saying use a temporary pointer and then t@l one if you want to call it, uh how do you initialize t@l one?


session: M05-02
timestamp: 00:13:48.20
speaker: LOW
utterance:
that's not null so move over here, that's not null, so you move here and that's not null so we move over here # that's not null so you move over here +...


session: M05-02
timestamp: 00:14:10.17
speaker: LOW
utterance:
alright, so this is a common mistake uh but you caught it which, you know # you marched this thing off the end of the list.


session: M05-02
timestamp: 00:14:35.16
speaker: LOW
utterance:
in our picture they say something about blah blah blah so I think they'd be happy with that but uh two pointers really works nicely here also.


session: M05-02
timestamp: 00:14:42.26
speaker: LOW
utterance:
move t@l one and t@l two across and it can use this while t@l one is not null sort of thing when t@l on falls off, t@l two is pointing at the last node.


session: M05-02
timestamp: 00:14:51.17
speaker: LOW
utterance:
if the list is empty t@l two tells you that xxx xxx but this works uh for what we're talking about here assuming +// it assumes that t@l h@l one is not the end of the list.


session: M05-02
timestamp: 00:15:29.03
speaker: LOW
utterance:
and maybe it's a kind of a weird linked list now so the linked list has it's header as h@l one but it also has this pointer to the middle of it.


session: M05-02
timestamp: 00:15:38.29
speaker: LOW
utterance:
I don't think they worry about this on the pretest or posttest but we should probably set that value as null, right.


session: M05-02
timestamp: 00:15:45.06
speaker: LOW
utterance:
it's only one list not two lists or h@l two equals h@l one if it's the same +// but yeah not pointing to the middle of some other list.


session: M05-02
timestamp: 00:16:39.28
speaker: LOW
utterance:
The picture a minute ago was real simple we were just putting the lists end to end # now we're kind of sticking this list in the middle of that list.


session: M05-02
timestamp: 00:16:52.29
speaker: 002
utterance:
okay so if you want to do that you start with +// say you have a temporary uh pointer so t@l one is equal to h@l one and while t@l one is not equal to +// or t@l one dot get info is not equal to k@l it keeps on moving along here and then +// well then you have uh t@l one dot next and you keep on going here so once it reaches k@l +...


session: M05-02
timestamp: 00:17:31.08
speaker: 002
utterance:
after t@l one +// after t@l one dot get info is equal to k@l then you have to, here's the tricky part, you have to point +// this one has to go down next then you have to go iterate through here then this one has to go to here so now how do you do that?


session: M05-02
timestamp: 00:18:24.26
speaker: 002
utterance:
so what you could do is t@l one can go to h@l two, go to the end of here, point to whatever k@l is pointing to here then you won't lose +// so then you have that pointer here and you could have +// point t@l one or t@l one dot next could be here and point here.


session: M05-02
timestamp: 00:18:44.28
speaker: LOW
utterance:
alright, so if you really really want to move this link right now and make it point here then you need a temporary +...


session: M05-02
timestamp: 00:18:53.24
speaker: LOW
utterance:
you don't really need that temporary if you'll wait on that make those +// you could certainly use another temporary # what are you going to do with h@l two?


session: M05-02
timestamp: 00:19:13.00
speaker: LOW
utterance:
right, so as you said it, a temporary here which we talked about before I guess in this case you could use that look ahead again, I mean you don't just want to march in until t@l two is null (be)cause now t@l two would be null (un)til t@l two next is.


session: M05-02
timestamp: 00:19:23.29
speaker: LOW
utterance:
alright so we can find the end of the list and now you could use a temporary three if you needed to but you don't need to do this in the right order now because now you can do what?


session: M05-02
timestamp: 00:19:33.14
speaker: 002
utterance:
so now the t@l two dot next is equal to t@l one dot next so you have this pointer point over here and then once that's linked then you have t@l one dot next equal h@l two.


session: M05-02
timestamp: 00:22:31.05
speaker: LOW
utterance:
so lets insert six into this binary search tree and make it a binary search tree and keep it a binary search tree.


session: M05-02
timestamp: 00:24:38.01
speaker: 002
utterance:
well, nine is greater than the root yet it's +// it's greater than the root but it's also greater than eight.


session: M05-02
timestamp: 00:29:17.12
speaker: LOW
utterance:
+, in the lefthand side seven is bigger than five so of course it's bigger than all those guys without even looking.


session: M05-02
timestamp: 00:29:24.29
speaker: LOW
utterance:
so you just discovered the basic algorithm which is difficult and you should not have known beforehand.


session: M05-02
timestamp: 00:29:50.11
speaker: LOW
utterance:
uh a minute ago +// I can't put integers in anymore but if we put in two and a half it would go right here, wouldn't it?


session: M05-02
timestamp: 00:29:58.24
speaker: LOW
utterance:
it's less than five, bigger than two and less than three so two and a half would go there but three would still move up.


session: M05-02
timestamp: 00:30:11.25
speaker: LOW
utterance:
so it's not necessarily a leaf rule but it's still the biggest on this side and the smallest on that side.


session: M05-02
timestamp: 00:31:26.03
speaker: LOW
utterance:
so in fact, this guy can only have a left tree but not necessarily a left tree and he can't have a right tree.


session: M05-02
timestamp: 00:31:31.19
speaker: LOW
utterance:
so what my point is by changing this node that has two kids by getting this one to move up you're not creating another problem with two kids.


session: M05-02
timestamp: 00:31:50.28
speaker: LOW
utterance:
uh how would you tell the computer +// you could just scan these nodes and find it +// how would you tell the computer to find this guy.


session: M05-02
timestamp: 00:32:47.10
speaker: LOW
utterance:
if I wanted to delete one that only had one child I would just do the grandfather to grandson +// child +// grandfather to grandchild thing.


session: M05-02
timestamp: 00:34:08.08
speaker: LOW
utterance:
so in fact if somebody was very helpful and put the nodes in order for us it would be a terrible tree, right?


session: M05-03
timestamp: 00:00:04.02
speaker: LOW
utterance:
um # you did well on the pretest so not too much to talk about but uh +// alright let's +// the first one seems pretty simple.


session: M05-03
timestamp: 00:00:32.01
speaker: LOW
utterance:
alright, it's a linked list so all you really have is this header +// pointer to the header node, right?


session: M05-03
timestamp: 00:00:53.11
speaker: 003
utterance:
yeah, let's say t@l one and then traverse the list and then each time I store the node to the t@l one and start from the header.


session: M05-03
timestamp: 00:01:34.04
speaker: 003
utterance:
oh when you make the connection between these two +// I mean when you delete the a@l we lose the next thing to point out the what should be the next of the e@l.


session: M05-03
timestamp: 00:01:49.01
speaker: 003
utterance:
so we need temporary to store the uh this e@l to point to this m@l +// I mean right next to a@l so +...


session: M05-03
timestamp: 00:02:26.05
speaker: LOW
utterance:
but if we changed it we would lose access to the only +// before we get started the only person in the universe that knows where this list is h@l two.


session: M05-03
timestamp: 00:02:41.00
speaker: LOW
utterance:
so we start as you were doing t@l one is equal to h@l two is the way to get started and now suppose that it's a very long list all the way the heck down there.


session: M05-03
timestamp: 00:03:28.27
speaker: LOW
utterance:
+< we're going to have some sort of while here in it that's while you're saying t@l one equals t@l one dot next, right?


session: M05-03
timestamp: 00:03:38.21
speaker: 003
utterance:
I need to stop when I reach the end of the list because this last node will point to the null # xxx xx xxx.


session: M05-03
timestamp: 00:04:18.13
speaker: LOW
utterance:
well, it could happen that t@l one +// if a@l is not in the list what's going to eventually happen if we keep doing this?


session: M05-03
timestamp: 00:04:52.08
speaker: LOW
utterance:
uh that's also # let's go back to that (be)cause that's the first time you said that which is a very very good idea because what's going to happen if we don't do that?


session: M05-03
timestamp: 00:05:11.27
speaker: LOW
utterance:
but you also want to stop so you're going to stop +// you're going to do a while t@l one is not null and also uh there are a couple of ands here and also uh t@l one dot +// should we just call it info? +// isn't a@l maybe it's xx or something like that?


session: M05-03
timestamp: 00:05:51.18
speaker: 003
utterance:
uh but here is kind of a problem if a@l is not equal in the node after this while loop we just got the null as a t@l one.


session: M05-03
timestamp: 00:06:05.27
speaker: 003
utterance:
++ oh yeah # in this case, in this specific case we will find the a@l as a t@l one when you assign it because the while loop is xx with this condition so after this while, t@l one points to this node.


session: M05-03
timestamp: 00:06:41.17
speaker: LOW
utterance:
alright that's exactly what I was getting at because if you want to delete this node you need a pointer to the first one.


session: M05-03
timestamp: 00:06:48.24
speaker: LOW
utterance:
so I guess in this case it would work if we snuck in while t@l one next is not null # uh would we need a next here or not?


session: M05-03
timestamp: 00:07:23.22
speaker: 003
utterance:
yeah, we got this uh t@l one's pointer to point to the e@l and then we know that t@l one's next is a@l so # uh we assign the t@l one's next, next +...


session: M05-03
timestamp: 00:07:57.08
speaker: LOW
utterance:
okay uh I think that would be just fine on pretest or posttest but you uh # you seem to be a very good student and you were concerned about uh running off the end of the list if there was no way in there.


session: M05-03
timestamp: 00:09:25.10
speaker: LOW
utterance:
so I think that would be fine for the pretest and posttest because they're assuming that a@l is somewhere in the middle but how can we make it work for the first one?


session: M05-03
timestamp: 00:09:34.05
speaker: LOW
utterance:
well, it's a special case so you could always just do it +// check for it right here before the loop, right?


session: M05-03
timestamp: 00:09:50.04
speaker: LOW
utterance:
h@l two # the first element is a@l and then uh m@l and then e@l but we don't really care (be)cause we're not going to go there but you know how it goes.


session: M05-03
timestamp: 00:10:03.21
speaker: LOW
utterance:
um okay let's call (th)em t@l one and t@l two but uh t@l one will be in front and t@l two will be right behind t@l one.


session: M05-03
timestamp: 00:10:17.15
speaker: LOW
utterance:
so here's how we set it up:  t@l one is h@l two and t@l two is null so in the picture t@l one is right there and t@l two is null.


session: M05-03
timestamp: 00:10:29.05
speaker: LOW
utterance:
now if we're looking for e@l and we're going to move these two across the list until we find the e@l in the list the point is t@l two is going to be behind t@l one which we need if we're going to do surgery, right?


session: M05-03
timestamp: 00:11:08.09
speaker: LOW
utterance:
so I move (th)em both forward but first you got to put t@l two where t@l one was and then you got to put t@l one forward.


session: M05-03
timestamp: 00:11:16.08
speaker: LOW
utterance:
so it's got two statements in the loop instead of one so that would find the e@l and of course we can now do surgery.


session: M05-03
timestamp: 00:11:46.18
speaker: LOW
utterance:
and the special case here, of course, is that t@l two is null so we can have if t@l two is still null I'll just say then special case first element else or it's the general case.


session: M05-03
timestamp: 00:12:06.14
speaker: LOW
utterance:
and of course in the general case we just do what you did a minute ago we just say uh t@l two's next equals t@l one's next.


session: M05-03
timestamp: 00:12:52.14
speaker: LOW
utterance:
so what you did I think is fine but it didn't work if a@l was the first element so you always need in linked lists to look for those special cases.


session: M05-03
timestamp: 00:13:10.18
speaker: LOW
utterance:
alright, if there is no a@l then we need to, of course, before we check t@l one's info because we're advancing it we have to check to see if t@l one is null and uh if t@l one is null we basically get out of here # there's nothing to do, right?


session: M05-03
timestamp: 00:13:28.24
speaker: LOW
utterance:
so indeed uh you've made the sort of assumption was that the first element # I made the assumption that it was in there but we could fix that by putting in here t@l one is not null and also this other stuff and then to get out if t@l one is null then I guess we simply return, right?


session: M05-03
timestamp: 00:14:04.04
speaker: LOW
utterance:
um # I got it already setup here so let's talk about uh +// describe the sequence of operations to add list two to the end of list one.


session: M05-03
timestamp: 00:14:41.17
speaker: 003
utterance:
okay we have to traverse the h@l one to find end of the last node +// keep checking the node is next reference is null.


session: M05-03
timestamp: 00:15:12.03
speaker: 003
utterance:
and then t@l one we just found the t@l one's next is null so we assign the uh h@l two to as a t@l one's next.


session: M05-03
timestamp: 00:15:28.01
speaker: LOW
utterance:
I don't think they care but we should probably say something like h@l two equals null because now we have a list of seven elements and you shouldn't have a pointer into the middle of a list, right?


session: M05-03
timestamp: 00:15:58.01
speaker: LOW
utterance:
okay, so that certainly works for this four element list because t@l one goes here # that's not null.


session: M05-03
timestamp: 00:16:39.26
speaker: LOW
utterance:
because if it works for one +// if there was only one node you set t@l one here and t@l one's next is null so it stops but you're correct


session: M05-03
timestamp: 00:16:55.14
speaker: LOW
utterance:
so that's again you could do the same sort of two pointer or you can have a special case out in front here but they're not looking I think for that kind of detail.


session: M05-03
timestamp: 00:17:08.28
speaker: LOW
utterance:
uh # okay we haven't messed up our picture too much so why don't we look at this last one before we talk about binary trees for a second.


session: M05-03
timestamp: 00:17:16.19
speaker: LOW
utterance:
uh describe the sequence of operations to insert list two into list one after the node that contains k@l.


session: M05-03
timestamp: 00:17:45.12
speaker: LOW
utterance:
okay so we've done a traversal until we found the k@l and again we have a problem # is there a k@l or isn't there one?


session: M05-03
timestamp: 00:17:54.07
speaker: 003
utterance:
then once you've found the k@l as t@l one we just change the k@l's next +// I mean t@l one's next to point to the h@l two.


session: M05-03
timestamp: 00:18:25.01
speaker: 003
utterance:
yeah, t@l two and then we assign h@l two as a t@l one's next +// oh before we do that, we have to +...


session: M05-03
timestamp: 00:18:43.14
speaker: 003
utterance:
yeah, we have to do something before losing this connection because we need to move this thing also to assign this as a t@l two's next.


session: M05-03
timestamp: 00:19:49.07
speaker: LOW
utterance:
alright so their definition is of course smaller ones have to be left and bigger ones have to be right.


session: M05-03
timestamp: 00:19:54.04
speaker: LOW
utterance:
sometimes you can fool a student by saying seven +// look, these are smaller than seven and these are all bigger than seven.


session: M05-03
timestamp: 00:20:50.25
speaker: 003
utterance:
yeah, we need to compare these element with eight and then we found that our target eight is bigger than this one.


session: M05-03
timestamp: 00:22:12.07
speaker: 003
utterance:
yeah I'm not sure the exact operation to follow but can't you just do it intuitively by comparing to find the same elements?


session: M05-03
timestamp: 00:24:48.22
speaker: LOW
utterance:
well, that sounds really nasty because it's the root but it isn't really nastier than anybody else except it's nasty because five has two subtrees.


session: M05-03
timestamp: 00:24:58.24
speaker: LOW
utterance:
alright they want us to delete five, they want us to move as few nodes as possible, and they want us to keep it a binary search tree but they don't say that.


session: M05-03
timestamp: 00:25:21.02
speaker: LOW
utterance:
before we do that perhaps +// you making up the test what would be one of the easiest nodes to delete?


session: M05-03
timestamp: 00:25:52.16
speaker: LOW
utterance:
we're going to pick up a node over here to promote or we're going to pick a node over here to promote.


session: M05-03
timestamp: 00:25:58.20
speaker: LOW
utterance:
we're going to try and replace five with one of these guys or we're going to replace five with one of these guys.


session: M05-03
timestamp: 00:26:39.03
speaker: LOW
utterance:
uh it doesn't sound good because two has two kids and you know but # also will there be other changes to this left subtree?


session: M05-03
timestamp: 00:28:31.14
speaker: LOW
utterance:
here's a general binary search tree and it's got some giant left subtree and it's got some giant right subtree.


session: M05-03
timestamp: 00:29:44.12
speaker: LOW
utterance:
I can't use integers anymore but if we put two and a half in the tree then it would go right here, wouldn't it?


session: M05-03
timestamp: 00:30:02.19
speaker: LOW
utterance:
could this node we're trying to get rid of which has two kids could be replaced with a node with two kids and this would keep happening all the way down the tree?


session: M05-03
timestamp: 00:31:19.27
speaker: LOW
utterance:
well, generally when I think you write an algorithm you'll write one that will always pick this one or will always +// otherwise you'll have to write the code.


session: M05-03
timestamp: 00:31:33.07
speaker: LOW
utterance:
so again if three had a kid but seven didn't then in this case it would be easier to move seven than it would be to move three.


session: M05-03
timestamp: 00:31:39.22
speaker: LOW
utterance:
but I don't think they're going to try to trick you like that on the posttest or anything like that.


session: M05-03
timestamp: 00:31:44.27
speaker: LOW
utterance:
in general, the algorithm just picks one +// will always do the bigger one on the right or the smaller on the right.


session: M05-03
timestamp: 00:32:17.03
speaker: LOW
utterance:
lets try to point out that that's not the only binary search tree that could possibly exist on those seven nodes.


session: M05-03
timestamp: 00:32:54.10
speaker: LOW
utterance:
and then two or nine was next so, you know, if you start with three +// you know, order the nodes any way you want to.


session: M05-03
timestamp: 00:33:31.10
speaker: LOW
utterance:
um sort of the worst case would be if some friendly person sorted these numbers before he or she gave them to you and built a binary tree.


session: M05-04
timestamp: 00:00:02.25
speaker: LOW
utterance:
now we have some exercises here # we're going to talk about linked lists and binary search trees so I've just +// they've given us these two linked lists.


session: M05-04
timestamp: 00:00:11.21
speaker: LOW
utterance:
a four element one and a three element one and we haven't got a heck of a lot of time so +// that first problem is pretty easy so let's look at problem number two.


session: M05-04
timestamp: 00:00:28.15
speaker: LOW
utterance:
so uh we want to talk about how we get rid of a@l um and of course, all you have is this header node to the first list, okay?


session: M05-04
timestamp: 00:01:01.15
speaker: 004
utterance:
well, to get to this node I know what h@l +// that the h@l two so I +// and I also know the distance +// I know that this node is uh I guess two nexts +// it's next +// it's next and a next so I can tell +// so I can tell this node that the +// sets the next of this node to be the next and the next of this node.


session: M05-04
timestamp: 00:01:34.14
speaker: LOW
utterance:
um I guess we shouldn't +// we should assume that's there's an a@l somewhere in this list but maybe it's making it too simple if we assume it's exactly three nodes and it's in the middle of the list so let's suppose just kind of a picture and in fact there's a, you know, 17 nodes and a@l somewhere in the middle there.


session: M05-04
timestamp: 00:01:55.07
speaker: LOW
utterance:
so how do we find +// so you're exactly right you want to set the next of this node to its own next next, right?


session: M05-04
timestamp: 00:03:24.28
speaker: 004
utterance:
it's not null +// the t@l one is equal to +// while t@l one is not null or um not equals to e@l +// to a@l.


session: M05-04
timestamp: 00:03:31.14
speaker: LOW
utterance:
yeah, I think you want, and not equal to a@l uh t@l one's +// let's just call it info is not equal to a@l.


session: M05-04
timestamp: 00:03:55.01
speaker: LOW
utterance:
alright so in the picture t@l one is here and uh that's not null, of course, and that's not a@l so what do we do inside the while loop?


session: M05-04
timestamp: 00:04:18.04
speaker: 004
utterance:
okay yeah then we suddenly lost the linkage # so maybe we can have another um pointer that will be, you know, in the shift +// in a delay form.


session: M05-04
timestamp: 00:04:34.18
speaker: LOW
utterance:
alright so, we'll call it t@l two so in the picture uh t@l one would be there and t@l two would be here, right?


session: M05-04
timestamp: 00:05:42.24
speaker: LOW
utterance:
alright so in fact that would be the initial value in this particular case # t@l one is here, t@l two is t@l one's next and then until we find the a@l we just keep going across.


session: M05-04
timestamp: 00:05:51.12
speaker: LOW
utterance:
okay that would work # we'll come back with a little problem in a second but that would work pretty nicely.


session: M05-04
timestamp: 00:05:58.05
speaker: LOW
utterance:
uh alright so we get out of the loop with this and now you basically told me to write it down # what's the +// what's the thing we need to do now?


session: M05-04
timestamp: 00:06:31.15
speaker: LOW
utterance:
yeah and a minute ago you were saying, t@l one next dot next which would work too but we got t@l two so we don't need to do all that stuff.


session: M05-04
timestamp: 00:06:48.12
speaker: LOW
utterance:
uh you seem to be working which is very good on the assumption that there might not be an a@l in the list, right?


session: M05-04
timestamp: 00:06:56.25
speaker: LOW
utterance:
(be)cause you were worried about t@l two going null so really before we do this surgery right here # we want to see whether t@l two is null, right?


session: M05-04
timestamp: 00:07:08.03
speaker: LOW
utterance:
so if +// if we didn't find it # if there is no a@l in this list then these keep moving, these keep moving, and these keep moving and then t@l two eventually dies.


session: M05-04
timestamp: 00:07:19.24
speaker: LOW
utterance:
so if t@l two is null we don't want to do this, in fact, we're trying to delete a node which can't be found so there's nothing to do so we just do a return, right?


session: M05-04
timestamp: 00:07:58.03
speaker: LOW
utterance:
alright so you could uh +// we could check for that as you just suggested right up here we could check if uh if t@l two is null now we could check for that.


session: M05-04
timestamp: 00:08:10.10
speaker: LOW
utterance:
but in fact, actually # yeah +// you were correct you have a problem in a one element list but you also missed the a@l at the very beginning.


session: M05-04
timestamp: 00:08:19.07
speaker: LOW
utterance:
in fact, if you just change this to the a@l and change this to the e@l (be)cause you're starting you're looking at the second of the xx, right?


session: M05-04
timestamp: 00:08:25.16
speaker: LOW
utterance:
uh but I think for the pretest/posttest these are fine but, you know, it's good to be able to get the extra issues.


session: M05-04
timestamp: 00:08:43.13
speaker: 004
utterance:
then you +// if yeah +// if the t@l one is a@l or if a@l is h@l two next is a@l then h@l two equals whatever a@l is.


session: M05-04
timestamp: 00:08:55.28
speaker: LOW
utterance:
exactly so there's one case when h@l two moves, you know, mainly if you're deleting a@l from this list h@l two doesn't change, well yes it does if it's the first node.


session: M05-04
timestamp: 00:09:08.11
speaker: LOW
utterance:
uh # number three here # describe the sequence of operations to add list two to the end of list one.


session: M05-04
timestamp: 00:09:20.01
speaker: LOW
utterance:
alright so let's, you know +// pictures are real simple but uh they want us to describe the sequence of operations.


session: M05-04
timestamp: 00:09:34.24
speaker: 004
utterance:
well, we basically want to have the last one if we're going to traverse and if this one the next +// for this one if the next is null it would be equal +...


session: M05-04
timestamp: 00:09:56.24
speaker: 004
utterance:
okay uh haha, I was just talking like in abstract like when you write the code if you scrutinize it.


session: M05-04
timestamp: 00:10:31.08
speaker: 004
utterance:
and when you get out of the loop t@l one is equals to this node and then we'll setup whatever t@l one next is is h@l two.


session: M05-04
timestamp: 00:10:51.25
speaker: LOW
utterance:
so if you're looking for special cases uh I mean, we got a four element list here it's going to work on a 17 element list # it's going to work on a 4,000 element list.


session: M05-04
timestamp: 00:11:35.26
speaker: LOW
utterance:
t@l one is here # while doesn't do anything because that is null and then we just stick it in, alright?


session: M05-04
timestamp: 00:12:00.16
speaker: LOW
utterance:
yeah, actually if h@l two is empty I think we're okay because this changes this null to a null but if h@l one is empty then we're in trouble because you can't do this next.


session: M05-04
timestamp: 00:12:16.03
speaker: LOW
utterance:
again, I think they're not really that concerned about that on the pretest because they showed you that a@l wasn't uh +// this list wasn't empty but uh we could check for that so if t@l one is null +// let's just check for it right here.


session: M05-04
timestamp: 00:12:41.08
speaker: LOW
utterance:
exactly so if I put before xx so if h@l one is really really null then we just say h@l one equals h@l two.


session: M05-04
timestamp: 00:14:46.21
speaker: 004
utterance:
ah okay so everything that's smaller +// everything that's here # is smaller than everything up here.


session: M05-04
timestamp: 00:15:48.24
speaker: LOW
utterance:
I mean they'll say, 'seven's bigger than these guys and seven's less than those guys so it's a binary search tree.'


session: M05-04
timestamp: 00:18:45.08
speaker: LOW
utterance:
now they would like you to insert six into this binary search tree and keep it a binary search tree.


session: M05-04
timestamp: 00:19:47.02
speaker: LOW
utterance:
so it turns out that six works here but let me show you the general algorithm for insertion in a binary search tree.


session: M05-04
timestamp: 00:20:11.28
speaker: LOW
utterance:
in the algorithm you will learn in the class the insertion algorithm first uses the search algorithm.


session: M05-04
timestamp: 00:21:30.13
speaker: 004
utterance:
well, I guess I would have to shift # well +// here I know what's underneath so I can just basically shift if up.


session: M05-04
timestamp: 00:22:15.14
speaker: LOW
utterance:
you're suggesting if a node only has one child you are by bringing this up I think you mean that five is going to point to this?


session: M05-04
timestamp: 00:22:42.06
speaker: LOW
utterance:
if you're making up a test and you're going to make it easy for yourself which of these seven nodes are you going to suggest to delete?


session: M05-04
timestamp: 00:24:08.28
speaker: 004
utterance:
and basically start to add +// this is a tree and start adding # each +// you can traverse through all of it and going to the average [?] and it adds it # to this tree.


session: M05-04
timestamp: 00:24:32.19
speaker: LOW
utterance:
these are all smaller than that so they're going to come out +// I mean these are all smaller than five.


session: M05-04
timestamp: 00:26:16.07
speaker: 004
utterance:
I'm taking this two and from here I'm trying to go as right as possible and here I'm trying to go as right as possible.


session: M05-04
timestamp: 00:27:20.05
speaker: LOW
utterance:
and sometimes people have trouble finding the biggest but you already told me go left once and go right, right, right.


session: M05-04
timestamp: 00:27:24.13
speaker: LOW
utterance:
(be)cause that's going to get you into the smaller ones and that will get you bigger, bigger, bigger.


session: M05-04
timestamp: 00:27:27.29
speaker: LOW
utterance:
or find the smallest one over here by going left and then going right and then left, left, left, left.


session: M05-04
timestamp: 00:27:45.16
speaker: LOW
utterance:
I can't put whole numbers in here anymore but if I put two and a half in this tree # 2.5 it would be right here, wouldn't it?


session: M05-04
timestamp: 00:28:19.19
speaker: LOW
utterance:
so this one can't have a right if it's +// we could've gone to the right, right, right, right which is good.


session: M05-04
timestamp: 00:28:30.08
speaker: LOW
utterance:
so if you want to move three up in this case you just do the grandparent to grandchild thing and move three up there.


session: M05-04
timestamp: 00:28:35.15
speaker: LOW
utterance:
if +// in this case if seven might be slightly simpler because seven is a leaf and you just put it up there.


session: M05-04
timestamp: 00:28:50.02
speaker: LOW
utterance:
it could have seven point five and below that could be smaller stuff between seven and seven and a half.


session: M05-04
timestamp: 00:29:23.07
speaker: LOW
utterance:
uh this is +// what they want you to see is that this isn't the only possible binary search tree on those seven nodes, of course.


session: M05-04
timestamp: 00:30:02.21
speaker: LOW
utterance:
any one of them can be the root and if it's not one or nine, in fact, the tree has both a left and a right subtree.


session: M05-04
timestamp: 00:30:10.27
speaker: LOW
utterance:
but that's a fairly balanced +// we can balance a little bit better by making eight the right child of five and make seven and nine be eight's kids, right?


session: M05-04
timestamp: 00:30:34.04
speaker: LOW
utterance:
by balanced I simply mean that there's the same amount of stuff on the left as there is on the right.


session: M05-04
timestamp: 00:30:55.00
speaker: LOW
utterance:
whereas here it's going to be binary search it's going to be uh # going to be logarithmic as opposed to linear if you want to talk about those kinds of things.


session: M05-05
timestamp: 00:00:25.00
speaker: 005
utterance:
I would use a temporary here and then connect it to xx to indicate that um if a@l temporary cursor xxx then it's a@l and you can move m@l and xxx.


session: M05-05
timestamp: 00:00:40.00
speaker: LOW
utterance:
so you're +// alright so we're going to use a temporary pointer # how do we initialize this temporary pointer?


session: M05-05
timestamp: 00:01:51.25
speaker: LOW
utterance:
so if you did that then you're t@l one would end up over here or depending on how you did it so +...


session: M05-05
timestamp: 00:02:08.00
speaker: LOW
utterance:
okay so once you use your while idea # uh to sort of look for the a@l so t@l one is at the front of the list which is the only thing you can see.


session: M05-05
timestamp: 00:02:36.24
speaker: LOW
utterance:
and inside the loop here you're going to say, t@l one next equals +// oops +// t@l one equals t@l one next, right?


session: M05-05
timestamp: 00:03:52.01
speaker: LOW
utterance:
how (a)bout we're looking for a@l so instead of +// instead of putting null here why don't we put +...


session: M05-05
timestamp: 00:04:01.03
speaker: 005
utterance:
but xx # in this case I think it doesn't allow it so the proper I think is t@l one dot next and dot element or something like that, yeah.


session: M05-05
timestamp: 00:04:15.07
speaker: LOW
utterance:
you're very very correct we should put something there because this is a pointer and that's an element.


session: M05-05
timestamp: 00:04:24.16
speaker: LOW
utterance:
so let's suppose that it's not the second element but the 22nd element so, you know, this is going to move t@l one across (un)til t@l one's next element is a@l.


session: M05-05
timestamp: 00:04:50.12
speaker: LOW
utterance:
alright so uh but we've got a pointer right there so outside of the loop we say, t@l one's next and we want to save this and you said, a@l dot next, but of course a@l is an element so you have to have uh xx.


session: M05-05
timestamp: 00:05:28.19
speaker: LOW
utterance:
we could have used a second pointer here and then we could have said, t@l two dot next, but that's fine.


session: M05-05
timestamp: 00:05:44.13
speaker: LOW
utterance:
alright now in what case +// you brought up a good question +// in what case would uh h@l two change?


session: M05-05
timestamp: 00:06:33.19
speaker: LOW
utterance:
so if this +// if we were looking for m@l, if we were trying to delete m@l instead of a@l we'd have, while t@l dot next element is not equal to m@l so where would t@l one stop in that case?


session: M05-05
timestamp: 00:06:53.03
speaker: LOW
utterance:
and then you would set t@l one's next equals to its next next which is the null # so it works for the last element.


session: M05-05
timestamp: 00:07:30.08
speaker: LOW
utterance:
so we really should have an if out here at the top # if +// how could we tell that it's the first element?


session: M05-05
timestamp: 00:08:26.24
speaker: LOW
utterance:
if you have this three element list and you deleted the first element so what would the picture look like?


session: M05-05
timestamp: 00:08:36.19
speaker: LOW
utterance:
yeah, that says a@l and this is e@l over here, yeah, so if we're deleting a@l what would the picture look like so you do have the three element list # one, two, three.


session: M05-05
timestamp: 00:09:15.23
speaker: LOW
utterance:
or else # we uh do what you have here we have to find it, it's not the first element so we go looking for it.


session: M05-05
timestamp: 00:09:34.13
speaker: LOW
utterance:
describe the sequence of operations to add list two to the end of list one so I've redrawn it again here.


session: M05-05
timestamp: 00:09:42.11
speaker: LOW
utterance:
so they want to stick list two at the end of list one and they want to append or concatenate this list to that list.


session: M05-05
timestamp: 00:10:56.02
speaker: LOW
utterance:
so its next is not equal to null then it goes there and we still got the same thing inside the loop # t@l one equals t@l dot next.


session: M05-05
timestamp: 00:11:02.11
speaker: LOW
utterance:
yeah alright so t@l one goes here # that's not null so t@l one goes here # that's not null so t@l one goes here that is null so we exit the loop.


session: M05-05
timestamp: 00:11:19.00
speaker: LOW
utterance:
okay so outside of the loop we say t@l one dot next is h@l two and we get this picture and then probably, I don't think they care about it on the pre- posttest, but probably +// we got a weird situation here we got this new list with seven elements and we got a pointer that's in the middle of it.


session: M05-05
timestamp: 00:11:47.02
speaker: LOW
utterance:
we might copy these, I mean we can copy these instead of +// but I think that no they just mean to move them in but we might +// yeah it doesn't really matter pretty much so h@l two is null so don't have a pointer in the middle of the list anymore.


session: M05-05
timestamp: 00:12:01.15
speaker: LOW
utterance:
add list two to the end of list one and do what with list two, you know, but it sounded like a good idea.


session: M05-05
timestamp: 00:13:00.08
speaker: LOW
utterance:
describe the sequence of operations to insert list two after list one after the node that contains k@l.


session: M05-05
timestamp: 00:14:19.08
speaker: LOW
utterance:
do you need the dot next in this case, that is, back here you sort of needed the dot next because when you found the a@l +...


session: M05-05
timestamp: 00:14:32.04
speaker: LOW
utterance:
yeah you want +// right +// but also back up here you needed to do surgery to the node before a@l but here which node do you need to do surgery to node k@l, right?


session: M05-05
timestamp: 00:15:09.17
speaker: LOW
utterance:
we could have done it with t@l one dot next thing but then you would have to +// then t@l one would have been pointing here and that would have made it a little harder to change this pointer than having t@l one point here, right?


session: M05-05
timestamp: 00:15:45.14
speaker: 005
utterance:
okay because in my mind, recursive way is really easy to recognize [?] all this and it can be called back from +// if I connect from +... +// if I just say that t@l one dot next equal e@l +// t@l one dot next is a@l too.


session: M05-05
timestamp: 00:16:19.17
speaker: LOW
utterance:
and maybe it's a good idea when you draw your pictures # you've done that and of course you have broken this link, right?


session: M05-05
timestamp: 00:17:05.26
speaker: LOW
utterance:
as I was showing you in the picture once you did that you had broken this and never found it # alright so good idea, let's put t@l two here and you got to do it first # t@l two equals t@l one dot next.


session: M05-05
timestamp: 00:17:23.11
speaker: 005
utterance:
t@l one dot next is h@l two so and while +// while +// oh no, it doesn't matter so either way it goes +// xxx xxx xxx next xxx xxx xxx it was k@l so it stop pointing here so # uh can you use this element name or it can be longer?


session: M05-05
timestamp: 00:18:17.00
speaker: LOW
utterance:
technically, we could use t@l one again we don't really have a need for it anymore but maybe it's cleaner if we use t@l three?


session: M05-05
timestamp: 00:18:55.03
speaker: LOW
utterance:
okay so that's t@l three, that's not null, also that's t@l three, that's not null so that's t@l three and that is null.


session: M05-05
timestamp: 00:19:18.03
speaker: LOW
utterance:
uh # I think the only problem would be, suppose +// if h@l two is null then this won't work # if h@l two is the empty list we'd still be trying to stick this list in the middle here but it would be empty so nothing would happen, right?


session: M05-05
timestamp: 00:19:34.16
speaker: LOW
utterance:
um you set t@l three to null and then you did t@l three dot next so you're assuming that the picture shows it has at least one element which I think is good enough for now but I just want to point out that you really need to be careful when you're doing this.


session: M05-05
timestamp: 00:19:48.18
speaker: LOW
utterance:
you're doing a look ahead while t@l three dot next is not equal to null and you really have to +// only an if here, if t@l three is null then have a special case and have to do something.


session: M05-05
timestamp: 00:20:07.09
speaker: LOW
utterance:
if t@l three is null, then this list is empty and so you insert the empty list to this list and well, it doesn't change.


session: M05-05
timestamp: 00:20:19.21
speaker: LOW
utterance:
okay so let's look at some binary trees for a minute here and spend some time on that before we run out of time.


session: M05-05
timestamp: 00:21:13.19
speaker: LOW
utterance:
so here of course they didn't really show it in the diagrams but just like the linked lists you have a pointer to the first node and in the binary search tree you get a pointer to the root, okay?


session: M05-05
timestamp: 00:24:09.14
speaker: LOW
utterance:
uh they want you +// so I guess we should pretend that six and four are not in this tree for a minute.


session: M05-05
timestamp: 00:24:16.00
speaker: LOW
utterance:
they want you to delete nine and make it still be a binary search tree and do as little moving around of nodes as possible.


session: M05-05
timestamp: 00:25:01.24
speaker: LOW
utterance:
and then in terms of talking about trees and people and so on the grandparent can just point to the grandchild, alright?


session: M05-05
timestamp: 00:25:12.13
speaker: LOW
utterance:
this node only has one child so on this side of the tree this grandparent only has this one grandchild, okay?


session: M05-05
timestamp: 00:27:01.13
speaker: LOW
utterance:
there are two numbers, there was one over here in this tree and there was one over here in this tree that can easily replace the root.


session: M05-05
timestamp: 00:28:39.09
speaker: LOW
utterance:
the smallest one +// the only one that can move up is the smallest one because it is bigger than all these guys and it's the smallest of those guys, okay?


session: M05-05
timestamp: 00:29:32.17
speaker: LOW
utterance:
one and one and a half and one and a fourth and one and point seven-five and so on but it's alright.


session: M05-06
timestamp: 00:00:04.27
speaker: LOW
utterance:
uh but basically we're going to talk about linked lists, and trees and I'm going to give you a little posttest.


session: M05-06
timestamp: 00:00:11.13
speaker: LOW
utterance:
um they gave us some problems to play with here # I just drew out a couple of them so we can look at them.


session: M05-06
timestamp: 00:00:27.26
speaker: LOW
utterance:
um we should imagine this as some linked list not necessarily just three elements but you know maybe 27 elements or something like that.


session: M05-06
timestamp: 00:00:50.14
speaker: LOW
utterance:
okay so this is obviously the picture we want to do and as I said, we shouldn't assume that a@l is the second element let's assume there's a whole bunch of other elements in here.


session: M05-06
timestamp: 00:01:35.13
speaker: LOW
utterance:
alright and now # we want to delete a@l so the first thing you got to do is you got to kind of find a@l, right?


session: M05-06
timestamp: 00:01:47.16
speaker: 006
utterance:
um we would use t@l one to look for the next element or you would search for the element in the first uh first node in t@l one which would be e@l so # you would setup a comparison for a@l.


session: M05-06
timestamp: 00:02:08.19
speaker: LOW
utterance:
okay so you're saying, t@l one's element uh you got looking for a@l # isn't a@l so you're suggesting a loop here I think, right?


session: M05-06
timestamp: 00:02:53.16
speaker: LOW
utterance:
um # which would have been +// that could have been an exercise right there, you know, find the a@l # already done that.


session: M05-06
timestamp: 00:03:40.07
speaker: LOW
utterance:
alright so the idea is uh t@l one will be in front as we march through the list and t@l two will be right behind it as we go through the list.


session: M05-06
timestamp: 00:03:50.27
speaker: LOW
utterance:
alright so I don't know if you've done this before or not but the way to get started of course, t@l one is h@l two.


session: M05-06
timestamp: 00:04:10.03
speaker: LOW
utterance:
alright but that's not t@l one's not the a@l so we march t@l one forward and as you said, we also march t@l two forward # does it matter?


session: M05-06
timestamp: 00:04:41.11
speaker: LOW
utterance:
and move t@l two there and move t@l one +// alright but in this case it would stop right there (be)cause t@l one is the a@l.


session: M05-06
timestamp: 00:04:52.08
speaker: LOW
utterance:
um # and then what do we say when we get out of the loop, of course, we found it and so it's easy when you get out of the loop you say +...


session: M05-06
timestamp: 00:05:09.02
speaker: LOW
utterance:
I think there's only one little tiny worry that I don't even think they're worried about in the next room.


session: M05-06
timestamp: 00:05:20.10
speaker: LOW
utterance:
and we could find it when it's the 22nd element # we could find it +// would this work if a@l was the last element in the list?


session: M05-06
timestamp: 00:05:29.01
speaker: LOW
utterance:
uh # t@l one or t@l two over here, then over here, well in fact if we were looking for m@l we just change that to m@l.


session: M05-06
timestamp: 00:05:41.18
speaker: LOW
utterance:
t@l two's next would be t@l one's next would be the xx so it works if a@l is the last element but it doesn't work if a@l is the +...


session: M05-06
timestamp: 00:05:58.10
speaker: LOW
utterance:
t@l one would be right here and t@l one's element is a@l and what should really +// so you couldn't do this because t@l two would be null.


session: M05-06
timestamp: 00:06:12.26
speaker: LOW
utterance:
well of course, don't do this if t@l two is null so if t@l two isn't null we can do that and xxx properly # thinking I put it in here.


session: M05-06
timestamp: 00:06:46.01
speaker: LOW
utterance:
it was a three element list now it's a two element list and the first element is gone so the thing that changes +...


session: M05-06
timestamp: 00:07:11.07
speaker: LOW
utterance:
well, not in general (be)cause it's down in the middle of the list but if it's the first thing in the list then the header does change, okay?


session: M05-06
timestamp: 00:07:30.03
speaker: LOW
utterance:
so concatenate that or append that one to this one so we'll have a seven element list when we get done.


session: M05-06
timestamp: 00:08:10.05
speaker: LOW
utterance:
okay we forgot to write what goes on in the loop which is of course t@l one is equal to t@l one dot next.


session: M05-06
timestamp: 00:08:29.06
speaker: LOW
utterance:
well, worked with a four element list therefore it would work on a 47 element list uh # special cases, well will it work with a one element list?


session: M05-06
timestamp: 00:08:57.05
speaker: LOW
utterance:
so if it works for a four element list, it would work for a 40,000 element list, it would work for a one element list # is there any list it doesn't work for?


session: M05-06
timestamp: 00:09:05.03
speaker: LOW
utterance:
yeah, if the list is empty (be)cause again the same sort of thing # if the list is empty then t@l one is null and you can't do t@l one next # but if the list +// if h@l one is empty we could test for that real quickly.


session: M05-06
timestamp: 00:09:20.02
speaker: LOW
utterance:
I'll say +// we can say if h@l one is not null then do all this # else +// what would do if h@l one was empty?


session: M05-06
timestamp: 00:09:41.16
speaker: LOW
utterance:
and then maybe in all cases I mean maybe it's kind of weird here h@l one is now this new seven element list or in this case it's empty h@l one has a got a pointer into the middle of the list.


session: M05-06
timestamp: 00:09:53.14
speaker: LOW
utterance:
you know, it's weird here so probably I don't think they care next door on the posttest or pretest but probably we should do something like that.


session: M05-06
timestamp: 00:10:02.03
speaker: LOW
utterance:
there's only one list they don't really tell us what to do but after you stuff this list at the end of that list there's only one list and there are not two lists anymore.


session: M05-06
timestamp: 00:12:21.12
speaker: LOW
utterance:
oh, by the way, I think they show this on the pre and posttest but just like you keep track of a linked list with a header node to the first node you keep track with a binary tree with a pointer to the root.


session: M05-06
timestamp: 00:12:57.06
speaker: LOW
utterance:
okay so we're searching for eight, again it's kind of like a linked list and we only have access to the root.


session: M05-06
timestamp: 00:14:30.05
speaker: LOW
utterance:
it would have to be in the right tree of two because it's bigger and it would have to be in the right tree of three because there is no right tree of three so put it there.


session: M05-06
timestamp: 00:14:56.16
speaker: LOW
utterance:
when the search +// use the search and if it fails +// of course +// I guess +// we're thinking of having a node in here exactly once so say if it's insert five it's already in the tree so don't do anything.


session: M05-06
timestamp: 00:15:13.19
speaker: LOW
utterance:
I guess with deletion we should pretend there is no six and pretend there is no four and we'll go back to the orignal tree.


session: M05-06
timestamp: 00:15:58.07
speaker: LOW
utterance:
so do you see an easy way to +// oh, they want you to take nine out of the tree and of course they want you to keep it a binary search tree and they want you do to as little moving of nodes around or pointers around as you can.


session: M05-06
timestamp: 00:16:24.05
speaker: LOW
utterance:
so we just do, in terms of talking about families, this is the grandparent # and this is the grandchild.


session: M05-06
timestamp: 00:16:47.11
speaker: LOW
utterance:
okay so that's basically just changes this one pointer and it's still a binary search tree because all of these guys +// we didn't do anything to this tree over here.


session: M05-06
timestamp: 00:17:09.26
speaker: LOW
utterance:
suppose you were making up the posttest and you wanted to make up a really really easy deletion problem.


session: M05-06
timestamp: 00:17:29.05
speaker: LOW
utterance:
so these are called leaves, they have no children, you know, in tree languages these are called leaves.


session: M05-06
timestamp: 00:17:49.01
speaker: LOW
utterance:
so they want us to delete the node five from this tree moving as few nodes as possible, keeping it a binary search tree.


session: M05-06
timestamp: 00:17:56.07
speaker: LOW
utterance:
it isn't really a worse case that five is the root it's just we're going to do this same thing for anybody that has two kids.


session: M05-06
timestamp: 00:18:27.10
speaker: LOW
utterance:
it turns out that there is one node on this side and one node on this side that can replace n@l and we're done.


session: M05-06
timestamp: 00:19:14.23
speaker: LOW
utterance:
and three is less than five which is less than all these guys and so three is going to be right on that side.


session: M05-06
timestamp: 00:19:32.07
speaker: LOW
utterance:
and so seven is going to be fine with the left tree and what property does three have on this side and what property does seven have on this side?


session: M05-06
timestamp: 00:19:44.19
speaker: LOW
utterance:
suppose you put two and a half in this tree (be)cause one has no children but we don't want to move one up.


session: M05-06
timestamp: 00:19:51.16
speaker: LOW
utterance:
if two and a half +// I have to go to halves because there aren't any integers that will fit but two and a half is less than five.


session: M05-06
timestamp: 00:20:24.20
speaker: LOW
utterance:
I could put a ten off here and then I could give +// and ten has no +// put twelve in the tree also.


session: M05-06
timestamp: 00:21:25.01
speaker: LOW
utterance:
how do I tell the computer if I was writing pseudo-code, they don't care about it next door, how do I tell it do find it?


session: M05-06
timestamp: 00:22:12.07
speaker: LOW
utterance:
so we know that this node we're moving up is either case zero, is a leaf which is what they showed in the picture.


session: M05-06
timestamp: 00:23:02.20
speaker: LOW
utterance:
the smallest on the left side +// oops, the biggest on the left side or the smallest on the right side.


session: M05-06
timestamp: 00:23:18.18
speaker: LOW
utterance:
in this problem number seven, it's kind of a weird problem, just in case they do something like this on the posttest.


session: M05-06
timestamp: 00:23:25.26
speaker: LOW
utterance:
they're just trying to point out to you that this is not the only possible binary search tree on those seven nodes.


session: M05-06
timestamp: 00:23:55.08
speaker: LOW
utterance:
seven is your favorite and then if seven weren't there you would choose +// just give me a random order of these guys.


session: M05-06
timestamp: 00:25:06.05
speaker: LOW
utterance:
if I put the nine here I would have put the nine on the right before I put the one on the left but that wouldn't change the tree.


session: M05-06
timestamp: 00:25:42.13
speaker: LOW
utterance:
uh, deletion # look for one of the two easy ones if they're asking for a node that has two children.


session: S06-29
timestamp: 00:01:09.09
speaker: JAC
utterance:
uh and as we add new information +// as we add new letters, we put that in the new Lego and we add it on top.


session: S06-29
timestamp: 00:02:10.00
speaker: JAC
utterance:
uh <we have another um> [//] when we were making the stack, we would have had push, and we would have had push a@l, O_K_?


session: S06-29
timestamp: 00:07:16.24
speaker: JAC
utterance:
so if we want to check to see if this is a binary search tree, we go to the right, and we see eleven, and we see eleven is greater than seven.


session: S06-29
timestamp: 00:07:30.23
speaker: JAC
utterance:
<so if we consider eleven has its own> [//] so if we ignore this and say eleven is a new parent, it has its own children, right?


session: S06-29
timestamp: 00:08:09.18
speaker: JAC
utterance:
so we find eight, which is less than eleven, and then we have ten, which is also less than eleven, but is greater than eight.


session: S06-29
timestamp: 00:08:21.17
speaker: JAC
utterance:
okay so now if we check the left side, we have a four, which is less than seven, and four's right child which is five, which is greater than four.


session: S06-29
timestamp: 00:08:30.25
speaker: JAC
utterance:
so if we were trying to find out if this is a binary search tree, this is a binary search tree, O_K_?


session: S06-29
timestamp: 00:09:11.19
speaker: JAC
utterance:
now if this eight was over here instead then there would be a binary search tree as long as this is fine # which this portion is.


session: S06-29
timestamp: 00:09:32.08
speaker: JAC
utterance:
you can have trees like that but you usually when we are trying to develop a binary search tree we don't want it heavy like this.


session: S06-29
timestamp: 00:10:51.20
speaker: JAC
utterance:
so if I have +// if you have words, O_K_, if I have apple, and you want to compare it to orange +...


session: S06-29
timestamp: 00:11:17.19
speaker: JAC
utterance:
<so this would be +// so, apple would be> [//] depends on how you find the apple, we'll say if it comes up first in the dictionary, it's less.


session: S06-29
timestamp: 00:11:34.22
speaker: JAC
utterance:
now it could be different, depending on whether, you're in an environment where it's case sensitive, so apple might be different then Apple.


session: S06-29
timestamp: 00:11:55.16
speaker: JAC
utterance:
okay so there it would have to make the decision, does small a@l come before big A@l, or does big A@l come before small a@l?


session: S06-29
timestamp: 00:12:24.18
speaker: JAC
utterance:
so O_K_, moving right along with binary trees, O_K_, we're going to work with this binary search tree for a little bit.


session: S06-29
timestamp: 00:14:44.10
speaker: JAC
utterance:
<so that we would have> [//] I'm just going to redraw the one side, so we don't have to delete the other.


session: S06-29
timestamp: 00:15:19.18
speaker: JAC
utterance:
so we look all the way down, we look at the first right child and we go down as far left as we can go, and we find eleven.


session: S06-29
timestamp: 00:16:10.25
speaker: JAC
utterance:
and I inherit nine's left child so basically what I just did was I inherited nine's right child which was 15.


session: S06-29
timestamp: 00:16:29.08
speaker: JAC
utterance:
now the reason I did that was, if I promoted 15 up here, which might be considered the most logical choice, I'll just move this one up.


session: S06-29
timestamp: 00:16:42.26
speaker: JAC
utterance:
and now I have ten here, and now I have to put ten on the other side, and I've got to do a lot of extra work.


session: S06-29
timestamp: 00:17:57.02
speaker: JAC
utterance:
and then you're going to go find the least +// you're going to keep going all the way down the left.


session: S06-29
timestamp: 00:18:45.17
speaker: JAC
utterance:
<so we could have +// we could have> [//] with a really deep tree we could have you know a thousand levels, right?


session: S06-29
timestamp: 00:19:30.14
speaker: JAC
utterance:
if we wanted to try and find four, what we do is we compare five and four, we do the same thing we do with six.


session: S06-29
timestamp: 00:20:33.07
speaker: JAC
utterance:
like you can say, you can check and say if I find this, if you find the number I'm searching for, return true.


session: S06-29
timestamp: 00:22:02.08
speaker: JAC
utterance:
we have you know +// we are working with integers, but there is nothing saying we can't be using decimals.


session: S06-29
timestamp: 00:22:16.18
speaker: JAC
utterance:
O_K_ since everything at the bottom is always pointing to null, when we find null, will we know this?


session: S06-29
timestamp: 00:25:43.08
speaker: JAC
utterance:
so um and we can use the stack in order to go the binary search tree by just popping them off the top.


session: S06-29
timestamp: 00:26:17.05
speaker: JAC
utterance:
and the thought is, O_K_ anything I search for, I'm likely to search for again in the near future, than I am for any other number.


session: S06-29
timestamp: 00:26:26.26
speaker: JAC
utterance:
so what it does instead of leaving it all the way at the bottom, is start rotating it up to the top until it's at the root.


session: S06-29
timestamp: 00:27:19.01
speaker: JAC
utterance:
but yeah I mean, there are ways to make it more balanced so that a search down the left side is equivalent to a search down the right side.


session: S06-29
timestamp: 00:28:12.29
speaker: JAC
utterance:
so if some friend comes up and says, `where is the end of the line,` well here is the front of the line.


session: S06-29
timestamp: 00:28:54.02
speaker: JAC
utterance:
so we go and we ask the first person on the end of the line, `hey, is this, *uh, who is behind you?`


session: S06-29
timestamp: 00:29:24.26
speaker: JAC
utterance:
so if we want to insert something right after we would keep looking and asking each one, `hey, is null behind you?`


session: S06-29
timestamp: 00:29:49.02
speaker: JAC
utterance:
so instead of saying that your pointing to null +// instead of saying null is behind you, I want you to point to me, okay?


session: S06-29
timestamp: 00:30:30.12
speaker: JAC
utterance:
so if we insert +// if we say we want to insert a new node, which contains g@l into the list, after the node that contains b@l.


session: S06-29
timestamp: 00:33:29.04
speaker: JAC
utterance:
we don't want to leave this pointing to, or leave it there, we want to delete it because it could be taking up space, or if for some reason we try and access this, we would have two things that would point to Al.


session: S06-29
timestamp: 00:35:34.26
speaker: JAC
utterance:
<if you're told b@l> [//] it's no different than if I tell you to insert after k@l or after f@l, I mean it's all the same.


session: S06-29
timestamp: 00:36:01.26
speaker: 229
utterance:
O_K_ so if you're going to place this whole thing between k@l and b@l, you're going to have to like delete this head, and +...


session: S06-29
timestamp: 00:36:08.29
speaker: JAC
utterance:
+< well you don't want to delete the head, you want to delete the head last, because you still want to be able to point to this, right.


session: S06-30
timestamp: 00:00:31.16
speaker: LOW
utterance:
but basically, we keep track of the link lists, with a pointer to, basically the address to the first node.


session: S06-30
timestamp: 00:01:03.01
speaker: LOW
utterance:
it's k@l, which has the address of the third one which has a b@l, which has the address of the fourth one.


session: S06-30
timestamp: 00:01:28.21
speaker: LOW
utterance:
so the first example here, they want us to describe a sequence of operations to insert a new node, which contains g@l, in this first list, after the node that contains b@l.


session: S06-30
timestamp: 00:01:39.12
speaker: LOW
utterance:
well, one thing with working with link lists, and with binary search trees, and with stacks, and with data structures, you always draw pictures, O_K_?


session: S06-30
timestamp: 00:02:24.22
speaker: LOW
utterance:
all right, we're not going to write it in any specific language, we're going to write pseudo code, it's called.


session: S06-30
timestamp: 00:02:29.19
speaker: LOW
utterance:
all right, um well, so the trick is here, that before you can insert this node after the node that contains b@l, you got to find the b@l, O_K_?


session: S06-30
timestamp: 00:03:13.03
speaker: LOW
utterance:
so what I'm going to do is +// the only piece of information I have is the address of the first node, O_K_?


session: S06-30
timestamp: 00:04:34.09
speaker: LOW
utterance:
and the reason we didn't move h@l one across here, is if you move h@l one, you could totally lose this node, O_K_?


session: S06-30
timestamp: 00:05:01.26
speaker: LOW
utterance:
so *uh, we'll call it *uh, new node and we have to pass it the information you want to put in there.


session: S06-30
timestamp: 00:05:36.01
speaker: LOW
utterance:
we find the node that contains b@l, create this new node with g@l in it, and now link it in to the list, O_K_?


session: S06-30
timestamp: 00:07:06.22
speaker: LOW
utterance:
that says <next of p@l> [//] next of the node p@l points to, <is the new copied> [//] the value copied in the next field of node t@l points to.


session: S06-30
timestamp: 00:07:29.08
speaker: LOW
utterance:
we didn't want very many lines of code, we found the node that contains, we created the new node, and we linked it in, okay?


session: S06-30
timestamp: 00:07:54.23
speaker: LOW
utterance:
<and well this had a> [//] this was a three element list, so it should be a two element list, right?


session: S06-30
timestamp: 00:09:47.19
speaker: LOW
utterance:
so the picture I want is, p@l is going to move forward to here, and q@l is going to move forward to here, O_K_?


session: S06-30
timestamp: 00:10:44.17
speaker: LOW
utterance:
and imagine we weren't looking for a@l, and imagine that wasn't a@l, then these things just move across the list.


session: S06-30
timestamp: 00:12:27.25
speaker: LOW
utterance:
so that's marking the end of the list, so you're just putting it over to mark this as the end of the list.


session: S06-30
timestamp: 00:13:15.23
speaker: LOW
utterance:
<so if q@l is really equal to null> [///] *uh, how about if q@l is not equal to null because, I have right here what we would do if q@l is not equal to null.


session: S06-30
timestamp: 00:13:33.23
speaker: LOW
utterance:
I got e@l pointing right now at a@l, which points to m@l, this is a three element list, and this is h@l two.


session: S06-30
timestamp: 00:13:57.05
speaker: LOW
utterance:
how do you make it? +// it used to be the three element list e@l, a@l, m@l, now it's supposed to be the two element list a@l, m@l.


session: S06-30
timestamp: 00:14:41.25
speaker: LOW
utterance:
*uh, but the special case was, if the node you're trying to delete was the first one, then q@l is null, and you can't do this.


session: S06-30
timestamp: 00:15:06.11
speaker: LOW
utterance:
<*uh, but where originally> +// *uh, one source of the name would be a stack of trays in a cafeteria.


session: S06-30
timestamp: 00:15:34.12
speaker: LOW
utterance:
and you take off that tray, and then the spring doesn't have as much weight on it and it pops up one more tray, okay?


session: S06-30
timestamp: 00:16:21.06
speaker: LOW
utterance:
*uh, push is the insert, so this is basically the delete function, and this is the insertion function.


session: S06-30
timestamp: 00:16:52.07
speaker: LOW
utterance:
(be)cause basically what this does is <it shows you> [//] it gives you back whats on top, but it doesn't destroy the stack.


session: S06-30
timestamp: 00:18:19.09
speaker: LOW
utterance:
we'll increment the counter, we'll pop off another one, increment a counter, pop off another one, increment a counter, pop off another one, increment a counter, so we can return four.


session: S06-30
timestamp: 00:19:17.21
speaker: LOW
utterance:
we're going to pop the p@l off and increment a counter, and we're going to put it somewhere where we can store it later.


session: S06-30
timestamp: 00:21:46.25
speaker: LOW
utterance:
and that would, *uh +// so draw a new picture of s@l here, pop the a@l, pop the d@l, pop the g@l, pop the p@l, now s@l is back.


session: S06-30
timestamp: 00:22:48.10
speaker: LOW
utterance:
and what makes it a binary search tree is it has to have the following property:  that, not just at the root, but at every node you look at, the things on the left are smaller, and the things on the right are bigger.


session: S06-30
timestamp: 00:23:18.10
speaker: LOW
utterance:
so they have this property that at every node, the things on the left are smaller, and four and five are smaller than seven.


session: S06-30
timestamp: 00:24:25.15
speaker: LOW
utterance:
(be)cause these are all bigger than the eight, and these are smaller, and these are bigger than five, so its just total reversed.


session: S06-30
timestamp: 00:24:36.16
speaker: LOW
utterance:
oh by the way, they don't show you this, but they keep track of the binary search tree by pointer to the root.


session: S06-30
timestamp: 00:24:43.22
speaker: LOW
utterance:
*uh, pointer to the root, and it's the binary search tree, because these guys are less than five, and that's less then two and that's bigger than two, and these guys are bigger than five, and all right, O_K_.


session: S06-30
timestamp: 00:25:14.12
speaker: LOW
utterance:
uh if you're using names or whatever, alphabetically before would be left, alphabetically after would be right.


session: S06-30
timestamp: 00:25:26.02
speaker: LOW
utterance:
well, it's called a binary search tree, so your not going to be surprised to learn one thing that you can do with these things is to search them efficiently.


session: S06-30
timestamp: 00:27:33.18
speaker: LOW
utterance:
O_K_, so, six would be, yeah, I can't put six over here, it wouldn't be a binary search tree, all right?


session: S06-30
timestamp: 00:28:21.08
speaker: LOW
utterance:
so we change that null pointer to get a new node, and we get a new node +// we're not going to write this out +// and we get a new node and we make this guy point to xxx.


session: S06-30
timestamp: 00:29:32.10
speaker: LOW
utterance:
moving as few nodes as possible, and they don't say it here, but they mean it, keep it a binary search tree, O_K_?


session: S06-30
timestamp: 00:33:05.01
speaker: LOW
utterance:
alright, if we brought three up, then two and one are happy, because they are smaller, and these are all bigger than five, so this is bigger than three.


session: S06-30
timestamp: 00:33:20.11
speaker: LOW
utterance:
<so how in general do we find, in an arbitrary tree, binary search tree> [//] how do we find this node counts as a three and this node counts as a seven?


session: S06-30
timestamp: 00:34:06.19
speaker: LOW
utterance:
pick your choice, if you pick seven, you can delete seven from the tree, and put it here, and now it is still a binary search tree.


session: S06-30
timestamp: 00:34:59.05
speaker: LOW
utterance:
but we'd still want to promote seven because that is what you by going right and then going left as far as you can.


session: S06-30
timestamp: 00:35:31.20
speaker: LOW
utterance:
and that might require, for example, uh if we put two and a half in here, two and a half would be less bigger less, than three would have one child, okay?


session: S06-31
timestamp: 00:00:45.24
speaker: LOW
utterance:
so there's the information and then there is a next field, which is basically the address of the next node.


session: S06-31
timestamp: 00:01:01.09
speaker: LOW
utterance:
and then there is a special null pointer, they use a fancy notation here in rounding it, but I just use a slash, to indicate no more, O_K_?


session: S06-31
timestamp: 00:01:14.13
speaker: LOW
utterance:
so the first example they give here is to describe the sequence of operations to insert a new node which contains g@l in this list, after the node that contains b@l.


session: S06-31
timestamp: 00:02:42.17
speaker: LOW
utterance:
we don't want to move h@l one over here, because it would suddenly no longer be a four element list, we would have lost.


session: S06-31
timestamp: 00:03:25.12
speaker: LOW
utterance:
and again each node has two parts, the information and the *uh next, so we're going to say while the info, in t@l is not equal to b@l, O_K_?


session: S06-31
timestamp: 00:03:38.12
speaker: LOW
utterance:
and we want t@l to move over there, so we want t@l to take on this value that's at it's own next field.


session: S06-31
timestamp: 00:04:20.20
speaker: LOW
utterance:
that's what they're wanting us to do, but in reality we have to be careful because this wouldn't work if there was no b@l.


session: S06-31
timestamp: 00:04:28.05
speaker: LOW
utterance:
uh so now when we get out of the loop, we're going to suppose that there is <a cheap way> [//] an easy way to get a new node, so we'll just call it new node.


session: S06-31
timestamp: 00:06:35.12
speaker: LOW
utterance:
so I do number two first, next of n@l gets the address that is stored right here, so it points there.


session: S06-31
timestamp: 00:07:08.13
speaker: LOW
utterance:
h@l two is this three element list, and when I delete a@l, it will be a two element list, and the first element will be e@l, and it will point to the second element n@l.


session: S06-31
timestamp: 00:09:58.09
speaker: LOW
utterance:
so when we get out of this loop we say, being a little careful> [//] we say this thing right here needs to change.


session: S06-31
timestamp: 00:10:36.08
speaker: LOW
utterance:
but I think if you see it's a 20,000 element list and a@l is somewhere in the middle, that would be fine.


session: S06-31
timestamp: 00:12:03.13
speaker: LOW
utterance:
it's a three element list, you want to delete e@l, it's going to be a two element list, so what has to change?


session: S06-31
timestamp: 00:13:27.16
speaker: LOW
utterance:
and then the *uh guy comes out of the kitchen and puts more trays on, one at a time, this spring pushes down.


session: S06-31
timestamp: 00:14:28.03
speaker: LOW
utterance:
top, I sometimes call it peak, pop peaks at this, and tells you that r@l is the top thing on the stack, at leaves it there.


session: S06-31
timestamp: 00:14:43.09
speaker: LOW
utterance:
if I pop this stack it will give me the r@l, if I push it back on it then I will have equivalent of top.


session: S06-31
timestamp: 00:15:05.11
speaker: LOW
utterance:
and see there is an r@l, but if you keep using top, you will get yourself in an infinite loop because top is r@l, r@l, r@l, r@l.


session: S06-31
timestamp: 00:15:20.28
speaker: LOW
utterance:
<but the trouble with doing that is> [//] O_K_, so let me put a counter here, so if I pop r@l off one, pop q@l off two, pop d@l off three, pop a@l off four +...


session: S06-31
timestamp: 00:16:40.25
speaker: LOW
utterance:
uh but you see the thing is, we got to save these things, because we are destroying it, and we got to restore them.


session: S06-31
timestamp: 00:19:04.15
speaker: LOW
utterance:
or tenary trees where it could have +//	you know these are binary trees, so it could have each node +...


session: S06-31
timestamp: 00:19:14.12
speaker: LOW
utterance:
*uh, and what makes it a binary search tree is a very special property, *uh we'll see what we can illustrate it here.


session: S06-31
timestamp: 00:19:24.09
speaker: LOW
utterance:
at every node, not just at the root, but at every node, the things on the left are smaller, and the things on the right are larger.


session: S06-31
timestamp: 00:20:45.07
speaker: LOW
utterance:
*uh, for some reason, I think they give you the hard problems and then the medium problems and then the easy problems.


session: S06-31
timestamp: 00:22:42.06
speaker: LOW
utterance:
yeah this is why I wanted to do the search first, because the algorithm for inserting it is look for it.


session: S06-31
timestamp: 00:23:25.02
speaker: LOW
utterance:
alright, so there is a case zero that they don't even ask you about here which is easy, and that's what we call a leaf.


session: S06-31
timestamp: 00:25:31.09
speaker: LOW
utterance:
we didn't +// we changed one pointer, we didn't move a lot of stuff around, it was still a binary search tree.


session: S06-31
timestamp: 00:28:27.12
speaker: LOW
utterance:
so to get to the biggest one over here, you go into this tree, and then you go right not once but +...


session: S06-31
timestamp: 00:29:06.18
speaker: LOW
utterance:
could it be the one you're trying to move up itself has two kids which causes it to case two to create another case two to create another case two, it'll be a nightmare.


session: S06-31
timestamp: 00:29:44.03
speaker: LOW
utterance:
<seven and a half, seven and three quarters, seven and> [//] everything bigger than seven and less than eight would be over here.


session: S06-31
timestamp: 00:29:57.18
speaker: LOW
utterance:
so the final answer is, you could move up the biggest and the left, or the smallest in the right, and that will not cause another case two.


session: S06-31
timestamp: 00:30:18.11
speaker: LOW
utterance:
and if you wanted to move the seven up, you could move it up, and just make eight point to xxx # if there is one.


session: S06-31
timestamp: 00:30:43.18
speaker: LOW
utterance:
the important thing is that this is just one of many many many binary search trees you could have on those seven nodes.


session: S06-31
timestamp: 00:32:01.08
speaker: LOW
utterance:
so that just shows you, rearranging those to create another tree, this is another tree, which is a binary search tree on those same nodes.


session: S06-31
timestamp: 00:32:13.23
speaker: LOW
utterance:
and so suppose somebody was being very helpful, and sorted thee nodes before you tried to build the tree.


session: S06-31
timestamp: 00:33:17.04
speaker: LOW
utterance:
so what uh +// I guess the simplest thing to do would be to go back and look at one of these link list examples.


session: S06-31
timestamp: 00:33:34.13
speaker: LOW
utterance:
I will quickly make up another one, because that's what they do on the test (be)cause we got a couple copies of the test.


session: S06-31
timestamp: 00:33:44.08
speaker: LOW
utterance:
so lets see if we can quickly decide the sequence of operations to add list two to the end of list one.


session: S06-31
timestamp: 00:33:50.05
speaker: LOW
utterance:
so instead if having a four element list, we can have a three element list, and have one, and seven on the list.


session: S06-31
timestamp: 00:34:10.09
speaker: LOW
utterance:
and probably we should also set h@l two equal to null, because we might want a pointer in the middle of the list.


session: S06-31
timestamp: 00:34:16.00
speaker: LOW
utterance:
O_K_, so once again, all you have to do is find the end of this list, and then make this point there.


session: S06-31
timestamp: 00:35:16.01
speaker: LOW
utterance:
and then what do we say, when q@l comes out of the loop once again we needed p@l to define the end of the list.


session: S06-32
timestamp: 00:01:05.02
speaker: LOW
utterance:
there's the contents of these nodes, there should be a big record, there should be a single stupid letter.


session: S06-32
timestamp: 00:01:34.23
speaker: LOW
utterance:
O_K_, so the first exercise here is to describe the sequence of operations to insert a new node, with g@l in it, after the node that contains b@l.


session: S06-32
timestamp: 00:01:44.24
speaker: LOW
utterance:
all right the link lists with all of these data structures you should be drawing all kinds of pictures.


session: S06-32
timestamp: 00:01:56.00
speaker: LOW
utterance:
you got a new node with g@l in it, and this +// it's after the one that has b@l so we change this link here, and make this guy point there, and this guy point here.


session: S06-32
timestamp: 00:02:56.25
speaker: LOW
utterance:
and we can't say go three times, it's just a specific example, so we're going to use a while loop, okay?


session: S06-32
timestamp: 00:03:57.18
speaker: LOW
utterance:
O_K_, and now we *uh, lets assume there is a method, we'll just call it a new node, give me a new node, and I pass the information g@l and, and it creates this new node, and passes back it's address.


session: S06-32
timestamp: 00:04:23.17
speaker: 232
utterance:
when we're putting a new node, it's very much understands the point at which the new node is placed.


session: S06-32
timestamp: 00:04:29.10
speaker: 232
utterance:
we could just go up here with the pointer and with the first statement, compare with the pointer equal to the pointer of t@l.


session: S06-32
timestamp: 00:04:39.26
speaker: LOW
utterance:
O_K_ this pointer is not going to be equal to the pointer of t@ (be)cause this new node is going to be one we haven't used before.


session: S06-32
timestamp: 00:04:48.24
speaker: 232
utterance:
no, if you're creating a new node with this combined, we will assume that the program knows where the node is.


session: S06-32
timestamp: 00:05:02.25
speaker: LOW
utterance:
so it goes out and finds a memory that's not being used, and puts g@l in the content field, data field, and returns the address.


session: S06-32
timestamp: 00:05:23.04
speaker: LOW
utterance:
well, where is it, it's this address right here you want to change, and that is in the next of t@l, okay?


session: S06-32
timestamp: 00:08:08.07
speaker: LOW
utterance:
it's a three element list, it's going to be a two element list, so if we take the a@l out, well than theres two elements, e@l and m@l, so m@l has to point to +...


session: S06-32
timestamp: 00:08:23.19
speaker: LOW
utterance:
right, so what we really need +// so if we do the same sort of thing that we did up there, and move t@l over here. that isn't going to help us.


session: S06-32
timestamp: 00:09:39.29
speaker: LOW
utterance:
so imagine that this is a big long list and we're not looking for a@l, so s@l would go here, t@l would go forward, s@l is going to +...


session: S06-32
timestamp: 00:10:19.13
speaker: LOW
utterance:
<and which, do you want to do either one of those before you> [//] does it matter which one you do first?


session: S06-32
timestamp: 00:12:20.10
speaker: LOW
utterance:
but I think you see if it's got a hundred elements in it, a@l is anywhere in the middle, it's going to work.


session: S06-32
timestamp: 00:12:56.16
speaker: LOW
utterance:
t@l is equal to h@l two, and then while info of a@l is not equal to e@l, it is equal to e@l so nothing would happen.


session: S06-32
timestamp: 00:14:22.07
speaker: LOW
utterance:
if we're at the beginning of the list then you set h@l two equal to next of itself if you want it, or of t@l.


session: S06-32
timestamp: 00:15:42.03
speaker: LOW
utterance:
and of course you can take a tray off and a guy can come out of the kitchen, nice clean trays, and put them all on the thing one at a time.


session: S06-32
timestamp: 00:15:49.18
speaker: LOW
utterance:
and if you take one off, the spring has less weight on it, and it expands out a little bit, and one more tray comes on top.


session: S06-32
timestamp: 00:15:56.10
speaker: LOW
utterance:
and if you put another tray on, you only have to compress this little bit, but when you come up here, it looks like it's one tray, all right?


session: S06-32
timestamp: 00:17:58.06
speaker: LOW
utterance:
<so if you push q@l> [//] if you push r@l onto this list, on the stack, than it would get a new element, r@l on top, O_K_?


session: S06-32
timestamp: 00:18:35.11
speaker: LOW
utterance:
i call it peak sometimes, if you top this stack it will give you back the q@l, but it doesn't take it off.


session: S06-32
timestamp: 00:18:56.15
speaker: LOW
utterance:
and then finally we have a Boolean function empty # which returns true or false, whether it's empty or not.


session: S06-32
timestamp: 00:20:55.04
speaker: LOW
utterance:
because I was going to ask you, so we pop and push and count and pop and push and count, and pop and push and count.


session: S06-32
timestamp: 00:21:17.05
speaker: LOW
utterance:
so exactly what you said, we'll do one more loop here, and this time we'll pop from t@l, and we'll push back on s@l.


session: S06-32
timestamp: 00:21:26.04
speaker: 232
utterance:
O_K_, if you could actually want to have another stack, named r@l you could just *uh do it as a sequence.


session: S06-32
timestamp: 00:21:39.11
speaker: LOW
utterance:
well, <but you can't start> [/] you can't start that inversion until you until you get this one full.


session: S06-32
timestamp: 00:22:16.08
speaker: LOW
utterance:
O_K_, um so remember that everything happens at the top of the stack, and the only two things that really happen are pop and push.


session: S06-32
timestamp: 00:22:46.12
speaker: LOW
utterance:
but if they were turnary you would have the right one in the center and the left one xxx but they're binary.


session: S06-32
timestamp: 00:23:05.29
speaker: LOW
utterance:
a binary search tree has a special property that in every node, not just the root, but every node, stuff on the left is smaller, and stuff on the right is bigger.


session: S06-32
timestamp: 00:25:08.15
speaker: LOW
utterance:
we didn't really say it, but you keep track of the binary search tree by keeping a pointer to the group, the first node.


session: S06-32
timestamp: 00:25:27.19
speaker: LOW
utterance:
O_K_, um, so this is a binary search tree, because these guys are less than five, and these guys are bigger than five, and less than and bigger than two and now, allright.


session: S06-32
timestamp: 00:25:56.11
speaker: LOW
utterance:
and by the way, this is a pretty doggone efficient search (be)cause you just threw away half of the tree.


session: S06-32
timestamp: 00:27:08.27
speaker: LOW
utterance:
as you might expect, since they are called binary search trees, search is very simple, and it's very efficient.


session: S06-32
timestamp: 00:27:15.03
speaker: LOW
utterance:
lets go back and talk about insertion, and then we'll go back and talk about deletion, and use binary search trees.


session: S06-32
timestamp: 00:27:26.22
speaker: LOW
utterance:
lets insert six in this binary search tree, so that the thing when we get done is still a binary search tree, O_K_?


session: S06-32
timestamp: 00:27:55.13
speaker: LOW
utterance:
so in other words, that's why these problems occur in a strange order, because if you can search, than you can insert.


session: S06-32
timestamp: 00:28:18.07
speaker: LOW
utterance:
they have two problems, but they're really three cases, but they leave, they don't have an example there, because one of them is really really really really simple.


session: S06-32
timestamp: 00:29:12.03
speaker: LOW
utterance:
yeah, five has a couple of grandchildren on this side, but we're talking about nine has one kid, so nine's parent points to nine's kid.


session: S06-32
timestamp: 00:30:35.08
speaker: LOW
utterance:
++ three could come up, because three is bigger than these guys, and three is <bigger> [//] smaller than five, so it's clearly smaller than six.


session: S06-32
timestamp: 00:31:44.20
speaker: LOW
utterance:
how do you find the node that corresponds to three over here, and how do you find the node that corresponds to seven in there?


session: S06-32
timestamp: 00:32:16.02
speaker: LOW
utterance:
and if you want the smallest one over here, of course you go over here, you go to the right once, and left until the end.


session: S06-32
timestamp: 00:32:41.13
speaker: LOW
utterance:
seven could have a kid, for example, I have to go to fractions, but seven and a half would be right here.


session: S06-32
timestamp: 00:32:49.02
speaker: LOW
utterance:
seven and a half is bigger than five, so it's belongs over here, smaller, bigger, in fact we could put seven and a quarter in here, and seven and three quarters.


session: S06-32
timestamp: 00:32:58.17
speaker: LOW
utterance:
could it be that this one has two kids and causes another problem, you know causes another node two case?


session: S06-32
timestamp: 00:33:21.29
speaker: LOW
utterance:
but this guy could have a left kid, but two and a half could go over here and so on and so on, okay?


session: S06-32
timestamp: 00:34:15.04
speaker: LOW
utterance:
they're just trying to point out to you that there are many many many search trees on these seven nodes.


session: S06-32
timestamp: 00:34:56.17
speaker: LOW
utterance:
so that's going to be a very funny tree, so nine is the root, eight is smaller, seven is smaller, so this still is a binary search tree, but it's not a very nice one.


session: S06-32
timestamp: 00:35:26.19
speaker: LOW
utterance:
we'll make seven the root, we'll make nine next, which has to go right, and then eight next which has to go +...


session: S06-32
timestamp: 00:35:51.05
speaker: LOW
utterance:
this is another binary search tree, it's not terribly well balanced, but yeah, just put the nodes down in any order, and +...


session: S06-32
timestamp: 00:36:40.28
speaker: LOW
utterance:
you'll throw away half the tree, but it becomes, instead of it becoming binary search it becomes linear search.


session: S06-32
timestamp: 00:36:54.28
speaker: LOW
utterance:
well, if you're using them, if you're using binary search, you like you're tree to be somewhat balanced.


session: S06-32
timestamp: 00:37:13.05
speaker: LOW
utterance:
to look up  *uh telephone number, in the telephone book, you could imagine the computers splits the book in the looks for a name, looking for a name and if it's before that page +...


session: S06-32
timestamp: 00:38:37.09
speaker: LOW
utterance:
so I've got a four element list, and a three element list, I want to make a new seven element list, O_K_?


session: S06-32
timestamp: 00:38:52.22
speaker: LOW
utterance:
O_K_, so don't think about this solution, just first draw me what the heck it's going to look like at the end.


session: S06-32
timestamp: 00:39:49.20
speaker: LOW
utterance:
O_K_, so that's a slightly +// that's slightly dangerous because suppose the list were empty, then +...


session: S06-32
timestamp: 00:41:20.13
speaker: LOW
utterance:
<so this list should probably be> [///] we don't want this pointer in the middle of this other list.


session: S06-32
timestamp: 00:43:22.13
speaker: LOW
utterance:
and instead of using a temporary, well lets just say well, h@l one is not null, count it and make h@l one equal to next of itself.


session: S06-32
timestamp: 00:44:15.11
speaker: LOW
utterance:
that's right so if you use a temporary we don't have to restore it and then we couldn't even restore it because because we've lost it.


session: S06-33
timestamp: 00:00:18.16
speaker: LOW
utterance:
so lets just start with this first exercise here, describe a sequence of operations to insert a new node, which contains g@l in list one, after the node that contains b@l.


session: S06-33
timestamp: 00:01:24.01
speaker: LOW
utterance:
you go to the second node, you can find where the third one is, you go to the third one, you can find where the fourth one is.


session: S06-33
timestamp: 00:01:45.29
speaker: LOW
utterance:
but it could be, the first node is somewhere in memory which points to somewhere else in memory, which points to somewhere else in memory.


session: S06-33
timestamp: 00:01:55.02
speaker: LOW
utterance:
O_K_, and what we want to do with this exercise one is put a new node which contains g@l, after node b@l.


session: S06-33
timestamp: 00:02:09.16
speaker: LOW
utterance:
we get a new node, and put g@l in it, and it's going to be after the one that contains b@l, so we'll just have to change this link, and make it point here, and make this link point here, that doesn't break this link, okay?


session: S06-33
timestamp: 00:02:28.14
speaker: LOW
utterance:
well, they want us to describe a sequence of operations that does this, but it's important to draw the picture.


session: S06-33
timestamp: 00:02:54.19
speaker: LOW
utterance:
because you can't say here is b@l <so now the only thing you have> [//] the only thing you're given is h@l one.


session: S06-33
timestamp: 00:03:14.17
speaker: LOW
utterance:
and here is the thing, it says you can use the temporary pointer and we'll use maybe more than one in a minute.


session: S06-33
timestamp: 00:03:23.26
speaker: LOW
utterance:
so what I want to do is I want to travel across this list, I want to traverse this list, with p@l until I get to b@l, okay?


session: S06-33
timestamp: 00:03:46.25
speaker: LOW
utterance:
so it's going to be while <and I'm not writing any> [//] I'm not writing Java, or C@l or anything, I'm just writing psuedo-code.


session: S06-33
timestamp: 00:04:00.23
speaker: LOW
utterance:
um, we should by the way, of course, the thing we are storing in these node is probably some giant record.


session: S06-33
timestamp: 00:04:39.21
speaker: LOW
utterance:
so we look at the info to see if it's b@l, if it's not, we just say, O_K_ p@l, assign yourself to the address that's stored right here, the next node.


session: S06-33
timestamp: 00:05:42.13
speaker: LOW
utterance:
alright, so then we'll assume there is a new procedure we can call on then to construct out node our whatever, and then we construct a node with g@l in it.


session: S06-33
timestamp: 00:08:44.22
speaker: LOW
utterance:
O_K_, once again, nothing you're given is h@l two, so lets use a temporary, alright, lets call it p@l.


session: S06-33
timestamp: 00:08:59.11
speaker: LOW
utterance:
and we can +// we're going to do the same sort of thing as before, if you want to delete the node that contains a@l the first thing you got to do is find the node that contains a@l.


session: S06-33
timestamp: 00:10:04.12
speaker: LOW
utterance:
so if this is a big list, they're going to move across this list, p@l, q@l, p@l, q@l, q@l will be right behind p@l.


session: S06-33
timestamp: 00:10:47.07
speaker: LOW
utterance:
well, in the picture, when I advance p@l and q@l, p@l would be here, and q@l would be here, right behind it, alright?


session: S06-33
timestamp: 00:11:28.21
speaker: LOW
utterance:
and lets pretend for a minute we weren't looking for a@l, pretend we were looking for x@l, way down here on this list.


session: S06-33
timestamp: 00:12:20.17
speaker: LOW
utterance:
well, when we use our picture we want to just change this one pointer here, to make this guy point to that guy.


session: S06-33
timestamp: 00:12:52.00
speaker: LOW
utterance:
I use it to indicate the beginning, so p@l points to the first node, there is no node behind the first node.


session: S06-33
timestamp: 00:13:16.12
speaker: LOW
utterance:
<you need some special> [//] think of it as zero, in the numeric sense, you need some special pointer that says nothing, O_K_?


session: S06-33
timestamp: 00:13:27.13
speaker: LOW
utterance:
it's used to mark the end of the list, and I use it here to indicate that there is nothing in front of the first one, okay?


session: S06-33
timestamp: 00:13:33.24
speaker: LOW
utterance:
alright, so what we think we want to do, is we want to just change this pointer right here, next of q@l.


session: S06-33
timestamp: 00:13:47.17
speaker: LOW
utterance:
so the way we leap frog is we say next of q@l, copy in the address, it's right there, in next of p@l, okay?


session: S06-33
timestamp: 00:14:46.26
speaker: LOW
utterance:
if we are looking for c@l, then p@l would equals h@l one would be right here, with while wouldn't execute at all.


session: S06-33
timestamp: 00:15:20.19
speaker: LOW
utterance:
if a@l is the last element in the list, then it would go to a two element list, to a one element list.


session: S06-33
timestamp: 00:16:26.10
speaker: LOW
utterance:
O_K_, delete the a@l is easy to do, but it was a four element list, and now it should be a three element list, so what does, what happens?


session: S06-33
timestamp: 00:16:50.21
speaker: LOW
utterance:
because the header points to the first node, but the first node has disappeared, so the header has to change.


session: S06-33
timestamp: 00:17:48.22
speaker: LOW
utterance:
imagine in a very very fancy restaurant, only it's a very fancy cafeteria, it has a spring down there.


session: S06-33
timestamp: 00:18:52.10
speaker: LOW
utterance:
um and the operations you can perform are pop, so you pop the stack s@l, and that returns a value for it.


session: S06-33
timestamp: 00:19:05.14
speaker: LOW
utterance:
so this is a function, and when you pop this stack, you get the top element, you get the q@l, and the stack, and spring put the stack now has p@l on top of it.


session: S06-33
timestamp: 00:19:16.10
speaker: LOW
utterance:
*uh, you can push, which is a void function, you push s@l, and you push something on the stack and you need a variable so I'll call it v@l again.


session: S06-33
timestamp: 00:20:05.27
speaker: LOW
utterance:
you pop it off, and then the head pushes it off, and then you push it right back on and you've changed it.


session: S06-33
timestamp: 00:20:15.15
speaker: LOW
utterance:
*uh, I guess we also need a, 'Boolean is empty' # which returns true or false, you know here it's false, not here.


session: S06-33
timestamp: 00:21:37.26
speaker: LOW
utterance:
so keeping track of what going on over there, count was zero, pop off the q@l, and the count is one.


session: S06-33
timestamp: 00:22:47.19
speaker: LOW
utterance:
we got to count them well, we take them off, but then we got to keep them somewhere and put them back on.


session: S06-33
timestamp: 00:23:03.21
speaker: LOW
utterance:
so v@l is going to be q@l +// the next time around v@l on is going to be p@l, and the next time around v@l is going to be just a single variable.


session: S06-33
timestamp: 00:27:25.17
speaker: LOW
utterance:
this one is a binary search tree, these guys are less than eleven, these guys are less than seven, bigger than seven, you know, alright.


session: S06-33
timestamp: 00:28:07.02
speaker: LOW
utterance:
and I think the order of these problems is not very good, so I want to start with the easy one, and I'll start here with number five.


session: S06-33
timestamp: 00:28:19.19
speaker: LOW
utterance:
well, it's a binary search tree, so believe it or not, it's pretty efficient to search a binary search tree.


session: S06-33
timestamp: 00:28:33.01
speaker: LOW
utterance:
you just have to start, just like at the link list, you have to start at the first node and tree and start the root, O_K_?


session: S06-33
timestamp: 00:29:06.22
speaker: LOW
utterance:
in fact there is no right tree, you have to imagine this is a big example to throw away half of what left.


session: S06-33
timestamp: 00:30:00.10
speaker: LOW
utterance:
the next thing they want us to do lets go +//, well not the xxx, but the next reasonable thing is to do +// lets insert six into this tree.


session: S06-33
timestamp: 00:31:04.29
speaker: LOW
utterance:
um and then we got so that we have search which is what was really efficient about these things, so then we can insert stuff which is to search then followed by insertion.


session: S06-33
timestamp: 00:33:24.24
speaker: LOW
utterance:
uh and sometimes in trees you talk about parents and kids, and I have already talked about kids and children and parents and ancestors and descendents like the family tree.


session: S06-33
timestamp: 00:35:30.27
speaker: LOW
utterance:
it's a small tree, it's kind of hard to see anyway what's special about it, it's kind of hard to find.


session: S06-33
timestamp: 00:36:40.14
speaker: LOW
utterance:
suppose I had +// I'm trying to delete this node, and there is a giant tree here on the left, and there is a giant tree here on the right.


session: S06-33
timestamp: 00:36:51.06
speaker: LOW
utterance:
can you describe what node over here, to replace this with, or what node I could use over here to replace this with?


session: S06-33
timestamp: 00:37:46.09
speaker: LOW
utterance:
so that's what we do over here, and it's hard to see, you went left once, and then you went right to the end.


session: S06-33
timestamp: 00:38:46.02
speaker: LOW
utterance:
so we could bring either the three up, and everybody is happy if I use a grandparent to grandchild thing.


session: S06-33
timestamp: 00:38:52.07
speaker: LOW
utterance:
because three was bigger than, well, lets go back to this example, this biggest guy up, because everybody over here was smaller than it.


session: S06-33
timestamp: 00:39:08.27
speaker: LOW
utterance:
and this guys cannot have another right kid if it has a left tree we'll just do another grandparent to grandchild type of thing, O_K_?


session: S06-34
timestamp: 00:01:52.25
speaker: LOW
utterance:
once again, you can only +// all you have is the pointer or an address, you know where the first one is.


session: S06-34
timestamp: 00:02:10.21
speaker: LOW
utterance:
describe a sequence of operations to insert a new node which contains g@l into list one, after he node which contains b@l.


session: S06-34
timestamp: 00:02:23.17
speaker: LOW
utterance:
afterwards, they said they wanted to get a new node and put g@l in it, and put it in the list after the one that has b@l in it.


session: S06-34
timestamp: 00:03:09.12
speaker: LOW
utterance:
so the three things to do, you got to find this node, we got to get this new node, and then we got to do this couple of pointers, O_K_?


session: S06-34
timestamp: 00:05:05.07
speaker: LOW
utterance:
I have just a single letter in there, and xxx a name and an address and a zip code and a whole record.


session: S06-34
timestamp: 00:05:59.04
speaker: LOW
utterance:
alright, so now we need you +// well lets just assume there is a call to a constructor here, give me a new node, put g@l in it.


session: S06-34
timestamp: 00:08:15.22
speaker: LOW
utterance:
so it's going to be a list of two elements, so the after picture is, I've got to change this node right, I've got to change this address right here.


session: S06-34
timestamp: 00:08:44.16
speaker: LOW
utterance:
I think you may have sort of indicated kind of a problem, because you said a minute ago, e@l, not a@l.


session: S06-34
timestamp: 00:09:23.29
speaker: LOW
utterance:
saying that then p@l points to the first element, and then q@l points nowhere because before the first element, O_K_?


session: S06-34
timestamp: 00:10:02.02
speaker: LOW
utterance:
so that's what I want to do is move these two together across the list, so the q@l is right behind p@l.


session: S06-34
timestamp: 00:10:34.02
speaker: LOW
utterance:
but when we get out of this loop, the info of p@l is a@l, and q@l is pointing to the one right behind it.


session: S06-34
timestamp: 00:10:42.19
speaker: LOW
utterance:
this is what needs to change in fact I found it with the p@l but I'm going to use q@l to say what the search is.


session: S06-34
timestamp: 00:11:54.13
speaker: LOW
utterance:
and no big deal, I just copy it over, next of q@l here would be this value, so I just copy the null in here.


session: S06-34
timestamp: 00:13:57.03
speaker: LOW
utterance:
uh there is no q@l, I can't do that sort of a thing, but it used to be a four element list, and now it's going to be a three element list, so, the header, which points to a@l has to point to +...


session: S06-34
timestamp: 00:14:19.24
speaker: LOW
utterance:
<so else we say, h@l a right code for this list> [//] and so we say h@l two equals next of p@l, okay?


session: S06-34
timestamp: 00:14:43.06
speaker: LOW
utterance:
lets go to it and look at *uh stacks # which is +// there are no stack problems here, but they look at that and they ask you a stack question.


session: S06-34
timestamp: 00:15:08.12
speaker: LOW
utterance:
so the stack +// lets make up one here that has x@l in it, and d@l and p@l and q@l # how about that?


session: S06-34
timestamp: 00:15:51.26
speaker: LOW
utterance:
*uh, push is usually where there is a void function, so you push onto the stack s@l when you want to push some value.


session: S06-34
timestamp: 00:16:06.04
speaker: LOW
utterance:
<you can't see just like a link list> [//] you can't see that there is four, five or three elements in there.


session: S06-34
timestamp: 00:19:23.05
speaker: LOW
utterance:
well we could use a link list as someone suggested, more easily or we could use more easily a temporary stack t@l.


session: S06-34
timestamp: 00:21:52.00
speaker: LOW
utterance:
a binary search tree has a special property that at every node, not just the root, but every node, things to the left are smaller, and things to the right are bigger.


session: S06-34
timestamp: 00:23:15.02
speaker: LOW
utterance:
(be)cause these are all less, than eleven, these are all less than seven, these are all bigger than seven.


session: S06-34
timestamp: 00:23:44.28
speaker: LOW
utterance:
and O_K_, so the root of the tree is five, and these guys are less than five, and these guys are bigger than five and then everywhere, yeah.


session: S06-34
timestamp: 00:24:42.27
speaker: LOW
utterance:
it isn't very hard, and that's why they are called binary search trees, they have an efficient search on them.


session: S06-34
timestamp: 00:25:16.01
speaker: LOW
utterance:
but you threw away this half of the tree, and the tree went large and you threw away half of what was left each time, there's only half of what left.


session: S06-34
timestamp: 00:25:59.15
speaker: LOW
utterance:
*uh we want to put six in here, so it's still +// they don't say it in the problem but they mean it +// a binary search tree.


session: S06-34
timestamp: 00:26:28.09
speaker: LOW
utterance:
so what you just did you just searched for six, and when it fails, you just put it right there, where it failed.


session: S06-34
timestamp: 00:27:17.13
speaker: LOW
utterance:
*uh, they don't have an example there, but lets suppose six isn't here so suppose you want to delete seven.


session: S06-34
timestamp: 00:27:53.19
speaker: LOW
utterance:
<alright, so do you see a> [///] delete nine from this binary search tree, and leave it a binary search tree.


session: S06-34
timestamp: 00:28:21.13
speaker: LOW
utterance:
yeah, five has a couple grandkids over here on the left side, but, five only has one grandchild on the right side, because nine only has one kid.


session: S06-34
timestamp: 00:28:35.20
speaker: LOW
utterance:
that's what we mean about doing this easy as possible, simple as possible, moving around as little as possible.


session: S06-34
timestamp: 00:29:15.00
speaker: LOW
utterance:
just because this tree is so small and I need to keep it as many nodes as I can and it'll show you what's going on.


session: S06-34
timestamp: 00:29:39.05
speaker: LOW
utterance:
you can't put two up there, because three, and I'm not quite sure what that means, but three can't be on the left subtree at two.


session: S06-34
timestamp: 00:31:07.00
speaker: LOW
utterance:
here you went right, and then you went left, and the six would be the new one to put up there, who was in a tree, and five and a half again.


session: S06-34
timestamp: 00:31:37.01
speaker: LOW
utterance:
or the smallest one here, is fine with the right subtree, it's smaller than all them, but it's bigger than it used to be, because it's on the right tree.


session: S06-34
timestamp: 00:31:48.25
speaker: LOW
utterance:
*uh, could it be, in my simple example that three and seven are leaves +// I'm going to show you it don't have to be.


session: S06-34
timestamp: 00:32:05.11
speaker: LOW
utterance:
and in fact we could put seven and a quarter in here, and seven and thre quarters and all kinds of stuff in here.


session: S06-34
timestamp: 00:32:42.15
speaker: LOW
utterance:
so it could be, if you choose to move three up, it could be you have one of these grandparent to grandchild things to do.


session: S06-34
timestamp: 00:33:43.11
speaker: LOW
utterance:
so I think that means right now I got a one, two, three, four element list, and I got a three element list.


session: S06-34
timestamp: 00:34:39.27
speaker: LOW
utterance:
so I'm going to say while p@l ain't null, and what Im going to do is move both forward and put q@l where p@l is and move p@l forward which is p@l equals next of p@l.


session: S06-34
timestamp: 00:35:24.15
speaker: LOW
utterance:
so all we need to say then is next of q@l, which is right now null, next of q@l should be this address right here.


session: S06-34
timestamp: 00:35:43.25
speaker: LOW
utterance:
and then we're in some sense done but we probably should also say h@l two equals null because we don't want a pointer in the middle of the list.


session: S06-34
timestamp: 00:36:10.02
speaker: LOW
utterance:
so again with a link list it's always draw the picture, first, and then think about what we need to do.


session: S06-34
timestamp: 00:36:19.15
speaker: LOW
utterance:
uh real quickly, lets describe a sequence of operations to list two into list one, after the node that contains k@l.


session: S06-34
timestamp: 00:37:28.03
speaker: LOW
utterance:
so once again, very important that we draw pictures (be)cause really then all we need to do is these two pieces of surgery.


session: S06-34
timestamp: 00:37:41.25
speaker: LOW
utterance:
O_K_, but we don't need two pointers this time, because when I find the k@l, I want to do the surgery to that node, not one before, okay?


session: S06-34
timestamp: 00:38:02.14
speaker: LOW
utterance:
so like I did before, I would race across here with another set of pointers over here, like we did with q@l and r@l.


session: S06-34
timestamp: 00:38:43.09
speaker: LOW
utterance:
alright that was a great +// that was a good one to look at quickly (be)cause it's like the first one we did.


session: S06-35
timestamp: 00:00:44.01
speaker: LOW
utterance:
so the info should be a whole record of stuff, you know first name last name telephone number zip code and it's just single letter to make it's own code.


session: S06-35
timestamp: 00:01:01.28
speaker: LOW
utterance:
so you get the pointer to the first one, which tells you where the second one is, which tells you where the third one is, which tells you where the fourth one is.


session: S06-35
timestamp: 00:01:18.10
speaker: LOW
utterance:
yeah and I got to mark the end of the list, because you can just left garbage in there, there is a fifth one up there, mess up.


session: S06-35
timestamp: 00:01:35.20
speaker: LOW
utterance:
as this doesn't live next to this, which lives next to this, but in fact this may be the middle of memory, and then this might be back early in memory, and then late in memory and, it could be all over the place.


session: S06-35
timestamp: 00:01:51.08
speaker: LOW
utterance:
if it's sequentially stored and you want to get rid of one of these, you want to move everything else up.


session: S06-35
timestamp: 00:01:58.28
speaker: LOW
utterance:
but this first exercise here says describe a sequence of operations to insert a new node which contains g@l in list one after the node which contains b@l, alright?


session: S06-35
timestamp: 00:02:11.21
speaker: LOW
utterance:
so thats the before picture, and here is the after picture, and the new node you put g@l in it, and we link it in and make it be after b@l.


session: S06-35
timestamp: 00:03:37.28
speaker: LOW
utterance:
and the way we do that is we can give p@l a new value and the value we give it is what stored over there.


session: S06-35
timestamp: 00:04:40.03
speaker: LOW
utterance:
alright, so step one is find the b@l, step two is get this new node, we'll assume that's atomic more or less.


session: S06-35
timestamp: 00:06:25.01
speaker: LOW
utterance:
one, we have found a node that contains b@l and we created a new node # and it's got a couple of pointers.


session: S06-35
timestamp: 00:06:58.25
speaker: LOW
utterance:
O_K_, similar to before, this time we want to delete a node, we got to find the a@l, and then delete it.


session: S06-35
timestamp: 00:07:32.23
speaker: LOW
utterance:
alright so this is not the a@l, so I'm going to move forward, and of course this will be the a@l so that while loop will execute many times.


session: S06-35
timestamp: 00:09:21.12
speaker: LOW
utterance:
I believe, even though we have just simple list here with three elements, that we probably believe that this would work, if a@l is anywhere in the middle.


session: S06-35
timestamp: 00:10:03.08
speaker: LOW
utterance:
there's a@l, which points to another element, d@l # which points to another element x@l which points to another element v@l.


session: S06-35
timestamp: 00:11:26.03
speaker: LOW
utterance:
how do you take this thing from a four element list to a three element list when there is nothing in front of a@l, you just change +...


session: S06-35
timestamp: 00:11:46.18
speaker: LOW
utterance:
so if it +// if q@l is not null, and you're in the middle, and you do this, else, you're at the beginning and you change h@l two.


session: S06-35
timestamp: 00:12:06.11
speaker: LOW
utterance:
so always watch for special cases in these things too which is why the pictures help, except you have to think of other pictures other than the one that you drew.


session: S06-35
timestamp: 00:12:41.25
speaker: LOW
utterance:
uh where it gets its name from is, this is what I tell my students, this very expensive cafeteria with a very fancy stack of trays.


session: S06-35
timestamp: 00:12:59.02
speaker: LOW
utterance:
and you can take one tray off, and when you do the spring is so precisely loaded that it pushes the next tray up.


session: S06-35
timestamp: 00:13:58.00
speaker: LOW
utterance:
so if I have this stack and I push a t@l on it, then I can't see the q@l anymore, and the top is t@l.


session: S06-35
timestamp: 00:15:22.29
speaker: LOW
utterance:
well you'll never get anywhere if you keep peaking because it never changes you have an infinite loop.


session: S06-35
timestamp: 00:16:50.27
speaker: LOW
utterance:
so people wouldn't be very happy calling this function the node that used to contain four, but it xxx xxx.


session: S06-35
timestamp: 00:17:00.05
speaker: LOW
utterance:
but we +// yeah, but we really have to because like we said, peaking ain't going to get you nowhere.


session: S06-35
timestamp: 00:17:08.20
speaker: LOW
utterance:
I mean, we popped off the q@l, and then the next time we popped off the d@l, and then the next time we popped off the t@l.


session: S06-35
timestamp: 00:17:42.17
speaker: LOW
utterance:
and we pop off the d@l, and we put it here, and we pop the t@l, count, go to three, put the t@l here.


session: S06-35
timestamp: 00:17:53.07
speaker: LOW
utterance:
we still got the four, which is the correct answer, and now we got the stack of four elements, so can I simply say, x@l equals t@l?


session: S06-35
timestamp: 00:18:09.21
speaker: LOW
utterance:
so that at least gives you back the stack of four elements, but not quite the same stacks so don't do that.


session: S06-35
timestamp: 00:18:19.00
speaker: LOW
utterance:
the same process, so I won't bother writing it out, but while t@l isn't empty pop it off of t@l and push it onto s@l, right?


session: S06-35
timestamp: 00:19:01.27
speaker: LOW
utterance:
it would be pretty awful if they used a stack, because if you got there early in the morning you would wait all day.


session: S06-35
timestamp: 00:21:48.11
speaker: LOW
utterance:
alright, so they give us a binary search tree, and quickly verify it is, these guys were less than five, these guys were bigger than five.


session: S06-35
timestamp: 00:22:02.20
speaker: LOW
utterance:
and now I think these exercises are in a weird order, so I'm going to start with number +// I'm going to start at the easiest and then work with the hardest.


session: S06-35
timestamp: 00:22:26.24
speaker: LOW
utterance:
if you start at the root, just like you have to start at the first node in the link list, you have to start at the root, and since you're looking for eight, you will go +...


session: S06-35
timestamp: 00:22:52.02
speaker: LOW
utterance:
but, if there is a thousand nodes here, and it's well balanced, you looked here in the middle at 500, and you're searching for 800 or something, and you threw these away.


session: S06-35
timestamp: 00:24:43.12
speaker: LOW
utterance:
search failed on the left of seven, so we put a new node on the left of seven, and that's where six goes.


session: S06-35
timestamp: 00:24:53.28
speaker: LOW
utterance:
so you discovered the binary tree search algorithm for searching binary search trees which is very simple.


session: S06-35
timestamp: 00:25:01.18
speaker: LOW
utterance:
and then you discovered the insertion algorithm, which is search, and when the search fails, put it there where the failure occurred.


session: S06-35
timestamp: 00:25:43.16
speaker: LOW
utterance:
the edge of the tree, just pluck that leaf off, so we just change that pointer to a null and it's gone.


session: S06-35
timestamp: 00:27:13.12
speaker: LOW
utterance:
but I don't really need to move seven up if I move five to point at eight, then seven gets moved up to the second generation.


session: S06-35
timestamp: 00:28:29.13
speaker: LOW
utterance:
that's the last one, because we are in a binary tree, so two kids, one kid, or no kids are the only possibilities.


session: S06-35
timestamp: 00:31:47.15
speaker: LOW
utterance:
so you have told me how to find the node, either of the two nodes that is going to replace the node we're trying to delete.


session: S06-35
timestamp: 00:32:22.00
speaker: LOW
utterance:
and in fact, if we put seven and a quarter in, and seven and three quarters in, and you know all kinds of decimals, I could get a giant tree here, under the right side.


session: S06-35
timestamp: 00:33:05.01
speaker: LOW
utterance:
yeah you did very well seeing how to find the, that was the biggest on the smallest on the right and how to find that and replace it.


session: S06-35
timestamp: 00:33:26.18
speaker: LOW
utterance:
so what +// I think what they are trying to emphasize here is that this is just one of many many many trees.


session: S06-35
timestamp: 00:35:35.02
speaker: LOW
utterance:
O_K_, so, almost any random order of the nodes will give you a different binary search tree is what I'm trying to point out.


session: S06-35
timestamp: 00:35:58.22
speaker: LOW
utterance:
yeah yeah, if somebody put them in order for you, either ascending or descending, you would have a binary tree that looked like that, or a binary tree that looked like that.


session: S06-35
timestamp: 00:36:15.23
speaker: LOW
utterance:
so this would be the one, and then two would be bigger than three would be bigger than four would be bigger than, and your only using the right link each time.


session: S06-36
timestamp: 00:00:39.03
speaker: LOW
utterance:
*uh, the information should in fact be a big record of first name, last name, home address, campus address, and cell numbers.


session: S06-36
timestamp: 00:01:19.27
speaker: LOW
utterance:
and when you get to the second node, you find out that the contents is k@l, and you find out that the third node is here.


session: S06-36
timestamp: 00:01:46.03
speaker: LOW
utterance:
you can see it's a four element list, but you can't do that without going here, going here, going here.


session: S06-36
timestamp: 00:01:52.03
speaker: LOW
utterance:
and to keep the picture sort of reasonable I've drawn them each to the right of the other, but really in reality, this is some address in the middle of the RAM, pointing to some address at the beginning of RAM.


session: S06-36
timestamp: 00:02:15.04
speaker: LOW
utterance:
and what's nice about link list is it's pretty easy to insert and delete, which is what we're going to do right now.


session: S06-36
timestamp: 00:02:22.03
speaker: LOW
utterance:
so they want us to describe a sequence of operations to insert a new node which contains g@l, after the node which contains b@l.


session: S06-36
timestamp: 00:02:24.11
speaker: LOW
utterance:
if you had these things in an array, or something where they are sequential, in order to insert a new one you would have to move a bunch of them out of the way.


session: S06-36
timestamp: 00:02:57.17
speaker: LOW
utterance:
so it's important with link lists, and trees, and stacks, and all these things, that you draw pictures.


session: S06-36
timestamp: 00:03:23.08
speaker: LOW
utterance:
so the first thing we have to do is find this node that contains b@l, get a new node, and then set these links.


session: S06-36
timestamp: 00:03:59.02
speaker: LOW
utterance:
it's just an address, so it doesn't matter where it points at the top or the side or the bottom or whatever.


session: S06-36
timestamp: 00:04:05.04
speaker: LOW
utterance:
alright, and then we can't go, we can't say go next twice, because we can't assume b@l is the third element.


session: S06-36
timestamp: 00:04:23.07
speaker: LOW
utterance:
and then you can look at the info that another node p@l points to, or you can look at the next field that p@l points to.


session: S06-36
timestamp: 00:05:16.01
speaker: LOW
utterance:
next thing we do is we get a new node, so we'll assume there is this constructor who will give us a new node.


session: S06-36
timestamp: 00:05:45.02
speaker: LOW
utterance:
we found the b@l, we created the new node, all you have to do is put these two links in, and put it in the list.


session: S06-36
timestamp: 00:07:39.08
speaker: LOW
utterance:
alright so we're going to attempt the same kind of thing as we did before, but it's got a new wrinkle in it.


session: S06-36
timestamp: 00:07:45.18
speaker: LOW
utterance:
so to start off p@l equals h@l two # leave a little room, while the info of node p@l is not a@l, we'll move p@l forward.


session: S06-36
timestamp: 00:08:27.06
speaker: LOW
utterance:
but that's a bit of a problem, because p@l points at this node, and the surgery recurs to the node before it.


session: S06-36
timestamp: 00:10:58.18
speaker: LOW
utterance:
so it works for this three element list, and it also works for a 3,000 element list with a@l somewhere in the middle.


session: S06-36
timestamp: 00:13:40.20
speaker: LOW
utterance:
if q@l has moved, and you found the a@l somewhere in the middle, and you'd say, then next of q@l is next of p@l.


session: S06-36
timestamp: 00:13:53.20
speaker: LOW
utterance:
common to use two pointers to traverse a list because when you find something, you need the one before.


session: S06-36
timestamp: 00:14:30.17
speaker: LOW
utterance:
um I explain to students it comes about in a very very fancy, very expensive cafeteria where you have a stack of trays.


session: S06-36
timestamp: 00:14:40.10
speaker: LOW
utterance:
and the only thing you +// the spring is so carefully balanced and loaded that the only thing you can see is one tray on top.


session: S06-36
timestamp: 00:14:53.24
speaker: LOW
utterance:
you can't tell that there is four elements in there, and what you can do is you can take that top thing off, it's called pop.


session: S06-36
timestamp: 00:15:07.07
speaker: LOW
utterance:
so they went +// if you could push a new one on in the spring, the spring will spring back down, you would still only see one of them.


session: S06-36
timestamp: 00:15:26.11
speaker: LOW
utterance:
so we pop the stack s@l, and that's a function that returns the value +//excuse me +// that you popped off.


session: S06-36
timestamp: 00:16:04.23
speaker: LOW
utterance:
push is the insertion, and push needs to know what stack you're pushing on, and what you're pushing.


session: S06-36
timestamp: 00:16:38.17
speaker: LOW
utterance:
if you peak, peak, peak, you obviously never +// it never changes the stack so you keep peaking you keep the q@l.


session: S06-36
timestamp: 00:16:44.04
speaker: LOW
utterance:
*uh, the reason it's not terribly fundamental is peak is really +// if you wanted to write it yourself, you could pop it to push.


session: S06-36
timestamp: 00:17:47.03
speaker: LOW
utterance:
so it can be while s@l +// while +// how about not s@l is +// while not is empty while not is empty s@l +// lets try that again.


session: S06-36
timestamp: 00:18:12.23
speaker: LOW
utterance:
*uh, lets pop something off, so put v@l equals pop s@l and of course we're going to increment the counter.


session: S06-36
timestamp: 00:19:04.25
speaker: LOW
utterance:
so people probably aren't very happy to call this a function, which is how many elements were on the stack before you called it, alright.


session: S06-36
timestamp: 00:19:15.01
speaker: LOW
utterance:
we have to do basically this, because push isn't going to help you count the stack, and peak isn't going to help you because it doesn't ever empty a stack.


session: S06-36
timestamp: 00:20:44.23
speaker: LOW
utterance:
so how can we got t@l, which is in reverse order, restored exactly so it is in fact the same thing it was before.


session: S06-36
timestamp: 00:21:56.01
speaker: LOW
utterance:
and we call this the left child the seven, and lets look at this one # we'll start with the first one.


session: S06-36
timestamp: 00:22:40.01
speaker: LOW
utterance:
a binary search tree has a special property that everywhere the things on the left are smaller, the things on the right are larger.


session: S06-36
timestamp: 00:23:55.29
speaker: LOW
utterance:
yeah so you saw that the five and the 11 were on the wrong side, but the seven and the four were on the wrong side of five and these are the wrong side of eleven.


session: S06-36
timestamp: 00:25:11.04
speaker: LOW
utterance:
it's a very small tree here, but if there are thousands of node in here, you've thrown away half of the nodes that they have found.


session: S06-36
timestamp: 00:25:26.08
speaker: LOW
utterance:
but you didn't mess around over here at all, and you didn't mess around over here, where there is no tree.


session: S06-36
timestamp: 00:26:07.04
speaker: LOW
utterance:
now you look on the right side, and now you look on the right side and there is nothing there, O_K_?


session: S06-36
timestamp: 00:26:22.09
speaker: LOW
utterance:
if four is on this tree, it can't be on the left of two, and you threw away half the nodes that were left # there are now only a fourth of the original nodes.


session: S06-36
timestamp: 00:28:46.15
speaker: LOW
utterance:
so can you find a way to delete the nine and still make it, don't change things a lot, but keep it a binary search tree?


session: S06-36
timestamp: 00:29:31.23
speaker: LOW
utterance:
grandparent has a couple grandchildren on the left, and on the right we're talking about, and on the right, there is only one grandchild, so we just call it grandparent to grandchild.


session: S06-36
timestamp: 00:29:47.10
speaker: LOW
utterance:
and it's still a binary search which you still didn't do anything to this side of the tree, so that's still alright.


session: S06-36
timestamp: 00:30:11.25
speaker: LOW
utterance:
*uh alright, lets go back to the original tree, because the tree is so small, you have to have as many nodes in here as possible.


session: S06-36
timestamp: 00:31:38.25
speaker: LOW
utterance:
moving nine up is a bad idea, because even only nine has one kid, because these guys can't be, they can't stay in the right subtree of nine, because these guys are smaller.


session: S06-36
timestamp: 00:31:48.25
speaker: LOW
utterance:
but there is in fact such a small tree, there is always a node here on the left they can move up, and there is always a node here on the right they can move up.


session: S06-36
timestamp: 00:33:25.23
speaker: 236
utterance:
it's always like um +// it's always going to be like the youngest +// um youngest generation as possible.


session: S06-36
timestamp: 00:33:38.16
speaker: 236
utterance:
+< the one and three *uh but then the difference between one and three is that um, it's got to satisfy the root.


session: S06-36
timestamp: 00:35:17.01
speaker: LOW
utterance:
so we went right and left, left and six is in here, and we come down to six and five and a half is in here, and five in here.


session: S06-36
timestamp: 00:35:23.11
speaker: LOW
utterance:
and if four is in here, and we go left once and then right, and then right to four point five and right to four point five.


session: S06-36
timestamp: 00:35:48.17
speaker: LOW
utterance:
because it's bigger than five, it's less than nine, it's less than eight, and it's bigger than seven.


session: S06-36
timestamp: 00:35:54.14
speaker: LOW
utterance:
and then seven and a quarter, seven and three quarters and there could be a giant underneath the right side of seven.


session: S06-36
timestamp: 00:36:01.18
speaker: LOW
utterance:
but this can't be a +// this can't be a node with two kids, because you said go left as far as you can.


session: S06-36
timestamp: 00:36:19.24
speaker: LOW
utterance:
this could also have a left tree, like two point five, less than five, bigger than two less than three.


session: S06-37
timestamp: 00:00:43.10
speaker: LOW
utterance:
and the info should in fact in the real world be a giant record of first name, last name, phone number, and zip code, all that stuff.


session: S06-37
timestamp: 00:01:04.00
speaker: LOW
utterance:
in order to go directly to that second node, you have to go here, and find out the first guy is a c@l and there is the second one.


session: S06-37
timestamp: 00:01:15.14
speaker: LOW
utterance:
now in order to get to the second one, it's a k@l and there is the third one, and that's a b@l and there is the fourth one.


session: S06-37
timestamp: 00:01:26.11
speaker: LOW
utterance:
it's a link list, and there is the first element, and that tells you where the second is and so on and so on and so on.


session: S06-37
timestamp: 00:01:42.09
speaker: LOW
utterance:
all right, so what they want us to do is describe a sequence of operations to insert a new node, which contains g@l in this list, after the node that contains b@l.


session: S06-37
timestamp: 00:01:52.23
speaker: LOW
utterance:
*uh, this also say that I have drawn these, and they look like they're left or right in memory, but that's just for my convenience and my picture.


session: S06-37
timestamp: 00:02:02.15
speaker: LOW
utterance:
the first node might be in the middle of memory, and then the second node is in the beginning of memory, and the third node is in the end of memory, and then the forth node is back in the middle of memory.


session: S06-37
timestamp: 00:02:20.05
speaker: LOW
utterance:
if these were stored one after the other to put one in the middle, and then move a bunch of guys out of the way to make room for it.


session: S06-37
timestamp: 00:02:58.21
speaker: LOW
utterance:
<all right, now we have to, we're not done> [//] we have to write the pseudo-code to tell the computer how to do this.


session: S06-37
timestamp: 00:03:09.07
speaker: LOW
utterance:
since we have only the header in each one, we've got to find node b@l, we got to get this new node which we'll assume is sort of xxx.


session: S06-37
timestamp: 00:03:40.19
speaker: LOW
utterance:
so that +// the only thing I could do to get started, is I set p@l equal to h@l one (be)cause h@l one is the only thing I have to the address of this first node.


session: S06-37
timestamp: 00:04:11.01
speaker: LOW
utterance:
there is also the next field and sometimes students get confused between these, realize that the info here is a character, the info is some record of information.


session: S06-37
timestamp: 00:05:07.13
speaker: LOW
utterance:
it can pass for a new node, and we pass it in the g@l, and we put in there, and it passes us back the address, of this new node that's called n@l for no [?].


session: S06-37
timestamp: 00:05:47.08
speaker: LOW
utterance:
but *uh oh, now if I want to set number two, that's next of this node n@l, and what's the address of this node?


session: S06-37
timestamp: 00:07:05.10
speaker: LOW
utterance:
there is the before picture, and the after picture is well, of course it was a three element list, it now is a two element list.


session: S06-37
timestamp: 00:07:44.26
speaker: LOW
utterance:
and so that puts +// it initializes p@l right here, and so it moves p@l across the list until we find the a@l.


session: S06-37
timestamp: 00:09:19.16
speaker: LOW
utterance:
we just say next of q@l is equal to, and what the address of the node that's stored right there, next of p@l.


session: S06-37
timestamp: 00:09:39.12
speaker: LOW
utterance:
and that's what the pictures help us do that too, but we have to be more general about our pictures.


session: S06-37
timestamp: 00:09:44.02
speaker: LOW
utterance:
so hopefully I think I convinced you that if a@l is anywhere in the middle of the list, this will work.


session: S06-37
timestamp: 00:09:51.10
speaker: LOW
utterance:
and we got a three element list with a@l in the middle but if we have a three thousand element list with a@l anywhere in the middle what we're doing is we're linking the one before a@l to the one after a@l, O_K_?


session: S06-37
timestamp: 00:10:57.14
speaker: LOW
utterance:
all right this is a four element list, and we're getting rid of a@l, so it's going to be a three element list.


session: S06-37
timestamp: 00:11:36.15
speaker: LOW
utterance:
we found it right away, and unfortunatly we can't do this, because there is no next of q@l, because q@l is null.


session: S06-37
timestamp: 00:12:58.11
speaker: LOW
utterance:
I've explained to students that it comes from this very fancy and very expensive cafeteria # where they have a stack of trays.


session: S06-37
timestamp: 00:13:07.05
speaker: LOW
utterance:
and they have this very expensive, very precise spring in here and it only shows you one tray on top.


session: S06-37
timestamp: 00:13:24.04
speaker: LOW
utterance:
and the guy comes out of the kitchen with the clean trays and he pushes them one at a time on to here.


session: S06-37
timestamp: 00:13:44.01
speaker: LOW
utterance:
alright, the point is, once again, you can't tell it's a stack of four, you can only see the top one.


session: S06-37
timestamp: 00:14:40.24
speaker: LOW
utterance:
and push is a void function, it takes the stack you want to push on and the value you want to stack # and want to push.


session: S06-37
timestamp: 00:14:48.13
speaker: LOW
utterance:
so if I pushed an r@l on the stack, push s@l r@l, I'd put r@l up here and, you know, build the stack up.


session: S06-37
timestamp: 00:14:47.08
speaker: LOW
utterance:
sometimes people use a peak operation # and that's essentially the pop but it's not destructive so if you peak this it gives you back t@l.


session: S06-37
timestamp: 00:15:36.24
speaker: LOW
utterance:
besides this we should also have an, 'is empty' function which is a Boolean function returning true or false.


session: S06-37
timestamp: 00:16:38.18
speaker: LOW
utterance:
and we're going to increment the counter, plus plus, some languages use that to add one to the counter.


session: S06-37
timestamp: 00:17:21.11
speaker: LOW
utterance:
and peaking it will always get t@l, t@l, t@l, t@l and an infinite loop so we popped it so now we saw that t@l was on top and we got rid of it.


session: S06-37
timestamp: 00:17:58.16
speaker: LOW
utterance:
people won't be too happy with this function that counts their stack and tells them how many it used to have.


session: S06-37
timestamp: 00:19:48.09
speaker: LOW
utterance:
so we'll put the a@l back, we'll put the p@l back, we'll put the q@l back, and we'll put the t@l back.


session: S06-37
timestamp: 00:21:00.18
speaker: LOW
utterance:
everywhere, I'm pointing at the root, but I said everywhere +// the nodes on the left are smaller and nodes on the right are bigger.


session: S06-37
timestamp: 00:22:46.15
speaker: LOW
utterance:
so this is a binary search tree and you are going to invent the search algorithm for this binary search tree.


session: S06-37
timestamp: 00:23:00.26
speaker: LOW
utterance:
and it's such a small tree but I want to point out to you that if this is a tree with thousands of nodes and it's balanced pretty well, you throw away half the tree.


session: S06-37
timestamp: 00:23:44.24
speaker: LOW
utterance:
but it was an efficient search for four and we didn't look over here, there's no use looking over here.


session: S06-37
timestamp: 00:23:51.17
speaker: LOW
utterance:
so you looked at this node and you looked at one node at this level and one node at this level and then it failed.


session: S06-37
timestamp: 00:23:57.12
speaker: LOW
utterance:
okay, so you've discovered what's called binary tree search and you've also discovered the search algorithm.


session: S06-37
timestamp: 00:24:51.06
speaker: LOW
utterance:
so that's why it's important that you understand search first because insertion is search and when it fails you put it right there where it failed.


session: S06-37
timestamp: 00:25:43.13
speaker: LOW
utterance:
alright, so suppose +// this is so simple +// suppose you want to delete seven, you just change this parent to a null pointer.


session: S06-37
timestamp: 00:26:15.24
speaker: LOW
utterance:
so do you see a way to delete nine and they don't say it but they mean it, and keep it a binary search tree and do as little work as possible.


session: S06-37
timestamp: 00:26:42.01
speaker: LOW
utterance:
this pointer or whatever so you need to indeed we're going to sort of break that pointer but we also need to +...


session: S06-37
timestamp: 00:27:12.25
speaker: LOW
utterance:
since nine only has one kid, five only has one grandchild so we just jump a generation and go from grandparent to grandchild, okay?


session: S06-37
timestamp: 00:27:33.01
speaker: LOW
utterance:
uh, I'm going to +// lets assume nine is back in the tree because I need as many nodes as possible to talk about the next one.


session: S06-37
timestamp: 00:27:56.05
speaker: LOW
utterance:
yeah # because a node can only have # zero kids, one kid, or two kids in a binary search tree +// binary tree so this is it.


session: S06-37
timestamp: 00:28:32.20
speaker: LOW
utterance:
well, moving the two up is going to be hard because its got two kids itself so I've got to move one of them up and they might have two kids but anyway.


session: S06-37
timestamp: 00:28:40.00
speaker: LOW
utterance:
ignoring that fact, no, you can't move two up because two can't be the root of this tree with the tree in it.


session: S06-37
timestamp: 00:28:52.18
speaker: LOW
utterance:
but, it turns out there's always one node here on the left and there's always one node here on the right that you can move up.


session: S06-37
timestamp: 00:30:11.10
speaker: LOW
utterance:
I've got a binary search tree and I'm trying to replace this node and I've got a giant left subtree and I've got a giant right subtree.


session: S06-37
timestamp: 00:31:06.18
speaker: LOW
utterance:
oops, you go right once +// xxx you go right once and then you go left as many times as you can # which is what we did.


session: S06-37
timestamp: 00:31:34.16
speaker: LOW
utterance:
they don't have to be leaves, for example, if seven and a half is in this tree it would be right here.


session: S06-37
timestamp: 00:31:46.08
speaker: LOW
utterance:
and if seven and a quarter is in this tree it would be here and seven and three quarters and all kinds of decimals I could make a giant tree here and a giant tree here.


session: S06-37
timestamp: 00:31:58.23
speaker: LOW
utterance:
over here, you said go right as many times as possible so there can't be a right tree but two and a half would go here and two and a fourth and two and three fourths.


session: S06-37
timestamp: 00:33:13.00
speaker: LOW
utterance:
uh, I think they're just trying to show you there are many, many, many binary search trees on these seven nodes.


session: S06-37
timestamp: 00:34:26.08
speaker: LOW
utterance:
uh, if somebody were really helpful and did what to the list of numbers before you build the tree, it would be pretty awful.


session: S06-37
timestamp: 00:34:48.04
speaker: LOW
utterance:
right, if they're in order then you start with one and one is over here and then you add two and then you add three and then you add, you know, whatever.


session: S06-37
timestamp: 00:34:57.27
speaker: LOW
utterance:
so they're using only the right pointers which is essentially a linked list, all the left pointers are null.


session: S06-37
timestamp: 00:35:08.16
speaker: LOW
utterance:
and here binary search isn't going to work very well because if you're looking for seven or whatever you've always got to go +// it's linear search.


session: S06-37
timestamp: 00:35:17.10
speaker: LOW
utterance:
yeah so if your tree is terribly unbalanced, if your tree is a stick then it's become a linear sort of thing.


session: S06-37
timestamp: 00:35:23.10
speaker: LOW
utterance:
but if your tree is balanced well then this really is efficient because you're are throwing away half the tree every time you do it.


session: S06-37
timestamp: 00:35:30.27
speaker: LOW
utterance:
okay, um, they want to keep the time about the same for each student and I'm trying to remember +...


session: S06-37
timestamp: 00:35:52.02
speaker: LOW
utterance:
alright, so this is an easy one:  describe the sequence of operations to add list two to the end of list one.


session: S06-37
timestamp: 00:36:00.26
speaker: LOW
utterance:
yeah this is the pointers so h@l one is this list of four elements and h@l two is this list of three elements.


session: S06-37
timestamp: 00:36:42.12
speaker: LOW
utterance:
alright, so we have to find this node to be able to do this surgery so it's always find the node you want and then do the linking that you need to do.


session: S06-37
timestamp: 00:36:56.00
speaker: LOW
utterance:
so we'll use +// you got to start here at the beginning so we'll do p@l equals h@l one and how do you find the end of the list?


session: S06-37
timestamp: 00:37:09.01
speaker: LOW
utterance:
so we do while p@l is not null it just sort of falls off the end of the earth when it gets to the end.


session: S06-37
timestamp: 00:37:22.05
speaker: LOW
utterance:
alright so p@l would be here then p@l would go here and then p@l would go here and p@l would go here and then p@l would go null.


session: S06-37
timestamp: 00:38:12.15
speaker: LOW
utterance:
so when we get out of the while all you need to do is to set this thing right here which is a next of q@l, p@l is null so we can't use that.


session: S06-37
timestamp: 00:38:31.06
speaker: LOW
utterance:
okay we probably should also say h@l two equals null (be)cause there used to be two lists but now there's only one and we don't want a pointer into the middle of the list.


session: S06-37
timestamp: 00:38:42.01
speaker: LOW
utterance:
but I think this is probably sort of optional if they're asking or talking about if but it's a good idea not to have a pointer into the middle of the list.


session: S06-38
timestamp: 00:00:20.09
speaker: LOW
utterance:
describe the first sequence of operations to insert a new node, with g@l in it, after the node that contains b@l.


session: S06-38
timestamp: 00:01:21.28
speaker: LOW
utterance:
it should be a first name, last name, zip code, home address, campus address, telephone number, social security number, blah blah blah, O_K_?


session: S06-38
timestamp: 00:01:36.29
speaker: LOW
utterance:
and then there is a small, maybe 32 bits, address field, that contains the address of the next node.


session: S06-38
timestamp: 00:02:21.27
speaker: LOW
utterance:
and I have it drawn like they are kind of sequential in memory, but that's just for simplicity on my paper.


session: S06-38
timestamp: 00:02:27.18
speaker: LOW
utterance:
the first node may be in the middle of the memory, and it points to a node early in memory for the second one.


session: S06-38
timestamp: 00:02:33.10
speaker: LOW
utterance:
and then the third node is at the far end of the memory, and the fourth node is back in the middle of memory.


session: S06-38
timestamp: 00:02:41.15
speaker: LOW
utterance:
if they are stored sequencialy, and you wanted to put another one in the middle, you would have to move things out of the way.


session: S06-38
timestamp: 00:03:13.28
speaker: LOW
utterance:
O_K_, lets +// that's the picture, but now they want us to describe a sequence of operations to do this.


session: S06-38
timestamp: 00:04:57.01
speaker: LOW
utterance:
start at the front of the list, while you haven't found the p@l, and go to the next one, go to the next one, go to the next one.


session: S06-38
timestamp: 00:05:07.23
speaker: LOW
utterance:
alright, and now we get a new node, so we'll assume there is a constructor we can call, that will create a node with g@l in it.


session: S06-38
timestamp: 00:06:53.20
speaker: LOW
utterance:
if I change this one first then nobody knows where f@l is so I have to set that one first, and then do this one.


session: S06-38
timestamp: 00:07:01.27
speaker: LOW
utterance:
those half dozen lines are what they were looking for, if what they are looking for if they ask that question.


session: S06-38
timestamp: 00:07:37.03
speaker: LOW
utterance:
they want us to delete the node that contains a@l, so, e@l has to be one, the node that contains e@l has to point to this last node.


session: S06-38
timestamp: 00:07:55.05
speaker: LOW
utterance:
p@l equals h@l two, leave some space, and while the info of p@l is not equal to a@l, look for the a@l.


session: S06-38
timestamp: 00:09:12.29
speaker: LOW
utterance:
so p@l is initialized to the first node, there is no node behind the first node, so I set q@l equal to null to signify that.


session: S06-38
timestamp: 00:13:29.17
speaker: LOW
utterance:
well first of all, always draw pictures, but be careful of the pictures, and watch out for special cases.


session: S06-38
timestamp: 00:13:34.04
speaker: LOW
utterance:
so one thing, it shows you to watch out for special cases, it also shows you that very often you need two pointers to traverse the list well.


session: S06-38
timestamp: 00:14:23.03
speaker: LOW
utterance:
yeah so this is a very very very expensive, very fancy cafeteria, where the spring is very neatly loaded.


session: S06-38
timestamp: 00:14:37.07
speaker: LOW
utterance:
and when the guy comes out of the kitchen and puts new tray on, he pushes them on, and the spring pushes down.


session: S06-38
timestamp: 00:15:02.09
speaker: LOW
utterance:
you can't tell +// kind of like the link list you can't tell theres four elements, you can only see the top.


session: S06-38
timestamp: 00:15:32.26
speaker: LOW
utterance:
there is sometimes, people talk about a peak, which is also returning the value, but it doesn't +// it's not destructive.


session: S06-38
timestamp: 00:15:58.11
speaker: LOW
utterance:
we have a method empty, which is a Boolean, it returns true or false, right now it's false, it's not empty.


session: S06-38
timestamp: 00:17:41.28
speaker: LOW
utterance:
and we could tell them it used to have four elements, and a good stack had four elements, but now it's got zero.


session: S06-38
timestamp: 00:17:57.04
speaker: LOW
utterance:
so we popped off the q@l, and we popped off the d@l, and we popped off the t@l, so we got to save these things.


session: S06-38
timestamp: 00:19:52.16
speaker: LOW
utterance:
and then we did the opposite, popping and pushing to get it back +// restored, and either one of them we counted it.


session: S06-38
timestamp: 00:21:02.25
speaker: LOW
utterance:
but everywhere, these guys are less than eleven, the left tree is less than eleven, and the right tree is bigger than eleven.


session: S06-38
timestamp: 00:21:13.16
speaker: LOW
utterance:
O_K_, so this is a binary search tree, everywhere it has this property, left is less, and right is bigger.


session: S06-38
timestamp: 00:21:43.00
speaker: LOW
utterance:
but these are all less then eleven, and these are all less than seven, and bigger than seven, and you know, right?


session: S06-38
timestamp: 00:22:02.03
speaker: LOW
utterance:
because this ought to be the right tree, this ought to be the left tree, and this ought to be everywhere.


session: S06-38
timestamp: 00:22:42.23
speaker: LOW
utterance:
and then it give us about a half a dozen problems to do here, and let me do them easiest to hardest.


session: S06-38
timestamp: 00:22:50.03
speaker: LOW
utterance:
this is called a binary search tree, so it wouldn't surprise you to learn that it is very easy to search this tree.


session: S06-38
timestamp: 00:23:26.01
speaker: LOW
utterance:
we only looked at the root, and then one of these nodes at this level, and one of the nodes at this level and you found the eight.


session: S06-38
timestamp: 00:23:45.24
speaker: LOW
utterance:
<go to the right throwing away> [//] you threw away half of the tree, you threw away another half of what was left.


session: S06-38
timestamp: 00:25:12.10
speaker: LOW
utterance:
it failed here at node seven, we are looking at the left of seven, so we put it in the left of seven.


session: S06-38
timestamp: 00:26:37.18
speaker: LOW
utterance:
O_K_, so in terms of moving the pointers, you got to move eight up to where nine was, and five to a point at eight, right?


session: S06-38
timestamp: 00:26:46.17
speaker: LOW
utterance:
so I'm just going to change this pointer right here instead of making it point here, I'm just going to make it point here, O_K_?


session: S06-38
timestamp: 00:27:32.25
speaker: LOW
utterance:
I mean imagine eight has a right subtree, and seven has a left, you know, all kinds of stuff down here.


session: S06-38
timestamp: 00:28:35.17
speaker: LOW
utterance:
(be)cause students usually, what everybody wants to do is two to nine, we'll try to move one of these kids up.


session: S06-38
timestamp: 00:28:44.15
speaker: LOW
utterance:
I'm not quite sure what it means to move it up anyway, but if i put two here, it won't work, because three is bigger than two, and two can't be the root of this left tree, with three in it.


session: S06-38
timestamp: 00:28:54.27
speaker: LOW
utterance:
if you move nine up, these guys are smaller than nine, they can't be in this right tree, and it doesn't work.


session: S06-38
timestamp: 00:29:36.20
speaker: LOW
utterance:
I got this node with two kids, and there is a monstrous left tree, and there is a monstrous right tree.


session: S06-38
timestamp: 00:31:34.20
speaker: LOW
utterance:
and seven and a quarter, and seven and three quarters, and we could make giant trees, decimals, underneath seven on the right side.


session: S06-38
timestamp: 00:31:47.07
speaker: LOW
utterance:
likewise two and a half would go here, and two and a fourth and two and three quarters, and all kinds of junk.


session: S06-38
timestamp: 00:32:28.08
speaker: LOW
utterance:
you know, they should have put three and a half in and seven and a half in, and then you would have had which ever one you would have chose you would have had to go grandparent to grandchild to be able to do it.


session: S06-38
timestamp: 00:33:06.13
speaker: LOW
utterance:
so to prove that, just give me these numbers one, two, three, five, seven, eight, nine in any order at all, pick your favorite number first.


session: S06-38
timestamp: 00:35:11.17
speaker: LOW
utterance:
so just for example, by choosing a different number, you can certainly get a different tree, because that first number would be your root.


session: S06-38
timestamp: 00:35:23.06
speaker: LOW
utterance:
*uh, suppose somebody was very very helpful, and sorted the numbers for you, what kind of tree would you have?


session: S06-38
timestamp: 00:36:00.01
speaker: LOW
utterance:
it's a terrible tree, but it's essentially a one dimensional thing, which is equivalent to a link list.


session: S06-38
timestamp: 00:36:09.18
speaker: LOW
utterance:
the reason this is not good, is when you start searching, you're always going to throw away the left tree with nothing in it.


session: S06-39
timestamp: 00:00:55.04
speaker: LOW
utterance:
and the info should be very large, it could be a name and an address and a zipcode and a telephone and a zip code and social security number and a mother's maiden name and all kinds of, you know, stuff.


session: S06-39
timestamp: 00:01:05.04
speaker: LOW
utterance:
but since we don't want to write that all down over and over and over, all of our fields are a single character.


session: S06-39
timestamp: 00:01:14.28
speaker: LOW
utterance:
<and # that's +// I'm trying to sort of describe> that's a big field, in my case it's just a single character.


session: S06-39
timestamp: 00:01:21.09
speaker: LOW
utterance:
but in a real example it's a big piece of information, about a person, or about a product, or about something.


session: S06-39
timestamp: 00:01:51.22
speaker: LOW
utterance:
that has a k@l in it, and gives you a link to the third node, which has a b@l in it, and gives you a link to the fourth node, which has a special null pointer in it, that says on the end.


session: S06-39
timestamp: 00:02:01.21
speaker: LOW
utterance:
because if we left garbage there, we think there is a fifth node somewhere, and there might be a sixth node there somewhere or whatever.


session: S06-39
timestamp: 00:02:22.29
speaker: LOW
utterance:
all you can tell is that there is the first element, and then you can find the second, and you can find the third.


session: S06-39
timestamp: 00:03:02.03
speaker: LOW
utterance:
if these are sequential, and you want to put something in the middle, then you got to move these all down out of the way.


session: S06-39
timestamp: 00:03:16.18
speaker: LOW
utterance:
they want us to describe a sequence of operations to put a new node which contains g@l in this list after the node that contains b@l.


