Consider a list of n positive integers a1, a2, ..., an. Given a query positive integer m, we are required to determine if there is a prefix (that is, a₁, a2,..., a) of this list that sums to m. To solve such query problems, we precompute all prefix sums (there are n of them) and keep them in an array whose ith element is a₁ + a₂ +... .+ai. Now, the most efficient way of searching this list for m is to do a (a) Linear search (b) Binary search (c) Random search (d) None of the above

icon
Related questions
Question
Consider a list of n positive integers a1, a2,
9
an. Given a query positive integer m, we are required
to determine if there is a prefix (that is, a₁, a2, ..., a;) of this list that sums to m. To solve such query
problems, we precompute all prefix sums (there are n of them) and keep them in an array whose ith
element is a₁ + a₂ + + ai. Now, the most efficient way of searching this list for m is to do a
(a) Linear search
(b) Binary search
(c) Random search
(d) None of the above
Ans:
Transcribed Image Text:Consider a list of n positive integers a1, a2, 9 an. Given a query positive integer m, we are required to determine if there is a prefix (that is, a₁, a2, ..., a;) of this list that sums to m. To solve such query problems, we precompute all prefix sums (there are n of them) and keep them in an array whose ith element is a₁ + a₂ + + ai. Now, the most efficient way of searching this list for m is to do a (a) Linear search (b) Binary search (c) Random search (d) None of the above Ans:
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer