ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
WordBreak.h File Reference

Is it Italian? More...

#include <cstddef>
#include "ADS/Contract.h"
#include <numeric>
#include <optional>
#include <string>
#include <vector>
#include "ADS/string/impl/WordBreak.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

template<class F>
std::optional< std::vector< std::string > > ADS::wordBreak (const std::string &s, F &&lookup, std::size_t longest=std::string::npos, long *lookups=nullptr)
 the words of \( s \), if it is a sequence of words, by the lookup( word ) of a dictionary; the lookups made go to *lookups, if given

Detailed description

Is it Italian?

(exercise 13.13): a string \( s[ 0 .. n - 1 ] \) with no spaces is a sequence of words of a dictionary if one of its prefixes \( s[ 0 .. j ) \) is and \( s[ j .. i ) \) is a word, i.e., \( \mathit{DP}[ i ] \) is true if and only if there is \( j < i \) with \( \mathit{DP}[ j ] \) true and \( s[ j .. i ) \) in the dictionary, and \( \mathit{DP}[ 0 ] \) is true; \( O( n^2 ) \) lookups, or \( O( n w ) \) if no word is longer than \( w \). The words are read back from the table.

The contracts [see Contract.h]: the words found, joined, give back the string. The operations are defined in WordBreak.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, exercise 13.13, https://algoritmicamente.it/materiali/libro/capitoli/cap13.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa