Kunc effectively elevates programming from mere syntax to a rigorous mental discipline of dismantling complexity. It is a vital bridge between academic theory and the pragmatic problem-solving required in high-stakes industry environments.
深掘り
前提条件
- データがありません。
次のステップ
- データがありません。
深掘り
COMP1511 Week 10 Lecture 1追加:
talk loudly and hope that everyone could hear. Um, >> okay, cool. So, um, yeah, so I spent a long time in 1511. I then left 1511, did an internship at Optivva, came back to Optiva as a grad, uh, and I've now been working at Optivva for three and a half years, I think. Um, and Optiviver and COP 1511 are closely involved with each other. I think there's like a sponsorship or something, but basically what I got told is, hey, you get a chance to come back to 1511. Would wouldn't that be great? And I said, absolutely. So, I want to do two things during the hour that we've got together.
The first one is talk a little bit about sort of career, about life outside of university, working for a company, and some of the lessons that you've learned in 1511 that you can take to apply to your real world work. Uh and then the other thing is that I know you've got an exam coming up. Uh I have written many of such exams. Uh so I wanted to show a couple questions that I think have a nice relationship between the work we do in industry and the work you've learned to do here. Sound good? Cool. Um very briefly for those of you who don't know what Optiva is, um Optiva is a company that is in the sort of financial markets. What we do is we sit around waiting for somebody to come along saying I want to buy something or I want to sell something and then we are always willing to provide a price. Um, so what that means is that we trade all over the world on many different stock exchanges.
And doing that really requires a lot of technology. It requires technology because it's got to be fast. It requires technology because it's got to be accurate. Because if you've got hundreds of thousands of different things that you're trading, you cannot scale that by just hiring more people. So we have a very very large technology department.
Technology is sort of the biggest piece of what we do. Um, which means that we then need to come to universities and say, "Hello, are you looking for a job?
If so, come chat to us. So that's part of the reason why why I'm here. Um, so yeah, we use technology to make decisions sort of on a nancond [snorts] scale. So using both C and other languages like that as well as some hardware that we do as well uh to be able to trade very very quickly uh but also accurately. Um but at its core like what Optiviver is doing is like solving problems. The reason why Opivvo is able to make money is because we solve issues where for example information has not been put into the market or where you know there's two markets that basically need to stay in in line with each other.
These all require basically technology and they require solving difficult problems. Uh and so that's why we come to places like this to find people to help us solve those hard problems. Um so that's that's Optivva. Um me very briefly. Uh that's not the best font, but okay. Uh so I am now a team lead in what we call the research >> great photo.
>> Thank you. Thank you. Yeah, terrible font. That's that's okay. Uh I lead the research platform team and so what we do is we work with our sort of researchers and traders to help them do research on the financial markets and that involves a lot of data. It involves a lot of compute. So a lot of what I'm doing all day is thinking about how can we scale this up for pabytes worth of data or for hundreds of thousands of different processes happening at once. Um before that uh so comp 6991 I'm actually not admining this term so this is the first term in a while I won't be teaching anything at UNSW but have been involved with 6991 which is the Rust course for quite a while and before that I was also involved in comp 1511 this wonderful course as well as a couple others. Um, cool.
So, question for the audience. What did you learn this term that will be most valuable after university? Any suggestions?
>> No pressure.
>> No pressure.
>> Oh, even better. Yeah.
>> Link list.
>> Link list. Yes.
>> Thank you very much.
>> Absolutely.
>> Uh, anyone else? the furthest person.
[laughter] >> Preferably someone over here so we can see an even longer throw. Any suggestions? What else did you learn that was valuable? Yep.
>> How to have good style.
>> Good style. Okay. Yep. Absolutely.
Anything else? Yep.
>> That was terrible.
>> The percentage thing like modulo.
>> Yeah, modulo.
>> Absolutely. Yeah, definitely.
>> Oh, good.
>> This is gonna be really good. All right, watch everyone. Ready?
>> That was pretty good.
Anything else you learned that was valuable?
>> No, I'm terrible at throwing.
>> Perseverance.
>> Perseverance. Yeah, >> absolutely.
>> That was such a nice one. That wasn't too bad.
>> Nice. Um, yeah. So, I I was expecting some of the answers around like, oh, lick list, learning C, learning programs are useful, but actually I think perseverance is a really good one as well. Um, so let me try and move my screen. Is that going to work? There we go. So, is that the next slide? Yes.
Cool. So, I would argue that the thing that you were doing while you were here was really just learning problem solving. Now, you had to problem solve with link lists. You had to problem solve with the percent operator. You maybe had to problem solve with determination. Just be like, okay, I don't know why this is thing is working.
And just bash your head against it. But the thing that you are learning in this course apart from the specific syntax of C, how to make an if statement or a while loop is how to break problems down. Now you're going to leave 1511 unfortunately uh and you're going to go into further on courses and you'll learn harder and harder problems. But the techniques that you'll be learning will stay basically the same. Even when I'm sitting at my desk at work and dealing with a really hard problem, it's not all that different to the things that we were doing at 1511. It's just that unfortunately the problems are a little bit larger. So things that will help asking good questions. I'm sure many of you have learned this in help sessions in your tutors to each other to the internet. Asking those questions is a really important skill and it's a skill that you've been practicing while you've been here. Maybe implicitly, but it's a really important one. Breaking problems down is another one. I can't tell you the number of times at work where I've got a really big thing I've got to do.
You write down all the steps that you've got to do. you break them down into smaller and smaller steps and then you start on one of them and it actually takes a lot less time than you think to go from the first step to the last one.
So that ability to break problems down is is really really important. And as you said, you stole my line, perseverance is exactly right. Like you're going to run into really difficult problems and that's okay. It is a good thing to face those problems to be like, yeah, this this is really hard, but you keep going, you get through it. There is almost always a solution to that problem somewhere. Uh so so that is really important. I would argue that like the thing that you're learning here is also just a way of seeing the world. So solving computer science problems, yeah, sure it's great for like being able to make a link list that has an extra element on the end or to be able to find the largest element in an array, but the the mindset that you're bringing to this is a mindset that is somewhat unique among the workplace. If you go and work in a business with people who aren't necessarily from an engineering background, the way that you see the world will be different. So I think that's quite a sort of a journey that you've started on here that I think is going to be really important and useful.
Um and as I say like they can be applied to nontechnical problems. So not all of you have to necessarily go into a job where you're writing code all day. I would actually argue many of you won't.
You might be working in a job where you're coding a little bit. Maybe where there's AI doing the coding. Uh oh, I said the AI word scary. But uh all of these skills that you're learning are still incredibly valuable because they will influence how you see the world.
So, I think this is a useful lens to take out of this course in addition to needing to pass the exam, which you probably do need to pass the exam. Sorry to break it to you, but more importantly, these are the life skills that you're learning.
Um, another thing that you've learned is in fact Coding. Um, so there are many languages as you may or may not know.
It's not just C. So, why should you learn C first? Why why did you learn C first? C is not the easiest language.
I'm sorry as well. you guys have had a slightly harder time of it than if you were learning to code in, I don't know, Python or something because you've got to deal with all these different types.
You've got to deal with memory. You have to deal with pointers like ghinters, right? Fun, but complicated. So, it's also, and this might be bad saying this in front of Sasha and friends, but it's also not the necessarily most useful language. Like, if you're building a startup tomorrow, I wouldn't recommend that you go and do it in C, especially if you're building a website or something or a mobile app. C is quite a lowlevel language. Uh so yeah, no beautiful web apps from C. But the thing that you're getting is a picture of how a computer actually works and that is a really important thing to have. If you only learn, you know, Python or or JavaScript or one of the other languages that you you'll probably learn in future courses, you wouldn't have this detailed image of here is how the computer works on the lowest level. Here is what memory is. Here is what is being represented when I have a number. And those facts, those like uh that picture of the world is really really important. It's particularly important for a company like Optiva. What we do is very low level. It's very fast and performance is really important. And because it's so important, uh we need to use low-level languages to describe what we're doing.
We often wrote won't write things in Python because Python is too slow and it doesn't give you the control that you need. So having this picture as the first point that you come into with uh in your sort of computer science education is really useful.
Another thing understanding requirements. So when you go out of uh uh 1511 and you go into the workforce, unfortunately you're not going to be given a specification that's as nice as the specifications you got for your project. I had a look at the projects and they looked really fun. So I hope you enjoyed doing them as well, even if it is sort of a bit of a slog at the end when you're trying to get to the deadline. But anyway, um, being able to read the spec to understand the spec is important because in the real world, you're going to have to ask people questions and understand what they're asking you for. Very rarely at Optivva would it be that somebody plunks down next to you and says, "Here is the spec.
Just go and implement this." What more likely happens is you have some conversations with people and you're trying to understand what do they need?
What are their requirements? and you have to then synthesize those, get them together into a bigger list that you can then use um to generate the project that you're working on. So yeah, reading the spec is a really important part of um like learning how to do that process, how to understand requirements.
A style guide, someone mentioned the style guide as well. In industry, you will be expected to follow a style guide. Now, it might not be the one that 1511 uses and it might not even be written out sort of line by line as like a explicit here is what you have to do.
It might just be this is the convention that we use within our company. But that style guide is really important because if you don't follow it, then when you send your code off to get reviewed by somebody else, it's going to be much harder for them to review that code and it's going to be slower. So, understanding requirements includes a star guide. And then, yeah, having code reviewed. This is something that you've had a little bit because your uh markers have reviewed your code. You probably got feedback on assignment one I'm guessing sometime at the end of last week or something. Yeah. Nice. Uh so looking at that review and understanding those reviews again that's a really important piece and it's a skill that you've sort of got first exposed to here that's going to grow and grow as you go through the rest of your education and then into the workforce.
Last adult life. Um out of curiosity this is term one right. So, who here this is their first term at UNSW?
Most people, pretty much everyone. Okay, cool. So, you probably had to learn some of these things this uh this term as well. Time management. We were just speaking before the lecture about how time management is a is a big problem and you'll often end up doing things the night before or the morning of. That is not new, I guess, to some of you, but it's also probably the first time you've really had to manage multiple different schedules yourself where you don't have to get the work done. No teacher's going to come and follow up. you're just not going to get the marks. So that time management is a skill that you're learning here that's going to continue being important. Uh learning new things is another big one. So for some of you, this will be the first introduction you've had to computer science. And so there's a whole bunch of new stuff you've got to understand. So um like that's another skill that you're sort of practicing while you're here. working with others uh not necessarily on group work right at the moment but I'm sure that you're all sitting with each other in the ches maybe outside grabbing a coffee or a bubble tea or something asking questions trying to understand how the spec works that sort of working with others is really important uh I mentioned freedom to do multiple things at once and then also getting to choose what you do to some extent here you got to choose to come to this course in a way that maybe you didn't get to choose to do maths or English at high school so that's another really big pit point as well Um, I'm like contractually obligated to show this slide. If you're interested in careers, uh, we run a program called Future Focus, which is like a sort of early career uh, experience what Optiva does. I'm just going to mention it briefly here and I'll put the slide back up at the end. All it is to say is that if you're looking and you're interested in some of the stuff that you'll be seeing in this lecture, there's ways that you can get involved.
Um, okay, let's dig into a problem. And while I do that, I'm just going to go and grab my water bottle because I'm going to need it.
the sound.
>> Oh yeah, you're getting the real full Yeah, full full sound. So, what I'm hoping to do here is to walk through a problem that we actually have at Optiv.
Um, in fact, before I do that, any questions about what I just said? I'll check.
No silence. We might have some time at the end as well, or I'll stick around for a little bit. But, um, this is a problem that we actually face at Optiva.
I'm going to describe to you the problem as it would be described to you if you were to walk into Optiv and have to solve it. Um, and then we're going to write some C code that actually solves the problem. And I'm hoping what you'll see from this is that what you've learned in this course is useful to solve real world problems already. You know enough now that you could walk into Optivan.
The way that that looks is at the top there's this big sort of building. We call that an exchange. That's where all the different people come in and put in orders to buy or sell. So, for example, when you open up your phone and you say, "I'd like to buy some stocks or some ETFs or something." You do that. It goes to an exchange. Optiva also connects to the exchange and there's a pipe between us that sends messages back and forth. A message might say, "Hey, I want to place this order." Another message might say, "Hey, the order that you placed has traded. Somebody else wanted to trade with you. Trade is done.
Now, importantly, we don't just want to send messages back and forth. We'd like to record those messages as well. Can anyone guess why am I recording these messages as opposed to having something further down? You know, maybe like every time I see a trade message, maybe I put a separate record in. Why would I want to record the raw conversation between me and the exchange? Any ideas?
>> Yeah.
It is.
>> Yeah, absolutely. So, so keeping this information just generally is really useful because we want to know what the conversation between us and the exchange was. So maybe for future trades we could use that information.
Also, this is the rawest form of information we can get. This is like the messages between me and the exchange are the simplest sort of mo most unprocessed thing that I have. We do lots of other stuff as well. Maybe we process that information, we you know decode it, we do more things, but the messages between us and the exchange are the rurest information of like here's what we thought the exchange was doing at a particular time. So these messages between us and the exchange are really valuable. They're really important to us. They're so important in fact that this setup has a problem. Can anyone tell me what might be wrong with this setup? What am I missing here? If these messages are super important, what should I do with this setup to make sure that Yep.
Redundancy. What do you mean by that?
>> Copies.
>> Copies. Yeah. So, backup, right? I don't want to just have one one connection between me and the exchange. If I just had one connection, if that connection goes down, I don't get any messages at all. So, what should I do? I should put a couple of links in and I should record all of them. And now, if one of them goes down or if there's a problem or something, it doesn't matter. I've got multiple sort of uh threads that I can pull on to listen to messages from the exchange.
And you also mentioned backups as well.
Absolutely. That thing in the corner there, the little database that we've got that's saving all this message traffic between us and the exchange, that should also be backed up. Let's just assume that that's done. Very important though. So, I've got these different sort of uh links to the exchange. Can anyone take a guess what might a problem with these links be?
Let's assume they're all sending the exact same messages. What might happen?
>> Yep.
>> They might not be synchronized.
>> They might not be synchronized. What do you mean by that?
>> They might send the same information before each other and maybe the rate at which sending changes over time. So it's not always the same.
>> Yep. So maybe they're not going to set uh send messages at the exact same frequency. Exactly right. So the one on the left might be slightly faster except on Tuesdays where the one on the right might be faster except at 11:00 at night and then in the in that case the middle one will be faster. And this again is a very realistic problem that we have at Optivva. Often we will connect to multiple exchange handoffs we call them like multiple sort of connections because one of them might be faster or slower than another. And so it's both for redundancy and it's also because you end up with multiple different sort of like uh they might be out of sync with each other. one might send slightly faster than another.
Here's what that looks like. So, this is sort of a weird graph where this way is time and I've written out all the different orders that I might be getting from the exchange. This is the exchange telling me, hey, a particular message came through at a particular time. So, order one on connection one came through at time one. The same order came through very slightly later on connection two.
And then on connection three, it came in slightly later again. But it's not necessarily always going to be true that connection one is the fastest. You can see here that in this case order two came through slightly earlier on connection two.
And so there's sort of two things then that I care about if I'm a trader.
One of them is I'd like to just have all of the messages colleated in order. So I want to know I don't really care that there were three connections. I just want to know what is the feed of all the messages that I got in the order that I received them. And so what that would look like is you would sort of sort them together. So the order one on connection one comes first, then order one on connection two, and then order one on connection three. Something like this.
Let's see if that work.
There we go. Something like this.
So I've taken these three different connections that I've got and I've squished them together into one big piece of information.
What's the other thing I might want to do as well? Any thoughts? What else could I do to simplify this?
Yeah.
>> Only have each order in the list once.
Absolutely. If I was going to get rid of some orders, which orders would I want to get rid of?
[clears throat] >> Yeah. So, we only want to get the orders that have the shortest time, as in the one that we received first. So, one way you can think about this is if I'm sitting on on the Octiv side and I'm getting all these messages, what I want to do is I want to figure out which message came through first. When was the earliest that I heard about something?
If it comes through again on a second feed later on a second connection, I don't really care about it that much because I already found out about the information. And so, that would look something like this. Now, I've only got three orders and I know at what time those orders came through. Does that make sense? Any questions about that?
No. Cool. So, what I want to do for a little bit is I've written out some code. Uh, I'll get rid of that. I'll go here. Hopefully, this is going to be a little bit delayed, so I'm hoping this will this will work. Okay. Um, here's some code that I've written, some C code, and I'll make it a bit bigger as well.
Uh, is that visible to everyone? Are people happy with that size?
Pink is a bit rough. Okay. Uh I the pink is thankfully the least important part.
Those are just the numbers. So what this is saying is I've defined myself an order strct and that strct contains three things. The feed ID. So that's which connection we handle it from. We often call that a feed. So feed A, feed B, feed C. Uh in the example we had before. The order ID and that's a number that uniquely tells you which message is it. So for example on three different feeds A, B and C, you would get the same order ID across all three of them. And the last thing is some time in milliseconds and that tells you okay when did I receive that? Um those are the those are the three fields. You can imagine that in a real problem here we'd have like 10 fields and it would also tell you hey what was the thing that traded for what price?
Who traded it? You know was Optiva who traded or was it somebody else? But I've sort of omitted that because it doesn't matter for the purposes of this example.
If it was real, this would be like 200 things in the strct, but let's ignore that for the moment. Then I've got these two feeds here. I've got A and B. And so both of these, let me see if highlighting it makes it any better. Is that better or worse? Worse, I think I tried. Um so this is a list that says that for order uh for order feed A we received message ID one at time 100 milliseconds, message ID 2 at 200 milliseconds and so forth. And then I have a second uh order feed that contains the same IDs but at slightly different times. So in some cases the messages came through a bit early, in other cases the messages came through a little bit late. And so what I'm going to want to do is two things. The first one is to generate the let me go back here. Generate this raw this raw format. So take these two order feeds and join them together. And the second thing I'm going to want to do is to then filter them down so that I only have the sort of processed final we would call a sifted feed where we've only got the the fastest order to come through.
Seems sensible.
Any questions?
Okay.
So maybe let's jump down here. You can see that all I've done in my main function is I've got a list of the merged orders. That's where we're going to store this merged list of all the orders. I have a function called merge orders which will take these two order feeds and merge them together. And then at the end I'm going to print them all out.
Got a little to-do up here for merge orders.
Does someone want to sort of give me a higher level? What am I going to want to do? Maybe like what's the first step that I should take? What's the first thing I should do?
>> Yeah.
>> Yeah. So, the first thing to do is to create a new array that contains my output. Absolutely right. Thankfully, I've actually done that in the main function already. So, we've got that here and I'm passing it into this function as output. So here you can see I've got feed one and feed two. I've got output which is where we're going to place that. And then for the purposes of this problem, we can assume that all the order feeds have the same length because they should contain all the same orders maybe just in a slightly different uh slightly different times. Um so let's imagine maybe I'll go back to my diagram for a second.
If I've got let's let's say I've got three order feeds here, which is the first thing I should select to put into my merged list?
Which order goes in first?
Sorry.
>> Order one from which connection?
Connection one. Exactly. So, how did you figure that out?
>> Yep. It's got the first time inter absolutely but there's three connections. So it's got the first time inter interval. You might say it's got the first among those three connections.
Right? So you can look at the first order in order one, the first order in sorry first order in connection one, the first order in connection two and the first order in connection three and you can say oh time one is from connection one. I'm going to take that first.
What is the next step? What's the next thing I've got to do after I take order one connection uh order one from connection one?
>> Yep.
>> Just a clarification connection or always guaranteed to be in the right order.
>> Let's say for now, yes, absolutely.
Maybe we can come back to that because it's a great question to ask. It's a good clarification to get. So, if I've already taken order one out of my out of that connection, what's the next order I should put in?
>> Y.
>> Which one is the second fastest? And which one is that?
Connection two order one. Exactly. But when you were doing that, what were you comparing between the between all these?
No.
>> Sure. So, for the moment, we can kind of ignore order two here because we know that these order ones are faster. But from I guess like a the perspective if if we're trying to um look at all of these connections, one way you could think about it is that you're looking now at order two from connection one and the two orders from connection two and connection three. So basically we've gotten rid of order one and now we're comparing order two at time 9, order one at time two and order one at time three.
And now obviously order one at time two is the next. So we'll take that we'll put it into our list. What comes after that?
If we've taken order one out of connection one, order one out of connection two, what should go next?
[clears throat] Order one from connection three.
Exactly. And now we've dealt with all of the order ones. The next thing we've got to do is deal with this order two. But the way that you can see that that works is that we've taken connection one, order one, we've put it into our list.
We've taken order one, connection two, put it into our list. take an order one connection three and now we're only left with these order twos and we've got to compare between them to figure out which of those orders is first and which is the first of the order twos connection two. Yeah. So let's take a look at how we might do that in code.
So we're probably going to need a while loop here because we're looking through all of these orders and we're trying to put them into some order. So, I'll put it in a while loop. Often my strategy here is just to like write out some of the things that I need and try and put them in the right places.
I know I'm definitely going to need to have some integer that iterates through because I'm looking through all the orders. So, I'm going to make int uh let's call it i.
Let's be more specific than that. When we were doing this before, we were iterating through the various different feats. So, am I going to need one integer to keep track of where I'm at, or am I going to need one per feed?
>> Yep.
>> One per feed. I need one per feed because I got to keep track of I've gone through connection one and I'm looking at all of those. I'm going through connection two as well. And in the example before, I was going through connection three as well. So, in this case, I'm going to make one called uh let's call it uh position one.
And I'm going to make another one called position two. And so this is saying this is where I'm up to in the list of orders on feed one and where I'm up to on the list of orders in feed two.
Make sense so far?
Now this is a little bit tricky. It's a bit of a tricky point because it's not clear what the while condition should be.
Normally in a lot of our examples, you would just say something like, "Oh, well, position one is less than length."
If there was just one array, it's very simple. I'd go through the array, but I'm going through two arrays. And so now I've got to keep track of, well, am I dealing with position one? I'm dealing with position two. How am I iterating through both of these arrays?
>> Yep.
added together.
>> Uh yes, and indeed you you can assume that the length of feed one is equal to length >> and the length of feed two is equal to length.
>> So they're >> they're the same length definitely.
Yeah, there might be a world later where you have extra orders in one and the other, but we'll ignore that for now. So I've got my two positions here. These are my positions within each of those order feeds.
Now I've got to figure out what is this while condition going to be when we were going through before when we were looking at this diagram.
How would you phrase the while condition that we had here? What were we trying to do?
We took one, we took another one, we kept taking them. When would we stop taking things out of this diagram?
Sorry.
>> When all of the orders are exhausted.
Absolutely.
So the way we would phrase that is maybe it's well when connection one we've got no orders left and when connection two we've got no orders left and when connection three we've got no orders left. Something like that. Okay.
So we can try and do that then. So while pause one is less than length and pause 2 is less than length.
This is something like what we could write. Now this is not quite the same thing as what I think you just said.
What I think you just said is we should go through all of the orders.
Let's imagine that we're iterating through this image here with that condition. The condition being let's go through all of these until our position in connection one is equal to its length or our position in connection two is equal to its length. Maybe for the moment we can ignore connection three and we'll just look at connection one and two. I'll zoom in a little bit to make that true.
That did not work. Let's ignore connection three for the moment. We'll just stick with connection one and two.
So I grab order one out of connection one.
I grab order one out of connection two.
I grab order two out of connection two.
I grab order two out of connection one.
Now what do I do? Let's take order three out of connection one.
What what happens then? My condition was while I have some room left in sorry while I have while position one is less than length and position two is less than length.
I've taken order three out of connection one. I haven't yet taken order three out of connection two. But my condition is true.
My position in connection one is now equal to its length. So the easiest way of dealing with this is to say ah that's kind of complicated.
Let me just stick with this for the moment and we'll come back and check it later. I'm going to try and get some progress, get something done without necessarily thinking, "Oh, I'm kind of confused about this. Let me just try this and see where I can get to." So, we've now got our condition. We don't know if this condition is right. In fact, we think there might be something wrong with it. But, I'm going to try and see how this actually goes.
So, now we've got to do something inside of here.
We've only got two feeds to deal with.
Thank goodness the diagram has three, but we don't have to worry about the third connection. So, let's just look at position one and position two. So, which out of position one and position two two should I take out of my feed?
How do I decide which of those two orders do I take?
>> Yep.
>> Yeah, it's a great idea. We could do that.
Let's come back to that in a minute because I think it's a good idea, but we should take a look. So, let's let's for the moment we'll stick with this, but I agree with you. Maybe we do want to use the or um where was I? Yes. So, how do I decide which of the orders that I'm taking?
What was the comparison that we were doing before? Yep.
>> Yeah. So, I need to check the time, right? And so what I might say is something like well if feed one position one dot and then let's call time ms time in milliseconds time ms is less than feed 2 position 2 dot time ms then in here I'm going to do some logic. What should my logic be? What am I trying to do in here?
>> Yep.
>> Yeah. Append feed one to the merge or that the current order in feed one to the merge list. Now, there's a slight problem here. I don't actually know where I'm up to in my output list.
Right? We said append, but I'm not keeping track of how much stuff is already in my merged list. So, let's do that. We'll make a new integer called output pause. Our position in the output output pause equals zero.
And so now I can say something like output output pause equals feed one pause one. So what we're saying here is take whichever message we're up to in feed one and put that into the output array at position output pause.
Now, in the very first instance, if we're just dealing with sort of everything being zeros, what that says is if the first thing in feed one has a time in milliseconds less than the first thing in feed 2, then I want to take out of feed one that first order and put it into position zero in my output array.
So, assuming we're at the start of the list, that makes sense. We're saying take from the start of feed one and put it into the output array.
Now, is that it? Can I leave this branch or is there anything else I need to do before I move on?
>> Yeah.
>> Exactly. So, whenever you're inside a while loop, you're always going to need to iterate something. Need to move it along. And in this case, I'm going to do output pause plus equals 1.
add one if I can type add one to the output position and also I'm gonna want to add one to position one. So now at the end of this while loop I would be comparing the second thing in feed one to the first thing in feed two.
Does that make sense?
So we've got this condition. What do we think an appropriate condition for our like else block should be? Can we have multiple? Can we have one? What should we do next?
>> Okay. Absolutely. Um so it would be something like else if that happy with that. Cool.
Seems sensible. What should I do inside of here?
>> Yep. So, a copy whatever I had up here, but replace feed one with feed two, position one with position two, and then position two over here. Great.
Looking pretty good. We're getting closer. This feels like it's doing something about right.
Is there anything in here that should be a little bit scary to us?
Uh, I'll see if anyone else can see something weird. Yeah, off the back.
>> Is it possible that two orders come in at the same time?
>> Is it possible two orders come in the same time? Excellent question. Maybe through random chance, one order could come earlier, one could come later.
Maybe two might come at the exact same instant if that happens. Question is, what should we do? Currently, what would happen? Can someone tell me what would happen if an order came in with two being equal? Yep.
>> Wouldn't be accounted for. What do you mean by wouldn't be accounted for?
Yep. So, it'll skip this if case.
Absolutely right. But it's even worse than just skipping the case because what happens at the end of this loop? We go back to the start again. What's it going to do then?
>> It's going to skip that case over and over and over and we're going to end up in an infinite loop. So, definitely not what we want. The easiest way of solving that problem is well there's a couple ways. Anyone want to suggest one maybe?
Yeah. Off the back.
Something like that. Is that sort of what you meant?
>> Yeah. So, this does solve our problem.
Absolutely. If we do this, then we're going to make sure that because we can see with our eyes, less than or equal is one one case. Greater than is the other case. That must cover all cases. Another way you could do this, if you don't want to have to worry during an exam or something about the, you know, have I covered all my cases exclusively, we could just make this an else condition.
We should always be making progress in this loop. We should always be picking one or the other. So, I know that if I haven't taken from one, I must take from the other.
Now, this is pretty good. We're pretty close. Let's see how well we've done.
I'm going to do some compilation now.
Uh, where am I? DCC.
Hopefully, this works. Oh, first that never happens. Something's something's definitely broken here because if it compiles first go, that's always a bad sign. Um, whoa, runtime error. Uninitialized variable accessed. Okay, let's have a look at what happened.
So, we can see that we went through it mostly worked. So, you can see that we sort of have the feed A, feed B. It's kind of slightly cut off on the side of the screen, but it's showing us that we got most of these messages coming through correctly. It all looks pretty reasonably, pretty reasonable. What's missing?
>> Exactly. And the 10th one is missing.
And what case is that?
like like how did we end up in that situation? What was going on?
>> Yeah, >> we only took the last packet from one stream instead of both.
>> Exactly. We only took the last packet from one stream instead of both. And so this is the concern that I kind of pointed out earlier. Now you had a great point. We should probably change this condition. The condition is, you know, like probably something a little bit incorrect. Um because what I want to say here really is while position one is less than length or position two is less than length. Right? I'm waiting until I've gotten all the data out of all of those streams. And so what I can do here is I can change this to an or. Let's try that.
Oh, that didn't work. Something else has changed now.
Okay, I've got another error. This one's even more kind of confusing. Now, it's complaining about something inside our if condition.
What's it complaining about? So, it's saying here, scroll up.
Global buffer overflow illegal array something something outside of going outside of length 10. We could spend a bit of time reading this. In fact, let's do it. Why not? So, it's saying this is the error line. If feed one pause one times less than equal to feed 2, pause 2 times. Now, we're seeing we can fill in some of these values.
Feed one and feed two. Those are the arrays. Pause one is equal to 9 and then pause 2 is equal to 10.
Can anyone see what that problem is?
Yeah.
Absolutely.
>> Yeah.
Yeah. Yeah.
>> Okay. Yeah. So Okay, so what we're sort of saying here is that this condition is assuming that we're inbounds, but we're actually not necessarily like staying in bounds.
We're going off the end. There are a couple of different suggestions. Maybe we add some new if conditions in. Maybe, yeah, as you say, we add an extra check inside of our if condition. Now, I want you all to imagine here that you're in an exam. I'm sorry to put you in this place, but you're stressed. You know, you've got half an hour left. the exam is ending. You're worried about it. You still what? Three hour exam, something like that. Okay, 3 hours exam. So, you're sort of get getting stressed here. Now, I kind of want to walk you through maybe one way that you could think about solving this problem because there are a couple ways of doing it.
Now, in this case, I think that there's some condition here that I need to figure out, but I'm really not sure what it is. as you mentioned, it could be something like, oh, I've got to add in some extra conditions here, and I could play around with trying to um change the conditions, trying to make them work correctly. Let me go back to what I had before, though.
So, here, this was working. It didn't crash, but it did have a slight problem.
Let's compile it.
Oh, sorry. This did crash. Uh, did I compile?
Live demos always scary.
While pause one less than length and pause two is less than length.
I messed something up here. That should be live demo is always the scariest.
Oh, uninitialized variable access. Okay.
So, what this is saying is this is almost working correctly.
It's just that when we get to that last element, we've not taken it out of the list. So, 19 out of 20 of the values have been gathered correctly, but this last one hasn't. Now, I could spend some time trying to figure out the right condition and maybe I'll leave that as an exercise to you. But all I know, the problem that I'm aware of here is that we've not quite accounted for the last couple of values.
One way you could think about this is I've solved most of the problem. I've only got a little bit of problem to solve. What do I do about extra values at the end of my list? So going back into my code, you might say something like, look, this is I'm really close here. I could spend some time messing with the conditions.
Or what I could do is observe, well, here all I've got to do is grab the the bits of the orders that remain, the last little bits of the order. So, either I know at this point that I've got a little bit left in feed number one, or I got a little bit left in feed number two, but not both. Can everyone agree that that's the case?
I know that cuz if it was going to be that both of them are sort of not quite done, I'd still be inside my while loop.
So, what's a simple thing I could do here?
>> Yep.
>> Yep. And what would I do with that check?
>> Yep. So something like uh and a condition would be something like if pause one is less than length then I could do something in here.
And then another one here is if position two is less than length then I could do something here.
What could I do inside of here? Any thoughts?
No ideas?
We're so close. We're on the final stretch. You've got 30 minutes left in the exam. There's something we can do.
Yeah.
>> Exactly. I can add them all remaining back to the output. So rather than doing an if, I could say while pause one is less than length. All I'm going to do here is say output output pause equals feed one pause one output pause plus = 1 pause one plus equals 1.
And then I can do the same thing down here with feed two.
Feed two. Feed two.
And we'll make that a while condition as well.
And so admittedly, this is probably not the nicest code in the world. And to be telling you the truth, there's a couple different ways you can do this. And you could maybe try and find some other ways of solving this problem. And maybe you'll find some of them are nicer than this one. But because I know I've completed most of the problem already, it's a nice little way of saying, "Okay, well, look, just for now, I'm going to see if this finishes the problem off."
And indeed, if we merge this it works.
So if you're sitting in the exam, my advice here would be, you know, take that deep breath and if you think you've solved some part of the problem or most of the problem, see if you can just do a little bit at the end to solve it. If that doesn't work, maybe you tried this and you couldn't get it working, then maybe you can also go and try and update the existing condition that you've got.
there's just different tools that you can do use, different strategies you can use, particularly in some of the slightly harder questions. This may be something that helps you. Not always, but it might be an idea. So, going back to our code, let's just review what we've done.
So, we had to merge these two order lists. We had two different lists, so we made two different positions. We also needed to keep track of our output position.
We went through both of them, and we weren't sure about this condition, right? And we maybe like, oh, do I do an and? Do I do an or? So, we tried one.
We tried it. We did some work. Okay, we kind of got to an okay place. It was sort of working. And then we iterated on that and we said, well, okay, maybe let's try the other condition. That doesn't work either. Okay, went back and forth. We tried adding this little bit on the end and it worked. Now, in your own time, you can go away and have a look if you can figure out what the condition here would be. So that while pause one less than length or pause two less than length works. It's a little bit trickier than it looks but it might be an interesting exercise for some of you. But that is in summary us having solved the real problem that we have at Optivva. So this problem at Optivva rather than having maybe 10 messages on two feeds we might have tens or hundreds of feeds and the list of messages is you know gigabytes or pabytes long but it's the same thing we've got to do internally. we have to run effectively this process and we generate these data sets and we provide them to our traders.
Now given the time I will leave sifting those orders as an exercise to you but it might be an interesting exercise for you to do because it's another interesting arrays question and this is also absolutely something that we have to think about at Optiva. If you don't get time to do it don't worry comp 2521 you will learn about this in length I suspect. So it will come up probably soon. You'll know how to do it by the end of next term maybe. Um given it's 12:00 any questions?
>> Yep.
Great. What language do I code in at work? So, it's a mix for me between a tiny bit of C. We more use C++ in our AP pack offices, but our US offices often use C as well. Um, I write a lot of Python as well, but that's because it's the language that the researchers use.
So, for sort of data sciency sort of stuff. Uh, I write a reasonable amount of Rust now as well, which is sort of a language kind of like C and C++, but more modern in some ways. Uh, and then there's a smattering of other ones that I'll write as well, like Java, some bash, depends, whatever's needed. Um, normally most people off the road are writing C or C++, though.
Cool. Any other questions?
I'm going to hand the lecture theater back then to Sasha. Thank you very much for having me. Um, I'll stick around for a bit as well, but thank you very much and good luck for your assignment and exams. [applause] Cool.
>> Thank you very much, Tom. I think it's a good time to have a little break.
Five minute break.
>> Everyone's cooked.
>> Cool.
>> Okay. Five minute break.
[music] >> [music] [music] >> Hey, hey, hey.
Heat.
[music] Heat.
>> [music] >> Hey.
Hey. Hey.
Heat. Heat.
>> [music] >> Hey, [music] Hey, hey, hey.
>> [music] >> I know.
[music] Hey, hey, hey.
Hey, you got >> [music] >> Heat. Heat.
I know you.
[music] >> [music] >> Hey, hey, hey. [music] Hey, you are Heat. Heat.
[music] [music] >> [music] >> Heat. Hey. Hey. Hey.
I know.
[music] and then wait.
Also, if you have any more questions for Tom, he will come back at one o'clock >> because I'm kicking him out in one minute. [laughter] What is um what is going on with the cahoot? Can you see like the numbers?
They're going up, down, up, down.
>> Yeah.
>> Is it >> Is it me? Am I the problem?
All right.
>> All right, let's do it. See you at 1:00.
Tom, thank you so much. That was so good. Yay, Tom.
>> Hey, Tom. You forgot your Optiva branded water bottle to go with your Optiva branded jumper.
>> To go with your Optiva branded backpack, I bet.
>> Ah.
>> Oh, socks. God, why?
And the the admin that came after Tom actually also works at Optivva. That's that's where I Yeah, that's where I lose admins. And the other one works at not Optiva. What's the other one? It's another one that's trading Jane Street.
>> Rory, he went to Hey, >> maybe I see. All right, let's do it. It doesn't really matter. It was not an important Clearly, this is your pathway. No, it's not. There's many pathways.
That's right.
>> What did you say? You want to do a PhD?
That's right. Yes, you do.
>> There is an in between.
>> There's no in between.
>> Do a PhD.
I've been to both.
>> PhD is better.
>> All right. Oh, I've started. I didn't even realize. I just click clicked and then it started.
>> Well, I'm playing it, but it's >> What?
What?
It's really stressful though now.
>> Oh. Oh, that's very nice.
>> I don't think that's ever happened.
>> Wow. Tom's Tom's um Tom's example really must have done the trick. All right.
Now, I've I've decided to be a bit mean on this one. Sorry. Thank you.
Okay. It's too loud for me.
>> You're very in tune to it.
There was two things malicked. There was something inside the node that was malicked as well.
>> I know. That was fun.
So, you go from the inside out.
Classy bat. I don't think I've ever met a bat that's classy, but okay.
Is it different music for every single question? F different questions. Not every >> Oh.
>> Oh.
Oh, very nice.
Great job.
Classy bat ex genius hawk. Fearsome bunny.
A It's like Zootopia.
>> Yeah, it was a fearsome bunny.
>> Yeah, it's so cute.
Do not start me on that song. I could not get out of my head the whole week.
>> Nope, it's there now.
>> Oh, how exciting. Kind of.
That's okay. Probably couldn't remember which one was the destination, which one was the source.
>> And what about the next one?
The last question, if you got it wrong, you should now get this one correct.
You're going to run out of space because there's not enough space in one of the arrays to copy because it had one extra character.
very Very good.
Ah, excited. Yak.
Oh, >> cuz I was trying to access a null pointer.
[clears throat] I just like this.
Yay!
Good job.
All right, last few.
very good.
All right, last question on the second last cahoot.
Genius Sable is now coming first.
Check the condition over here.
All right, that would have knocked a few people off [snorts] >> in the duplicate of the second last cahoot. Good names, good variable names, good style. Why is there no music now?
>> Who's come first? Genius Sable.
>> Is Is anyone in the room?
>> Which one? First, second, or third?
Amazing.
>> All right. Oh god, it's 12:25. Time sure flies when you're having fun. Um, okay.
Um, my experience surveys for those of you that haven't done it, please, please do so. Um, it lets us improve the course.
Todd, we've had the guest lecture. All right. So, I've got some sample problems today. And I think I even made the slides. Um, they are up. Um, and the poll said that you want to do linked list questions and array hurdle questions and then you might want to see a three dot. Is that right? Even if it's not, that's what the poll said and no one's replying back. Everyone's gone back to sleep. Um, so we're going to do some linked list hurdles. Can I get a poll in the lecture now whether you want one linked list hurdles or two dot link list hurdles, which means question one or question three.
How's that going?
pardon.
>> Four dots.
>> It'd be fun, but it wouldn't be a it wouldn't like it wouldn't be as useful for the rest of the, you know, it wouldn't be as useful for the majority.
>> Okay, let's go look at some two dots.
Here we go. Okay, and I think we can do it quickly.
Um, okay. So, two dot problem with a deletion. Delete the first note in the list that is divisible by six.
>> Okay. Do you feel like you read that, you're sitting in the exam, you've read that, you feel good?
You feel like you're doing great. You can answer it. You You feel like you don't care. You're about to care in two weeks.
And that's the wrong Oh my god, >> I can't hear you. I'm sorry.
All right.
Okay. So, oh, problem seven. That's why it doesn't match because I went to six, not seven.
Okay, great. Let's do this problem. So, you've got a problem. It's going to look something like this in the exam. Um, and also this week in your labs and stuff, you're going to log into the exam environment. I'm not going to demonstrate it in the lecture because the last time I did that, I accidentally revealed my password and then had to take everything offline. So, we're not risking that again. Um, and instead you're going to see it in the lab.
There's also going to be a video made available that's going to show you how to log into the exam environment and to actually click through on the exam environment. Um, and basically when you get into the exam environment, you will have just your VS code and you can rightclick to see the course website and everything on the course website and and all of those things are available to you. So, it's just giving you the ability to see what is actually there.
Okay. So, when you get your starter code, then you'll see something like this. Again, you're going to have the code down the bottom and the code down the bottom is going to have um the stuff that allows us to give you a linked list and the stuff that you will use to test a linked list with. Okay? So, you will only just have to do the function that actually does the thing that the question is asking, which will also have assumptions and clarifications. And whatever we don't ask you to do, you don't have to worry about it, right? So, you don't have to think that there's going to be an edge case that is there to trick you in any way. That's not the case at all. Everything that you need to do will be in the question. Everything that you don't need to do will be specified in the question. If you thought of something else, it means you don't have to consider it. It will not be tested. Okay. So, what's the first thing that you do? So, let's say this question should delete the first note that is divisible by six. If there are no nodes that are divisible by six, it should return the list unchanged. So, what do you think would be the way that you would solve it just in plain English terms? Like how would you how would you do it?
>> Yeah. So, we want to traverse the list, find the node that divides by six and um gives zero. Yeah. So, that means no remainders when it's modulated by six.
And then what do you want to do with that node? You want to delete it. Yep.
And therefore then make all the other connections that you need to make.
>> Okay. Great. So what do we do to traverse the list? What's the first thing that we do?
>> Yeah. So first thing we do set the current to a head. And then we're going to use that current to traverse our list with. Okay. Um, and someone on the chat is saying, "Make a previous pointer as well for when we find a value divisible by six." Okay, we can do that. So, we can do a previous node as well. And we can set the previous node to null. So, before our list, before anything happens, and then we're just going to keep updating as we go.
Okay, great. So, then we need a while loop to traverse our list. And what should the condition be in our while loop?
What do we reckon?
>> Yeah. So whilst current is not equal to null, are we going to go all the way through the list? We're going to go past the end of the list.
We're going to go all the way through the list because we want to make sure that we check the last node as well. And if you ever do currents not equal to null, then you run your code and you can see that something has happened, it's gone past the end, you've accessed the null pointer, then you always go back and change your condition.
Okay, great. And of course, we also want to move our current as well as we go. So what is the condition? So we're traversing the list. Now we want to find the node to delete by six to give us zero as remainder. So it's going to be an if condition and we've kind of said what the if condition will be. So if your current data modulus 6 is equal to zero that means you have found a node that is divisible by six. Yep. So then we want to delete. Okay. So how will we delete the node?
Yeah. So, what's the first thing that we should consider when we're deleting?
>> Sorry. Yeah.
>> Yeah. So, we don't want to lose track of the list. And we also want to always consider what happens if it was the very first node that this condition happened in. So we need to delete at the head of the list because then my previous is going to be equal to null which means I'm going to have some issues with my memory as I try to rejig what's going on.
So case one is it is my first node and I'm deleting the head off the list.
Okay. So how will I check that if it's the first node that I'm deleting? Yeah.
>> Yep. Excellent. So I will check if my previous is equal to null in here. And if it is, that means that I'm deleting the very first node in the list. So what can I do here? How will I move my list by one before I delete it?
Yeah. So head is equal to current next which basically means that I'm going to shift over by one the address in stored inside the head. Okay great otherwise if I'm not at the head of the list I'm going to um do something else. Yeah. So if I have let's say two 12 um four five. So I will need to delete this 12. Which means what I want to do is I want my previous node.
This is my current node.
And that means that this is my current next over here. And this is my current next. Next. So if I want to delete this 12, then what I want to do is I want the previous next to point to the current next. Yeah.
So I'll say that previous next is equal to the current next which means what I've just done is I've connected this node to this node by passing this node but I haven't freed it yet.
Okay. So then perhaps here after the if condition I can free the node and what will I free?
>> Yeah. So, I'll free my current node.
And will I do anything else?
No, I'm done.
>> I do want to return. Where will I return the head? I'm still inside the while loop. So, yeah, I'll return the head. And I think there is just one more thing missing in this piece of code.
Okay, so the list is empty. We'll cover because whilst current is not equal to null. So if it is equal to now, I'll skip right down to return head. But there's one thing I haven't done.
Yeah.
>> Yeah, I've I've got an infinite loop currently. Bit of a situation happening.
I'm not moving along. So, I want to move my current along, but I also want to move my previous along. Which one will I do first? Will I move the previous first or will I move the current first?
>> Yep. Excellent. Because if I move the current first, then I will lose um the current next. Okay. So, do we think that this is going to be Yeah.
Yeah, first first divisible by it.
>> I will need to return. You're right.
Because right now I'm deleting every single node divisible by six. I will keep going in that while loop and keep perusing through the linked list until what that means is I will show on the um okay so let's compile and I'll show you what we mean. Say problem seven.
Okay. Line 32.
Okay. So because in the exam remember that if you are compiling then you're running we're reading the list of command line arguments which is what allows you to test it. So let's test it with um give me some test cases that you want to test it with. Where will be the divisible by six thing at the head?
Amazing. We've we've got an error. Malo use after free.
So what does that error mean?
>> Yeah.
>> Yeah. So basically we freed the current here and then we've moved things along and that's occurring because we haven't returned inside um after after our freeing. So again because we are returning just we're deleting the very first node we want to return after we have deleted the node as opposed to keeping on going. So we'll return head in here and then this condition will only stand for as we keep going looking for this node that's divisible by six.
Okay. So let's save and let's try again.
Okay. And then let's run it again. Okay.
So now it's deleting at the head. Um then we should try what else should we try?
>> Try one that doesn't have any.
>> Yep. What else will I try if I'm sitting in the exam and I need to try things?
>> Nothing in the list.
Yep. Okay. And then anything else? Yeah.
>> If it has it twice. Yep.
>> Well, that's great. It deleted one, which is what we want to see. I don't know which one it deleted, but hopefully the first time it occurred.
>> Zero.
Um, yep.
Yeah, I think what it it seems to be working.
>> Yeah, kind of. I mean, it's got an issue with zero mathematically.
>> Okay.
Yay. You've solved an exam question and you just got a two dot hurdle.
Okay. Let's go to the next one because that's how we're going to speed through them so that we can get through a few.
>> Pardon?
>> Exams will have what?
>> Exams won't have three dots.
>> They absolutely will.
>> Question nine onwards is three dots.
>> Okay.
>> Yeah. Yeah. Yeah. And enjoy.
>> Yeah. That's why we I would like for you to do the first eight attempt the first eight questions, right? Anything after that's a bonus and that's why the marks get less after question nine. So it becomes 11 marks and then 10 marks so that it's not right. It's if you want a HD then you start doing the three dots and stuff but it's you can do very well in the exam without doing 9 10 or 11.
Yeah. Um, okay. Duplicate every node in the list by inserting the same node after the original node or insert a sum node at the head of the list that contains the total sum of all the previous nodes as data. We're going to vote on which one to do. Uh, you can you do a poll. We Which one do you want to see? Eight, nine, or 10? Because there's probably going to be Oh, one that we make, but I couldn't help myself. I made it up in the lecture notes as well. um after every two nodes insert a new node whose value is the sum of the previous two nodes.
This is like in the exam our questions become really convoluted sometimes like they're not things that you will need to do in real life but it's to test that you understand how to do conditions and do something based on a condition. So you want to duplicate every node in the list by inserting the same node after the original node and also the exam questions will be much better speced out. Some node at the head of the list that contains the total sum of all the nodes in that list or after every two nodes insert a new node whose value is the sum of those two previous nodes. So question seven, no eight, nine or 10.
>> All right, question 10.
>> Hey Uh, >> okay. Let's do it.
Bless you.
>> All right.
Okay. So if I'm inserting this node after every two nodes. Okay, that's that's fine. Let's just first of all you see this question in the exam. You're thinking what the heck who was on what when they came up with this question.
So you're going to do always start with the very basic thing that you can start with. Okay. So I know that I'm going to have to insert a node in there somewhere. Surely the actual making of the node will give me some marks. How do I make a new node to in preparation to insert a new node? So what are the steps I would do to insert a new node?
>> Yeah. So I would malic some space for it.
And what would I do then?
>> Why did you get upset?
Oh, you don't know who said that?
>> Cuz so many of them were your best throws.
>> Yeah. What What happened after I Malik some space? Come on, live a little.
There's only 10 minutes to go.
>> Please. You were so nice for Tom. Be nice for me.
You've malic. Did you want to put some data into it? Do you want to? You don't know what data you're putting into it yet, but you might. But you want to initialize some stuff. Maybe if I can spell initialize.
Okay, I'm going to malik some space. strct node new node is equal to malik size of strruct node. Okay, so that's going to create me some space for my new node.
I've got my standard library included in here. So I've got access to malik.
Amazing. Okay. So now whenever I'm going to be I could have just pressed tab. Okay, what happens? Where will be my edge cases in this question? So, I need to sum up the first two nodes, then the next two nodes, then the next two nodes, and the next two nodes. Yeah.
>> If I have an odd number of nodes, that's going to be a nightmare. Yep. What else?
>> Yeah.
>> There are less than two nodes or if the list is empty. Yep. So, we've got two things we may want to speak about. Odd number of nodes. And in the exam, the exam question would then say always assume there's an even number of nodes because this is a nightmare to like think about in the exam where you're time constricted. So odd number of nodes and in the exam you would have a clarification that would say even number of nodes only.
So that will be nice. You won't have to consider that. But what you will have to consider is if the list is empty list or if it has less than two nodes to start with. Okay. So how will I check if the list is empty before anything commences?
>> Yep. So if head is equal to null.
And now I want to check also that it has a little bit of stuff in it that I can work with. And how will I check that?
Yeah. So, I'm going to check if head next is equal to null because that tells me there's not really two nodes in this list. And if the list is empty or if there is less than two elements, then I'm just going to return the head of the head back to wherever it came from because I haven't modified anything.
Yeah, >> you could actually. Yes. Yes, you could.
Absolutely. Yep.
And you would save yourself one little bit of memory. Okay, great. You can absolutely do that if if you do assume that it's all good. Okay, great. Then what will I need to do next? I'm going to need to traverse the list, right?
Because I'm going to need to get the first two nodes, add them up, insert after them, get the next two, blah blah blah. But in any case, what I do need to do is I'm going to need at some point to traverse this list to make things happen.
So I'm going to set a current to the head of the list ready for my traversal.
Um and then I would like to have a condition and the condition will allow me to move through my list.
Okay. And what will my condition be?
current next is not equal to null or current is not equal to null or both or none.
>> Depends how you do it. You're right.
There is many different ways to do it.
>> Okay. So, you're suggesting current next.
>> Yes.
>> Just for those playing along at home, you want a diagram.
And I'm going to do it the way you've said just because for fun. Why not?
You're participating. I'm I'm I'm along for the party. Okay. So, we're looking through now. We need to be able to sum our first two nodes. How will we do that? What do we need to sum? Well, we need a plus sign. What else do we need?
Yeah, we need we need the things that we're summing. And we probably also need the variable that we're going to store the sum into. So, I'm going to have an insum and I'm going to say, can I please have the current data plus my current next data.
Okay, great. So, what that's done here is that's summed up two things for me.
And now I want to create the new node with this in it. So, I'm going to move my creation in here.
I did not mean to do that.
Okay. So, I'm going to malic some stuff.
I've created a new node by calling memory allocation. And now I'm going to initialize it with the things that it needs to have in it. So, the new node data is going to be equal to what?
>> The sum. Exactly. So, it's going to put into it the number that I've got in here, which is the addition of my current and my next nodes data. And then I'm going to need my new node next to initialize. And what's that going to be to start with?
Okay. No, no, go on.
>> And I will also what? Delete.
Yeah. So again, there's Yeah. So there's you're solving it a slightly different way which will impact how you're maneuvering through it. But this is what I want you to understand. There is not one single way to do something, right?
There's going to be two or three different ways even in the exam, even for these simple problems. Um okay, I'm going to leave it as that for a second.
We're going to come back to it in a second. Um, and we can solve it the other way as well, just so that you can see it solved in a number of ways.
But in the interest of time, I'm just going to uh move it along. Okay. So, great. So, I've got a new node now. Now, I need to insert that new node in. Okay.
And that new node has to be inserted because I was after those two nodes after the second of the two nodes that I have added up. What a I want to swear at this question actually. What was I on when I decided this was a good idea. Um and I feel like I don't have time to draw. So I I know I will draw it tomorrow. Don't worry. Okay. So what have we got? So, let's say we've got something that looks like this. 2 3 four five six seven.
And right now we've got this is my current.
That means this is my current next.
This means this is my current next.
Next.
And so on and so forth. Yeah.
Okay. So, this one is my current. This one is my current next. This one is my current next next. So, what I want to be doing, I've just summed up these two.
That was the current data plus current next data. And it gave me a new node with the sum five. And now I want to insert that new node in here in between these two after my two nodes.
So, how will I do the insertion now?
>> And this is going Someone is saying something. It's really hard to fil.
>> Okay. So, we're saying we want to do current.
Next, next.
Yeah. So, that that will give me from here to here. Yeah. Is going to be equal to >> the new node.
>> Pardon?
Yeah. Yeah. Yeah. Yeah. Yeah. So, now we've lost a little bit of something here because now we've lost the whole back of this list. It's gone. It's disappeared. We might need to something to keep track of that back section of the list as well. I can do that. And then what did you say? Sorry.
Say it again.
>> Yes.
>> So new node next is equal to the current next. That means that my new node next is going to get the current next is going to get it's going to point to >> next next.
>> Okay, great. So now my new node is pointing to this back end of the things >> and then I'm going to do current next is going to be pointing to the new node and will that turn it around?
>> Okay. And then current next >> is equal to new node.
>> I mean we can try it. That's the best way to do it. And then I really want to move things along here. Yeah. So I'm going to move my current and I want to skip the currents, don't I? So will I move my current too? Because I want to skip two nodes at a time.
Yep.
Or I can just if I did this correctly, I can just say new node next. Yeah.
Because that means I've got the node after the new node that I've inserted.
So I'll have my next two.
Yes. No. Maybe everyone's just going like, "What the heck is happening here?"
Should we try it?
Let's try it.
Okay.
Okay, that was amazing. It compiled.
Okay. And let's do this. 2 3 4 5 6 7 list. Let's see what happens. Amazing.
That list is empty.
It could be because I've >> No, that's all.
>> Ah, what should I return?
>> Head. Yeah. And note for the exam, the exam question always has return null or return something random. Don't forget to change the return like that.
Okay, let's run it. Okay, great. So now we have uh not correct but starting to get there is a new node but it's in the wrong place and there is four.
Now it's adding these two nodes. Yeah.
So it's working but there are some logic issues. Yeah. And it's 12:57, which means we don't have time to fix the logic issues today, but we do have time to fix the logic issues tomorrow. Okay?
And I would say that it's all the next next and next and next next that are causing the logic issues, which is why it's time to draw a diagram. But it's not time to draw a diagram. It's actually time to go and have some lunch and then draw a diagram tomorrow.
All right. I hope today was good. Is there anything left in the lolly bag?
Give it out.
>> Enjoy the rest of your day and I will see you tomorrow.
>> If anyone wants a lolly or chocolate, just Heat. Heat.
関連おすすめ
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











