Note that your final mark will not be saved in the system.
Algorithms (2.1) GapFill
You must fill all the gaps before clicking ‘Check Answers!’
An algorithm is . There are many different types of algorithm, including searching and sorting algorithms. The following is an implementation of a linear search algorithm in pseudocode:
array numbers[5]
numbers[0] = 4
numbers[1] = 8
numbers[2] = 7
numbers[3] = 1
numbers[4] = 2
found =
x = 0
toFind =
("What number are you looking for?")
while NOT found AND numbers.length
x
if numbers[x]
toFind then
found = True
else
x = x + 1
endif
endwhile
if found == True then
print("That number is in the list")
print("That number is not in the list")
endif
The linear search algorithm checks every element in a list in the order that they appear until the element that is being searched for is found, or it reaches the end of the list. If the list is twice as long, searching using this technique will, on average, require twice as much time. To speed up searching, the search algorithm can be used instead. This algorithm checks the element of the list, and if the element being checked is not the same element that is being searched for, that element is discarded along with every element that comes before or after it in the list (depending on whether the element being checked is lower or higher than the element being searched for). This type of search can be significantly faster than a linear search, but can only be used if the list .
Sorting algorithms can be used to rearrange the order of elements in a list. There are a number of sorting algorithms, including: the sort, which starts with a single element list and adds new elements one at a time to the correct place in the list; the sort, which splits the list into single elements and combines them into larger and larger sorted lists; and the sort, which goes along the list to check every pair of elements and swaps elements that are in the wrong order.