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
BRAINLIEST plz help
avanturin [10]

Answer:C

Explanation:

8 0
3 years ago
What are the coordinates of point B in the diagram? A. (3.25, -2.5) B. (4, -5) C. (1, 3) D. (2.5, 0)
Pie
Isn't it B because the x is increasing by .75 and y is deceasing by 2.5
8 0
3 years ago
Read 2 more answers
Which of the following is considered a benefit of using simulation programs? a. They allow users to experience potentially dange
erica [24]

Answer:

All of the above

Explanation:

7 0
3 years ago
4. Why isn't it realistic to market a new product using promoted tweets?
erica [24]

Answer:

Great question

Explanation:

is not realistic because nearly everyone doesn't even consider to look at the ad. Most people actually find it annoying when they are scrolling on their feed and all of a sudden an ad pops up.

3 0
3 years ago
Read 2 more answers
To turn off the AutoCorrect features, navigate to the AutoCorrect menu and deselect the box labeled_____.
barxatty [35]
Option A-Show AutoCorrect buttons, then you have the options to hide the autocorrect or to turn it on/off
4 0
3 years ago
Read 2 more answers
Other questions:
  • What type of lights are necessary for silhouettes?
    12·2 answers
  • Why does a HTML seen to work even when its broken? why does the code sometimes turn pink?
    9·1 answer
  • Create a style rule for the page body that sets the width to 95% of the browser window ranging from 640 pixels up to 960 pixels.
    11·1 answer
  • Explain the history of computing of mechanical era
    14·2 answers
  • When you open as many links as you want, and still stay in the same browser window instead of cluttering your screen with multip
    5·1 answer
  • Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages, Create a se
    12·1 answer
  • The road is closed a head
    9·1 answer
  • List the operating system you recommend, and write a sentence explaining why.
    8·1 answer
  • Question 3
    13·1 answer
  • Why is the song Twinkle Twinkle Little Star an example of ternary form?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!