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
George wants to edit the font of the title text in his presentation. Where can he find the option to edit it?
liberstina [14]
The answer is the answer choice D
4 0
3 years ago
Read 2 more answers
All of the following can be caused by the movement of geologic plates EXCEPT
Aleks04 [339]
I think storm surges cause fro means world "earth" so a storm surge is like a flood SO plates would cause earth quakes and stuff
8 0
4 years ago
What is returned by the code: range (5, 100, 25) ?
Nataly [62]
You would have to add them up need more info on the returned video
6 0
3 years ago
Read 2 more answers
What are barcode and rfid tags ​
Solnce55 [7]

Answer:

They are both ways to identify assets (e.g., persons, animals, objects).

Explanation:

A barcode is a bit of information (usually a number) printed as a line or block pattern on a surface (e.g., a sticker).

An RFID is a bit of computer memory with an antenna.

Both can be read with the appropriate scanner device.

7 0
3 years ago
Read 2 more answers
In which generation of computers are we in?​
qwelly [4]
It should be the Sixth generation
4 0
3 years ago
Other questions:
  • Which of the following is the best definition of a workplace policy?
    13·2 answers
  • Web pages often have built-in connections, or links, to other documents, graphics, other web pages, or web sites. true or false?
    9·1 answer
  • A slideshow that accompanies an oral report is known as what?
    6·1 answer
  • You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips
    10·2 answers
  • You are creating a database for your computer club. Most of the students live in your town, Durham. How can you make Durham appe
    11·1 answer
  • Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme
    15·1 answer
  • Why is data processing done in computer?​
    14·1 answer
  • JAVA
    12·1 answer
  • The program DebugTwo2.cs has syntax and/or logical errors. Determine the problem(s) and fix the program.// This program greets t
    5·1 answer
  • Which of the following database object hold data?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!