Algo
Algo
AIM
Write a python program to find the Fibonacci series
algo
1. Read n
2. Set fst = 0, sec = 1
3. Print fst, sec
4. for i in range 0 to n-2, loop:
4.1. set sum = fst + sec
4.2. set fst = sec, sec = sum
4.3. print sum
RESULT
The program was coded and run successfully
-----------------------------------------------------
AIM
Write a python program to find the factorial of a number using
function
algo
1. define function fact(n):
1.1. set p=1
1.2. for i in range 1 to n+1, loop:
1.2.1. set p=p*i
1.3. if n==0, then return 1
1.4. else return p
2. Read n
3. Call res=fact(n)
4. Print res
RESULT
The program was coded and run successfully
---------------------------------------------------------
AIM
Write a python program to implement binary search in a list
algo
1. define function binsearch (lis, val, beg, end):
1.1. set loc=0
1.2. while beg<=end, loop:
1.2.1. set mid = int((beg+end)//2)
1.2.2. if a[mid]<val, set beg=mid+1
1.2.3. else if a[mid]>val, set end=mid-1
1.2.4. else, return mid
1.3. return -1
2. Read list a
3. Set l = length of a
4. Sort list a
5. Read Enter value to be found
6. Call result= binsearch (a,value,0,l-1)
7. Print index position = result
RESULT
The program was coded and run successfully
----------------------
AIM
Write a python program to implement linear search in a
dictionary
algo
1. create dictionary dict = {}
2. Read elements of dict
3. Set l= length of dict
RESULT
The program was coded and run successfully