QUICK Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Bubble sort

A

Procedure BubbleSort(List)
n = len(list)
repeat
swapped = false
for i = n to n - 1
if list[i - 1] > list[i] then
temp = list[i - 1]
list[i-1] =list[i]
list[i] = temp
swapped = true
end if
end for
until not swapped
end procedure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

insertion sort

A

Procedure InsertionSort(List)
n = len(list)
for i = n to n - 1
temp = list[i]
z = i
if z > 0 and list[z - 1] > temp
list[z] = List[z-1]
z = z - 1
End While
List[z] = Temp
Next i
End Procedure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

binary search

A

Function BinarySearch(List, SearchItem)
Lo = 0
Hi = Len(List) - 1
While Hi >= Lo
Mid = Lo + (Hi - Lo ) DIV 2
If SearchItem = List[Mid] Then Return Mid
Else if SearchItem < List[Mid]
Then
Hi = Mid - 1
Else
Lo = Mid + 1
End If
End While
Return -1
End Function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly