Question: 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.

Part 2: Detect Anagram and Complexity Analysis Step 1: Implement check_anagram() One

#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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!