Lecture 8_Data structure and algorithm
Lecture 8_Data structure and algorithm
Programming Methodology
Lecture 8
Data Structure and Algorithm - Intro
Prof. Jiangfan Yu
School of Science and Engineering
Data structure and algorithm
• A data structure is a systematic way of organizing and
accessing data
• Perform independent
experiments on many
different test inputs of
various sizes
• This activation record stores the function call’s parameters and local
variables
• For any index j, we know that all the values stored at indices 0, . . . ,
j−1 are less than or equal to the value at index j, and all the values
stored at indices j+1, . . . ,n−1 are greater than or equal to that at
index j
The strategy of binary search
• We call an element of the sequence a candidate if, at the current
stage of the search, we cannot rule out that this item matches the
target
• The algorithm maintains two parameters, low and high, such that all
the candidate entries have index at least low and at most high
• Initially, low = 0 and high = n−1. We then compare the target value to
the median candidate, that is, the item data[mid] with index
mid = (low+high)/2
The strategy of binary search
• If the target equals data[mid], then we have found the item we
are looking for, and the search terminates successfully