Question: 9 . Let s be a string of size n = 2 k for some k < 2 6 that consists of only lowercase letters.

9. Let s be a string of size n =2k for some k <26 that consists of only lowercase letters. The string s is said to be c-beautiful (c is an arbitrary character) if one of the three conditions is satisfied:
The size of s is 1 and it consists of the character c.
The size of s is greater than 1, the first half of s only consists of c (s1= s2=...= sn/2= c) and the second half of s (sn/2+1sn/2+2...sn) is a (c +1)-beautiful string.
The size of s is greater than 1, the first half of s (s1s2...sn/2) is a (c +1)-beautiful string and the second half of s only consists of c (sn/2+1= sn/2+2=...= sn = c).
(c +1) denotes the next lowercase letter after c in alphabetical order. For example, ccde is c-beautiful, and jjlkiiii is i-beautiful.
In an operation, you can choose any index in s and change the letter at that index to an arbitrary character. Design an O(n log n) D&C algorithm to find the minimum number of operations to convert s into an a-beautiful string.
Hint: When the size of s is 1, its the base case. When the size of s is greater than 1, there are only two cases, consider those two cases and take the minimum. (5)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!