Question: Develop an algorithm to count the number of subsequences of a sequence of n characters (for example the number of subsequences of the sequence [b,c,d,e,f]
Develop an algorithm to count the number of subsequences of a sequence of n characters (for example the number of subsequences of the sequence [b,c,d,e,f] is 15) by following the logic given below. What is the complexity class of your algorithm?
- Count all the subsequences starting from the first character in a variable named count.
- Then count all the subsequences starting from the second character and add this number in the variable count.
- Then count all the subsequences starting from the third character and add this number in the variable count.
- Keep on doing this until you count the last subsequence containing only the last character and add this number in the variable count.
- Finally output the count.
The algorithms starting sentences are as follows:
ALGORITHM CountSubSequence ( A[0.n-1]) //Implements Count all the subsequences //Input: An array A[0.n-1] of n characters //Output: The count of all the subsequences of the sequence
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
