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
The title element in the head section of an HTML document specifies the text
bagirrra123 [75]

Answer: c. that's displayed in the title bar of the browser

Explanation:

The title element in the html write up is used to describe the title of the work that is been carried out.

It has the format <title></title>, the title name is indicated between the opening and closing title tag.

The title does not display on the main page of the Web user's display, but it can be seen on the title bar of the Web browser.

The title element help Web user to have an idea of what a Web page is about.

7 0
3 years ago
Let T(n) denote the running time for the Sort-and-Count algorithm (below). Sort-and-Count(L) { if list L has one element return
butalik [34]

Answer:

The answer is "\bold{T(n) = 2T(\frac{n}{2}) + n}"

Explanation:

Given:

The Merge-And-Count of (A,B) runs in time |Al+IB|

T(n) recurrence=?

Calculating the value of the recurrence:

\to  T(n) = T(\frac{n}{2}) + T(\frac{n}{2}) + f(|A| + |B|)\\\\  \therefore f(|A| + |B|) = n\\\\ \to T(n) = 2T(\frac{n}{2}) + n

7 0
3 years ago
Jack has determined that a virus has infiltrated his computer and corrupted several of his data files. Which two utilities would
Romashka [77]
Antivirus programs to detect and eliminate viruses such as Malwarebytes, Stinger, etc.

A hard drive to backup all of his remaining files.

Corrupted files are not always possible to recover, but it's worth a try using a software such as Recuva.
7 0
3 years ago
Read 2 more answers
Assignment 2: Room area
Y_Kistochka [10]

Answer:

a = float(input("Enter Side A: "))

b = float(input("Enter Side B: "))

c = float(input("Enter Side C: "))

d = float(input("Enter Side D: "))

e = float(input("Enter Side E: "))

area1 = 1.0* a * b

area2 = (a - c) * (d - e -b)

area3 = 0.5 * (a - c) * e

print ("Room Area: " + str(area1 + area2 + area3))

Explanation:

happy to help ^3^

5 0
3 years ago
Python full code not displaying<br>only hello prints
tankabanditka [31]
From the code you posted, there is no function call to vendingMachine()

Try at the top of your code:

print ("hello")
vendingMachine()

def vendingMachine():
...
5 0
3 years ago
Other questions:
  • , = , ?<br><br>) ..(++ &lt;= );<br><br>) ..(++ &lt;= );​
    10·1 answer
  • The drone intercepts at 1256 hour. what time do they plane to take control of the drone
    11·1 answer
  • Which of the following subjects is considered technical education
    11·1 answer
  • Assume s is a string of lower case characters.
    15·1 answer
  • The PRNG variable ___________ is defined in NIST SP 800-90 as a number associated with the amount of work required to break a cr
    7·1 answer
  • Which factor helps drive globalization?
    9·1 answer
  • Teachers can organize the classroom environment to facilitate activities and to prevent problems. True Or False
    15·1 answer
  • IN WHICH COUNTRY DO THEY LET YOU PLAY MINECRAFT IN SCHOOL?
    8·2 answers
  • Realiza una tabla acerca de los escenarios de usos más comunes de Excel.
    15·1 answer
  • An IP address specifically belongs to:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!