Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If S and T are strings, we say that S is a subsequence of T if all the letters of S appear in T in

If S and T are strings, we say that S is a subsequence of T if all the letters of S appear in T in the same relative order that they appear in S. For example, pin is a subsequence of the programming, and the string singe is a subsequence of springtime. However, steal is not a subsequence of least, since the letters are in the wrong order, and p is not a subsequence of team because there is no p in team.

Note that the empty string () is a subsequence of every string.

A. Write a function named hasSubsequence that given two strings returns a Boolean to represent whether the second string is a subsequence of the first. Your solution must be recursive and must use the following function prototype:

bool hasSubsequence(const string& T, const string& S);

Note: This problem has a beautiful recursive decomposition. Think about the following questions: What strings are subsequences of an empty string?

What happens if the first character of the parameter S matches the first character of the parameter T? What happens if it doesn't? You can assume that the strings are case-sensitive, so the word AGREE is not a subsequence of the word agreeable.

B. Calculate the time complexity of hasSubsequence. (answers.pdf)

C. Write a main function that calls and tests hasSubsequence.

PROGRAMMING LANGUAGE: C++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Appreciate important legal implications of performance appraisals

Answered: 1 week ago