0% found this document useful (0 votes)
5 views5 pages

Algorithms

The document outlines four algorithms: Bubble Sort, Insertion Sort, Linear Search, and Binary Search. Each algorithm is described with pseudocode, detailing the steps for sorting a list or searching for an item within a list. The document emphasizes the need for sorting before applying the Binary Search algorithm.

Uploaded by

hamoget616
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Algorithms

The document outlines four algorithms: Bubble Sort, Insertion Sort, Linear Search, and Binary Search. Each algorithm is described with pseudocode, detailing the steps for sorting a list or searching for an item within a list. The document emphasizes the need for sorting before applying the Binary Search algorithm.

Uploaded by

hamoget616
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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]

If the List is not in order, a sorting algorithm is applied

SearchItem = Input(“Enter the item you are looking for: “)

FOUND = False

Lower = 0

Upper = Length(List) – 1 (Last item in the list)

While FOUND = False and Lower <= Upper

MiddlePosition = (Lower + Upper) DIV 2

IF List[MiddlePosition] < SearchItem Then

Lower = MiddlePostition + 1

ELSE

IF List[MiddlePosition] > SearchItem Then

Upper = MiddlePostition – 1

ELSE

FOUND = True

ENDIF

ENDIF

End While

IF Found = True Then

Print the item found

Else

Print the item is not in the list

End If

You might also like