0
0
Intro to Computingfundamentals~20 mins

Search and find operations in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Linear Search

Imagine you have a list of names on a paper. You want to find if the name "Alice" is in the list by checking each name one by one from the start.

Which description best matches this search method?

ACheck each item from start to end until you find "Alice" or reach the end.
BJump to the middle of the list and decide which half to search next.
CSort the list first, then look for "Alice" using a fast method.
DRandomly pick names until you find "Alice".
Attempts:
2 left
💡 Hint

Think about checking names one by one in order.

trace
intermediate
2:00remaining
Trace Binary Search Steps

You have a sorted list: [2, 4, 6, 8, 10, 12, 14]. You want to find the number 10 using binary search.

Which sequence of middle elements will the search check?

A8, 10
B8, 12, 10
C10
D6, 10
Attempts:
2 left
💡 Hint

Binary search picks the middle element each time and narrows down the search.

identification
advanced
2:30remaining
Identify the Error in Search Algorithm

Consider this pseudocode for searching a value in a list:

start = 0
end = length(list) - 1
while start <= end:
  mid = (start + end) // 2
  if list[mid] == target:
    return mid
  elif list[mid] < target:
    start = mid + 1
  else:
    end = mid - 1
return -1

What is the mistake in this binary search implementation?

AThe update of 'end' and 'start' is reversed; 'start' should increase when list[mid] < target.
BThe function should return mid + 1 when the target is found.
CThe condition in the while loop should be start < end, not start <= end.
DThe calculation of 'mid' should use floating division instead of integer division.
Attempts:
2 left
💡 Hint

Think about which half to search next when the middle value is less than the target.

Comparison
advanced
2:30remaining
Compare Search Methods Efficiency

Which statement correctly compares linear search and binary search on a sorted list of 1,000,000 items?

ALinear search is faster because it checks items one by one, which is simpler.
BLinear search is faster because binary search requires sorting first.
CBoth searches take the same time because they look for the same item.
DBinary search is faster because it divides the list and eliminates half each time.
Attempts:
2 left
💡 Hint

Think about how many items each method checks in the worst case.

🚀 Application
expert
3:00remaining
Find the Number of Comparisons in Binary Search

You use binary search to find a number in a sorted list of 1023 elements.

What is the maximum number of comparisons binary search will make before concluding?

A11
B9
C10
D8
Attempts:
2 left
💡 Hint

Binary search maximum comparisons relate to the power of 2 just greater than the list size.