b. Searching algorithms:

Cards (45)

  • Searching algorithms are methods used to locate a specific item called the target
  • The linear search algorithm checks each item sequentially until the target is found
    True
  • The linear search algorithm checks each item sequentially until the target is found or the list is exhausted
  • The worst-case time complexity of the linear search algorithm is O(n)
  • The time complexity of the binary search algorithm is O(log n)
  • The binary search algorithm repeats until the target is found or the interval is empty
  • What is the worst-case time complexity of the linear search algorithm?
    O(n)
  • The linear search algorithm requires the list to be sorted beforehand.
    False
  • Match the search algorithm with its time complexity:
    Linear Search ↔️ O(n)
    Binary Search ↔️ O(log n)
  • What is the first step of the binary search algorithm?
    Find the middle element
  • What is the time complexity of the binary search algorithm?
    O(log n)
  • What is a disadvantage of using binary search?
    Requires a sorted list
  • The binary search algorithm is used to find a target element within a sorted list.
  • What is the time complexity of binary search for large sorted lists?
    O(log n)
  • Linear search is efficient for large, sorted lists.
    False
  • When is binary search most effective?
    Large, sorted lists
  • The linear search algorithm checks each item sequentially until the target is found.
  • What is the worst-case time complexity of linear search?
    O(n)
  • Steps of the linear search algorithm
    1️⃣ Start at the first element
    2️⃣ Compare each element with the target
    3️⃣ If the element matches the target, return the index
    4️⃣ Continue checking until the end of the list if the target is not found
    5️⃣ Indicate the target is not in the list if not found
  • The worst-case time complexity of linear search is O(n)
  • Binary search is more efficient than linear search for unsorted lists.
    False
  • Steps of the binary search algorithm
    1️⃣ Find the middle element of the sorted list
    2️⃣ Compare the middle element with the target
    3️⃣ If equal, return the index
    4️⃣ If the target is greater, search the right half
    5️⃣ If the target is less, search the left half
    6️⃣ Repeat steps 1-2 until found or the interval is empty
  • The binary search algorithm requires the list to be sorted
  • The binary search algorithm has a time complexity of O(n).
    False
  • The linear search algorithm requires the list to be sorted.
    False
  • The binary search algorithm requires the data to be sorted.

    True
  • The binary search algorithm is suitable for unsorted lists.
    False
  • Steps of the binary search algorithm
    1️⃣ Find the middle element
    2️⃣ Compare the middle element with the target
    3️⃣ If equal, return the index
    4️⃣ If target is greater, search the right half
    5️⃣ If target is smaller, search the left half
    6️⃣ Repeat until the target is found or the interval is empty
  • The linear search algorithm starts at the first element of the list
  • Why is the linear search algorithm inefficient for large lists?
    It checks every element
  • The binary search algorithm works on a sorted list.
  • If the target in binary search is greater than the middle element, the right half of the list is searched next.

    True
  • Match the feature with the corresponding search algorithm:
    Requires a sorted list ↔️ Binary Search
    No sorting needed ↔️ Linear Search
  • The linear search algorithm is best suited for smaller, unsorted lists.
  • Steps of the binary search algorithm
    1️⃣ Find the middle element of the sorted list.
    2️⃣ Compare the middle element with the target.
    3️⃣ If equal, return the index.
    4️⃣ If the target is greater, search the right half.
    5️⃣ If the target is less, search the left half.
    6️⃣ Repeat until found or interval is empty.
  • Binary search requires the list to be sorted beforehand.
  • What is the time complexity of linear search?
    O(n)
  • Linear search is best suited for small, unsorted lists.
  • Searching algorithms aim to find a target within a search space quickly.

    True
  • The linear search algorithm requires the list to be sorted.
    False