Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are competing with your friends to type text messages on your smartphone as quickly as possible. Here are the rules: you use two

image text in transcribed

You are competing with your friends to type text messages on your smartphone as quickly as possible. Here are the rules: you use two thumbs for texting and they start out on the bottom left and bottom right keys of the keyboard. To type a character, you move either thumb from its current key to the key you need to press, and it takes time equal to the distance between the keys. You can assume the following: The keyboard has keys labeled {1,2,..., k} and there is a function dist (i,j) to calculate the distance between two keys i and j. (To visualize this, you may want to imagine the digits 1 through 9 arranged on a standard numeric keypad). Your left thumb starts on key a, and your right thumb starts on key b. (For example, on the 9-digit numeric keypad, a = 7 is the bottom left key, and b = 9 is the bottom right key.) You can press any key with either thumb Both thumbs can rest on the same key if necessary The characters to by typed are cC2 Cn, where c; E {1, 2,..., k} is the ith key to push Homework 4 3 Design an algorithm that finds the fastest way to type the message. In other words, your algorithm needs to decide which thumb to use to type each character, and it should minimize the total distance moved by your two thumbs. Try to use O(nk2) time.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To design an algorithm that finds the fastest way to type the message with a complexity of Onk we can use dynamic programming Lets define a function d... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Global Strategy

Authors: Mike W. Peng

5th Edition

0357512367, 978-0357512364

More Books

Students also viewed these Programming questions

Question

P(c Z 1.09) = 0.8415

Answered: 1 week ago

Question

discuss the key benefits of service - oriented computing

Answered: 1 week ago

Question

What kind of rays are X-rays?

Answered: 1 week ago