u2 Flashcards
precondition
a proposition concerning the inputs of an algorithm, such that if every precondition holds, then the algorithm will terminate with the correct output.
postcondition
a proposition relating the outputs to the inputsof an algorithm, such that if every precondition holds, then when the algorithm terminates, each postcondition holds
Inertial convention
Aspects of an ADT’s state not referred to in the postcondition for an operation are unaffected by the operation
invariant
a proposition concerning ADTs state that is always TRUE
Binary search
•Set the partition to be the input sequence.
•Find the index of the midpoint of the partition. If the target is at the midpoint then the item is found. Otherwise divide the partition into two halves, Left and Right, at the midpoint. If the targetis less than the item at the midpoint then make Left the new partition. Otherwise make Right the new partition. Repeat the process with the new partition.
O(log n)