Searching and Sorting Algorithms
- 87Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
87 questions
- 1An algorithm is a set of_____instructions for solving a problem.
Hint
Think of the ordered actions needed to accomplish a task.
Answer
step-by-step
Explanation
An algorithm specifies steps to follow to solve a particular problem.
- 2In computing, sorting information means arranging it according to an order, such as smallest to largest or_____.
Hint
Consider a common way to order names in a list.
Answer
alphabetically
Explanation
Sorting arranges information according to a chosen ordering rule, such as numeric order or alphabetical order.
- 3The task of looking for a particular piece of information is called_____.
Hint
It is the process of finding whether a value or item is present.
Answer
searching
Explanation
Searching is the process of looking for specific information in a collection.
- 4Counting people one at a time requires work that grows in direct proportion to the number of people, so its growth is_____.
Hint
A graph of this growth is a straight line.
Answer
linear
Explanation
If each additional person requires one additional counting step, the running time grows linearly with the number of people.
- 5Counting two people at a time is still a linear-time approach, but it is faster because each step handles a_____number of people.
Hint
The amount handled per step does not increase with the total group size.
Answer
constant
Explanation
Counting by twos changes the constant factor in the work, but the total work still grows linearly as the group grows.
- 6In the paired attendance algorithm, each standing person combines their count with a partner's count, then one person sits, so the remaining group is approximately_____after each round.
Hint
Each pair becomes one person who remains standing.
Answer
halved
Explanation
Pairing people and having one member of each pair sit reduces the number still participating by about half each round.
- 7The paired attendance procedure repeats its pairing and addition steps until the process reaches a stopping condition; this repeated control structure is a_____.
Hint
It is a programming structure that performs steps repeatedly.
Answer
loop
Explanation
A loop repeats a sequence of steps while a condition remains true, such as continuing while people are still standing.
- 8When a problem is repeatedly divided into halves, doubling its size adds only about_____step to the number of divisions.
Hint
Compare the number of halving rounds needed for a group and for twice that group.
Answer
one
Explanation
Each additional halving round can account for a doubling in the original problem size.
- 9If a problem is divided in half repeatedly, multiplying its size by four adds_____halving rounds.
Hint
Four is obtained by doubling twice.
Answer
two
Explanation
Two extra halvings reduce a problem by a factor of four, so a fourfold increase in size adds two rounds.
- 10Time, money, and storage space are examples of limited resources whose use can be treated as an algorithm's_____.
Hint
It is a general term for the resources an algorithm consumes.
Answer
cost
Explanation
Algorithm cost can refer to time, memory, money, or another limited resource.
- 11An array stores its elements in adjacent locations in memory, a property described as_____storage.
Hint
The values are placed directly next to one another.
Answer
back-to-back
Explanation
Array elements occupy consecutive memory locations, one after another.
- 12In the basic computer model used in the lecture, code accesses_____array value at a time.
Hint
The computer must visit a location to inspect its value.
Answer
one
Explanation
The model assumes that a computer must access values individually rather than see an entire array at once.
- 13When an array has n elements and indexing starts at zero, its last valid index is_____.
Hint
The first element uses index zero, so the final index is one less than the element count.
Answer
n−1
Explanation
Zero-based indexing assigns indices from zero through n−1 to an array of n elements.
- 14Searching an array by checking its elements one at a time from one end is called_____.
Hint
Its name reflects moving along the elements in sequence.
Answer
linear search
Explanation
Linear search examines elements sequentially until it finds the target or reaches the end.
- 15Linear search can proceed from left to right or right to left because it does not require the array to be in a particular_____.
Hint
The elements do not need to be sorted for this method.
Answer
order
Explanation
Linear search checks elements one by one and can find a target regardless of the array's ordering.
- 16When the contents of lockers have no known order, checking them one by one is more dependable than choosing a direction based on_____.
Hint
There is no evidence that the target is more likely to be at either end.
Answer
guesswork
Explanation
Without information about the arrangement, starting at the opposite end or choosing locations randomly does not reliably improve the search.
- 17A random search order may require extra memory to remember which locations have already been_____.
Hint
Tracking visited lockers prevents repeatedly checking the same location.
Answer
opened
Explanation
If locations are visited randomly, the search may need to record which ones have already been examined.
- 18Binary search can discard half of the remaining candidates only when the data is_____.
Hint
The method relies on knowing which side contains smaller or larger values.
Answer
sorted
Explanation
Binary search uses the ordering of sorted data to decide which half can be eliminated.
- 19In binary search, if the target is smaller than the middle value, the next search is in the_____half.
Hint
Smaller values appear on this side when the array is sorted in ascending order.
Answer
left
Explanation
For ascending sorted data, a target smaller than the middle value must be in the left half, if it is present.
- 20In binary search, if the target is greater than the middle value, the next search is in the_____half.
Hint
Larger values appear on this side when the array is sorted in ascending order.
Answer
right
Explanation
For ascending sorted data, a target greater than the middle value must be in the right half, if it is present.
- 21If the target equals the value at the middle location during binary search, the algorithm can immediately return_____.
Hint
The search has found the requested value.
Answer
true
Explanation
The search goal is to determine whether the target is present, so finding it produces a true result.
- 22A binary search that has no locations left to examine should return_____.
Hint
There are no remaining candidates in which the target could appear.
Answer
false
Explanation
If the search range is empty, the target was not found and the boolean result is false.
- 23After checking the middle location in binary search, the next range excludes that location so it is not_____.
Hint
The value at the middle has already been compared with the target.
Answer
checked again
Explanation
The left range ends before the middle and the right range begins after it, avoiding redundant work.
- 24For an array indexed from zero, binary search can find the middle index by dividing the range's size by two and rounding_____.
Hint
An array index must be an integer.
Answer
down
Explanation
When the size divided by two is not an integer, rounding down gives a valid middle index.
- 25In pseudocode for linear search, returning false only after all locations have been checked prevents an early, incorrect_____.
Hint
The target might be in a later location even if it is not in the first one.
Answer
failure
Explanation
Returning false after checking only one location would stop the search before it had examined the rest of the array.
- 26In C, returning a value from a function immediately ends that function's_____.
Hint
No later statements in the function run after this point.
Answer
execution
Explanation
A return statement exits the current function and passes its result back to the caller.
- 27The running time of linear search in the worst case is expressed as_____.
Hint
The target may be at the final location, requiring a scan proportional to the array size.
Answer
O(n)
Explanation
In the worst case, linear search examines all n elements, so its upper-bound running time is O(n).
- 28The worst-case running time of binary search on sorted data is expressed as_____.
Hint
Each comparison halves the remaining search range.
Answer
O(logn)
Explanation
Repeatedly halving a problem of size n takes logarithmically many steps.
- 29Big O notation describes an algorithm's_____bound on growth.
Hint
It describes how large the running time can grow as the input increases.
Answer
upper
Explanation
Big O provides an asymptotic upper bound on an algorithm's growth.
- 30Omega notation describes an algorithm's_____bound on growth.
Hint
It can describe the algorithm's best-case growth.
Answer
lower
Explanation
Omega notation gives an asymptotic lower bound on an algorithm's growth.
- 31Theta notation can describe an algorithm when its Big O and Omega bounds have the same_____.
Hint
The upper and lower bounds agree asymptotically.
Answer
order
Explanation
When the upper and lower bounds match in order of growth, Theta notation gives a tight asymptotic bound.
- 32When simplifying an algorithm's growth rate, Big O analysis focuses on the_____term.
Hint
It is the term that matters most as the input becomes very large.
Answer
dominant
Explanation
The dominant term controls growth for large inputs, so lower-order terms are ignored.
- 33For Big O growth, constant factors such as dividing a linear running time by two do not change its_____class.
Hint
Both versions increase proportionally to the input size.
Answer
growth
Explanation
Big O ignores constant factors, so O(n/2) and O(n) describe the same asymptotic growth class.
- 34The notation used to describe algorithm behavior as input size grows very large is called_____notation.
Hint
It concerns behavior as a value approaches very large sizes.
Answer
asymptotic
Explanation
Asymptotic notation describes how an algorithm's resource use grows for large input sizes.
- 35The best-case running time of linear search is in_____because the target might be the first item checked.
Hint
The search may finish after a fixed number of steps, independent of the array size.
Answer
Ω(1)
Explanation
If the first element is the target, linear search takes constant time, giving a lower bound of Ω(1).
- 36The best-case running time of binary search is also in_____because the target might be at the middle location immediately.
Hint
A favorable input can be found with a single comparison.
Answer
Ω(1)
Explanation
When the middle element is the target, binary search can finish in constant time.
- 37If data will be searched only once, sorting it first may be wasteful, so a designer may choose_____instead.
Hint
This method does not require a preprocessing sort.
Answer
linear search
Explanation
Sorting has a cost. For a single search, scanning once may be less work than sorting and then searching.
- 38If data is searched repeatedly, the cost of preparing it for efficient searches can be spread across many searches; this is called_____the cost.
Hint
The preparation expense is distributed over repeated operations.
Answer
amortizing
Explanation
Repeated searches can make an initial sorting cost worthwhile because that cost is shared across many queries.
- 39A C array initialized with a known list of values in curly braces can have its size_____by the compiler.
Hint
The compiler can count the supplied initial values.
Answer
inferred
Explanation
When an array is initialized with a known list, the compiler can determine its size from the number of values.
- 40A for loop that searches an array from its first element typically initializes its index to_____.
Hint
C arrays use zero-based indexing.
Answer
zero
Explanation
The first element of a zero-indexed array is at index zero, so a left-to-right search begins there.
- 41In C, the equality operator used to compare integer values is_____.
Hint
It uses two equals signs rather than one assignment sign.
Answer
==
Explanation
The operator
==tests whether two values are equal; a single=assigns a value. - 42In C, the function used to compare two strings is_____.
Hint
Its name abbreviates string comparison.
Answer
strcmp
Explanation
The
strcmpfunction compares two strings character by character. - 43When_____
strcmpreports that two strings are equal, its return value is.Hint
In this function, equality is indicated by a value that is neither positive nor negative.
Answer
zero
Explanation
strcmpreturns zero when the strings match; a negative or positive result indicates an ordering difference. - 44The C header that declares_____
strcmpis.Hint
It is the string-related header file.
Answer
string.hExplanation
Including
string.hmakes the declaration ofstrcmpavailable to a C program. - 45A_____
strcmpresult less than zero or greater than zero can indicate which string comes first inorder.Hint
The comparison uses character values rather than a language-aware dictionary rule.
Answer
ASCII
Explanation
strcmpuses character codes to compare strings, which supports ordering based on ASCII values. - 46A phone number containing plus signs, dashes, or parentheses should be stored as a_____rather than as an integer.
Hint
This type can preserve punctuation as well as digits.
Answer
string
Explanation
Phone numbers can contain punctuation, so they are text data rather than ordinary integer values.
- 47Storing a phone number as a string can preserve a leading_____that would have no mathematical significance in an integer.
Hint
This digit can appear at the beginning of some phone numbers.
Answer
zero
Explanation
Integer representations discard leading zeros, while strings preserve them as characters.
- 48In a C program, returning zero from_____
mainconventionally indicates.Hint
It signals that the program completed normally.
Answer
success
Explanation
A zero exit status conventionally indicates successful program completion; a nonzero status indicates an error or other condition.
- 49Separate name and phone-number arrays rely on matching indices, which can fail if their lengths or ordering are not kept in_____.
Hint
The corresponding entries must remain aligned.
Answer
sync
Explanation
Parallel arrays depend on each person's name and number occupying corresponding positions, creating a risk of mismatched data.
- 50A C programmer can combine related values into a custom structure using_____
typedefand.Hint
This keyword groups multiple fields into a single type.
Answer
structExplanation
A structure groups related fields, and
typedefcan give the resulting type a convenient name. - 51In the phone-book example, a person structure groups a name and a phone number as_____.
Hint
These are the named pieces of data inside a structure.
Answer
fields
Explanation
The structure's name and number are fields that belong to the same person record.
- 52In C, the dot operator accesses a named_____within a structure.
Hint
It selects one component of a structured value.
Answer
field
Explanation
Dot notation, such as
people[i].name, accesses a specific field in a structure. - 53Keeping a person's name and number together in one structure is an example of data_____.
Hint
Related values are bundled together rather than kept in separate, independently aligned arrays.
Answer
encapsulation
Explanation
Encapsulation keeps related information together in a single data structure.
- 54An array of person structures can store multiple records while keeping each person's related values_____.
Hint
Each array element contains one complete record.
Answer
together
Explanation
Each element of the people array is a structure containing that person's name and number.
- 55An array is a simple data structure whose values of a given array share the same_____.
Hint
For example, an array may contain integers or strings.
Answer
type
Explanation
A C array stores elements of one type, whereas a structure can group fields of different types.
- 56Selection sort repeatedly finds the smallest value in the unsorted portion and swaps it into the next_____position.
Hint
The sorted portion grows from the beginning of the array.
Answer
available
Explanation
Each selection-sort pass places the smallest remaining value at the next position in the sorted prefix.
- 57After each pass of selection sort, the array's sorted_____grows by one element.
Hint
This is the already ordered section at the start of the array.
Answer
prefix
Explanation
Selection sort places one next-smallest element at the end of the sorted prefix on each pass.
- 58Selection sort swaps the smallest remaining element with the element at the current index rather than creating extra array_____.
Hint
The algorithm rearranges values within the original array.
Answer
space
Explanation
The demonstration swaps values in the fixed array instead of shifting elements into newly allocated locations.
- 59The comparisons made by selection sort add up to 2n(n−1), giving it a running time of_____.
Hint
The dominant term in the comparison count is proportional to the square of the input size.
Answer
O(n2)
Explanation
Selection sort performs roughly n2/2 comparisons, and Big O ignores constant factors and lower-order terms.
- 60Even when its input is already sorted, standard selection sort still scans for the smallest remaining value on every pass, so its best-case bound is_____.
Hint
The algorithm does not first check whether the array is already sorted.
Answer
Ω(n2)
Explanation
Selection sort performs its passes regardless of the initial order, so its best-case running time remains quadratic.
- 61Because selection sort has both an O(n2) upper bound and an Ω(n2) lower bound, its tight bound is_____.
Hint
Use the notation for matching upper and lower growth bounds.
Answer
Θ(n2)
Explanation
Matching quadratic upper and lower bounds mean selection sort has a tight bound of Θ(n2).
- 62Bubble sort compares adjacent values and swaps them when they are_____.
Hint
The comparison checks whether the pair is in the required sorted arrangement.
Answer
out of order
Explanation
Bubble sort repeatedly examines neighboring elements and swaps a pair if it violates the ordering.
- 63During a left-to-right pass of bubble sort, large values move toward the end of the array by_____upward through adjacent swaps.
Hint
The algorithm's name describes how these values move through the list.
Answer
bubbling
Explanation
Repeated adjacent swaps move large values toward their final positions at the end of the array.
- 64In a bubble-sort pass, the final left-hand index is at most n−2 so that comparing it with the next index does not go beyond the array's_____.
Hint
The last valid array index is n−1.
Answer
boundary
Explanation
The algorithm accesses the current index and the next index, so the current index cannot be the last valid one.
- 65Without an early-exit optimization, bubble sort makes repeated passes and has a worst-case running time of_____.
Hint
There are roughly n passes, each examining roughly n adjacent pairs.
Answer
O(n2)
Explanation
The nested repetition produces quadratic work in the worst case.
- 66An optimized bubble sort can stop after a pass in which it made_____.
Hint
If every adjacent pair was already in order, another pass is unnecessary.
Answer
no swaps
Explanation
A full pass with no swaps shows that the list is sorted, so the algorithm can terminate early.
- 67With the no-swap early exit, bubble sort has a best-case running time of_____.
Hint
It still needs one pass to verify that the array is already ordered.
Answer
Ω(n)
Explanation
An already sorted array requires a single linear pass to check all adjacent pairs, giving a linear lower bound.
- 68The no-swap optimization improves bubble sort when the data is already or mostly sorted, but its worst-case bound remains_____.
Hint
The optimization does not eliminate repeated passes when many swaps are needed.
Answer
O(n2)
Explanation
For disordered data, bubble sort can still make many passes of adjacent comparisons and swaps.
- 69A function that calls itself is described as_____.
Hint
The term applies to a function whose definition uses another call to itself.
Answer
recursive
Explanation
A recursive function invokes itself as part of solving a problem.
- 70A recursive algorithm avoids repeating the same problem forever by making each recursive call handle a_____problem.
Hint
Progress toward a stopping condition requires reducing the work still to be done.
Answer
smaller
Explanation
Recursive calls must make progress, often by operating on a smaller portion of the original input.
- 71A condition that provides an immediate answer and stops further recursive calls is a_____case.
Hint
It is the stopping point for a recursive definition.
Answer
base
Explanation
A base case handles a small or simple input directly, preventing recursion from continuing indefinitely.
- 72A recursive case performs more work by calling the function again on a smaller problem, while a_____case gives an immediate answer.
Hint
It is contrasted with the case that makes another recursive call.
Answer
base
Explanation
The recursive case reduces the problem; the base case terminates the chain of calls.
- 73In recursive binary search, searching the left or right half is a recursive call because the search procedure is applied again to a_____range.
Hint
Each comparison removes the middle value and one side from consideration.
Answer
smaller
Explanation
Binary search repeats its logic on one half of the remaining range, making progress toward an empty range or a match.
- 74Solving a problem with loops rather than self-calls is called_____.
Hint
This approach repeats instructions using loop structures.
Answer
iteration
Explanation
Iteration uses loops to repeat steps; recursion uses functions that call themselves.
- 75A recursive definition of a pyramid can describe a pyramid of a given height as a smaller pyramid plus_____.
Hint
Each step increases the height by a single layer.
Answer
one more row
Explanation
A pyramid of height n can be defined as a pyramid of height n−1 with one additional row.
- 76Repeated recursive calls use additional memory for each active call, so excessive recursion can exhaust the computer's_____.
Hint
Each call needs space to keep track of its own state.
Answer
memory
Explanation
Recursive calls consume memory while their function calls remain active; too many calls can exceed available memory.
- 77In the recursive pyramid example, a height less than or equal to zero is used as a stopping condition so no further_____calls occur.
Hint
The condition prevents the function from calling itself again.
Answer
recursive
Explanation
When the height reaches the base case, the function returns instead of making another recursive call.
- 78When a function calls itself, each call has its own local variables, so one call's current loop index is not automatically shared with the next call; each call has its own_____.
Hint
Think of each invocation as having separate local state.
Answer
copy
Explanation
Local variables belong to a particular function call, and another recursive invocation gets its own instance of those variables.
- 79Merge sort's three main operations are sorting the left half, sorting the right half, and then_____the sorted halves.
Hint
The final operation combines two ordered portions into one ordered list.
Answer
merging
Explanation
Merge sort recursively sorts each half and then merges the two sorted results.
- 80A list containing only one element is already sorted, so it serves as merge sort's_____case.
Hint
No further division or rearrangement is required for this smallest case.
Answer
base
Explanation
A one-element list needs no sorting, so recursion can stop at that base case.
- 81To merge two sorted lists, repeatedly compare their smallest unprocessed values and select the_____one next.
Hint
The combined output must remain in ascending order.
Answer
smaller
Explanation
The smaller of the two current values is the next value in the merged, sorted list.
- 82During the standard merge process, each input element is moved forward through its list at most once, so merging lists with n total elements takes_____steps.
Hint
The work grows in proportion to the total number of values being merged.
Answer
O(n)
Explanation
Each element is examined and added to the output once, making the merge operation linear in the total input size.
- 83Merge sort needs additional storage while combining its sorted halves, using about_____the space of the original list in the described approach.
Hint
The demonstration used the original data and another area for the merged result.
Answer
twice
Explanation
The described merge process uses an additional array-sized area to combine the halves, for roughly twice the original storage.
- 84In the described merge sort, the lower bound also grows as nlogn, so its tight bound is_____.
Hint
The upper and lower bounds have the same asymptotic growth.
Answer
Θ(nlogn)
Explanation
Because merge sort has matching O(nlogn) and Ω(nlogn) bounds, its tight bound is Θ(nlogn).
- 85Unlike selection sort and bubble sort, merge sort avoids repeatedly comparing many of the same values by dividing the problem and_____the sorted results.
Hint
The algorithm combines smaller ordered lists instead of repeatedly scanning all pairs.
Answer
merging
Explanation
Merge sort divides the data into smaller lists, sorts them, and combines the results with a linear merge at each level.
- 86When two sorted lists are merged, the two moving positions can advance only to the right, rather than repeatedly moving_____and forth.
Hint
Each position progresses through its own input list.
Answer
back
Explanation
The merge process advances through each input once, which avoids repeated backtracking and redundant comparisons.
- 87Because nlogn grows more slowly than n2 for large inputs, merge sort is generally faster than the two quadratic sorting algorithms discussed, though it uses more_____.
Hint
The extra resource is needed to hold merged values.
Answer
space
Explanation
Merge sort reduces running-time growth compared with quadratic sorts, at the cost of additional memory for merging.

Ask anything
We've read this whole study set, so questions about it get the best answers.