Algorithms
Algorithms
Bubble Sort
swap=True
size=nlist.length()
count = 0
While (count <= (size-1) AND swap == True)
swap = False
FOR index= 0 to (size-(count + 1))
if nlist[index] > nlist[index + 1] then
swap = True
temp = nlist[index]
nlist[index] = nlist[index + 1]
nlist[index + 1] = temp
endif
next index
count = count + 1
endwhile
Insertion Sort
Procedure insertionSort(aList:ByRef)
FOR index = 0 to aList.length() -1
currentValue = aList [index]
position = index
WHILE (position > 0 AND aList[position -1] > currentValue)
aList[position]= aList[position-1]
position = position -1
aList[position] = currentValue
ENDWHILE
NEXT index
End Procedure
Linear Search
A datastore is created (list, array etc)
SearchItem = Input(“Enter the item you are looking for: “)
FOUND = False
Index=0
While FOUND = False and index <Length(List)
IF List[index] = SearchItem THEN
FOUND = True
Else
Index = Index + 1
End IF
End While
IF Found = True Then
Print (“the item found”)
Else
Print (“the item is not in the list”)
Binary Search
Array list[20]
FOUND = False
Lower = 0
Lower = MiddlePostition + 1
ELSE
Upper = MiddlePostition – 1
ELSE
FOUND = True
ENDIF
ENDIF
End While
Else
End If