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
Robert gets home from school at 3 p.M. His mom has to leave for her shift at work at 3:15 and she wants him to watch his baby br
navik [9.2K]

Answer:

He should stay at home to take care of his baby brother.

Explanation:

Robert should not go downtown to hang out with his friends because of the following;

=> Robert should be obedient: Robert should be obedient to his mum since Robert's mum asked him to stay with his baby brother, he should do just that.

=> Taking the baby out to hangout with his friend or leaving the baby behind might poses great danger or harm to his baby brother: ones family comes first, the protection or safety of his baby brother should come first before thinking about pleasure. Even if the baby is not his brother the first thing is safety and protection for the baby before pleasure. That is the reason we are humans.

4 0
2 years ago
When your friend DaJuan turns on his computer, he hears four beeps. The computer won’t fully boot. DaJuan has a Dell computer wi
djyliett [7]

Answer:

4 beeps indicate a Memory Read / Write failure. Try re-seating the Memory module by removing and reinserting it in the slot. This could mean it could've just jiggled loose after a while or dust, there could be a hundred other problems but those are the two most common.n:

6 0
3 years ago
To open the dialog box for modifying styles, which step must you first complete in the Navigation pane?
castortr0y [4]
Sorry I do not know this. Maybe you can help me on it? 
7 0
2 years ago
Read 2 more answers
When we insert a new node into a red-black tree, we set the color of the newly inserted node n to red. observe that if we had ch
Vika [28.1K]
Cause u didnt want to
4 0
3 years ago
Question 4 (2 points)
rodikova [14]

Answer:

Add the broadcast jump! code to the end of Scratch Cat's code.

Explanation:

If we broadcast the jump! code, then the Gobo will listen, and he will start jumping up and down. It looks like that he is not getting what Scratch Cat is saying, and if the message of Scratch Cat is broadcasted then Gobo will listen to what Scratch Cat is telling. Hence, the above option is the correct option.

6 0
3 years ago
Read 2 more answers
Other questions:
  • WHAT SHOULD YOU DO IF AN ONCOMING CAR AT NIGHT APPROACHES WITH ITS HIGH-BEAMS ON?
    6·1 answer
  • Productivity software has been used for a number of years. Recent advancements in productivity software technology have made ___
    14·1 answer
  • How many host ip addresses are available on a network with a subnet mask of 255.255.255.192?
    6·1 answer
  • Suppose your SOHO network connects to the Internet using cable modem. When you open your browser and try to access a web site, y
    8·1 answer
  • Please help me complete this task for ICT! Its about Hardware and Software
    12·1 answer
  • Which of the following is constantly changing and advancing?
    11·1 answer
  • One of the functions of an IDE is to check for: flowchart errors. Syntax errors. memory errors X input and output.​
    12·2 answers
  • 4.5 code practice computer science
    5·1 answer
  • Que relacion tiene Las palabras: fermentacion-vino y clonacion- dolly​
    9·1 answer
  • To create an SSL connection, a Web server requires a ________, which is an electronic document that confirms the identity of a w
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!