1. Home
  2. Explore
  3. Computer Science
  4. Week 3: Algorithms

Study methods

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

Week 3: Algorithms

  • 34Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Searching Algorithms
In linear search, after checking every element without finding the target, the algorithm returns
.

34 questions

  1. 1
    In linear search, after checking every element without finding the target, the algorithm returns
    _____
    .
    Hint

    Think about the Boolean value returned when the search fails.

    Answer

    false

  2. 2
    Binary search requires the data to be
    _____
    in order to work correctly.
    Hint

    What property of the phone book allowed divide-and-conquer?

    Answer

    sorted

  3. 3
    In binary search, if the target is less than the middle element, the algorithm searches the
    _____
    half.
    Hint

    Which side contains smaller numbers?

    Answer

    left

  4. 4
    Returning false inside the linear search loop (instead of after it) causes the function to return
    _____
    prematurely.
    Hint

    What Boolean value is returned incorrectly on the first mismatch?

    Answer

    false

  5. 5
    The base case in recursive binary search occurs when
    _____
    doors are left.
    Hint

    When can we definitively say the target is absent?

    Answer

    no

  6. 6
    Big O notation describes the
    _____
    bound on an algorithm's running time.
    Hint

    Think 'worst-case' or 'maximum' steps.

    Answer

    upper

  7. 7
    Linear search in the worst case has a running time of O(
    _____
    ).
    Hint

    It may need to check every element.

    Answer

    n

  8. 8
    Binary search in the worst case has a running time of O(
    _____
    ).
    Hint

    Think about dividing the problem in half repeatedly.

    Answer

    log n

  9. 9
    The symbol for the lower bound on running time is
    _____
    .
    Hint

    It's a Greek letter often used for 'best-case' scenarios.

    Answer

    omega

  10. 10
    When an algorithm's upper and lower bounds are the same, we say it is
    _____
    of that function.
    Hint

    It's the Greek letter that represents both O and Ω together.

    Answer

    theta

  11. 11
    Selection sort has a worst-case running time of O(
    _____
    ).
    Hint

    Think about nested loops: one to pick each element, one to find the smallest.

    Answer

    n²

  12. 12
    In selection sort, at each step we find the
    _____
    element in the unsorted portion.
    Hint

    What value are we looking for to place at the front?

    Answer

    smallest

  13. 13
    Bubble sort works by comparing
    _____
    elements and swapping them if they are out of order.
    Hint

    Think of neighbors in the array.

    Answer

    adjacent

  14. 14
    An optimization for bubble sort is to stop early if a pass makes
    _____
    swaps.
    Hint

    If we check all pairs and none are swapped, what does that mean?

    Answer

    no

  15. 15
    The worst-case running time of bubble sort (without early stop) is O(
    _____
    ).
    Hint

    It uses nested loops similar to selection sort.

    Answer

    n²

  16. 16
    Merge sort has a running time of O(
    _____
    ).
    Hint

    Think about dividing and then merging.

    Answer

    n log n

  17. 17
    The three steps of merge sort are: sort the left half, sort the right half, and
    _____
    the sorted halves.
    Hint

    It's the step that combines two sorted lists into one.

    Answer

    merge

  18. 18
    The number of levels in merge sort's recursion tree is log₂
    _____
    .
    Hint

    How many times can you halve n until you get to 1?

    Answer

    n

  19. 19
    Merge sort requires additional
    _____
    to perform the merge step, unlike selection sort.
    Hint

    Yuliia used extra shelves to hold numbers temporarily.

    Answer

    space

  20. 20
    In C, an array's elements are stored
    _____
    in memory.
    Hint

    They are placed side-by-side without gaps.

    Answer

    contiguously

  21. 21
    If an array has n elements, the last element is at index
    _____
    .
    Hint

    Remember zero-indexing.

    Answer

    n-1

  22. 22
    To iterate over all elements of an array of size n, a for loop condition is typically i <
    _____
    .
    Hint

    The loop should stop before the index goes out of bounds.

    Answer

    n

  23. 23
    In the linear search C code, after finding the target, the program returns 0 to signal
    _____
    .
    Hint

    What return value indicates everything went well?

    Answer

    success

  24. 24
    An array can be initialized with specific values by enclosing them in
    _____
    braces.
    Hint

    These braces look like { and }.

    Answer

    curly

  25. 25
    If an array is not initialized, its elements contain
    _____
    values.
    Hint

    What leftover data might be in that memory?

    Answer

    garbage

  26. 26
    The function used to compare two strings in C is
    _____
    .
    Hint

    It's in the string.h library and returns an integer.

    Answer

    strcmp

  27. 27
    The strcmp function returns
    _____
    if the two strings are equal.
    Hint

    It's a specific integer value, not non-zero.

    Answer

    0

  28. 28
    To use strcmp, you must include the header file
    _____
    .
    Hint

    It's the header for string manipulation functions.

    Answer

    string.h

  29. 29
    A struct allows you to create a custom data type that
    _____
    multiple data types together.
    Hint

    It bundles related variables under one name.

    Answer

    encapsulates

  30. 30
    To access a field of a struct variable, you use the
    _____
    operator.
    Hint

    It's a period between the variable name and field name.

    Answer

    dot

  31. 31
    A recursive function is one that calls
    _____
    .
    Hint

    It's a self-referential definition.

    Answer

    itself

  32. 32
    In a recursive algorithm, the condition that stops the recursion is called the
    _____
    case.
    Hint

    It's the simplest instance that can be solved directly.

    Answer

    base

  33. 33
    In the recursive implementation of drawing a pyramid, the base case is when height equals
    _____
    .
    Hint

    What height pyramid requires no bricks?

    Answer

    0

  34. 34
    The iterative approach uses loops, while the recursive approach uses
    _____
    calls.
    Hint

    What kind of calls does recursion rely on?

    Answer

    function

1 of 34
Question 1 of 34

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent