Algorithms

studied byStudied by 0 people
0.0(0)
Get a hint
Hint

Binary Search

1 / 7

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

8 Terms

1

Binary Search

Starting at the middle item of the list and repeatedly dividing the list in half

New cards
2

Linear Search

Going through all the items in a list until the target item is found

New cards
3

Binary search pseudocode

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

New cards
4

Bubble sort

Continuously goes through a list until the list has been sorted.

  • It looks at the current value and checks it with the adjacent value. If the adjacent value is higher, the numbers are swapped

  • Each swap is called a pass

New cards
5

Bubble sort pseudocode

numbers = [9, 5, 4, 15, 3, 8, 11]

numItems = len(numbers

while i < (numItems - 1) and (flag=true)

flag = false

for j = 0 to (numItems - i - 2)

if number [j] > numbers [j+1]

temp = numbers [j]

numbers [j] = numbers [j+1]

numbers [j+1] = temp

flag = true

end if

print (numbers)

next i

New cards
6

Linear Search pseudocode

choice = input

found = false

counter = 0

while counter < len (names) and Found = false

if array [counter] = choice:

Found = true

position = counter

end if

counter = counter + 1

end while

New cards
7

Insertion Sort

Sorting into two columns, sorted & unsorted

  • The items from the unsorted column are moved to the sorted column in every pass

New cards
8

Insertion Sort pseudocode

First = 0

last = MaxItems

for count2 = First + 1 to last

currentItem = list(count2)

count = count2 - 1

do while list(count) > currentItem and count2 > 0

list (count+1) = list (count)

count = count - 1

loop

list(count + 1 = currentItem)

Next

New cards

Explore top notes

note Note
studied byStudied by 2 people
... ago
5.0(1)
note Note
studied byStudied by 26467 people
... ago
4.5(126)
note Note
studied byStudied by 14 people
... ago
5.0(2)
note Note
studied byStudied by 55 people
... ago
5.0(1)
note Note
studied byStudied by 1 person
... ago
5.0(1)
note Note
studied byStudied by 17 people
... ago
5.0(1)
note Note
studied byStudied by 158 people
... ago
5.0(1)
note Note
studied byStudied by 7 people
... ago
5.0(1)

Explore top flashcards

flashcards Flashcard (20)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (29)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (98)
studied byStudied by 23 people
... ago
4.0(1)
flashcards Flashcard (161)
studied byStudied by 8 people
... ago
5.0(1)
flashcards Flashcard (67)
studied byStudied by 16 people
... ago
5.0(1)
flashcards Flashcard (43)
studied byStudied by 9 people
... ago
5.0(1)
flashcards Flashcard (41)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (48)
studied byStudied by 9 people
... ago
5.0(1)
robot