 Welcome back in the last segment, we considered the problem of deciding whether a set of disks is intersecting or not intersecting. In this segment, we are going to look at arrays of graphics objects whether that is even possible and we are also going to conclude this entire lecture sequence. So, can we have arrays of graphics objects? Indeed we can, so if I create an array, we will end up creating multiple graphics objects. So, for example, I can write turtle t and that gets me an array of turtles, three turtles to be in particular. So, if I write such a statement, this statement has to appear after I write init canvas because when I create the turtle, the array of turtles, the turtles will be created on the canvas as well. So, such a statement has to appear after I have executed init canvas. And furthermore, if I create such an array, I will get three turtles and they will be created at the same position as what we get when we create a single turtle, which is all of them will be created sitting at the center of the screen and furthermore, they will be all facing right. So, I can in a similar manner, I can also create say circles. So, I can write say circle C maybe 15. Now, there is a slight difference between turtles and circles. So, when I create a circle, I am expecting to give it center and radius. So, when I create an array, there is no room for me here in this syntax to give the center and the radius. So, what I need to do if I am creating an array of circles or indeed creating an array of lines or rectangles is that subsequently, I have to execute C dot reset with X, Y or expand R for an individual circle or for an circle from an array, I have to issue say C dot C of I dot reset X, Y and R and here I can specify the X and Y coordinates of the center of the ith circle and also the radius of the ith circle. Reset command is discussed in chapter 5 of the book. So, this first circles will create, will indeed create an array of circles, but they will not have radii, they will not have centers, they will sort of be dummy circles until you do this reset. But coming back to turtles, if I issue this, you will indeed get turtles on the screen, but they will be sitting in the same position which is the center of the screen and pointing all pointing to the right. Now, I can talk to one turtle and I can write T of 1 dot right, which is what you might expect. This will turn the first turtle, remember there is a zero turtle as well, this will turn the first turtle right by 120 degrees. So here is the program, so let us see what it does. So it is going to first create the canvas, then it is going to have three turtles created, then it will turn T1 left by 120, T2 left by 240. So what is this going to do? So I have three turtles, one on top of the other, T1 is going to turn left by 120. So one of the turtles is going to start facing in this direction. So this is turtle 1, the other turtle is going to face by turn by 240, so it is going to face in this direction. So this is going to be turtle 2 and turtle 0 is going to be facing in the same direction. We have not changed the orientation of turtle 0. Next I have a repeat statement, but the repeat statement is a little bit complicated because inside it there is a for loop. So inside I am going to do something for every turtle, for every turtle I am going to do the same thing forward 100 and left 360 upon 8, you remember what this does? So if this had been just forward 100 and left 360 upon 8, this would have been drawing an octagon with side length 100. So effectively each turtle is going to draw an octagon, but this turtle is pointing in this direction. So it is going to draw an octagon which looks something like this. This turtle is going to draw an octagon which looks something like this. And this turtle is going to draw an octagon which looks something like this. So starting over here, so it is going to go forward, then left, so like this. So that is what it is going to do and then there is it is going to wait for you to see what has happened and that is the end of it. So let us see this in action. So this is the program, this is pretty much what you have on the slides. So let us compile it and let us run it. So you can see that the three turtles are drawing three octagons but they are drawing octagons in different positions and this way you can create interesting designs and interesting patterns or you can choreograph the turtles in interesting ways if you want. And incidentally you will remember that we did something like this earlier when we were looking at when we were studying chapter 5. Over there we just had names T1, T2, T3, but now we can actually use an array and since we have an array we do not have to write the commands separately for the separate turtles, we can put them in a loop. So this is as far as what I wanted to say about arrays and the applications of arrays and so let me make some concluding remarks for this entire lecture sequence. So first of all an array is just a way to store many objects of the same type in memory without having to define a separate variable for each object. So by defining an array you get many variables defined in one shot. So you do get all the variables you want but you do not need to define them one at a time separately. The index allows you to choose which of the variables you want to refer to at the current moment and the index must be between 0 and the length minus 1 or the size minus 1, the size of the array minus 1 and it can be an expression and index may sometimes play an active role in the sense that when the roll numbers are consecutive from 0 to n minus 1 we do not need to store the roll numbers. So the index or the position of the element is going to tell you what roll number it is. So we do not actually store the roll number, we do not actually store the index either but we can refer to the index, we can say give me the ith element of this array and that i is the index and that is sort of implicitly present and when we are dealing with certain kinds of problems. So if say the case of the roll numbers, if the roll numbers are in 0 through n minus 1 we do not really need to store the roll numbers. Similarly in the polynomial representation we had n coefficients but we do not need to store i, we just have to store ci or the ith coefficient because the coefficients are stored in sequence we know the which coefficient corresponds to which power in the polynomial. In the taxi dispatch the position, the index also played an active role because using that and using that variable front we could say, we could figure out which customer, which taxi driver came earlier and which tax driver came later. Sometimes of course the index may not have any significance. So in our example where we had roll numbers, sort of general roll numbers as well as marks. So we had to store the general variables as well and essentially what was going on over here is that we were storing sets of pairs and so those pairs could have been stored in an arbitrary order. One point that we have to note is that indexing into an array happens very fast independent of how many elements there are present in the array. So this is something that we will discuss a little bit later in the next lecture but this is something that you have to keep in mind. So when you write marks of i, some little bit extra time is there beyond accessing a variable, a simple variable but it is really pretty much the same time as accessing an ordinary variable just a little bit more and importantly it does not depend on how many elements you have in the array. One more remark when you have arrays there are some very natural idioms that you should understand. So the simplest thing is that you may have to scan through all the, go through all the elements in the array to find a matching element. So this is sometimes called a linear search. You may do some calculation which determines the index of the histogram, index of which element is to be looked at. So you are not going to, you may not go through the indices in order always but you may do some interesting calculation and this is something that happened in the histogram example. You may use an array like a queue of elements which wait for something to, which wait for something to happen and after which they leave the queue and this is something that happened in the taxi dispatch example. And of course we also saw the accumulation idiom and we also saw the filtering idiom. So that is basically it for this lecture. I will again remind you that in the textbook there are lots of problems related to arrays at the end of chapter 14 and I would like you to start solving those problems. But we are going to have an additional lecture on chapter 14 so which is going to come up next. So let me conclude this lecture at this point and thank you.