TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of Duval's algorithm. More...
#include <array>
#include <cassert>
#include <cstddef>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | string |
string manipulation algorithms | |
Functions | |
template<typename T > | |
size_t | string::duval (const T &s) |
Find the lexicographically smallest cyclic shift of a sequence. | |
static void | test () |
self test implementation returns void | |
int | main () |
main function | |
Implementation of Duval's algorithm.
Duval's algorithm is an algorithm to find the lexicographically smallest rotation of a string. It is based on the concept of Lyndon words. Lyndon words are defined as the lexicographically smallest string in a rotation equivalence class. A rotation equivalence class is a set of strings that can be obtained by rotating a string. For example, the rotation equivalence class of "abc" is {"abc", "bca", "cab"}. The lexicographically smallest string in this class is "abc".
Duval's algorithm works by iterating over the string and finding the smallest rotation of the string that is a Lyndon word. This is done by comparing the string with its suffixes and finding the smallest suffix that is lexicographically smaller than the string. This suffix is then added to the result and the process is repeated with the remaining string. The algorithm has a time complexity of O(n) where n is the length of the string.
Definition in file duval.cpp.
int main | ( | void | ) |
|
static |
self test implementation returns void
Definition at line 77 of file duval.cpp.