public void FindTheKthSmallestElementWithLinearTimeComplexity_PartOfTimeComplexityTests1() { int[] array = new int[] { 2, 3, 14, 5, 7, 8, 9, 11, 10, 1 }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.FindTheKthSmallestElementWithLinearTimeComplexity(array, 5); var expected = 7; Assert.AreEqual(expected, actual); }
public void FindKthSmallestElementUsingMinHeap_ShouldReturnFifthSmallestNumber() { int[] array = new int[] { 2, 3, 14, 5, 12, 17, 15, 7, 8, 9, 11, 10, 1 }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.FindKthSmallestElementUsingMinHeap(array, 5); var expected = 7; Assert.AreEqual(expected, actual); }
public void FindKthSmallestElementUsingMinHeap_IfTheSearchArrayIsEmpty_ShouldReturnIntMinValue() { int[] array = new int[] {}; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.FindKthSmallestElementUsingMinHeap(array, 5); var expected = int.MinValue; Assert.AreEqual(expected, actual); }
public void SortAndReturnKthSmallestElements_IfKthNumberIsZero_ShouldReturnEmptyArray() { int[] array = new int[] { 2, 3, 14, 5, 12, 17, 15, 7, 8, 9, 11, 10, 1 }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.SortAndReturnKthSmallestElements(array, 0); var expected = new int[0]; Assert.IsTrue(expected.SequenceEqual(actual)); }
public void SortAndReturnKthSmallestElements_IfKthNumberIsFive_ShouldReturnArrayOfSmallestFiveNumbers() { int[] array = new int[] { 2, 3, 14, 5, 12, 17, 15, 7, 8, 9, 11, 10, 1 }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.SortAndReturnKthSmallestElements(array, 5); var expected = new int[5] { 1, 2, 3, 5, 7 }; Assert.IsTrue(expected.SequenceEqual(actual)); }
public void FindTheKthSmallestElementWithLinearTimeComplexity_PartOfTimeComplexityTests2() { int[] array = new int[] { 484, 491, 494, 496, 497, 207, 213, 215, 217, 236, 248, 255, 259, 18, 31, 33, 45, 46, 51, 71, 78, 82, 86, 87, 380, 382, 386, 394, 296, 297, 127, 137, 139, 395, 397, 398, 90, 91, 95, 97, 311, 316, 317, 318, 322, 328, 98, 104, 106, 300, 306, 336, 109, 114, 116, 148, 153, 156, 163, 165, 176, 182, 183, 194, 206, 266, 270, 273, 277, 279, 440, 443, 446, 448, 450, 453, 347, 350, 351, 356, 361, 373, 401, 405, 412, 283, 290, 292, 294, 344, 420, 434, 438, 457, 459, 461, 467, 469, 472, 473, }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.FindTheKthSmallestElementWithLinearTimeComplexity(array, 5); var expected = 46; Assert.AreEqual(expected, actual); }
public void FindTheKthSmallestElementWithLinearTimeComplexity_PartOfTimeComplexityTests3() { int[] array = new int[] { 3096, 2524, 3726, 2099, 3971, 1378, 3323, 1099, 1459, 3724, 4480, 4774, 545, 3930, 4998, 4304, 4087, 2244, 3694, 4036, 3035, 466, 1730, 3643, 4641, 2013, 2913, 1302, 4401, 1179, 4600, 3528, 2802, 4001, 1237, 1652, 3925, 1724, 4256, 3324, 4567, 3716, 56, 1197, 184, 3290, 1463, 1263, 3550, 2229, 93, 3373, 2917, 2599, 2228, 906, 1782, 487, 4266, 666, 3293, 1379, 3885, 399, 3574, 4896, 1089, 3704, 3861, 390, 1773, 4884, 3902, 4109, 2671, 995, 570, 602, 588, 3517, 1820, 3112, 4581, 918, 2413, 58, 563, 1, 1476, 3540, 1752, 841, 2979, 548, 3455, 1015, 3329, 1410, 915, 454, 727, 4546, 355, 2899, 4013, 923, 3794, 1524, 1423, 4168, 2478, 4484, 3778, 2402, 4283, 3439, 3478, 4690, 3928, 1591, 1132, 575, 4053, 2766, 2176, 3409, 2849, 4783, 882, 4779, 2939, 522, 1946, 793, 3968, 4740, 4532, 4537, 94, 2283, 1005, 2879, 1496, 3664, 3674, 1624, 143, 764, 3220, 1064, 705, 3525, 1595, 2592, 1664, 850, 584, 3480, 1655, 1651, 1319, 1317, 4422, 4420, 2542, 1841, 3556, 4953, 1934, 3253, 4960, 3456, 2755, 3514, 668, 1694, 1364, 927, 2539, 4104, 1669, 4132, 4864, 244, 367, 4385, 1933, 171, 2421, 1406, 4843, 2389, 4044, 4339, 4469, 577, 2508, 3874, 1840, 3582, 1689, 1323, 4042, 2863, 3098, 3268, 2327, 4834, 2174, 2940, 1452, 2765, 3349, 1842, 415, 3731, 2624, 3695, 1510, 3722, 1402, 1884, 996, 2145, 984, 4301, 4395, 3280, 1985, 3705, 2956, 2270, 3106, 4058, 3159, 1100, 1388, 318, 2379, 3779, 778, 4514, 4111, 3605, 2056, 3956, 3070, 3809, 3312, 4504, 4396, 4665, 3948, 4917, 1876, 1228, 4780, 1567, 2628, 3147, 3473, 3218, 2290, 269, 2922, 619, 4175, 1613, 2587, 2326, 312, 3013, 2457, 2295, 3878, 4767, 42, 3753, 2369, 3645, 245, 3249, 73, 1182, 749, 4849, 212, 2996, 3092, 3691, 4063, 1596, 1042, 1485, 3908, 4887, 2705, 4839, 1939, 3071, 4268, 4500, 695, 1236, 4611, 4596, 1943, 2185, 1049, 1911, 496, 1385, 1027, 1638, 2929, 301, 3475, 3193, 2529, 1896, 1563, 3102, 2024, 2423, 3575, 4398, 267, 2494, 2560, 1979, 3464, 135, 1635, 2234, 352, 805, 1435, 1649, 1873, 4962, 4588, 3113, 2718, 3626, 3322, 3607, 1371, 4920, 707, 322, 2751, 4208, 601, 3803, 3126, 3863, 4784, 3997, 2209, 1758, 540, 1472, 2574, 3539, 2711, 4140, 3824, 3887, 154, 265, 544, 4819, 1436, 3162, 3983, 881, 4525, 420, 2638, 4046, 911, 1290, 3003, 328, 3676, 2836, 646, 3184, 4983, 955, 4, 4798, 1796, 4257, 1942, 2835, 41, 3967, 3662, 305, 4655, 2825, 1130, 655, 2230, 2299, 199, 3430, 4646, 1577, 2245, 2528, 187, 4397, 2651, 3637, 3163, 942, 1324, 1061, 2148, 3135, 1824, 455, 4520, 3888, 2052, 4061, 3258, 3717, 4200, 3783, 2371, 1386, 4209, 3620, 671, 1955, 2933, 3215, 1686, 4542, 1137, 1746, 713, 2268, 4229, 4435, 1414, 2698, 2639, 3150, 2773, 4103, 2859, 3152, 2124, 1257, 3706, 1104, 4450, 1558, 4959, 3650, 3903, 1721, 926, 3270, 677, 2367, 1188, 1000, 1562, 2414, 2577, 4601, 600, 1936, 2666, 293, 382, 789, 1879, 3615, 1141, 249, 480, 4068, 3773, 1394, 3128, 4996, 3869, 4272, 3289, 2597, 1680, 1614, 2373, 2729, 332, 2447, 704, 877, 2057, 2353, 938, 3812, 1187, 1437, 3806, 2278, 4162, 3046, 2873, 3175, 2525, 2047, 2117, 3565, 271, 4757, 4964, 1223, 2615, 2224, 1190, 685, 2106, 3578, 3437, 1892, 166, 3196, 288, 2381, 2288, 4895, 4987, 2998, 1373, 4448, 3397, 430, 3357, 3321, 151, 1806, 11, 2430, 1542, 4543, 1465, 4572, 2068, 1874, 4535, 2328, 4428, 762, 3939, 1174, 1084, 3482, 701, 188, 2427, 741, 4967, 1267, 4737, 2724, 3041, 4258, 518, 2646, 3520, 972, 1786, 3600, 3267, 1380, 2643, 4785, 839, 3444, 1592, 323, 4000, 2096, 1500, 3799, 2237, 2205, 4810, 1920, 4503, 1759, 2715, 909, 3198, 3459, 4968, 3256, 4530, 2945, 921, 4873, 225, 3628, 811, 3814, 3199, 4223, 2742, 729, 3094, 3391, 256, 2598, 4088, 3536, 4439, 4161, 4739, 4851, 4073, 815, 700, 3921, 4221, 1222, 4911, 404, 3274, 4591, 2334, 2689, 1688, 3341, 2439, 12, 453, 1968, 116, 1705, 1499, 1579, 945, 3634, 2668, 3692, 4198, 2021, 1983, 1888, 3264, 2320, 1217, 3179, 609, 215, 975, 4838, 3143, 97, 2150, 203, 4294, 1060, 763, 3805, 2644, 527, 368, 1207, 40, 2687, 2819, 4456, 3711, 4755, 716, 229, 787, 3802, 3542, 4239, 3949, 180, 505, 2812, 2318, 2442, 1816, 1914, 4584, 2018, 1043, 4173, 120, 4842, 194, 4533, 1111, 673, 1048, 1571, 4662, 1400, 747, 4303, 1229, 1604, 2938, 3019, 3408, 4136, 2391, 686, 3522, 4604, 1416, 1309, 1177, 2781, 3211, 3048, 4245, 1826, 4621, 4866, 821, 3610, 4177, 1244, 2583, 2338, 1675, 3161, 4743, 557, 4647, 3929, 1208, 2973, 2976, 659, 1671, 320, 4688, 795, 1508, 3160, 238, 3080, 1552, 2492, 1021, 2610, 262, 3757, 4871, 4496, 3754, 3519, 4521, 1863, 2486, 3114, 3631, 1339, 1886, 1129, 4945, 4417, 153, 2196, 4002, 3947, 1901, 4347, 4293, 4938, 4498, 3848, 2629, 2487, 2623, 847, 2787, 136, 1235, 3024, 2896, 364, 2193, 3954, 3918, 1693, 1143, 2642, 4045, 531, 1712, 1798, 3719, 2147, 2814, 871, 1335, 3845, 1419, 2547, 1898, 107, 887, 1215, 4545, 2885, 1991, 1950, 1318, 3288, 2479, 621, 4594, 1555, 4459, 3813, 3907, 4296, 4285, 703, 3591, 4307, 4879, 624, 3703, 2584, 2463, 483, 75, 418, 3021, 295, 2167, 788, 1554, 1902, 3364, 4096, 4686, 100, 1516, 4634, 792, 1513, 2606, 2472, 1615, 4098, 800, 2605, 3504, 550, 3738, 2969, 4276, 4981, 3677, 385, 2545, 1456, 2134, 758, 1405, 1753, 2462, 969, 3377, 228, 4940, 1439, 3855, 2020, 1521, 1519, 4410, 1745, 2950, 1744, 1728, 3490, 1273, 2908, 213, 2955, 113, 284, 270, 4771, 836, 2132, 2092, 3682, 4471, 848, 3138, 1274, 4862, 2837, 2874, 83, 1345, 2131, 2952, 1772, 172, 3438, 3559, 536, 567, 3503, 3702, 2531, 3146, 4196, 2051, 1534, 402, 596, 4613, 1964, 3029, 2861, 735, 3865, 4353, 2750, 2067, 4855, 1953, 721, 2544, 4593, 2163, 2365, 1344, 1925, 3204, 4467, 3294, 4976, 3838, 801, 2458, 4627, 3485, 2254, 2459, 157, 4333, 411, 3331, 3593, 2194, 1570, 1396, 1899, 1429, 4518, 2192, 4442, 2661, 4679, 2467, 2284, 1870, 2984, 3529, 4288, 3203, 1505, 2967, 4213, 2673, 3376, 1794, 1214, 2449, 1970, 2590, 1055, 1477, 3476, 2530, 3647, 3350, 1514 }; var ksmallestNumbers = new KSmallestElements(); var actual = ksmallestNumbers.FindTheKthSmallestElementWithLinearTimeComplexity(array, 5); var expected = 40; Assert.AreEqual(expected, actual); }