Skip to content

Assignment 1#1

Closed
mandana-g wants to merge 4 commits into
mainfrom
assignment-1
Closed

Assignment 1#1
mandana-g wants to merge 4 commits into
mainfrom
assignment-1

Conversation

@mandana-g
Copy link
Copy Markdown
Owner

What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)

adding code in assignment-1 for anagram_checker

What did you learn from the changes you have made?

practicing working with strings, function, etc.

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

checking ASCII codes could be another approach.

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

there were some redundancy in my code that I tried to handle by adding a new function.

How were these changes tested?

by setting different inputs for the function.

A reference to a related issue in your repository (if applicable)

Checklist

  • I can confirm that my changes are working as intended

@pedram-aliniaye-asli
Copy link
Copy Markdown

pedram-aliniaye-asli commented Dec 6, 2024

You did a great job here!
A few quick things to note, in part 1 your approach is reasonable but has some inefficiencies. Specifically, the nested loops you're using to compare characters are not needed for checking anagrams. You can simplify the solution by leveraging sorting or using a frequency count for characters. Additionally, you can directly check if the result array has only 1s by using all(result) without needing to compare each individual value with 1 directly.

In part 2, your implementation for checking anagram status with a case sensitivity flag is mostly on the right track, but there are a few issues and improvements that could be made:

Inefficiency in Nested Loops: The nested loops inside the comparison() function are inefficient because they compare each character of word_a to each character of word_b, leading to an O(n^2) time complexity. Instead, we can simplify it by sorting both words and comparing the sorted versions or using a frequency counter.

Result Array Logic: The result array is used to track matches, but you are resetting its values to 0 unnecessarily. Instead, a better approach would be to keep track of the frequencies of characters in both words.

Please go ahead and close this pull request, Thanks!

@mandana-g mandana-g closed this Dec 11, 2024
@mandana-g mandana-g mentioned this pull request Dec 11, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants