Question: A. Write an algorithm that implements the word wrap operation. It should take a string and an integer representing the screen width. The output should

A. Write an algorithm that implements the word wrap operation. It should take a string and an integer representing the screen width. The output should be a list of strings, each representing a line of text. Make sure your algorithm doesnt split any strings and correctly handles new line characters that are encountered. Find the time and space complexity of your algorithm. B. Suppose you are investing. You want to buy low and sell high to maximize your profit. Thanks to the magic of time travel you have acquired an array of future prices, but can only perform two trades, one buy and one sell. Your array of prices is in chronological order and your buy order must precede your sell order. Design a O(n log n) divide and conquer algorithm for finding the maximum profit you can make. Find the space complexity of your algorithm.

C. Design an algorithm to implement the paint fill function that one might see on many image editing programs. That is, given a screen (represented by a two dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color. Find the time and space complexity of your algorithm.

D. Given a string, write an algorithm to find the longest substring that is a palindrome. Find the time and space complexity of your algorithm. Example: suppose the input is: sampleracecartest, you should return racecar. (Note: The optimal solution for this problem uses dynamic programming and uses ?(n2) time and space.)

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 Databases Questions!