Types of Algorithms Flashcards

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

Features of a bubble sort

A
  • Uses an incremental approach
  • Slow and inefficient
  • Not for large lists
  • Simple to understand
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

n = items.length
swapped = True

while n > 0 AND swapped - False
n = n - 1
for index = 0 to n - 1
if items [index] > items [index + 1] then
swap (items[index], items[index+1])
swapped = True
end if
end for
end while

A

Bubble Sort Psuedocode

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

Features of an insertion sort

A
  • Uses an incremental approach
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

for index = 1 to items.length:
current = items[index]
index2 = index

while index2 > 0 AND items[index2 - 1] > current
items[index2] = items[index2 - 1]
index2 = index2 = 1
end while

items[index2] = current
end for

A

Insertion Sort Pseudocode

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

Features of a linear search

A
  • Start at the beginning of the list
  • Compare search value to 1st item
  • Can be an unordered list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

found = False
index = 0
while found == False AND index < items.length
if items[index] == item_to_find then
found = True
else
index = index + 1
end if
end while

A

Linear Search Pseudocode

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

Features of binary search

A
  • List must be ordered
  • Split list in half
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

found = False
first = 0
last = items.length - 1

while first <= last AND found == False
midpoint = (first + last) DIV 2
if items[midpoint] == item_to_find then
found = True
else
if items[midpoint] < item_to_find then
first = midpoint + 1
else
last = midpoint - 1
end if
end if
end while

A

Binary Search Pseudocode

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