00:01
Let x1, x2, x3 up to xn be an array, that is an array of n numbers.
00:09
Consider the following algorithm.
00:12
For i belonging to the set 1, 2, 3 up to floor of n -half, we do three operations, 3 3 assignments.
00:24
T is assigned the value of xi, xi is assigned the value of n, sorry, xn minus i plus 1, and then x n minus i plus 1 is assigned the value of t in part a we want to talk about how many operations of assignment does this algorithm perform and in part b what does the algorithm due to the array so let's see how many assignment operations and that's the first thing we've got to say is that this operation here we are counting is the assignment operations that is put a value on a memory location on the algorithm.
01:22
The assignment.
01:29
And as we see for each i in the set here, we have three assignments.
01:38
This first one, t is assigned the value of x sub i, then this next assignment, x sub i is assigned the value of x n minus i plus i, and then x n minus i plus side is assigned the value of t so we have three assignments for each value of this set so the number of assignments in the whole algorithm will be three times the number of values in the set from i equal one to up to floor of n half let me put here in fact this to be clear of that is the floor of and half that is we calculate the half of index n or number n number of elements of the array and then find the floor of that number that is the integer less than to that number the greatest of those integers if n over 2 that is n half is an integer itself floor of n half will be the same number and half but it's not an integer number we got to find find the integer number less than or equal to n -half that is closest to it.
03:04
So we have then three times number of assignments is three times the number of elements, as i said in this set of indices, and that is n -half floor.
03:25
So the option you got to choose in that case is the fourth option from top to button.
03:30
So it's the fourth option, top bottom, or the second from bottom to top.
03:46
And then, let me put that again here, three and have floor assignments.
03:59
And then what does this algorithm do to the array? well, as you can verify here, these operations, the three assignments here are swapping the values of xi and x minus i plus one.
04:14
So the three assignments in each loop inside the loop or inside the four statement, let us swap the values xi and xn minus i plus one in the array...