Photo AI

Figure 11 shows a binary search algorithm that has been programmed in C# - AQA - GCSE Computer Science - Question 12 - 2023 - Paper 1

Question icon

Question 12

Figure-11-shows-a-binary-search-algorithm-that-has-been-programmed-in-C#-AQA-GCSE Computer Science-Question 12-2023-Paper 1.png

Figure 11 shows a binary search algorithm that has been programmed in C#. The CompareTo method is used to compare two strings. It returns: - -1 if the first string ... show full transcript

Worked Solution & Example Answer:Figure 11 shows a binary search algorithm that has been programmed in C# - AQA - GCSE Computer Science - Question 12 - 2023 - Paper 1

Step 1

Complete the table below for the program in Figure 11 if the user input is wolf.

96%

114 rated

Answer

animalToFindvalidAnimalstartfinishmid
wolfFalse073
True076
True777

Step 2

Extend the program in Figure 12. Your answer must be written in C#.

99%

104 rated

Answer

string inputWord;
bool found = false;

Console.Write("What word would you like to find? ");
inputWord = Console.ReadLine();

for (int i = 0; i < fruits.Length; i++) {
    if (fruits[i] == inputWord) {
        found = true;
        break;
    }
}

Console.WriteLine(found ? "True" : "False");

Step 3

State why a binary search cannot be used on the array fruits.

96%

101 rated

Answer

A binary search cannot be used on the array fruits because the array is not ordered or sorted. The elements in the array must be in a sorted sequence for a binary search to work correctly.

Step 4

Rewrite line 1 and line 6 from Figure 13 to make the algorithm work as intended.

98%

120 rated

Answer

1   SUBROUTINE diffCurrencies()
6       OUTPUT(diffCurrencies(currencies[i]))

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;