# Duval's algorithm and Lyndon words

First, I am not a programmer(yet) and I can only understand basic algorithms written in pseudocode (+Dijkstra, which is a little harder then others, for me). I have been trough  logic, set theory, relations, combinatorics. Currently, I am studying graph theory.

Can you give me an simple explanation on how are Lyndon words constructed with Duval's algorithm? And how is that related to de Bruijn sequnces and what pseudocode is used to construct them. Simple, because I am not so math proficient in understanding some of the notation and concepts, and also because I haven't study algorithms and programming. This problem was in my graph theory lessons ----> Eulerian and Hamiltonian cycles.

I tried understanding it from the [wikipedia](https://en.wikipedia.org/wiki/Lyndon_word) but I only understood it in parts.  Here is the pseudocode I found, but it's not clear to me.

``````w[1] ← a
i ← 1
repeat
for j = 1 to n–i
do w[i+j] ← w[j]
/* at this point, w[1...i] is a Lyndon word */
i ← n
while i > 0 and w[i] = M
do i ← i–1
if i > 0 then w[i] ← s(w[i])
until i = 0

Let a be the smallest letter of the ordered alphabet A and M be the larger one.
Furthermore, for every letter x excepted M, s(x) is the letter that immediately larger than x in A. We denote by
w[1...n] an array of letters of dimension n.``````
```  I would be thankful if you could show me by example, with some letters or numbers, so that I can intuitively comprehend it. Thanks.```
``` ```
``` algorithm combinatorics asked Jan 18, 2017 by Marko Savic ```
``` ```
``` ```
``` ```