edited by
880 views

1 Answer

Best answer
4 votes
4 votes

To form a palindrome, you can fill anything you want for the first half of the string and in the second half you need to repeat what you filled in first half in reverse manner.

In case n is odd, there will be a middle element in which you can fill anything as this will always stay in middle when you reverse the string as well.

When n is even:

No of ways the first half of string can be filled = 2^(n/2)

No of ways to fill second half = 1 (since you have to repeat first half)

So no of palindromes = 2^(n/2) * 1 = 2^(n/2)

When n is odd:

No of ways the first half of string can be filled = 2^((n - 1)/2)

No of ways to fill middle bit = 2

No of ways to fill second half = 1 (since you have to repeat first half)

So no of palindromes = 2^((n - 1)/2) * 2 * 1  = 2^((n+1)/2)

Hope this helps!

selected by

Related questions

2 votes
2 votes
1 answer
1
anumita asked May 17, 2017
390 views
How many partial functions are there from a set with m elements to a set with n elements, where m and n are positive integers.Answer : (n+1)^mHow . Can anyone please help...
2 votes
2 votes
1 answer
4
anumita asked May 17, 2017
356 views
How many strings of 5 ASCII characters contain the character @ atleast once ? [ NOTE : there are 128 ascii characters ] Answer is : 1,321,368,961Can anyone explain how ?