Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

Question about construction of suffix array

Revision en1, by Azret, 2016-04-01 09:55:55

Hello.

Reading the article from e-maxx (ALERT! RUSSIAN!). A piece of code ("radix sort of equivalence classes" part):

	for (int i=0; i<n; ++i) {
		pn[i] = p[i] - (1<<h);
		if (pn[i] < 0)  pn[i] += n;
	}
	memset (cnt, 0, classes * sizeof(int));
	for (int i=0; i<n; ++i)
		++cnt[c[pn[i]]];
	for (int i=1; i<classes; ++i)
		cnt[i] += cnt[i-1];
	for (int i=n-1; i>=0; --i)
		p[--cnt[c[pn[i]]]] = pn[i];

Why p[] contains correct order of cyclic shifts of length 2k after?

Tags suffix, array, question, alert russian, construction

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Azret 2016-04-01 09:55:55 585 Initial revision for English translation
ru2 Russian Azret 2016-04-01 08:17:33 40
ru1 Russian Azret 2016-04-01 08:15:54 551 Первая редакция (опубликовано)