Hello. In this third sequence on algorithmics, we are going to talk about elementary instructions. We are going to look at the core of algorithmic, and explain in detail what instructions the computer is able to execute. The first one is an assignment, which we talked about in the previous sequence. We have a variable and we want to modify its value. There can be I which receives a given value, 0, 17, 42, or we can have a value calculated using other values and other variables, for example, I receive i+1, so if I equalled 3, it now equals 4. The next instruction is the test. So if the test is a Boolean value- a Boolean value is either right or wrong -then we execute an instruction, and if it is wrong, then we execute another instruction. So the Boolean test can be "is there a value higher than 10?", which will give us the Boolean result, so is the answer true or is it false? At that moment, we execute an instruction or another instruction. Another kind of test would be "is there a chance of going beyond maximal or minimal values for one kind of variable?". For example, if you have an integer value coded on a byte between 0 and 255, we may want to make sure the sum will not exceed 255. Another test case is when you access the inside of a chart, you want to make sure you are accessing the right memory space, so we are going to test that we are indeed inside two borders of a chart. The next instruction is the sequence. The point of the computer is that it is able to execute successively a certain amount of operations, in this case, instructions. For example, we can perform an assignment, then a test, or an assignment, a loop and a test, or a certain amount of successive assignments. There is a more interesting instruction, the loop. The best-known loop when talking about charts is the "for" loop, so for a certain variable iterating from one value to another value, a particular instruction is executed. It can be used For example when looking for the maximum value in a chart, we are going to browse it and look for the highest value. If you want to calculate the average mark, or if you want to fill a chart up to initialise it, you create a "for" loop. The "as long as" loop is a more general one so more things can be done with it, so that's "as long as" a certain Boolean, a certain instruction is executed. A classical use of the "as long as" loop is a convergent sequence, so when calculating the iterations of a certain sequence until the values do get close enough. Beware of the " as long as " loop, because you have to make sure the program will stop, because if not, the " as long as " loops may keep running indefinitely, and so the program would be running indefinitely, and so those problems are called termination problems, so make sure the algorithm is going to stop. So with all those instructions, the sequence, the test, the loop and the variable assignment, all the algorithms in the world can be done. Just take all those instructions, in any way you like, as much as you like, and you obtain any kind of algorithm. So you just need to know these instructions to be able to do anything in algorithmic. Now, in the "let's do something in algorithmic" series, I will present to you an example called the binary search. The idea is to start from a chart that has been classified, it's very important that it is, and we are going to look for a particular value. T is the chart, its size is N strictly positive, and we are going to look for the value V, if it is in the chart or not? The output is a Boolean, so true or false, which will define if that value appears in the chart. there are 2 variables, "inf" and "sup", that represent the part of the chart we are investigating. In the beginning, we are investigating the whole chart, then we are only going to look at half of the chart, a quarter of the chart, one-eighth of the chart, etc. To do that, take the part of the chart we are investigating which is between "inf" and "sup", then calculate the middle between the 2, that will be I, and so you look at the value you find there. If that value is higher than v, that means v, if it is there, it is in the left part of the chart, and if that value is smaller than v, that means it is in the right part of the chart. So we are going to modify "inf" and "sup" in order to keep only the smaller part of the chart, so the shrinking part where v is likely to be. If, in the end, "inf" and "sup" have swapped places, that may seem weird, but it will happen in the event that the element we are looking for isn't in the chart, then the output will be "false". A small example: here you have a small chart with 9 elements. You have to imagine this kind of algorithm is executed on charts, containing several million elements, so I search for 5, and yes, I know that there is No 5 in the chart, but that allows the algorithm to uncoil completely. Let's say I look for 5 to assess whether it is in the chart. So I have the "inf" and "sup" variables that are at both ends of the chart for now."inf" points towards -5 and "sup" points towards 25, so I calculate I which is between "inf" and "sup",so it gets here, so the value associated with I is 4. So 4, of course, is not 5, so it means I did not find the element, and then, 4 is smaller than 5, which means that if 5 is in the not chart, it is located in the upper part of the chart, so the new "inf" will be i+1 because I know the 5 can't be between the beginning and the I of the chart. So between "inf" and i, but I already know that I am not 5, so between "inf" and i-1, the new "sup", will be i-1, so it will also be "inf". Then I calculate the average between "inf" and "sup", the average will be exactly the same value, so pointing towards 4. Of course, I realise that 4 is still not 5, so 5 is in the upper part, so "sup" and "inf" have switched places, which allows me to stop the algorithm and say that 5 is not in the chart. Just a quick remark,actually it's better not to calculate (inf+sup)/2 but that other expression in order to avoid capacities overload.