#Coded by Stefan Ralph | Indenting is required DECLARE ARRAYLIST:ARRAY[1:11] OF INTEGER; //Enter Values inside the ARRAYLIST PROCEDURE BinarySearch(search:INTEGER,Array:ARRAY[1:10] OF INTEGERS) Max←10 Min←0 Found←False NotPresent←False while (Found=False) AND (NotPresent=False) DO Mid←(Max+Min)DIV 2 IF search=Array[Mid] THEN Found=True ELSE IF Min>= Max THEN NotPresent←True ELSE IF search < Array[Mid] THEN Max←Mid-1 ELSE Min←Mid+1 END IF END IF END IF END WHILE IF Found=True THEN OUTPUT("The position is at ", Mid," using binary search") ELSE OUTPUT("Not Found") END IF END PROCEDURE
This searching algorithm will only work for arrays that have numbers stores in it as there must be way to compare the weight of each value in each node. This could be improved for any sorting by converting characters to ASCII values but for school knowledge, this is enough...
The code is in python for this algorithm
The code is free for anyone to copy and use...The copied code must have the same code and indentation as above