Check Permutation: Given two strings, write a method to decide if one is a permutation of the other.
I’m working through algorithm exercises with a group of people, and there was a lot of confusion about what permutation means, and how it differs from anagrams and palindromes.
So, to clarify:
A permutation is one of several possible variations, in which a set of things (like numbers, characters or items in an array) can be ordered or arranged. A permutation of characters does not have to have meaning.
Example: Given the string
abcd, the permutations are
An anagram is a word, phrase, or name formed by rearranging the characters of a string. An anagram must have meaning, it can’t just be gibberish.
Example: These words are anagrams of
A palindrome is a word, phrase, or sequence that reads the same backward as forward. A palindrome must have meaning, it can’t just be gibberish.
noon are all palindromes.
All palindromes and anagrams are permutations, but not all permutations are either anagrams or palindromes.