1. Home
  2. Explore
  3. Computer Science
  4. Memory and Pointers

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Memory and Pointers

  • 74Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Algorithms
The computer's main memory, divided conceptually into bytes, is called
.

74 questions

  1. 1
    The computer's main memory, divided conceptually into bytes, is called
    _____
    .
    Hint

    Recall the abbreviation for Random Access Memory.

    Answer

    RAM (Random Access Memory)

    Explanation

    RAM is the computer memory described as a grid of individual bytes, which can be used to organize data.

  2. 2
    A computer examines an array's contents
    _____
    rather than taking in the entire array at once.
    Hint

    Think about how a computer checks lockers one at a time.

    Answer

    step by step

    Explanation

    A computer processes array elements sequentially, examining one element at a time rather than instantly seeing the whole collection.

  3. 3
    For a search problem, the Boolean output indicates whether the target is
    _____
    .
    Hint

    The output answers a yes-or-no question about the target and the collection.

    Answer

    among the items being searched

    Explanation

    The search returns true if the target is present and false if it is absent.

  4. 4
    An algorithm that checks array elements in a line, one after another, is called
    _____
    .
    Hint

    Its name describes following a line through the elements.

    Answer

    linear search

    Explanation

    Linear search checks elements sequentially until it finds the target or reaches the end.

  5. 5
    When an array is unsorted and the target might be in the last position, linear search may inspect
    _____
    elements.
    Hint

    Consider the worst case for searching from one end to the other.

    Answer

    all

    Explanation

    If the target is last—or absent—the search must check every element before it can finish.

  6. 6
    Binary search requires the items to be
    _____
    before it begins.
    Hint

    The algorithm decides which half to discard by comparing values.

    Answer

    sorted

    Explanation

    Binary search relies on sorted order to determine whether the target can only be in the left or right half.

  7. 7
    Binary search first checks the item in the
    _____
    of the current range.
    Hint

    This position lets the algorithm eliminate one half of the range.

    Answer

    middle

    Explanation

    By checking the middle item, binary search can keep the relevant half and discard the other half.

  8. 8
    If the target is smaller than the middle item in a sorted array, binary search continues in the
    _____
    half.
    Hint

    Smaller values appear on this side when the list is in ascending order.

    Answer

    left

    Explanation

    In ascending order, values smaller than the middle item must occur in the left half.

  9. 9
    If the target is larger than the middle item in a sorted array, binary search continues in the
    _____
    half.
    Hint

    Larger values appear on this side when the list is in ascending order.

    Answer

    right

    Explanation

    In ascending order, values larger than the middle item must occur in the right half.

  10. 10
    In recursive or repeated binary search, if the search range has no items left, the algorithm returns
    _____
    .
    Hint

    If the range is empty, the target was not found.

    Answer

    false

    Explanation

    An empty range contains no possible match, so the search concludes that the target is absent.

  11. 11
    The word “binary” describes the repeated division of the search problem into
    _____
    parts.
    Hint

    The prefix “bi” means this number.

    Answer

    two

    Explanation

    Binary search repeatedly divides the remaining problem in two, which is the source of its name.

  12. 12
    If a search finds its target at the first position it checks, it has taken
    _____
    step.
    Hint

    This is the best-case number of checks for either search method discussed.

    Answer

    one

    Explanation

    Both linear search and binary search can find a target immediately if it happens to be at the first position examined.

  13. 13
    Big O notation describes an algorithm's approximate
    _____
    bound on running time.
    Hint

    It is commonly used to describe the worst-case amount of work.

    Answer

    upper

    Explanation

    Big O gives an upper bound on how much time or how many steps an algorithm may require.

  14. 14
    Omega notation describes an algorithm's approximate
    _____
    bound on running time.
    Hint

    It can describe the best-case amount of work.

    Answer

    lower

    Explanation

    Omega notation gives a lower bound on the running time, such as the best case for a particular algorithm.

  15. 15
    When an algorithm's upper and lower bounds are the same, its running time can be described using
    _____
    notation.
    Hint

    This notation uses a Greek letter and summarizes matching bounds.

    Answer

    theta

    Explanation

    Theta notation describes a running time when its upper and lower bounds are identical.

  16. 16
    The phrase “on the order of” refers to
    _____
    notation.
    Hint

    It is written with a capital O and gives an approximate upper bound.

    Answer

    big O

    Explanation

    Big O notation is read as “on the order of” and summarizes the growth of an algorithm's running time.

  17. 17
    In big O analysis, a linear search through nnn items has a worst-case running time of
    _____
    .
    Hint

    In the worst case, the number of checks grows in proportion to the number of items.

    Answer

    O(n)O(n)O(n)

    Explanation

    Linear search may inspect all nnn elements, so its worst-case running time is O(n)O(n)O(n).

  18. 18
    In big O analysis, binary search has a worst-case running time of
    _____
    .
    Hint

    The search range is repeatedly divided in two.

    Answer

    O(log⁡n)O(\log n)O(logn)

    Explanation

    Repeatedly halving a collection of size nnn takes a number of steps proportional to log⁡n\log nlogn.

  19. 19
    For sufficiently large inputs, big O analysis ignores a constant factor such as the division by
    _____
    in n/2n/2n/2.
    Hint

    Constant multipliers do not change the overall growth category.

    Answer

    2

    Explanation

    Big O focuses on growth as the input grows, so nnn and n/2n/2n/2 are both classified as linear.

  20. 20
    For big O growth rates, changing the base of a logarithm changes its value only by a
    _____
    factor.
    Hint

    The difference between logarithm bases does not change the growth category.

    Answer

    constant

    Explanation

    Logarithms with different fixed bases differ by a constant multiplier, which big O notation ignores.

  21. 21
    An algorithm that counts every item must examine all items even in the best case, so its lower bound is
    _____
    .
    Hint

    Accurate counting requires inspecting each of the nnn items.

    Answer

    Ω(n)\Omega(n)Ω(n)

    Explanation

    To know the total number of items, the algorithm must count each one, giving a best-case lower bound of Ω(n)\Omega(n)Ω(n).

  22. 22
    Computer scientists often prioritize an algorithm's
    _____
    case because it describes how it performs on difficult inputs.
    Hint

    This is the case represented by an upper bound such as big O.

    Answer

    worst

    Explanation

    Worst-case performance is a useful guarantee about how much work an algorithm may require, even when its input is unfavorable.

  23. 23
    In C, an array can be initialized with a fixed list of values using
    _____
    braces.
    Hint

    The notation encloses the values with braces rather than parentheses.

    Answer

    curly

    Explanation

    A statically initialized array can be written with its values enclosed in curly braces.

  24. 24
    An array whose values are specified when it is declared is described as a
    _____
    initialized array.
    Hint

    The term contrasts with values supplied dynamically later.

    Answer

    statically

    Explanation

    A statically initialized array has its values specified in advance, such as in a brace-enclosed initializer.

  25. 25
    In C, an array with six elements has valid indices from 000 through
    _____
    .
    Hint

    Array indexing begins at zero, so the final index is one less than the size.

    Answer

    555

    Explanation

    A six-element array uses indices 000 through 555; the final index is the array size minus one.

  26. 26
    In C, the expression i++ is commonly used in a loop to
    _____
    the index.
    Hint

    It advances the loop variable by one.

    Answer

    increment

    Explanation

    The postfix increment operator adds one to the loop index, allowing the loop to move through an array.

  27. 27
    A C string is represented as an
    _____
    of characters, rather than as a single character.
    Hint

    A string can contain multiple characters stored together.

    Answer

    array

    Explanation

    In C, a string is an array of characters, which is why comparing strings differs from comparing single values such as integers.

  28. 28
    In C, the string-comparison function introduced in the lecture is called
    _____
    .
    Hint

    Its name abbreviates string comparison.

    Answer

    strcmp

    Explanation

    strcmp compares two strings and is declared in the string library header.

  29. 29
    The function strcmp returns
    _____
    when the two strings are the same.
    Hint

    Equality is represented by the neutral comparison result.

    Answer

    0

    Explanation

    A return value of zero from strcmp indicates that the two strings are equal.

  30. 30
    The strcmp function is declared in the C header file
    _____
    .
    Hint

    Its name is the standard header for string operations.

    Answer

    string.h

    Explanation

    Programs that use strcmp should include string.h so the function is declared.

  31. 31
    In the conventions used for the C program's main function, returning
    _____
    indicates success.
    Hint

    This is the conventional success exit status described in the lecture.

    Answer

    0

    Explanation

    The examples use return 0 to indicate that the program completed successfully.

  32. 32
    In the examples, returning
    _____
    from main indicates failure.
    Hint

    This nonzero exit status contrasts with the success value.

    Answer

    1

    Explanation

    The examples use return 1 to indicate an unsuccessful outcome.

  33. 33
    A phone number containing characters such as dashes or parentheses is better represented as a
    _____
    than as an integer.
    Hint

    These parts of a phone number are characters, not quantities for arithmetic.

    Answer

    string

    Explanation

    Phone numbers can include punctuation and leading zeros, so representing them as strings preserves their formatting.

  34. 34
    Representing a phone number as an integer can lose a leading
    _____
    .
    Hint

    This digit does not affect a number's mathematical value when placed at the beginning.

    Answer

    zero

    Explanation

    Leading zeros are dropped in numeric representations, even though they can be meaningful in a phone number.

  35. 35
    In C, a struct acts as a
    _____
    that can contain multiple data types.
    Hint

    It groups related fields together.

    Answer

    container

    Explanation

    A structure can hold multiple pieces of data, such as a person's name and phone number.

  36. 36
    The C keyword typedef is used to
    _____
    a type.
    Hint

    Its name describes creating a type name for use in a program.

    Answer

    define

    Explanation

    typedef allows a programmer to define a type name, including a custom structure type.

  37. 37
    A custom person type can keep a person's name and phone number
    _____
    in one structure.
    Hint

    Grouping them prevents their association from depending on separate arrays staying aligned.

    Answer

    together

    Explanation

    Encapsulating the related fields in one structure helps keep each person's name associated with the correct number.

  38. 38
    The dot operator accesses a particular
    _____
    of a structure, such as a person's name.
    Hint

    A structure contains named pieces of data.

    Answer

    field

    Explanation

    Expressions such as people[i].name use the dot operator to access a structure field.

  39. 39
    Keeping names and phone numbers in separate arrays relies on the arrays remaining in the same
    _____
    .
    Hint

    The name at one index must correspond to the number at that index.

    Answer

    order

    Explanation

    Separate arrays can become mismatched if one is rearranged without applying the same rearrangement to the other.

  40. 40
    A database commonly stores related pieces of information together using a form of
    _____
    .
    Hint

    This design principle groups related information into a single unit.

    Answer

    encapsulation

    Explanation

    The lecture connects custom structures and the grouping of related information to the way databases organize data.

  41. 41
    A sorting algorithm transforms an unsorted list into a list ordered from
    _____
    to largest.
    Hint

    This describes ascending numerical order.

    Answer

    smallest

    Explanation

    The sorting example arranges values from the smallest on the left to the largest on the right.

  42. 42
    Bubble sort compares
    _____
    elements and swaps them when they are out of order.
    Hint

    The elements are next to each other in the list.

    Answer

    adjacent

    Explanation

    Bubble sort repeatedly compares neighboring elements and swaps a pair if their order is incorrect.

  43. 43
    Bubble sort gets its name from larger values that appear to
    _____
    toward the end of the list.
    Hint

    The motion is compared to a value rising through repeated neighboring swaps.

    Answer

    bubble

    Explanation

    Repeated swaps move large values toward their correct positions at the right-hand end of the list.

  44. 44
    In the bubble sort pseudocode described, the algorithm repeats passes until there are no
    _____
    .
    Hint

    A pass with none indicates that no neighboring pair needed correction.

    Answer

    swaps

    Explanation

    If a full pass makes no swaps, the list is sorted and bubble sort can stop early.

  45. 45
    Selection sort repeatedly finds the next
    _____
    element in the unsorted portion of the list.
    Hint

    The selected value is placed into the next position in ascending order.

    Answer

    smallest

    Explanation

    Each selection sort pass searches the remaining elements for the smallest value and places it in its final position.

  46. 46
    After selection sort finds the smallest remaining element, it swaps it with the element at the current
    _____
    .
    Hint

    This position marks the next place to fill in the sorted portion.

    Answer

    index

    Explanation

    Selection sort puts the smallest remaining item at the current index, extending the sorted portion by one element.

  47. 47
    Selection sort can place a selected value by shifting other items or by
    _____
    the item occupying the desired position.
    Hint

    The lecture's alternative avoids moving every item over by one position.

    Answer

    evicting

    Explanation

    Instead of shifting all intervening values, the described approach swaps or evicts the item at the target position and handles it later.

  48. 48
    An election in which the candidate with the most votes wins is described as a
    _____
    election.
    Hint

    The method chooses the candidate with the greatest number of votes.

    Answer

    plurality

    Explanation

    In a plurality election, the candidate with the most votes wins, without requiring voters to rank preferences.

  49. 49
    In a runoff election, voters can
    _____
    their preferences among candidates.
    Hint

    This process records more than a single first choice.

    Answer

    rank

    Explanation

    A runoff system can use voters' ranked preferences to determine the winner through further tabulation.

  50. 50
    Different vote-tabulation
    _____
    can produce different election outcomes.
    Hint

    The procedure used to process votes may vary.

    Answer

    algorithms

    Explanation

    The lecture notes that different algorithms for tabulating votes can have real-world effects on election results.

  51. 51
    For bubble sort with nested passes that each take on the order of nnn steps, the worst-case running time is
    _____
    .
    Hint

    Multiply the growth of the outer and inner loops.

    Answer

    O(n2)O(n^2)O(n2)

    Explanation

    The two loops each take on the order of nnn steps, so bubble sort has a quadratic worst-case running time.

  52. 52
    The lecture's original bubble sort performs its nested passes even when the input is already sorted, giving it a best-case lower bound of
    _____
    .
    Hint

    That version does not stop early when a pass makes no swaps.

    Answer

    Ω(n2)\Omega(n^2)Ω(n2)

    Explanation

    Without an early-exit condition, the algorithm continues through its nested loops even for sorted input.

  53. 53
    With the improvement “repeat until no swaps,” bubble sort can finish an already sorted list in
    _____
    time.
    Hint

    It still has to compare each adjacent pair in one pass.

    Answer

    Ω(n)\Omega(n)Ω(n)

    Explanation

    For nnn elements, one pass checks n−1n-1n−1 adjacent pairs, so the best-case running time is linear.

  54. 54
    Selection sort examines the remaining unsorted elements on each pass, so its worst-case running time is
    _____
    .
    Hint

    The work decreases across passes but sums to a quadratic quantity.

    Answer

    O(n2)O(n^2)O(n2)

    Explanation

    The passes require roughly nnn, then n−1n-1n−1, then n−2n-2n−2 checks, summing to a quantity on the order of n2n^2n2.

  55. 55
    Selection sort still scans the remaining elements to verify the minimum, even when the list is already sorted, so its lower bound is
    _____
    .
    Hint

    The algorithm cannot infer that the first item is smallest without inspecting the rest.

    Answer

    Ω(n2)\Omega(n^2)Ω(n2)

    Explanation

    Selection sort follows the same search process on already sorted input, so its best-case work remains quadratic.

  56. 56
    The sum n+(n−1)+⋯+1n + (n-1) + \cdots + 1n+(n−1)+⋯+1 equals
    _____
    .
    Hint

    This is the formula for the sum of the first nnn positive integers.

    Answer

    n(n+1)2\frac{n(n+1)}{2}2n(n+1)​

    Explanation

    The repeated decreasing scans in selection sort sum to n(n+1)2\frac{n(n+1)}{2}2n(n+1)​, which grows on the order of n2n^2n2.

  57. 57
    In big O analysis, the highest-order term of n2−2n+1n^2 - 2n + 1n2−2n+1 is
    _____
    .
    Hint

    It grows faster than the other terms as nnn becomes large.

    Answer

    n2n^2n2

    Explanation

    As the input grows, the quadratic term dominates the linear and constant terms, so the expression is O(n2)O(n^2)O(n2).

  58. 58
    An iterative algorithm uses a
    _____
    to repeat instructions.
    Hint

    Examples include for and while constructs.

    Answer

    loop

    Explanation

    Iteration means repeating instructions, commonly by using a loop.

  59. 59
    A function is recursive when it
    _____
    .
    Hint

    Its own name appears in its implementation as a function call.

    Answer

    calls itself

    Explanation

    Recursion occurs when a function invokes itself, often on a smaller version of the original problem.

  60. 60
    A recursive function needs a
    _____
    case that stops further recursive calls.
    Hint

    It handles a simple situation directly, such as a pyramid of height zero.

    Answer

    base

    Explanation

    The base case prevents recursion from continuing forever by specifying when the function should stop.

  61. 61
    To recursively draw a pyramid of height hhh, the function first draws a smaller pyramid of height
    _____
    .
    Hint

    The smaller problem is one row shorter than the original.

    Answer

    h−1h-1h−1

    Explanation

    A pyramid of height hhh can be defined as a pyramid of height h−1h-1h−1 followed by one additional row.

  62. 62
    After drawing the pyramid of height h−1h-1h−1, the recursive pyramid function prints
    _____
    additional row.
    Hint

    This row completes the pyramid at the current height.

    Answer

    one

    Explanation

    The recursive definition builds the smaller pyramid first and then adds a row of hhh bricks.

  63. 63
    In the recursive pyramid example, a height of zero is the case in which the function should simply
    _____
    .
    Hint

    The function does not draw a row or call itself again in this case.

    Answer

    return

    Explanation

    Returning when the height is zero provides the base case that stops the recursive calls.

  64. 64
    A recursive call should work on a
    _____
    input than the function originally received.
    Hint

    The problem must move toward its base case.

    Answer

    smaller

    Explanation

    Reducing the input, such as changing height hhh to h−1h-1h−1, ensures recursive calls progress toward termination.

  65. 65
    In the pyramid example, recursive calls print the smaller rows first, so the rows appear while the calls
    _____
    .
    Hint

    After the base case returns, earlier function calls resume in reverse order.

    Answer

    unwind

    Explanation

    The function reaches the base case before printing the larger rows; as calls return, each one prints its additional row.

  66. 66
    Merge sort's base case is a list with
    _____
    item, which is already sorted.
    Hint

    There cannot be any out-of-order pair in a collection of this size.

    Answer

    one

    Explanation

    A list containing one item is sorted by definition, so merge sort can return without further work.

  67. 67
    For a list with more than one item, merge sort sorts the left half, sorts the right half, and then
    _____
    the halves.
    Hint

    The final step combines two already sorted lists into one sorted list.

    Answer

    merges

    Explanation

    Merge sort's recursive process is to sort each half and then merge the sorted halves together.

  68. 68
    During a merge, the algorithm repeatedly takes the smaller available item from the two sorted lists to preserve
    _____
    order.
    Hint

    The combined list should remain arranged from smallest to largest.

    Answer

    sorted

    Explanation

    Comparing the next available items and selecting the smaller one builds a correctly ordered merged list.

  69. 69
    Merging two sorted halves requires
    _____
    space in the lecture's example.
    Hint

    The elements are placed into a separate row before forming the combined result.

    Answer

    extra

    Explanation

    The example uses additional memory to combine the two sorted lists before producing the merged list.

  70. 70
    Repeatedly dividing a list in half produces a number of levels proportional to
    _____
    .
    Hint

    This is the growth pattern associated with repeatedly halving a problem.

    Answer

    log⁡n\log nlogn

    Explanation

    A list of size nnn can be halved about log⁡2n\log_2 nlog2​n times before reaching lists of size one; the base is omitted in the growth notation.

  71. 71
    At each level of merge sort, merging processes all
    _____
    elements.
    Hint

    The halves together contain the entire list.

    Answer

    nnn

    Explanation

    Although the list is split into smaller parts, merging across one level collectively touches all nnn elements.

  72. 72
    Because merging processes nnn elements across about log⁡n\log nlogn levels, merge sort has running time
    _____
    .
    Hint

    Multiply the work per level by the number of levels.

    Answer

    O(nlog⁡n)O(n\log n)O(nlogn)

    Explanation

    Merge sort performs linear work at each of its logarithmically many levels, giving an O(nlog⁡n)O(n\log n)O(nlogn) running time.

  73. 73
    The merge sort described does the same splitting and merging even for already sorted input, so its lower bound is
    _____
    .
    Hint

    Unlike optimized bubble sort, this version does not stop early based on the input order.

    Answer

    Ω(nlog⁡n)\Omega(n\log n)Ω(nlogn)

    Explanation

    The algorithm follows its recursive divisions and merges regardless of whether the input begins sorted, so the best-case work remains nlog⁡nn\log nnlogn.

  74. 74
    Because merge sort has matching bounds of O(nlog⁡n)O(n\log n)O(nlogn) and Ω(nlog⁡n)\Omega(n\log n)Ω(nlogn), its running time can also be written as
    _____
    .
    Hint

    Use the notation for identical upper and lower bounds.

    Answer

    Θ(nlog⁡n)\Theta(n\log n)Θ(nlogn)

    Explanation

    When an algorithm's upper and lower bounds match, theta notation summarizes both; merge sort is Θ(nlog⁡n)\Theta(n\log n)Θ(nlogn).

1 of 74
Question 1 of 74

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent