Skip to content

banitaba/Palindrome-Permutation-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Palindrome Permutation algorithm

TACOCAT and Algorithm Time complexity !!!

Published on September 9, 2018

Hossein Banitaba Full Stack Software Developer

What is the Time Complexity? In computer science, the time complexity is the computational complexity that describes the amount of time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform.

The above definition is actually what is written on the text books but I plan to describe the same concept with a very simple example of Palindrome Permutation algorithm in PHP.

A String is called Palindrome if it reads the same backwards as well as forwards. For example, the String can be read the same backwards as well as forwards like "tacocat".

Now, a Permutation of a String S is some String K where S and K contain the same set of characters, however, these characters need not necessarily have the same positions. For Example, consider the String . Here, the Strings :

1-acb 2-bca 3-bac 4-cab 5-cba are all permutations of it.

Now suppose that, given a String S consisting of lowercase English alphabets, you need to find out whether any permutation of this given String is a Palindrome. If yes, print "YES" (Without quotes) else, print "NO" without quotes.

like "tacocat" which is palindrome so the below strings are all Palindrome Permutation of "tacocat" whether those are palindrome or not:

1-accoatt 2-aaccott 3-aaocctt 4-actotca

It is clear that a Palindrome string can have number of even occurrence of any characters. but it only can have odd number of occurrence of a specific characters one time in the middle. so we can have the below algorithm to find whether a string is Palindrome Permutation or not.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages