0% found this document useful (0 votes)
8 views

Assignment 9

The document provides instructions for a programming assignment. Students are instructed to write a program that takes three strings as input and checks if one string is an interleaving of the other two strings, and if not, finds an interleaving with Hamming distance of 1. The program should run efficiently in O((n+m)mn) time. Sample outputs are provided.

Uploaded by

dhali.arghya2016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment 9

The document provides instructions for a programming assignment. Students are instructed to write a program that takes three strings as input and checks if one string is an interleaving of the other two strings, and if not, finds an interleaving with Hamming distance of 1. The program should run efficiently in O((n+m)mn) time. Sample outputs are provided.

Uploaded by

dhali.arghya2016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS29003 Algorithms Laboratory

Assignment

General instruction to be followed strictly


1. Do not use any global variable unless you are explicitly instructed so.

2. Do not use Standard Template Library (STL) of C++.

3. Use proper indentation in your code and comment.

4. Name your file as <roll_no>_a<asst_no>. For example, if your roll number is 14CS10001
and you are submitting Assignment 1, then name your file as 14CS10001_a1.c or
14CS10001_a1.cpp as applicable.

5. Write your name, roll number, and assignment number at the beginning of your program.

6. Make your program as efficient as possible. Follow best practices of programming.

7. Submit your program on Moodle before deadline. Submissions by email or any other means will
NOT be considered for evaluation.

Given three strings x, y, s, s is said to be an interleaving of x and y if the characters of s are formed by
the characters of x and y, plus x is a subsequence of s and y is also a subsequence of s. Eg. ADEBCF is
interleaving of ABC and DEF. If s is an interleaving of x and y and there is a common character in x and
y then that character appears multiple times in s. Eg. ACDABC is interleaving of ABC and ACD.
The Hamming distance between 2 strings s1 , s2 of the same length is the number of indices where
the two strings differ. Eg. rat and bat have a Hamming distance of 1.
Write a program to do the following:

1. Take as input 3 strings x, y, s. Let the length of x and the length of y be m and n respectively.

2. Check if s is an interleaving of x and y and print the result.

3. If s is not an interleaving of x and y, check if there is an interleaving of x and y that is at Hamming


distance 1 from s. (Hint: Guess the index where s is differing from the interleaving.)

4. Print the interleaving of x and y that has a Hamming distance of 1 with s, or say that no such
interleaving exists.

5. Your algorithm should run in O((n + m)mn) time.

You may write your own auxiliary functions.


Submit a single .c or .cpp file. Your code should get compiled properly by gcc or g++ compiler.

1
Sample Output

Input x: abcd
Input y: efgh
Input s: aefbghcd
$s$ is an interleaving of $x$ and $y$

Input x: abcd
Input y: efgh
Input s: abclfdgh
abcefdgh is an interleaving of x and y that has Hamming distance 1 with s

Policy on Plagiarism
Academic integrity is expected from
all the students. You should work on
the assignment/exam consulting
only the material we share with you.
You are required to properly
mention/cite anything else you look
at. Any student submitting
plagiarized code will be penalized
heavily. Repeated violators of our
policy will be deregistered from the
course. Read this to know what is
plagiarism.

You might also like