Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(using c programing languge) Part 1: Check if a String is valid shuffle of two String You are given 3 strings: str1, str2, and str3.

(using c programing languge)

Part 1: Check if a String is valid shuffle of two String

You are given 3 strings: str1, str2, and str3. str3 is said to be a shuffle of str1 and str2 if it can be formed by interleaving the characters of str1 and str2 in a way that maintains the left to right ordering of the characters from each string. For example, given first = "abc" and second = "def", third = "dabecf" is a valid shuffle since it preserves the character ordering of the two strings, but not "adecbf". So, given these 3 strings write a function that detects whether third String is a valid shuffle of first and second String.

This problem is very similar to the merge we have to do in the mergesort. You should try to first manually try to verify a few examples to see the pattern.

Part 2: Count unique characters in a string

Given a string, you should count how many different characters appeared in the string. The character can be a letter, a space, a comma, or any other symbol. Write a function that accepts a char* input, and return an integer. You might want to re-read the last section of the array and pointers lecture notes to do this part of the assignment.

The trick is: how do you know if the next character in the string is a new string?

Method 1: you can compare to all characters appeared before it, and see if it equals to any of them. If so, this is not a new character.

Method 2: Store all the characters you have seen before, and compare to all of them to see if this is a new character.

Given a short string, method 1 would be ok, but what if the string you need to parse is as long as the file moby_dick.txt? Then, reading all previous characters gets harder and harder as you approach the end of the file. However, there can only be so many characters in the world. So, comparitively, the method 2 would be better. However, to maintain such a list, you need to be able to change the size of the array to make sure that list of characters you have met can change size, as you do not know how many of them may appear.

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

More Books

Students also viewed these Databases questions

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago