Searching and Sorting Algorithms - Chapter 11 Flashcards
Blank is a search algorithm that starts from the beginning of a list, and checks each element until the search key is found or the end of the list is reached.
Linear search
An algorithm’s blank is the time the algorithm takes to execute. If each comparison takes 1 µs (1 microsecond), a linear search algorithm’s runtime is up to 1 second to search a list with 1million elements, 10 s for 10million elements, and so on. Ex: Searching Amazon’s online store, which has more than 200 million items, could require more than 3 minutes.
runtime
An algorithm typically uses a number of steps proportional to the size of the input. For a list with 32 elements, linear search requires at most blank comparisons
32
Blank checks the middle contact first. If the desired contact comes alphabetically before the middle contact, binary search will then search the first half and otherwise the last half. Each step reduces the contacts that need to be searched by half.
binary search,
Blank is a faster algorithm for searching a list if the list’s elements are sorted and directly accessible. Binary search first checks the middle element of the list. If the search key is found, the algorithm returns the matching location. If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element).
Binary search
In binary search, for an N element list, the maximum number of steps required to reduce the search space to an empty sublist is blank
floor(log2 N) + 1
Python has a special blank operator, //, that automatically drops the quotient’s decimal portion, so this operator is used when calculating the middle index: mid = (high + low) // 2.
floor division
A blank is an operation that, for a given processor, always operates in the same amount of time, regardless of input values.
constant time operation
In practice, designing an efficient algorithm aims to lower the amount of time that an algorithm runs. However, a single algorithm can always execute more quickly on a faster processor. Therefore, the theoretical analysis of an algorithm describes runtime in terms of number of blank, not nanoseconds.
constant time operations
The blank being used, as well as the blank running the code, both affect what is and what is not a constant time operation.
programming language
hardware
Common constant time operations
Addition, subtraction, multiplication, and division of fixed size integer or floating point values
Assignment of a reference, pointer, or other fixed size data value.
Comparison of two fixed size data values.
Read or write an array element at a particular index.
An algorithm with runtime complexity T(N) has a blank and blank.
lower bound and an upper bound
Blank A function f(N) that is ≤ the best case T(N), for all values of N ≥ 1.
Lower bound:
Blank: A function f(N) that is ≥ the worst case T(N), for all values of N ≥ 1.
Upper bound
Given a function T(N), an blank of lower bounds and upper bounds exist. Ex: If an algorithm’s best case runtime is T(N) = 5N + 4, then subtracting any nonnegative integer yields a lower bound: 5N + 3, 5N + 2, and so on.
infinite number
Two additional criteria are commonly used to choose a preferred upper or lower bound. The preferred bound:
is a single-term polynomial and
bounds T(N) as tightly as possible.
Blank is the classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function.
Asymptotic notation
Three asymptotic notations are commonly used in complexity analysis:
O notation
Ω notation
Θ notation provides a growth rate that is both an upper and lower bound.
Blank provides a growth rate for an algorithm’s upper bound.
O notation
Blank provides a growth rate for an algorithm’s lower bound.
Ω notation
Blank provides a growth rate that is both an upper and lower bound.
Θ notation
Blank is a mathematical way of describing how a function (running time, or runtime, of an algorithm) behaves in relation to the input size.
Big O notation
In Big O notation, all functions that have the same growth rate (as determined by the highest order term) are characterized using the same Big O notation. In essence, all functions that have the same growth rate are considered blank in Big O notation.
equivalent
Given a function that describes the runtime of an algorithm, the Big O notation for that function can be determined using the following rules
If f(x) is a sum of several terms, the highest order term (the one with the fastest growth rate) is kept and others are discarded.
If f(x) has a term that is a product of several factors, all constants (those that are not in terms of x) are omitted.