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
Hard disk works on the following technologies: (i) Technology used within the hard drive to read & write data to the drive a
Alex787 [66]

Answer:

The green-blue circuit board you can see in the first photo includes the disk controller, a circuit that allows the computer to operate the drive's mechanisms and read/write data to and from it. ... A small hard drive typically has only one platter, but each side of it has a magnetic coating

Explanation:

8 0
3 years ago
If u reading this ,DO THAT WORK
Ivenika [448]
I am.


Explanation


Characters
7 0
2 years ago
Pressing the Ctrl+Home keys moves the insertion point to the
rewona [7]
I'm going to go with A
5 0
3 years ago
9) If you are working on the part of 5-15 minutes, time-stamping (every 30 seconds) should start at: a) [00:05:00] b) [00:00:00]
loris [4]

Answer:

a) [00:05:00]

Explanation:

Timestamps are markers in a transcript which are used to represent when an event took place. Timestamps are in the format [HH:MM:SS] where HH is used to represent hour, MM to represent the minute and SS to represent the seconds. They are different types of timestamping such as:

i) Periodic time stamps: Occurs at a consistent frequency

ii) Paragraph time stamping: At the beginning of paragraphs

iii) Sentence time stamp: at the beginning of sentence

iv) Speaker time stamp: at change of speaker.

Since a part of 5-15 minutes with time-stamping (every 30 seconds), The time stamping should start at 5 minute [00:05:00] and end at [00:15:00]. This is a periodic time stamp since it occurs every 30 seconds, this means the next time stamp would be [00:05:30] and this continues until 15 minute [00:15:00]

3 0
3 years ago
If I wanted to repeat an action such as a heading for a paper, it would be helpful to _____.
NemiM [27]
Possibly rephrase or rewrite the heading or whatever else you decide to repeat. You should never say the exact thing twice. 
Hope I helped :)
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which program or security application prevents access between a private and trusted network, and other untrusted networks?
    8·2 answers
  • Which of the following is NOT one of the most important elements when designing a website?
    8·2 answers
  • 1. Mobile devices have a _________ viewport that displays a web page content that fits within a mobile screen.
    11·1 answer
  • 2. Consider the two-dimensional array A: int A[][] = new int[100][100]; where A[0][0] is at location 200 in a paged memory syste
    11·1 answer
  • This program will get you used to retrieving a value from a function. The function should be named getRandomNumber. The function
    15·1 answer
  • Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county s
    8·1 answer
  • HELP ME PLZ QUICK Adam is writing a program that: 1) has the user guess a number, and 2) tells the user how many guesses it took
    6·1 answer
  • ON QUIZ PLEASE HELP
    13·1 answer
  • A user logs into Active Directory on a workstation and the user home directory does not redirect to a network share on a file se
    15·1 answer
  • In the table below, identify the data type that would be most suitable for the second field.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!