Discrete Mathematics and Its Applications, Seventh Edition

Published by McGraw-Hill Education
ISBN 10: 0073383090
ISBN 13: 978-0-07338-309-5

Chapter 3 - Section 3.1 - Algorithms - Exercises - Page 203: 22

Answer

procedure longestword (String sentence : a series of characters and words separated by blank spaces) Split sentence into separate words: $w_1, w_2, w_3, .... w_n$ {Notice that this could be done by taking any set of characters between blank spaces as a word} word largest $:= w_1$ for $i: = 1$ to $n$ $\space\space\space$if length$($largest$)

Work Step by Step

The algorithm attempts to find the largest word in an English sentence. It does this by first splitting the sentence in separate words (based on blank spaces) and then comparing the lengths of each. Notice how our implementation is sort of high-level. For example, we did not implementing the split or length procedures. This would be allowed in high-level description of algorithms since this is not for a computer to read.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.