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
Discuss your favorite video games and why you like them. What types of features make a game fun to play? Why are they features e
Vesna [10]

Answer:

My favorite video games are Rainbow Six Seige and For Honor

Explanation:

I like RSS because it keeps me etertained for a long time compared to other games where I get bored of them quickly and also because when you play with friends it's even more fun. I enjoy For Honor because it's like an olden days kinda game which for some reason is fun. : ) The features in both games are very realistic and that's what I like about them because when you have your headset on and you really in the zone it can sometimes feel like your in the game

5 0
3 years ago
Read 2 more answers
Which is an example of synchronous communication? e-mail voicemail text message telephone conversation
professor190 [17]
Telephone conversation is the answer because the data works off the same clock and the data transfer occurs at regular intervals.
3 0
3 years ago
Read 2 more answers
What is the purpose of requirements gathering
inn [45]

Answer:

to determine customer needs for a software

application

to reduce over scheduling of project

resources

Explanation:

Requirement gathering and analysis involves a business analyst and the client. And this is done in various phases with the first phase involving the business analyst and the client. And the second phase of software requirement is also being covered, and that is done by a team of System analysts, business analyst, and technical writers are part of both the team. However, both the phases have nothing to do with the bugs, and hence the first and the third part is not the correct part. However, customer needs are noted down, and in the second phase when resource requirement other than technical requirement is studied, partly it is ensured that there is no over the scheduling of the project resources during the project. And hence the second and the fourth options are the correct options.

3 0
3 years ago
Read 2 more answers
What are the 4-bit patterns used to represent each of the characters in the string "1301"? Only represent the characters between
Alla [95]

Explanation:

The string "1301" can be converted into numbers by using the ASCII characters set.

1. Decimal ASCII

1=49, 3=51, 0=48, 1=49

Without space

"1301" = 49 51 48 49

with space included

"1 3 0 1" = 49 32 51 32 48 32 49

(white space is represented by 32 in Decimal ASCII)

2. Hexadecimal ASCII

1=31, 3=33, 0=30, 1=31

Without space

"1301" = 31 33 30 31

with space included

"1 3 0 1"= 31 20 33 20 30 20 31

(white space is represented by 20 in hexadecimal ASCII)

The magnitude can be found by traditional decimal to binary conversion (Divide by 2 until we are left with remainder 0 or 1) and sign can be represented by adding most significant bit (MSB) 0 for positive and 1 for negative.

A. -27

Magnitude: 00011011

Since the sign is negative add 1 to the MSB

which becomes 100011011

B. 140

Magnitude: 10001100

Since the sign is positive add 0 to the MSB

which becomes 010001100

C. -99

Magnitude: 01100011

Since the sign is negative add 1 to the MSB

which becomes 101100011

D. 46

Magnitude: 00101110

Since the sign is positive add 0 to the MSB

which becomes 000101110

7 0
3 years ago
Which of the following are reasons why it is important to properly recycle electronic equipment? Select all that apply.
faltersainse [42]
I think it is C. Sorry if I am wrong
4 0
3 years ago
Read 2 more answers
Other questions:
  • Which statement about word processing software is true? A)You can use it to perform mathematical calculations.B) You can use it
    6·2 answers
  • Morgan's cursor is blinking in the center of the page but he would like to move it to the left margin. He should _____.
    10·1 answer
  • Let's say you're creating a search stream in your hootsuite dashboard, to find mentions of the phrase vacation holiday getaway.
    15·1 answer
  • If a windows computer belongs to a domain, all security is managed by the network administrator for the entire network. true
    15·1 answer
  • Kareem is working on a project for his manager. He has a few questions for a co-worker who he knows is knowledgeable on the subj
    7·1 answer
  • Brian needs to see the space available to insert content on a slide in his presentation which feature of the presentation should
    10·1 answer
  • What allows customers to use the Web to find answers to their questions or solutions to their problems?
    5·2 answers
  • How to hide location on iphone without them knowing?.
    5·1 answer
  • How does defragmentation improve performance?
    9·1 answer
  • If you click on repeat header rows what will happen?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!