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]
3 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]3 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
Which of the following best explains what happens when a new device is connected to the Internet?
Radda [10]

Answer:

it will use up some of the internet and then you will have to pay for it later.

Explanation:

because it is taking up the internet so you will have to pay for it .

7 0
3 years ago
1. Using a microphone to create an audio file to accompany a message is an example of how data is processed and sent to an outpu
Svetllana [295]

Answer:

I would say true.

5 0
3 years ago
What social impact did the gunpowder have on society?
olga2289 [7]
It had a huge impact people could use other things than bows and arrows to fight in wars.
8 0
4 years ago
The hypothalamus controls the anterior pituitary by means of: a. releasing hormones b. second messengers c. third messengers d.
scoundrel [369]

Answer:

a. releasing hormones

Explanation:

The hypothalamus controls the anterior pituitary by means of corticotropin-releasing hormone (CRH). The hormone CRH is encoded by the CRH gene on eighth human chromosome. The anterior pituitary in turn regulates other endocrine glands by means of Adrenocorticotrophic Hormone (ACTH). These actions form part of the Hypothalamic–pituitary–adrenal(HPA) axis which is one of the important neuroendocrine systems in humans.

7 0
3 years ago
A device that is connected to the Internet is known as<br> a. Nexus. Backbone. Node. Link.
ikadub [295]
A device connected to the internet is known as a Node.
3 0
3 years ago
Read 2 more answers
Other questions:
  • What could prevent earmuffs from providing your ears good protection from noise?
    10·1 answer
  • . A program that can run more than one thread at once is called:
    9·1 answer
  • Given the security levels TOP SECRET, SECRET, CONFIDENTIAL, and UNCLASSIFIED (ordered from highest to lowest), and the categorie
    13·1 answer
  • How do you recognize the brand name of a drug in the package insert?
    15·1 answer
  • CodeHS 3.4.5. What is the code for four colored triangles.
    8·1 answer
  • To drive defensively means taking proactive measures to avoid accident situations regardless of their potential causes.
    6·2 answers
  • In the 1880’s advancements in technology and processes made photography available to the general public. Who is considered the m
    12·1 answer
  • What is the difference between i++ and ++ii?
    6·1 answer
  • Write a Python program to find whether a given number (accept from the user) is positive
    11·1 answer
  • If your cell phone rings while you are driving and you do not have a hands-free device you should
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!