Given an ordered array of integers "V" and a integer "Sum", write a function that would return "true" if it finds two numbers in V that add up to Sum, and "false" otherwise.

Because there is no unique solution to the problem the goal is to think different ways to approach an issue and ultimately opt for the best one in terms of complexity. There is an example of set of answers that would show creative thinking and good problem solving skills.1) Trivial solution, just make sure that it works by using 2 for loops to try every combination of sums-> O(n^2)2) Improved solution, realise that you can search faster by binary searching the second element of the sum -> O(nlog(n))3) Best solution, make the complexity linear by using two "pointers" to the start and the end of the vector and gradually step back or forward accordingly to the sum.

FD
Answered by Fabio D. Computing tutor

1678 Views

See similar Computing A Level tutors

Related Computing A Level answers

All answers ▸

Calculate -3 + 3 using Two's Complement and the Sign and Magnitude Method. Which works correctly?


Some problems are intractable. What does it mean for a problem to be described as intractable?


Give two types of management of either hardware or other resources that are performed by an operating system.


Given an unlimited number of light bulbs (that break at a certain height), and a building with 100 floors, how do you determine the height that the light bulb breaks?


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning