When searching for the entry X within the list R S T U V W Z
When searching for the entry X within the list R, S, T, U, V, W, Z how many entries will be considered before discovering that the entry is not present? (Note that the list is in alphabetical order.)
Solution
Please follow the data and description :
From the given list we could find that the list has 7 elements as R, S, T, U, V, W, Z.
So to check or discover that the required character is not found we need to iterate over the data of the elements. If this was an integer array the process could be easier but as these are the alphabets this could be simpler if it was with the ASCII codes so that if the successive code is not found the loop could be breaked down.
So the count could be till the preceeding elements of the X(element to be found) which is till W and the count is 6.
So that based on the ASCII code the loop goes till the W and breaks finding that the element X is not present where the count is 6.
So the answer is 6.
Hope this is helpful.
