the procedure numoccurrences is intended to count and return the number of times targetword appears in the…

the procedure numoccurrences is intended to count and return the number of times targetword appears in the list wordlist. the procedure does not work as intended.\nprocedure numoccurrences (wordlist, targetword)\ncount ← 0\nfor each word in wordlist\ncount ← 0\nif word = targetword\ncount ← count + 1\nreturn count\n67 mark for review\nfor which of the following code segments will the call to numoccurrences not return the intended value?\nselect two answers.\ntreelist ← \birch\, \maple\, \birch\\nnumoccurrences (treelist, \birch\)\ntreelist ← \birch\, \maple\, \oak\\nnumoccurrences (treelist, \maple\)\ntreelist ← \birch\, \maple\, \oak\\nnumoccurrences (treelist, \oak\)\ntreelist ← \birch\, \maple\, \oak\\nnumoccurrences (treelist, \spruce\)
Answer
Explanation:
Step1: Analyze the procedure
The NumOccurrences procedure has a logical error. The inner count variable is re - initialized to 0 in each iteration of the loop instead of maintaining the cumulative count.
Step2: Check each option
- For the list
["birch", "maple", "birch"]and target "birch", due to the error, it won't count correctly as the innercountis reset each time. - For the list
["birch", "maple", "oak"]and target "maple", it will have the same incorrect counting behavior. - For the list
["birch", "maple", "oak"]and target "oak", same issue. - For the list
["birch", "maple", "oak"]and target "spruce", since "spruce" is not in the list, the incorrect counting behavior still applies in the sense that the procedure won't work as intended.
Answer:
All four options will not return the intended value.