1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nekit [7.7K]
2 years ago
15

A palindrome is a string that reads the same from left to right and from right to left. Design an algorithm to find the minimum

number of characters required to make a given string to a palindrome if you are allowed to insert characters at any position
Computers and Technology
1 answer:
stepladder [879]2 years ago
3 0

Answer:

Explanation:

The following code is written in Python. It is a recursive function that tests the first and last character of the word and keeps checking to see if each change would create the palindrome. Finally, printing out the minimum number needed to create the palindrome.

import sys

def numOfSwitches(word, start, end):

   if (start > end):

       return sys.maxsize

   if (start == end):

       return 0

   if (start == end - 1):

       if (word[start] == word[end]):

           return 0

       else:

           return 1

   if (word[start] == word[end]):

       return numOfSwitches(word, start + 1, end - 1)

   else:

       return (min(numOfSwitches(word, start, end - 1),

                   numOfSwitches(word, start + 1, end)) + 1)

word = input("Enter a Word: ")

start = 0

end = len(word)-1

print("Number of switches required for palindrome: " + str(numOfSwitches(word, start, end)))

You might be interested in
Camille prepared excellent PowerPoint slides for her speech about education reform, but the speech didn't go as well as she had
Elanso [62]

Answer:

The answer is "she uses the keyboard unless she could quickly progress the slides".

Explanation:

Planning is the single least key aspect of having the performance effectively. It is a critical foundation and which can dedicate much space as possible to it and avoids loopholes.  

  • It is the proper planning that may also ensure, that you have fully considered.  
  • It is the thing, which we need to convey into your delivery and will also help to boost your trust.
6 0
3 years ago
What are informational sessions?
arsen [322]

Answer:B

Explanation:

7 0
3 years ago
The recommended flux for electrical soldering is A. antimony. B. sal ammoniac. C. rosin. D. muriatic acid.
expeople1 [14]
I pretty sure its D muriatic acid
3 0
3 years ago
Which nation has a command economy
Over [174]

Answer:command economy is a key feature of any communist society. Cuba, North Korea, and the former Soviet Union are examples of countries that have command economies, while China maintained a command economy for decades before transitioning to a mixed economy that features both communistic and capitalistic elements

5 0
3 years ago
Read 2 more answers
What do you think is the most important event in the history of the Internet? What event has had the biggest impact on your dail
lana [24]

Answer:the answer would be this serious when anonimous came to the world or rather when anonymity came

 

Explanation:

The most important events of all the Internet was when anonomous arrived and began to reveal secrets and things against the United States government

 

3 0
3 years ago
Other questions:
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • Help !!!!!
    9·1 answer
  • Which button, when pressed, allows light from the subject to fall on the sensor?
    8·1 answer
  • Assign jsonData with the parsed value of the stringData variable. Then, assign 29 to the points property in jsonData and assign
    13·1 answer
  • Analytical CRM systems are the input for operational CRM systems.<br><br> True<br><br> False
    11·1 answer
  • Life Decisions Cyber Cafe is a cafe with free Internet service and computers that are linked to various online career opportunit
    15·1 answer
  • Write a Python program that translates a binary number of n bits to a decimal number. Your program should first ask the user the
    8·1 answer
  • In a relational database, the three basic operations used to develop useful sets of data are:_________.
    14·1 answer
  • Agent Phil Coulson developed this program to register Avengers in S.H.I.E.L.D's database using cutting-edge programming language
    15·1 answer
  • 1. A cell is identified by its ........
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!