- Get link
- X
- Other Apps
Yes—if you mean constructing a searching algorithm, it commonly uses two fundamental control structures:
- Looping (iteration) — repeatedly checks elements until a condition is met or all elements have been checked.
- Selection (decision) — uses conditions such as
if/elseto decide whether the current element matches the search target.
For example, linear search:
for each element in the list:
if element == target:
return "Found"
return "Not found"
Here:
for each→ loopingif element == target→ selection
So, yes, a searching algorithm can be constructed using looping and selection, although algorithms can also use other structures depending on the search method.
Comments