Posts

Showing posts from August, 2021

Fisher-Yates Shuffle algorithm

 Fisher-Yates Shuffle algorithm Description: An algorithm for shuffling a finite sequence into randomized permutation. Process: Let arr be a finite sequence. Let n be the length of the finite sequence arr.  for i from n-1 downto 1 do:     j<- a random number which 0<=j<=i;     swap arr[i],arr[j]; Time  Complexity: O(n) where n is length of the sequence Code(C#): class Program     {         static void Main(string[] args)         {             Console.WriteLine("Hello World!");             char[] c = { 'A', 'B', 'C', 'D', 'E' };                          Console.Write("Before:");             PrintSequence(c);             Console.WriteLine();             FisherYatesShuffleFunc(ref c); ...