Searching Algorithms - AP Computer Science A

  1. How does binary search determine which half of the array to search next?
    Compares the middle element with the target. Comparison result determines which half to eliminate.
  2. What is an advantage of linear search?
    Simplicity and no need for sorted data. Works with any data arrangement without preprocessing.
  3. Which searching algorithm divides the dataset in half at each step?
    Binary search. Uses divide-and-conquer strategy to eliminate half the search space.
  4. How does binary search achieve efficiency compared to linear search?
    By reducing the search space exponentially. Halves search space each step versus linear progression.
  5. State the time complexity of binary search in the average case.
    O(log n)O(\text{log}\text{ }n). Binary search halves the search space at each step.
  6. Identify a situation that would lead to linear search outperforming binary search.
    A very small dataset or unsorted data. Linear search avoids sorting overhead for small datasets.
  7. Which searching algorithm is more efficient for small datasets?
    Linear search. Simple implementation with low overhead for small arrays.
  8. What condition triggers the best-case scenario for binary search?
    The target is the middle element. Found immediately without additional comparisons needed.
  9. Identify the searching algorithm with O(n)O(n) complexity for both average and worst case.
    Linear search. Sequential search has consistent linear time complexity.
  10. How does linear search find an element in an array?
    Checks each element sequentially. Examines elements one by one from beginning to end.
  11. What is the main advantage of binary search over linear search?
    Faster search time on sorted arrays. Logarithmic complexity significantly outperforms linear complexity.
  12. Identify the main disadvantage of linear search.
    Inefficient for large datasets; time complexity is O(n)O(n). Must check every element sequentially in worst case.
  13. What type of algorithm is a binary search classified as?
    Divide and conquer algorithm. Systematically divides problem into smaller subproblems.
  14. What is the first step in a binary search algorithm?
    Identify the middle element of the array. Start with the midpoint to divide search space.
  15. State a scenario where linear search is more suitable than binary search.
    When the data is unsorted. Binary search requires sorted data as prerequisite.
  16. What kind of search is typically used when data is consistently changing?
    Linear search, due to lack of sorting requirement. Dynamic data makes maintaining sorted order impractical.
  17. Which algorithm can be easily adapted to work with linked lists?
    Linear search. Sequential traversal is natural for linked data structures.
  18. State the condition under which binary search may not function correctly.
    When the array is unsorted. Binary search requires ordered data to function properly.
  19. What is the primary purpose of a searching algorithm?
    To find a specific value within a data structure. Searching algorithms locate elements within collections of data.
  20. What is the worst-case time complexity of binary search?
    O(log n)O(\text{log}\text{ }n). Maximum comparisons needed is log2 n\text{log}_2\text{ }n.
  21. What data structure is essential for efficient binary search?
    Sorted array or list. Binary search needs random access for efficient indexing.
  22. What prerequisite must be met for binary search to function correctly?
    The array must be sorted. Binary search requires ordered data to eliminate half the possibilities.
  23. What is the main criterion for choosing between linear and binary search?
    Whether the data is sorted or not. Data organization determines which algorithm is applicable.
  24. Name a searching algorithm that works on unsorted data.
    Linear search. Sequential search doesn't require data to be pre-sorted.
  25. Which search technique is inherently sequential?
    Linear search. Examines elements one after another in order.
  26. Which search algorithm requires direct access to elements for efficiency?
    Binary search. Random access enables efficient middle element selection.
  27. What is the time complexity of linear search in the worst case?
    O(n)O(n). Must examine every element when target is last or absent.
  28. Which algorithm is preferred for searching a large, sorted list?
    Binary search. Logarithmic time complexity is much faster than linear.
  29. For binary search, what is the initial step before performing the algorithm?
    Sort the array. Binary search only works on pre-sorted collections.
  30. What is the space complexity of binary search?
    O(1)O(1) for iterative, O(log n)O(\text{log}\text{ }n) for recursive. Iterative uses constant space; recursive uses call stack.
  31. What is a limitation of using binary search on linked lists?
    Inefficient due to no direct access to middle elements. Linked lists lack direct indexing for middle element access.
  32. How does binary search reduce the problem size at each step?
    By half. Eliminates half the remaining elements each iteration.
  33. Which searching algorithm has a time complexity of O(1)O(1) in the best case?
    Hash table search. Hash tables provide constant-time lookup with proper hash function.
  34. Which searching algorithm is optimal for searching linked lists?
    Linear search. No random access to middle elements in linked structures.
  35. What is the key operation performed in each step of binary search?
    Comparison with the middle element. Middle element comparison guides next search direction.
  36. State the best-case time complexity for linear search.
    O(1)O(1). Target element is found at the first position checked.
  37. What are the two main types of searching algorithms?
    Linear search and binary search. These are the fundamental search techniques in computer science.
  38. Which search method is easier to implement for various data structures?
    Linear search. Simple sequential approach works universally.
  39. Which algorithm is preferable for dynamic data structures where frequent insertions occur?
    Linear search. No need to maintain sorted order during insertions.
  40. State the primary characteristic of data suitable for binary search.
    Data must be sorted. Ordering enables efficient divide-and-conquer approach.

Study these flashcards