You are on page 1of 1

//ALGORITHM FOR BINARY SEARCH AND LINEAR SEARCH IN AN ARRAY START STEP 1: Read the size of array A[n]

STEP 2: For i=1 to n step 3 STEP 3: Read A[i] STEP 4: Read the number to be searched (m) STEP 5: Print 1.Binary search 2.Linear search STEP 6: Read choice (ch) STEP 7: Assign flag 0 STEP 8: if ch = 1 then STEP 9: Assign upper n, lower 1, mid ([upper+lower/2)] STEP 10: While upper is greater than or equal to lower repeat steps 11-16 STEP 11: if A[mid] = m then STEP 12: Print The position of m is mid STEP 13: Assign flag 1 STEP 14: Else if A[mid] is greater than x then STEP 15: Assign lower mid STEP16: Else assign upper mid STEP 17: if ch = 2 then STEP 18: For i=1 to n by 1 steps 19-20 STEP 19: if A[i] = x then STEP 20: Print the position of x is i STEP 21: if flag = 0 STEP 22: Print No: not found STOP

You might also like