ProgrammingVery hardTCS NQT · Accenture
The sentence "to be or not to be to" is split into words, and the procedure below prints the most frequent word (ties go to the first word that reaches the top count). What is printed?
The sentence "to be or not to be to" is split into words, and the procedure below prints the most frequent word (ties go to the first word that reaches the top count). What is printed?
count each word; choose the word with the highest count (first in the list on ties) Print the word
- A. to
- B. be
- C. or
- D. not
Correct answer: A. to
The word to occurs three times and be twice, so the most frequent word is to. Taking the second word gives be, the least frequent word with the first-occurrence tie rule is or, and the fourth word is not.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The string "aabbc" is examined by the procedure below, which counts the substrings (contiguous pieces, counted by position) that contain…
- The procedure below counts the positions i in "abbab" where the two-letter window s[i]s[i+1] is "ab" or "ba". What is printed? count = 0…
- The procedure below counts the positions i in "mississippi" where the two letters s[i]s[i+1] are both "s" (overlaps allowed, though "ss"…
- The palindromic substrings of length exactly 3 in the string "abacaba" are counted by the procedure below, which checks each window of…
- The number of distinct substrings (non-empty, counted once per distinct text) of the string "aab" is computed by the procedure below using…
- Two positions in the word "hello" are chosen (the letters at the two positions form a pair, and positions are distinct). The procedure…