ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions

AH Computing Science 2025 Question 2

5 marks · Binary search

State one reason why the data shown is suitable for this algorithm. State the maximum number of comparisons required to find any company name using this algorithm. The design of a binary search algorithm shown below contains three errors. 1. set low to 0 2. set high to 99 3. set found to false 4. get target company name 5. while not found and low ≠ high 6. set middle to (high − low) /2 7. if target = company name at middle position then 8. set found to true 9. else 10. if target is before company name at middle position then 11. set high to middle − 1 12. else 13. set high to middle − 1 14. end if 15. end if 16. end while 17. if found then 18. display share price at middle position 19. else 20. display not found message 21. end if Identify the three lines that contain an error and describe the corrections required. The share prices for the top 100 technology companies are stored in a program. The program uses an array of records called companies with fields for companyName and sharePrice. Sample data stored in the array of records is shown below. companyName sharePrice Apex Industries 87.23 Blue Horizon Ventures 56.89 Celestial Technologies 102.34 … … Vertex Cybersecurity 79.56 Zephyr Wind Power 67.89 Zeta Blockchain Systems 110.23 A binary search algorithm will be used to search for a company’s name and display its share price.

Marking scheme

The company names are in alphabetical order. Do not award mark for simply stating that data is in order; answer must clearly indicate that companyName field is ordered 7 comparisons • error 1 at Line 5. This should be low<=high to terminate the loop • error 2 at Line 6. This should be set middle value to (high + low)/2 • error 3 at Line 13. This should be set low to middle + 1 Award 1 mark for each error with correction indicated – do not award mark for simply stating the error. Accept error at Line 5 is high>=low

Previous question: AH Computing Science 2025 Question 1

Next question: AH Computing Science 2025 Question 3