기본 콘텐츠로 건너뛰기

1월, 2018의 게시물 표시

[Toy]SuffleDeck.js

SuffleDeck 덱을 랜덤하게 suffle하는 문제입니다. 전에 비슷한 문제를 푼적이 있어 그런식으로 해보았네요. /** Given an array containing a deck of cards, implement a function that shuffles the deck. * Example: var deck = orderedDeck(); // [“A♥”,”2♥”,”3♥”,…,”J♦”,”Q♦”,”K♦”] shuffleDeck(deck); // [“2♠”,”J♣”,”A♦”, … ,”7♣”,”8♣”,”K♠”] * Note: A shuffled deck should be completely random. That means that a given card should be as likely as any other to appear in a given deck index, completely independent of the order of the input deck. Think carefully about how to be sure your algorithm generates a properly shuffled deck— it is easy to accidentally create a biased algorithm. * Extra credit: Even a naive algorithm can easily run in linear time. However, does your algorithm remain unbiased as N (the deck size) increases? How do you know? Once you have created a properly random, linear algorithm, what is its space complexity? There is an algorithm that uses O(N) time and O(1) space (i.e., an in-place