Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Detect Anagram and Complexity Analysis Step 1: Implement check_anagram() One string is an anagram of another if the second is simply a rearrangement

Part 2: Detect Anagram and Complexity Analysis

Step 1: Implement check_anagram()

One string is an anagram of another if the second is simply a rearrangement of the first. For example, heart and earth and are anagrams. The strings python and typhon are anagrams as well. Assuming that the two strings in this question are of equal length and that they are made up of symbols from the set of 26 lowercase letters (a-z). In anagram.c (The code included below), Write a function check_anagram() that will take two strings and return 1 if they are anagrams, and return 0 if they are not.

Step 2: Analyze check_anagram()

Analyze the run-time complexity of the check_anagram() function you wrote using Big O notation, and put your explanation and result in a text file named anagram_analysis.txt.

Step 3: Optimize check_anagram()

There are multiple ways to tell whether the two given strings are anagrams or not, implement the function check_anagram() in anagram.c to detect anagrams with O(n) complexity.

image text in transcribed

#include

/*

The Function checks two given strings (a, b) and return

1 if they are anagram, and 0 otherwise

Assuming:

1. a and b are of the same length

2. a and b are made up of symbols from the set of 26 lowercase characters

*/

int check_anagram(char *a, char *b)

{

// FIXME:

return 0;

}

int main()

{

printf("Test 1..... ");

printf("\"heart\", \"earth\" ");

printf("Expected: 1 ");

printf("Acutal: %d ", check_anagram("heart", "earth"));

printf("Test 2..... ");

printf("\"python\", \"typhon\" ");

printf("Expected: 1 ");

printf("Acutal: %d ", check_anagram("python", "typhon"));

printf("Test 3..... ");

printf("\"race\", \"care\" ");

printf("Expected: 1 ");

printf("Acutal: %d ", check_anagram("race", "care"));

printf("Test 4..... ");

printf("\"listen\", \"silent\" ");

printf("Expected: 1 ");

printf("Acutal: %d ", check_anagram("listen", "silent"));

printf("Test 5..... ");

printf("\"seal\", \"leaf\" ");

printf("Expected: 0 ");

printf("Acutal: %d ", check_anagram("seal", "leaf"));

printf("Test 6..... ");

printf("\"asdfghjkl\", \"aasdfghjk\" ");

printf("Expected: 0 ");

printf("Acutal: %d ", check_anagram("asdfghjkl", "aasdfghjk"));

return 0;

}

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

state what is meant by the term performance management

Answered: 1 week ago