 Dear students in the last module we talked about recursion and this module is the continuation of the previous module where we defined an algorithm for binary search using recursion and we did not discuss that how this function will be terminated. So in today's module we will be discussing that how recursion can be controlled or how when that recursive function can be terminated. So remember this function that we have initially the whole list and the target value which is being sent to the function and then we are saying if list is empty this was the statement which we did not execute in the previous module and we will be doing it by today then we moved on that select the middle entry from the list and put it in the test entry and then see if the test entry is equal to the target value then it's okay we have found the required name however if target value is less than then select the sub list that is the portion of list preceding the test entry and that sub list should be passed to the search function again. So when we say that this is going to be passed to the function again this mean at this point this search function will be executed again by leaving whatever it was doing previously now with the sub list which has been now passed by this function. So this mean the actual list which was passed by a previous function is on hold as the call of your friend was on hold in the previous module and similarly if the target value is greater than test entry then the sub list is computed by getting the portion of the list following test entry and that sub list is again sending to the search function this means again the function is being executed. So let's execute this function for a normal value first and then we will check or go for the when the list is empty. So let's have these 15 names Abhidha, Ahmad, Asif, Aisha, Afzal, Bashir and so on and we want to search Zahid. So what would be the procedure? First of all you know that we will find the midpoint of this list. So the midpoint is Khalid. So we will take Khalid and we will compare Khalid with the Zahid versus Khalid in the first step. So when we compare it you can see that Z has bigger, larger, more ASCII code as compared to K. So this means that our required information lies in this list. So this is the sub list which will be passed again to the search function and we will leave all of this and we will not be searching and going over here. So this means next time we have the sub list only starting from 9th position until 15th position and then again we are trying to find the midpoint. So 1, 2, 3, 4, 5, 6, 7, 7 are the total elements and the midpoint is 1, 2, 3, 4, Yahya. So now Zahid will be compared with Yahya. So this is the second step and when we compare Yahya we again found that Z in Zahid has more ASCII value than Y in Yahya. So this means our actual list is not from here. It lies in this. So in the third step we are having only Eunus, Zahid and Zubair. And again we will find the midpoint and that midpoint is Zahid. When this Zahid will be compared with the Zahid which was our QD that will be completely compared as the ASCII values of both Zahid and Zahid is equal. So we found our match. So let's test this first condition that when the list is empty and how this function will terminate. So let's do it. So we now want to find for the same example we want to find Ajmal. So again first step would be to select the midpoint Khalid and this will be compared with Ajmal. And when we compared Ajmal with Khalid we found that this list is of our not of any use and our required information lies in the first seven entries. So this means Abidah, Ahmad, Asif, Aisha, Afsal, Bashir and Fawad will be selected to be proceeding for the next comparison. So these are seven. Again the midpoint will be selected which is Aisha. So this Ajmal will be compared with Aisha and again we will see that A is matched with the A that is fine but Y is not matched with the J. So the ASCII value of Y is more as compared to the ASCII value of J. So this means that Ajmal lies in the in somewhere upside. So this means next time this list will be selected and that is Abidah, Ahmad and Asif. Next time we will select again the midpoint which is Ahmad and we will compare it with the Ajmal and when we compare it with the Ajmal we can see that H is actually lower than the Ajmal. So this means Ajmal can be found somewhere after Ahmad. So we will select Asif. So the next iteration we will have only one entry as a sublist that is Asif and that is the midpoint as well. So that Asif will be compared with the Ajmal. So when we compare Asif with the Ajmal so we can see that A is compared with the A but J is not compared with the S because S has the greater ASCII value. So this means Ajmal can be found somewhere upside and you can see that in this list there is only one element and there is nothing upside. So this means this empty list will be selected and this empty list will be passed on to the search function again and when the search function will find this empty list in the first statement it says if list is empty, yes now the list is empty then report that the search failed. This means we did not find anything. So this is basically the recursion or a perfect example of recursion that how we have executed the binary search algorithm using number of steps and calling again and again the same function and at the end we are left with the empty list that becomes the base condition or base case or sometime it is called degenerative case for terminating or for completing the recursion process. So this first statement is basically the statement which is terminating this recursion process. So if we summarize today's module we have in depth learned about recursion and we have seen that how the recursion can be controlled. So this means when we want to define a function using recursion then the first statement of that function should be the base condition should be some condition which should terminate that function at certain point as we have seen that when the list was empty in our case the function was terminated but that condition should be written at the top of the recursive function normally and then it goes either in the left side or in the right side and so on.