this is part of the code for the quicksort algorithm, but really I don’t know why it uses rand() %n, please help me thanks
rand() %n
Swap(V,0,rand() %n) // move pivot elem to V[0]
Used to randomize Quick Sort to achieve nlgn average time complexity.
To quote from Wikipedia:
What makes random anchor points a good choice?, , . ; 25% , 25% . , 2log2n 1, .
What makes random anchor points a good choice?
, , . ; 25% , 25% . , 2log2n 1, .
O (nlog (n)), - n ^ 2 ( ). , O (nlog (n)), , rand()% n 0 n-1.
Source: https://habr.com/ru/post/1748965/More articles:Как я могу расшифровать сообщения, отправленные из log4j через сокет? - javaHow to save application state using NSUserDefaults on iPhone? - iphoneTortoise SVN: настройка разных разрешений для подпапок - permissionsASP.NET MVC 2 Tutorial - asp.netКак я могу найти размер файла/изображения ELF с информацией заголовка? - linuxCulture Independent CSV - csvhow to set style via javascript in IE right away - javascriptC language - Fscanf and sprint commands in unix environment - cLINQ: как преобразовать список, выполнив вычисления по каждому элементу - c#NSRunningApplication, a returned list of recently used applications? - cocoaAll Articles