é復å æ½åºã®é«éãã¤å®è£ ãç°¡åãªæ¹æ³ãèãã
â» @tomerun ããã«æ¸ãã¦ããã£ãã³ã¼ãã¨ãã®æ¤è¨¼çµæãè¨äºã®æå¾ã«è¿½è¨ãã¾ããï¼(2013-07-21 2:00)
ãµã¨ãããã£ããã§é復å æ½åº (random sampling without replacement) ãå®è£ ããã¨ãã«æ°ã«ãªã£ãã®ã§ã©ããªå®è£ ãããã®ãèãã¦ã¿ãï¼ãªãé復å æ½åºã¯ãã³ã´ã®ããã«ï¼Nåã®è¦ç´ ã®ä¸ããkåã®ç°ãªãè¦ç´ ãã©ã³ãã ã«é¸æããã¨ããæå³ã§ããï¼
復å æ½åºã«ã¤ãã¦ã¯ @unnonouno ããã®ããã°ãªã©ã«æ¸ãã¦ããï¼é復å æ½åºã«ã¤ãã¦ããªã³ã¯ãå¼µã£ã¦ãã£ãã®ã ããã©ï¼ãªã³ã¯å ã®ããã°è¨äºãèªããªãç¶æ ã«ãªã£ã¦ãã¦ããã®ãæ®å¿µï¼
ã¯ããã«
std::vector
ä»åã¯ä»¥ä¸ã®3ã¤ã®æ¹æ³ãèããï¼
- (1) std::setãç¨ããæ¹æ³
- (2) std::tr1::unordered_setãç¨ããæ¹æ³
- (3) std::vector + std::random_shuffleãç¨ããæ¹æ³
- â» æ¬ããã°è¨äºãã»ã¼æ¸ãçµãã£ãã¨ããã§Knuthå çã®æ¹æ³ãç¥ã£ãã®ã§ãã¨ã§è¿½è¨ orz
(1),(2)ã¯å ã®é åããã©ã³ãã ã«é¸æãã¦set/unordered_setã«insertãã¦ï¼ã³ã³ããã®å¤§ãããkã«ãªã£ããåæ¢ããã¨ãããã®ï¼(3)ã¯å ã®é åã®åè¦ç´ ã¸ã®ãã¤ã³ã¿ãä¿æããvectorãä½æãï¼ãããstd::random_shuffleãç¨ãã¦ã·ã£ããã«ãã¦å é ããkååå¾ããã°ããï¼
ä½ãèããã«å®è£ ããã¨ï¼ã©ã³ãã ã«è¦ç´ ãé¸æãã¦setã«æ¿å ¥ããæ¹æ³ãæãã¤ãï¼ãããsetã®å é¨ã¯mapã¨åæ§äºåæ¨ (赤é»æ¨) ã§å®è£ ããã¦ããã®ã§ï¼è¦ç´ ãå¢ããã¨ã³ã¹ãã大ãããªãã¨äºæ³ãããï¼ã¨ããããã§ããã·ã¥å®è£ ã§ããunordered_setã®å©ç¨ãæãã¤ãï¼ããã¦Nã®è¦ç´ ãå ¥ããé åãã·ã£ããã«ãããã¨ãã§ããã°kã®æ°ã«ä¾åããã«ä¸å®æéã§ä»»æã®æ°ã®é復å æ½åºãã§ãããããªããã¨æã£ã¦3çªç®ã®æ¹æ³ãæãã¤ãï¼
ãã£ã¨ãããã¸ãã誰ã§ãæãã¤ãã¬ãã«ãã¤å®è£
ãç°¡åãªæ¹æ³ã§ã¯ãªãã ãããï¼ã¨ããããã§ãã®3ã¤ã®æ¹æ³ã®é度ã®å·®ãæ¤è¨¼ãã¦ã¿ãï¼
å®é¨
å®é¨æ¡ä»¶
3ã¤ã®ææ³ã«ããå¦çæéã以ä¸ã®Nã¨kã®çµã¿åããã«ã¤ãã¦10åãã¤è¨æ¸¬ï¼ä»åã¯kãåºå®ã®æ°åã§ã¯ãªãæ¯çã¨ããï¼ããªãã¡N=1000, k=0.1ã®å ´åã«ã¯1000åã®è¦ç´ ã®ä¸ãã100åã®è¦ç´ ãé復å æ½åºããï¼
- N \in {10^3, 10^4,..., 10^8}
- k \in {0.1, 0.2, ..., 0.9}
- 測å®æ¹æ³
- gettimefoday(2)ã§å¦çæéãè¨æ¸¬
- â» random_shuffleã®å ´åã¯std::vector
ãæ§ç¯ããé¨åãæéã«å«ãã
å®é¨ã«å©ç¨ããã³ã¼ãã®ä¸é¨ã¯ä»¥ä¸ã®ã¨ããï¼
#define RAND (((double)rand()-1)/((double)RAND_MAX)) double test_set (int N, int k) { std::vector<int> vec(N); for (int i = 0; i < N; i++) { vec[ i ] = i; } double t1 = gettimeofday_sec(); std::set<int> s; while ((int)s.size() < k) { int idx = (int)(RAND * N); s.insert( vec[ idx ] ); } double t2 = gettimeofday_sec(); return (t2 - t1); } double test_hash (int N, int k) { std::vector<int> vec(N); for (int i = 0; i < N; i++) { vec[ i ] = i; } double t1 = gettimeofday_sec(); std::tr1::unordered_set<int> s; while ((int)s.size() < k) { int idx = (int)(RAND * N); s.insert( vec[ idx ] ); } double t2 = gettimeofday_sec(); return (t2 - t1); } double test_shuffle (int N, int k) { std::vector<int> vec(N); for (int i = 0; i < N; i++) { vec[ i ] = i; } double t1 = gettimeofday_sec(); std::vector<int*> shuffle_vec(N); for (int i = 0; i < (int)vec.size(); i++) { shuffle_vec[ i ] = &(vec[ i ]); } std::random_shuffle( shuffle_vec.begin(), shuffle_vec.end() ); double t2 = gettimeofday_sec(); return (t2 - t1); }
çµæ
ã¾ãNã¨kã«å¯¾ããå ¨ã¦ã®çµæã示ãï¼è¡¨ãè¦ã¥ãããªãã®ã§å¹³åå¤ã®ã¿ãè¨è¼ï¼(åæ£ã¯çµè«ã«å½±é¿ãä¸ããªãç¨åº¦ã®å¤§ããã ã£ã)
N | k (ratio) | set | unordered_set | random_shuffle |
---|---|---|---|---|
1000 | 0.1 | 0.000026 | 0.000023 | 0.000042 |
1000 | 0.2 | 0.000055 | 0.000045 | 0.000042 |
1000 | 0.3 | 0.000086 | 0.000062 | 0.000043 |
1000 | 0.4 | 0.000123 | 0.000081 | 0.000043 |
1000 | 0.5 | 0.000143 | 0.000054 | 0.000021 |
1000 | 0.6 | 0.000104 | 0.000067 | 0.000021 |
1000 | 0.7 | 0.000134 | 0.000078 | 0.000020 |
1000 | 0.8 | 0.000175 | 0.000092 | 0.000021 |
1000 | 0.9 | 0.000245 | 0.000122 | 0.000021 |
10000 | 0.1 | 0.000142 | 0.000097 | 0.000215 |
10000 | 0.2 | 0.000310 | 0.000206 | 0.000205 |
10000 | 0.3 | 0.000506 | 0.000290 | 0.000217 |
10000 | 0.4 | 0.000744 | 0.000461 | 0.000205 |
10000 | 0.5 | 0.001025 | 0.000543 | 0.000207 |
10000 | 0.6 | 0.001380 | 0.000665 | 0.000212 |
10000 | 0.7 | 0.001823 | 0.000809 | 0.000205 |
10000 | 0.8 | 0.002451 | 0.001154 | 0.000211 |
10000 | 0.9 | 0.003540 | 0.001388 | 0.000212 |
100000 | 0.1 | 0.0020 | 0.0012 | 0.0022 |
100000 | 0.2 | 0.0046 | 0.0025 | 0.0022 |
100000 | 0.3 | 0.0083 | 0.0039 | 0.0022 |
100000 | 0.4 | 0.0123 | 0.0058 | 0.0022 |
100000 | 0.5 | 0.0171 | 0.0073 | 0.0022 |
100000 | 0.6 | 0.0232 | 0.0090 | 0.0022 |
100000 | 0.7 | 0.0311 | 0.0121 | 0.0022 |
100000 | 0.8 | 0.0421 | 0.0143 | 0.0022 |
100000 | 0.9 | 0.0606 | 0.0177 | 0.0022 |
1000000 | 0.1 | 0.0324 | 0.0153 | 0.0265 |
1000000 | 0.2 | 0.0819 | 0.0364 | 0.0262 |
1000000 | 0.3 | 0.1547 | 0.0774 | 0.0264 |
1000000 | 0.4 | 0.2447 | 0.1005 | 0.0264 |
1000000 | 0.5 | 0.3583 | 0.1280 | 0.0263 |
1000000 | 0.6 | 0.5024 | 0.1990 | 0.0265 |
1000000 | 0.7 | 0.6924 | 0.2338 | 0.0267 |
1000000 | 0.8 | 0.9639 | 0.2818 | 0.0268 |
1000000 | 0.9 | 1.4319 | 0.3625 | 0.0264 |
10000000 | 0.1 | 0.7067 | 0.3181 | 0.6920 |
10000000 | 0.2 | 1.7642 | 0.7155 | 0.6909 |
10000000 | 0.3 | 3.0718 | 1.2310 | 0.6921 |
10000000 | 0.4 | 4.6572 | 1.5806 | 0.6909 |
10000000 | 0.5 | 6.5762 | 2.3766 | 0.6904 |
10000000 | 0.6 | 8.9766 | 2.7640 | 0.6929 |
10000000 | 0.7 | 12.1109 | 3.2506 | 0.6924 |
10000000 | 0.8 | 16.5619 | 3.9203 | 0.6911 |
10000000 | 0.9 | 24.2751 | 5.9600 | 0.6909 |
100000000 | 0.1 | 11.9186 | 5.0229 | 9.4275 |
100000000 | 0.2 | 28.4891 | 10.7473 | 9.4202 |
100000000 | 0.3 | 48.9235 | 14.4396 | 9.4179 |
100000000 | 0.4 | 73.7326 | 23.2700 | 9.4068 |
100000000 | 0.5 | 103.9370 | 27.3172 | 9.4198 |
100000000 | 0.6 | 141.7940 | 32.3755 | 9.4193 |
100000000 | 0.7 | 191.4050 | 38.9861 | 9.4176 |
100000000 | 0.8 | 262.2190 | 57.5724 | 9.4168 |
100000000 | 0.9 | 384.7380 | 71.8925 | 9.4186 |
ææ³æ¯ã«Nã¨kã®çµã¿åããã«ã¤ãã¦ã®3次å æ£ã°ã©ãã¯ä»¥ä¸ã®ã¨ããï¼ä¸æ®µã10^3~6ã¾ã§ï¼ä¸æ®µã10^3~5ã¾ã§ã®çµæãå ¨ã¦åã尺度ã§ç¤ºãã¦ããï¼
å®é¨ããï¼ä»¥ä¸ã®çµæã確èªããï¼
- k=0.1ã®å ´åã«å®è¡é度㯠unordered_set > random_shuffle > set
- kã0.2以ä¸ã®å ´åã«å®è¡é度㯠random_shuffle > unordered_set > set
- ãªããN=1000,k=0.1-0.4ã®random_shuffleãé ãï¼(ä½åãããç´ãã¦ãåç¾)
ãªãrandom_shuffleå®è£
ã«ããã¦ãã¤ã³ã¿è¦ç´ ã®é
åãä½æããå¦çãæéè¨æ¸¬ããå¤ããå ´åã«ããã¦ãä¸è¨ã®çµæã¯å¤ãããªãã£ãï¼
ã¾ã¨ã
ä¸è¨ã®çµæããï¼ä»¥ä¸ã®ç¥è¦ãå¾ãï¼
- ããããç¶æ³ã«ããã¦setã¯é ãï¼
- é復å æ½åºãè¡ãè¦ç´ æ°ãå°ãªãå ´åã«ã¯(2)ã®æ¹æ³ãç¨ãã
- 復å æ½åºãè¡ãè¦ç´ æ°ãæ½åºå ãµã¤ãºã®2å²ä»¥ä¸ã®å ´åã«ã¯(3)ã®æ¹æ³ãç¨ãã
- ãã¤ã³ã¿è¦ç´ ã®é åä½æã®ã³ã¹ããå°ãããã¨ããé åæä½ã¯é«éã¨ãããã¨ããããï¼
ãã¯ãtreeã¯ãã¤ã³ã¿ããã©ãã®ã§ãã£ãã·ã¥ãã¹ãçºçãããã->é ãï¼ã¨ããå°è±¡ãããã«å¼·ã¾ãçµæã§ãã£ãï¼N=1000,k=0.1-0.4ã®random_shuffleãé ãã®ã¯random_shuffleã®å®è£ ã調ã¹ãã°ãããã®ã ããã? é åã®å¤§ãããå°ããå ´åã«ã¯ï¼ã©ã³ãã æ§ãä¿è¨¼ããããã«ããããã·ã£ããã«ããã¨ã?
ãããªãsetï¼åã®ãã¨ã¯å¿ããªããï¼(ããï¼どっかã§èãããã¨ããã»ãªã?)
çºå±ææ³ã«ã¤ãã¦
ã©ãããKnuthå
çã®æ¬ã«é復å
æ½åºã®é«éãªã¢ã«ã´ãªãºã ãè¼ã£ã¦ãããããï¼
(åè: http://stackoverflow.com/questions/311703/algorithm-for-sampling-without-replacement)
ä»åã®å®é¨ã«åããã表è¨ã«ããã¨ãããªæãï¼
double test_knuth (int N, int k) { std::vector<int> vec(N); for (int i = 0; i < N; i++) { vec[ i ] = i; } double t1 = gettimeofday_sec(); std::vector<int> sample_vec(k); int t = 0; int m = 0; while (m < k) { double u = RAND; if ((N - t) * u >= (k - m)) { t++; } else { sample_vec[ m ] = vec[ t ]; t++; m++; } } double t2 = gettimeofday_sec(); return (t2 - t1); }
ãã£ã¨è©¦ãã¦ã¿ãã¨ããï¼ã©ãããä¸çªé«éããï¼ãããå®è£ ãç°¡åï¼ä»åã®å®é¨ã§è¡¨ã¨ã°ã©ããä½ã£ããã¨ã«ãã®æ¹æ³ãç¥ã£ãã®ã§ç¸å½ãããªããã¦ããï¼ã°ã©ããä½ãç´ãå æ°ã¯ãªãã£ãã®ã§ï¼æ´æ°ãã表ãæå¾ã«è¿½è¨ï¼
ã¾ãä»åã¯ç°¡åãªå®è£ ã¨ãããã¨ã§å¹ççãªå®è£ ã«ã¤ãã¦æ·±è¿½ãããªãã£ãããã©ï¼è«æã«ãªã£ã¦ããææ³ã§ã¯ä»¥ä¸ã®ãããªãã®ããããããï¼ãã£ã¨èªãã ããã©ã¾ã£ããç解ã§ããªãã£ãã®ã§è¦ãªãã£ããã¨ã«ããï¼
- J. S. Vitter, "An efficient algorithm for sequential random sampling", ACM TOMS vol.13(1), pp.58-67, 1987
Appendix
Knuthã®æ¹æ³ã®çµæã以ä¸ã«è¿½è¨ï¼
çµæã¯ä»¥ä¸ã®è§£éããã¦ããï¼
- Nã¨kã®æ°ãå ±ã«å°ããå ´åã«ã¯unordered_set
- ãã以å¤ã®å ´åã«ã¯Knuth
çµè«: Knuthå çããã!
N | k (ratio) | set | unordered_set | random_shuffle | knuth |
---|---|---|---|---|---|
1000 | 0.1 | 0.000026 | 0.000023 | 0.000042 | 0.000025 |
1000 | 0.2 | 0.000055 | 0.000045 | 0.000042 | 0.000030 |
1000 | 0.3 | 0.000086 | 0.000062 | 0.000043 | 0.000034 |
1000 | 0.4 | 0.000123 | 0.000081 | 0.000043 | 0.000038 |
1000 | 0.5 | 0.000143 | 0.000054 | 0.000021 | 0.000040 |
1000 | 0.6 | 0.000104 | 0.000067 | 0.000021 | 0.000118 |
1000 | 0.7 | 0.000134 | 0.000078 | 0.000020 | 0.000036 |
1000 | 0.8 | 0.000175 | 0.000092 | 0.000021 | 0.000032 |
1000 | 0.9 | 0.000245 | 0.000122 | 0.000021 | 0.000028 |
10000 | 0.1 | 0.000142 | 0.000097 | 0.000215 | 0.000253 |
10000 | 0.2 | 0.000310 | 0.000206 | 0.000205 | 0.000300 |
10000 | 0.3 | 0.000506 | 0.000290 | 0.000217 | 0.000184 |
10000 | 0.4 | 0.000744 | 0.000461 | 0.000205 | 0.000186 |
10000 | 0.5 | 0.001025 | 0.000543 | 0.000207 | 0.000195 |
10000 | 0.6 | 0.001380 | 0.000665 | 0.000212 | 0.000189 |
10000 | 0.7 | 0.001823 | 0.000809 | 0.000205 | 0.000170 |
10000 | 0.8 | 0.002451 | 0.001154 | 0.000211 | 0.000150 |
10000 | 0.9 | 0.003540 | 0.001388 | 0.000212 | 0.000134 |
100000 | 0.1 | 0.0020 | 0.0012 | 0.0022 | 0.0012 |
100000 | 0.2 | 0.0046 | 0.0025 | 0.0022 | 0.0014 |
100000 | 0.3 | 0.0083 | 0.0039 | 0.0022 | 0.0017 |
100000 | 0.4 | 0.0123 | 0.0058 | 0.0022 | 0.0018 |
100000 | 0.5 | 0.0171 | 0.0073 | 0.0022 | 0.0019 |
100000 | 0.6 | 0.0232 | 0.0090 | 0.0022 | 0.0019 |
100000 | 0.7 | 0.0311 | 0.0121 | 0.0022 | 0.0017 |
100000 | 0.8 | 0.0421 | 0.0143 | 0.0022 | 0.0015 |
100000 | 0.9 | 0.0606 | 0.0177 | 0.0022 | 0.0013 |
1000000 | 0.1 | 0.0324 | 0.0153 | 0.0265 | 0.0121 |
1000000 | 0.2 | 0.0819 | 0.0364 | 0.0262 | 0.0144 |
1000000 | 0.3 | 0.1547 | 0.0774 | 0.0264 | 0.0166 |
1000000 | 0.4 | 0.2447 | 0.1005 | 0.0264 | 0.0184 |
1000000 | 0.5 | 0.3583 | 0.1280 | 0.0263 | 0.0192 |
1000000 | 0.6 | 0.5024 | 0.1990 | 0.0265 | 0.0187 |
1000000 | 0.7 | 0.6924 | 0.2338 | 0.0267 | 0.0170 |
1000000 | 0.8 | 0.9639 | 0.2818 | 0.0268 | 0.0150 |
1000000 | 0.9 | 1.4319 | 0.3625 | 0.0264 | 0.0129 |
10000000 | 0.1 | 0.7067 | 0.3181 | 0.6920 | 0.1222 |
10000000 | 0.2 | 1.7642 | 0.7155 | 0.6909 | 0.1451 |
10000000 | 0.3 | 3.0718 | 1.2310 | 0.6921 | 0.1675 |
10000000 | 0.4 | 4.6572 | 1.5806 | 0.6909 | 0.1860 |
10000000 | 0.5 | 6.5762 | 2.3766 | 0.6904 | 0.1943 |
10000000 | 0.6 | 8.9766 | 2.7640 | 0.6929 | 0.1887 |
10000000 | 0.7 | 12.1109 | 3.2506 | 0.6924 | 0.1729 |
10000000 | 0.8 | 16.5619 | 3.9203 | 0.6911 | 0.1529 |
10000000 | 0.9 | 24.2751 | 5.9600 | 0.6909 | 0.1368 |
100000000 | 0.1 | 11.9186 | 5.0229 | 9.4275 | 1.2284 |
100000000 | 0.2 | 28.4891 | 10.7473 | 9.4202 | 1.4638 |
100000000 | 0.3 | 48.9235 | 14.4396 | 9.4179 | 1.6919 |
100000000 | 0.4 | 73.7326 | 23.2700 | 9.4068 | 1.8807 |
100000000 | 0.5 | 103.9370 | 27.3172 | 9.4198 | 1.9683 |
100000000 | 0.6 | 141.7940 | 32.3755 | 9.4193 | 1.9175 |
100000000 | 0.7 | 191.4050 | 38.9861 | 9.4176 | 1.7639 |
100000000 | 0.8 | 262.2190 | 57.5724 | 9.4168 | 1.5684 |
100000000 | 0.9 | 384.7380 | 71.8925 | 9.4186 | 1.3664 |
2013-07-21 2:00 è¿½è¨ (Thanks to @tomerun ãã)
ããã°è¨äºupã®ã¤ã¶ãããããã @tomerun ãããã以ä¸ã®è¿ä¿¡ãé ãï¼
ãããã¨ããããã¾ã! @tomerun ããã«æ¸ãã¦ããã£ãã³ã¼ãã®è©²å½é¨åã ãã転è¼ãã¾ãï¼
// Code by @tomerun ãã // http://ideone.com/raF3O4 ããå¼ç¨ double test_shuffle_partial (int N, int k) { std::vector<int> vec(N); for (int i = 0; i < N; i++) { vec[ i ] = i; } double t1 = gettimeofday_sec(); std::vector<int> shuffle_vec; for (int i = 0; i < k; ++i) { int pos = rand() % (N-i); shuffle_vec.push_back(vec[i + pos]); swap(vec[i], vec[i + pos]); } double t2 = gettimeofday_sec(); return (t2 - t1); }
ãããè¦ãã¨ï¼é¸æãããè¦ç´ 以å¤ããã©ã³ãã ã«é¸ã¶ï¼é¸æããããã®ãé åã®å é ã«ç§»ãã¦ï¼ãã以å¤ããã©ã³ãã ã«è¦ç´ ãé¸ã¶ï¼ã¨ãããã¨ãç¹°ãè¿ãã¦kåã®ã¢ã¤ãã ãåå¾ããï¼ç¾å®ä¸çã«ããããã³ã´ã®ãããªé復å æ½åºææ³ãã³ã¼ãã«è½ã¨ãè¾¼ãã æãï¼ãªãã»ã©ï¼ããå®è£ ããã°ããã®ã! ç®ãããããã§ãï¼
ãªãï¼è¶
ç´°ããã¨ããã§æ縮ãªã®ã ããã©push_backããã¨kã大ããå ´åã«ä½åº¦ãvectorã®reserve (realloc) ãèµ°ãã®ã§ï¼std::vector
ããããåãç°å¢ã§å®è¡ãã¦ä»¥ä¸ã®çµæãå¾ãï¼random_shuffle_partial以å¤ã¯ååã®æ°åï¼
N | k (ratio) | set | unordered_set | random_shuffle | knuth | random_shuffle_partial | |
---|---|---|---|---|---|---|---|
1000 | 0.1 | 0.000026 | 0.000023 | 0.000042 | 0.000025 | 0.000005 | |
1000 | 0.2 | 0.000055 | 0.000045 | 0.000042 | 0.000030 | 0.000007 | |
1000 | 0.3 | 0.000086 | 0.000062 | 0.000043 | 0.000034 | 0.000010 | |
1000 | 0.4 | 0.000123 | 0.000081 | 0.000043 | 0.000038 | 0.000013 | |
1000 | 0.5 | 0.000143 | 0.000054 | 0.000021 | 0.000040 | 0.000015 | |
1000 | 0.6 | 0.000104 | 0.000067 | 0.000021 | 0.000118 | 0.000019 | |
1000 | 0.7 | 0.000134 | 0.000078 | 0.000020 | 0.000036 | 0.000021 | |
1000 | 0.8 | 0.000175 | 0.000092 | 0.000021 | 0.000032 | 0.000024 | |
1000 | 0.9 | 0.000245 | 0.000122 | 0.000021 | 0.000028 | 0.000026 | |
10000 | 0.1 | 0.000142 | 0.000097 | 0.000215 | 0.000253 | 0.000113 | |
10000 | 0.2 | 0.000310 | 0.000206 | 0.000205 | 0.000300 | 0.000059 | |
10000 | 0.3 | 0.000506 | 0.000290 | 0.000217 | 0.000184 | 0.000087 | |
10000 | 0.4 | 0.000744 | 0.000461 | 0.000205 | 0.000186 | 0.000112 | |
10000 | 0.5 | 0.001025 | 0.000543 | 0.000207 | 0.000195 | 0.000091 | |
10000 | 0.6 | 0.001380 | 0.000665 | 0.000212 | 0.000189 | 0.000081 | |
10000 | 0.7 | 0.001823 | 0.000809 | 0.000205 | 0.000170 | 0.000096 | |
10000 | 0.8 | 0.002451 | 0.001154 | 0.000211 | 0.000150 | 0.000113 | |
10000 | 0.9 | 0.003540 | 0.001388 | 0.000212 | 0.000134 | 0.000128 | |
100000 | 0.1 | 0.0020 | 0.0012 | 0.0022 | 0.0012 | 0.0002 | |
100000 | 0.2 | 0.0046 | 0.0025 | 0.0022 | 0.0014 | 0.0003 | |
100000 | 0.3 | 0.0083 | 0.0039 | 0.0022 | 0.0017 | 0.0005 | |
100000 | 0.4 | 0.0123 | 0.0058 | 0.0022 | 0.0018 | 0.0008 | |
100000 | 0.5 | 0.0171 | 0.0073 | 0.0022 | 0.0019 | 0.0009 | |
100000 | 0.6 | 0.0232 | 0.0090 | 0.0022 | 0.0019 | 0.0011 | |
100000 | 0.7 | 0.0311 | 0.0121 | 0.0022 | 0.0017 | 0.0013 | |
100000 | 0.8 | 0.0421 | 0.0143 | 0.0022 | 0.0015 | 0.0014 | |
100000 | 0.9 | 0.0606 | 0.0177 | 0.0022 | 0.0013 | 0.0015 | |
1000000 | 0.1 | 0.0324 | 0.0153 | 0.0265 | 0.0121 | 0.0020 | |
1000000 | 0.2 | 0.0819 | 0.0364 | 0.0262 | 0.0144 | 0.0040 | |
1000000 | 0.3 | 0.1547 | 0.0774 | 0.0264 | 0.0166 | 0.0068 | |
1000000 | 0.4 | 0.2447 | 0.1005 | 0.0264 | 0.0184 | 0.0089 | |
1000000 | 0.5 | 0.3583 | 0.1280 | 0.0263 | 0.0192 | 0.0109 | |
1000000 | 0.6 | 0.5024 | 0.1990 | 0.0265 | 0.0187 | 0.0136 | |
1000000 | 0.7 | 0.6924 | 0.2338 | 0.0267 | 0.0170 | 0.0155 | |
1000000 | 0.8 | 0.9639 | 0.2818 | 0.0268 | 0.0150 | 0.0174 | |
1000000 | 0.9 | 1.4319 | 0.3625 | 0.0264 | 0.0129 | 0.0191 | |
10000000 | 0.1 | 0.7067 | 0.3181 | 0.6920 | 0.1222 | 0.0514 | |
10000000 | 0.2 | 1.7642 | 0.7155 | 0.6909 | 0.1451 | 0.1022 | |
10000000 | 0.3 | 3.0718 | 1.2310 | 0.6921 | 0.1675 | 0.1537 | |
10000000 | 0.4 | 4.6572 | 1.5806 | 0.6909 | 0.1860 | 0.2010 | |
10000000 | 0.5 | 6.5762 | 2.3766 | 0.6904 | 0.1943 | 0.2535 | |
10000000 | 0.6 | 8.9766 | 2.7640 | 0.6929 | 0.1887 | 0.2976 | |
10000000 | 0.7 | 12.1109 | 3.2506 | 0.6924 | 0.1729 | 0.3389 | |
10000000 | 0.8 | 16.5619 | 3.9203 | 0.6911 | 0.1529 | 0.3756 | |
10000000 | 0.9 | 24.2751 | 5.9600 | 0.6909 | 0.1368 | 0.4156 | |
100000000 | 0.1 | 11.9186 | 5.0229 | 9.4275 | 1.2284 | 0.6073 | |
100000000 | 0.2 | 28.4891 | 10.7473 | 9.4202 | 1.4638 | 1.2054 | |
100000000 | 0.3 | 48.9235 | 14.4396 | 9.4179 | 1.6919 | 1.7780 | |
100000000 | 0.4 | 73.7326 | 23.2700 | 9.4068 | 1.8807 | 2.3940 | |
100000000 | 0.5 | 103.9370 | 27.3172 | 9.4198 | 1.9683 | 2.9615 | |
100000000 | 0.6 | 141.7940 | 32.3755 | 9.4193 | 1.9175 | 3.5221 | |
100000000 | 0.7 | 191.4050 | 38.9861 | 9.4176 | 1.7639 | 4.1683 | |
100000000 | 0.8 | 262.2190 | 57.5724 | 9.4168 | 1.5684 | 4.7086 | |
100000000 | 0.9 | 384.7380 | 71.8925 | 9.4186 | 1.3664 | 5.2277 |
ãã¦å®é¨ãã以ä¸ã®çµæãå¾ãï¼
- N<=10^6ã¾ã§ã¯å ¨ã¦ã®ææ³ã§random_shuffle_partialãæé
- å ¨ã¦ã®N,kã«ããã¦random_shuffle_partial>random_shuffle
- Knuth vs. random_shuffle_parial æé対決
Nã¨kã大ãããªãã¨knuthå çã«è² ãã¦ãã¾ãï¼ããããkã®çµ¶å¯¾æ°ãå¢ããã¨swapã³ã¹ããå¹ãã¦ããã®ã ãããï¼ãããï¼å®é¨ã®ããk=0.1-0.9ãæ¤è¨¼ãã¦ããããã©ï¼å®éã«ã¯kã¯ãããªã«å¤§ãããªãå ´åã®æ¹ãå¤ãã®ã§ï¼@tomerun ããææ³ã®æ¹ãé«éãªå ´é¢ã®æ¹ãå¤ãã¨æãããï¼
æ¹ãã¦@tomerun ããã«æè¬ï¼ãããã§ãã人ã¯å¯¾å¿ãã³ã¼ãã3åã®éãã§ãã!