Random 什么';与其他洗牌算法相比,这种洗牌算法的缺点是什么?

Random 什么';与其他洗牌算法相比,这种洗牌算法的缺点是什么?,random,shuffle,Random,Shuffle,与其他洗牌算法相比,这种洗牌算法的缺点是什么?例如,Fisher–Yates 代码来源: 私有列表shufflist(列表输入列表) { List randomList=新列表(); 随机r=新随机(); int随机指数=0; 而(inputList.Count>0) { randomIndex=r.Next(0,inputList.Count);//在列表中选择一个随机对象 添加(inputList[randomIndex]);//将其添加到新的随机列表中 inputList.RemoveAt

与其他洗牌算法相比,这种洗牌算法的缺点是什么?例如,Fisher–Yates

代码来源:

私有列表shufflist(列表输入列表)
{
List randomList=新列表();
随机r=新随机();
int随机指数=0;
而(inputList.Count>0)
{
randomIndex=r.Next(0,inputList.Count);//在列表中选择一个随机对象
添加(inputList[randomIndex]);//将其添加到新的随机列表中
inputList.RemoveAt(randomIndex);//删除以避免重复
}
return randomList;//返回新的随机列表
}

顺便问一下,这个算法有名字吗

从生成的列表的角度来看,这个算法很好——事实上,元素的每一个可能排列都同样可能返回

缺点是它的复杂性,它在
O(n^2)
时间内运行,因为在每次迭代中,无论是查找元素(如果列表恰好是一个链表)还是将其从列表中删除(如果它恰好是一个数组列表),都需要线性时间

private List<E> ShuffleList<E>(List<E> inputList)
{
 List<E> randomList = new List<E>();

 Random r = new Random();
 int randomIndex = 0;
 while (inputList.Count > 0)
 {
      randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
      randomList.Add(inputList[randomIndex]); //add it to the new, random list
      inputList.RemoveAt(randomIndex); //remove to avoid duplicates
 }

 return randomList; //return the new random list
}