L/B Search Flashcards

1
Q

What’s linear search algorithm

A

Function linear_search(Array , value ):
Ptr = 0
While ptr <= len(A) and ptr[A] != value:
Ptr = ptr + 1
End while
If ptr. => len(A):
Return “failed”
Else
Return ptr
End if
End function

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

Binary search algorithm iterative

A

Function Binary ( A, Value , low , high )
Found = false
If high < low then
Return “not in order”
End if
While found == False:
Mid = (low + high /2)
If A[mid]< value then
High = mid-1
Elif A[mid]> value then
Low = mid +1
Else
found = true
End if
Endwhike
Return mid
End function

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

Linked list traversal - putting it in order

A

function outputLinkedListInOrder0
pt = start
repeat
node = node(pt)
return node
pir = node (pit -
until pt == 0 endfunction

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