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
Halp Computer Science
AleksandrR [38]

1st one: is memory

2nd one: is 8

8 0
3 years ago
Read 2 more answers
During slideshow mode hitting the b key will do which of these
Lemur [1.5K]
<span>If it's an multiple answer question it's....


</span><span>B.) Blank the screen with black screen (or return to the slide if you are currently blank).</span>
8 0
3 years ago
Technician A says that temperature sensors decrease in resistance as the temperature​ increases; this is called positive tempera
Reika [66]

Answer:

Technician B.

Explanation:

The claim of technician B that some vehicle manufacturers use a stepped ECT circuit inside the PCM to broaden the accuracy of the sensor is correct.

6 0
3 years ago
PLEASE HELP! WILL MARK AS BRAINLIEST JavaScript can be implemented using the _________ HTML tags in a web page.​
Keith_Richards [23]

Answer:

JavaScript can be implemented using JavaScript statements that are placed within the ...  HTML tag

Explanation:

8 0
2 years ago
Read 2 more answers
What is an IF statement used for?
kiruha [24]

The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria. The IF statement executes one set of code if a specified condition is met (TRUE) or another set of code evaluates to FALSE.

8 0
2 years ago
Other questions:
  • Is Apple a consumer or luxury brand? Give examples.
    10·1 answer
  • What is <br> Warehouse schema.
    14·1 answer
  • What country is now the number one source of attack traffic?
    5·1 answer
  • Scientific models can be used for a variety of different purposes. Which of the following statements about scientific models is
    7·2 answers
  • Which of the following represent emerging classes of application software? Check all of the boxes that apply.
    9·3 answers
  • Although the Earth's crust formed relatively early in the Earth's history, it was not present when the Earth first began to form
    12·2 answers
  • What is a computer network?
    5·1 answer
  • A hacker uses a valid IP address of an internal host, and then from an external system, the hacker attempts to establish a commu
    11·1 answer
  • Zach would like to reuse a spreadsheet that he created last year. However, he will need to delete the contents of several cells.
    5·1 answer
  • Display the total number of parking tickets.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!