Q. A list namely Adm stores admission numbers of 100 students in it, sorted in ascending order of admission numbers. Write a program that takes an admission number and looks for it in list Adm using binary search technique. The binary search function should use recursion in it.


You can understand by Watching video :-



Answer =

def ad ( adm , num , low = 0 , high = 99 ):
    if low > high :
        return num,"is not exist in adm"
    mid = int((low + high)/2)
    if num == adm[mid] :
        return num,"exit in on index  number : ",mid
    elif num < adm[ mid ] :
        high = mid-1
        return ad ( adm , num , low , high )
    elif num > adm[ mid ] :
        low = mid + 1
        return ad ( adm , num , low , high )
    else :
        return num,"is not exist in adm"
        
adm = eval(input("Enter list of 100 student : "))
num = int(input("Enter a number : "))
print(  ad ( adm , num) )

Output :-

Enter list of 100 student : [1332, 4046, 38352, 46742, 59041, 66755, 71962, 74474, 91218, 96831, 102676, 104670, 122989, 125446, 140543, 156829, 165044, 165952, 171412, 177484, 180288, 186913, 187107, 198536, 213977, 232908, 258800, 260184, 267397, 270060, 270138, 274469, 285150, 330869, 332027, 342698, 345563, 358846, 363698, 366076, 379771, 382261, 394258, 398026, 405305, 432709, 434943, 448019, 451367, 459455, 460265, 473065, 480441, 482909, 489097, 517987, 569324, 573629, 579570, 586111, 600919, 601620, 612782, 621224, 637010, 652234, 676225, 680108, 682364, 710911, 711744, 720095, 732746, 762496, 771681, 792615, 794064, 797157, 799053, 799546, 812835, 852521, 862308, 863911, 873328, 881161, 886017, 891828, 892341, 896553, 899672, 909789, 920731, 929754, 935556, 936345, 942234, 952776, 956536, 986789]
Enter a number : 394258
(394258, 'exit in on index  number : ', 42)
>>> 

Enter list of 100 student : [1332, 4046, 38352, 46742, 59041, 66755, 71962, 74474, 91218, 96831, 102676, 104670, 122989, 125446, 140543, 156829, 165044, 165952, 171412, 177484, 180288, 186913, 187107, 198536, 213977, 232908, 258800, 260184, 267397, 270060, 270138, 274469, 285150, 330869, 332027, 342698, 345563, 358846, 363698, 366076, 379771, 382261, 394258, 398026, 405305, 432709, 434943, 448019, 451367, 459455, 460265, 473065, 480441, 482909, 489097, 517987, 569324, 573629, 579570, 586111, 600919, 601620, 612782, 621224, 637010, 652234, 676225, 680108, 682364, 710911, 711744, 720095, 732746, 762496, 771681, 792615, 794064, 797157, 799053, 799546, 812835, 852521, 862308, 863911, 873328, 881161, 886017, 891828, 892341, 896553, 899672, 909789, 920731, 929754, 935556, 936345, 942234, 952776, 956536, 986789]
Enter a number : 874562
(874562, 'is not exist in adm')
>>>





Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post