With respect to a string of characters, this scenario defines a discontiguous pair as any two of the same character separated by exactly one character. The separating character may or may not be the same as the characters forming the discontiguous pair, a character can be included in more than one discontiguous pair and discontiguous pairs can interleave with each other. For example, the following string of characters contains exactly 3 discontiguous pairs, namely NN (first & second), NN (second & third) and 77, where the central N (second) simultaneously belongs to two different discontiguous pairs.
The functions LENGTH(str) and TAIL(str) return the length and tail of the input string str, respectively. The tail of a string refers to the portion of the string excluding the first character.
Use the LENGTH and TAIL functions to construct a recursive algorithm called countDisPairs(str) to output the total number of discontiguous pairs for an input string str.
Short Answer3 MarksPremium
0 Uses0 Views0 Likes