-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
666 lines (634 loc) · 476 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
<title>Алгоритмы и структура данных.md</title><link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' rel='stylesheet' type='text/css'><style type='text/css'>html, body {overflow-x: initial !important;}.CodeMirror { height: auto; }
.CodeMirror-scroll { overflow-y: hidden; overflow-x: auto; }
.CodeMirror-lines { padding: 4px 0px; }
.CodeMirror pre { }
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { background-color: white; }
.CodeMirror-gutters { border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); white-space: nowrap; }
.CodeMirror-linenumbers { }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.CodeMirror div.CodeMirror-cursor { border-left-width: 1px; border-left-style: solid; border-left-color: black; z-index: 3; }
.CodeMirror div.CodeMirror-secondarycursor { border-left-width: 1px; border-left-style: solid; border-left-color: silver; }
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor { width: auto; border: 0px; background-color: rgb(119, 238, 119); z-index: 1; background-position: initial initial; background-repeat: initial initial; }
.CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite { }
.cm-tab { display: inline-block; }
.cm-s-typora-default .cm-header, .cm-s-typora-default .cm-property { color: rgb(217, 79, 138); }
.cm-s-typora-default pre.cm-header1:not(.cm-atom) :not(.cm-overlay) { font-size: 2rem; line-height: 2rem; }
.cm-s-typora-default pre.cm-header2:not(.cm-atom) :not(.cm-overlay) { font-size: 1.4rem; line-height: 1.4rem; }
.cm-s-typora-default .cm-atom, .cm-s-typora-default .cm-number { color: rgb(149, 132, 134); }
.cm-s-typora-default .cm-table-row, .cm-s-typora-default .cm-block-start { font-family: monospace; }
.cm-s-typora-default .cm-comment, .cm-s-typora-default .cm-code { color: rgb(74, 90, 159); font-family: monospace; }
.cm-s-typora-default .cm-tag { color: rgb(169, 68, 66); }
.cm-s-typora-default .cm-string { color: rgb(126, 134, 169); }
.cm-s-typora-default .cm-link { color: rgb(196, 122, 15); text-decoration: underline; }
.cm-s-typora-default .cm-variable-2, .cm-s-typora-default .cm-variable-1 { color: inherit; }
.cm-s-typora-default .cm-overlay { font-size: 1rem; font-family: monospace; }
.CodeMirror.cm-s-typora-default div.CodeMirror-cursor { border-left-width: 3px; border-left-style: solid; border-left-color: rgb(228, 98, 154); }
.cm-s-typora-default .CodeMirror-activeline-background { left: -60px; right: -30px; background-color: rgba(204, 204, 204, 0.2); background-position: initial initial; background-repeat: initial initial; }
.cm-s-typora-default .CodeMirror-gutters { border-right-style: none; background-color: inherit; }
.cm-s-typora-default .cm-trailing-space-new-line::after, .cm-startspace::after, .cm-starttab .cm-tab::after { content: '•'; position: absolute; left: 0px; opacity: 0; font-family: LetterGothicStd, monospace; }
.os-windows .cm-startspace::after, .os-windows .cm-starttab .cm-tab::after { left: -0.1em; }
.cm-starttab .cm-tab::after { content: ' '; }
.cm-startspace, .cm-tab, .cm-starttab, .cm-trailing-space-a, .cm-trailing-space-b, .cm-trailing-space-new-line { font-family: monospace; position: relative; }
.cm-s-typora-default .cm-trailing-space-new-line::after { content: '↓'; opacity: 0.3; }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: black; }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-property { color: black; }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: blue; }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: bold; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: rgb(255, 0, 0); }
.cm-invalidchar { color: rgb(255, 0, 0); }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; background-position: inherit inherit; background-repeat: inherit inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { margin-bottom: -30px; margin-right: -30px; padding-bottom: 30px; padding-right: 30px; height: 100%; outline: none; position: relative; box-sizing: content-box; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { position: absolute; z-index: 6; display: none; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow-x: hidden; overflow-y: scroll; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow-y: hidden; overflow-x: scroll; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 30px; z-index: 3; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-width: 0px; background-color: transparent; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; word-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; background-position: initial initial; background-repeat: initial initial; }
.CodeMirror-wrap pre { word-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right-width: 30px; border-right-style: solid; border-right-color: transparent; width: -webkit-fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right-style: none; width: auto; }
.CodeMirror-linebackground { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-widget { }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right-style: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.CodeMirror-selected { background-color: rgb(217, 217, 217); background-position: initial initial; background-repeat: initial initial; }
.CodeMirror-focused .CodeMirror-selected { background-color: rgb(215, 212, 240); background-position: initial initial; background-repeat: initial initial; }
.cm-searching { background-color: rgba(255, 255, 0, 0.4); background-position: initial initial; background-repeat: initial initial; }
.CodeMirror span { }
@media print {
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}
.CodeMirror-lint-markers { width: 16px; }
.CodeMirror-lint-tooltip { background-color: infobackground; border: 1px solid black; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; color: infotext; font-family: monospace; overflow: hidden; padding: 2px 5px; position: fixed; white-space: pre-wrap; z-index: 10000; max-width: 600px; opacity: 0; -webkit-transition: opacity 0.4s; transition: opacity 0.4s; font-size: 0.8em; }
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { background-position: 0% 100%; background-repeat: repeat no-repeat; }
.CodeMirror-lint-mark-error { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==); }
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { cursor: pointer; display: inline-block; height: 16px; width: 16px; vertical-align: middle; position: relative; background-position: 50% 50%; background-repeat: no-repeat no-repeat; }
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { padding-left: 18px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; }
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=); }
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=); }
.CodeMirror-lint-marker-multiple { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC); width: 100%; height: 100%; background-position: 100% 100%; background-repeat: no-repeat no-repeat; }
html { font-size: 14px; background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); }
body { margin: 0px; padding: 0px; height: auto; bottom: 0px; top: 0px; left: 0px; right: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1rem; line-height: 1.42857143; overflow-x: hidden; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; background-position: inherit inherit; background-repeat: inherit inherit; }
a:active, a:hover { outline: 0px; }
.in-text-selection, ::selection { background-color: rgb(181, 214, 252); text-shadow: none; background-position: initial initial; background-repeat: initial initial; }
#write { margin: 0px auto; height: auto; width: inherit; word-break: normal; word-wrap: break-word; position: relative; padding-bottom: 70px; white-space: pre-wrap; overflow-x: auto; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
@media screen and (max-width: 500px) {
body.typora-export { padding-left: 0px; padding-right: 0px; }
.CodeMirror-sizer { margin-left: 0px !important; }
.CodeMirror-gutters { display: none !important; }
}
.typora-export #write { margin: 0px auto; }
#write > p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, #write > blockquote:first-child, #write > div:first-child, #write > table:first-child { margin-top: 30px; }
#write li > table:first-child { margin-top: -20px; }
img { max-width: 100%; vertical-align: middle; }
input, button, select, textarea { color: inherit; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-weight: inherit; line-height: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
::before, ::after, * { box-sizing: border-box; }
#write p, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write div, #write pre { width: inherit; }
#write p, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6 { position: relative; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
p { -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0px; -webkit-margin-end: 0px; }
.mathjax-block { margin-top: 0px; margin-bottom: 0px; -webkit-margin-before: 0rem; -webkit-margin-after: 0rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: bold; font-style: italic; }
a { cursor: pointer; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; margin: 4px 0px 0px; }
tr { page-break-inside: avoid; page-break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; page-break-inside: auto; text-align: left; }
table.md-table td { min-width: 80px; }
.CodeMirror-gutters { border-right-width: 0px; background-color: inherit; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
pre { white-space: pre-wrap; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; page-break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; background-position: inherit inherit; background-repeat: inherit inherit; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
.md-fences .CodeMirror.CodeMirror-wrap { top: -1.6em; margin-bottom: -1.6em; }
.md-fences.mock-cm { white-space: pre-wrap; }
.show-fences-line-number .md-fences { padding-left: 0px; }
.show-fences-line-number .md-fences.mock-cm { padding-left: 40px; }
.footnotes { opacity: 0.8; font-size: 0.9rem; padding-top: 1em; padding-bottom: 1em; }
.footnotes + .footnotes { margin-top: -1em; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background-color: transparent; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; line-height: normal; font-weight: normal; text-align: left; box-sizing: content-box; direction: ltr; background-position: initial initial; background-repeat: initial initial; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li p, li .mathjax-block { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; }
@media print {
html, body { height: 100%; }
.typora-export * { -webkit-print-color-adjust: exact; }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; orphans: 2; }
p { orphans: 4; }
html.blink-to-pdf { font-size: 13px; }
.typora-export #write { padding-left: 1cm; padding-right: 1cm; }
.typora-export #write::after { height: 0px; }
@page { margin: 20mm 0mm; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 2.86rem; white-space: pre-wrap; background-color: rgb(204, 204, 204); display: block; overflow-x: hidden; background-position: initial initial; background-repeat: initial initial; }
p .md-image:only-child { display: inline-block; width: 100%; text-align: center; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.mathjax-block { white-space: pre; overflow: hidden; width: 100%; }
p + .mathjax-block { margin-top: -1.143rem; }
.mathjax-block:not(:empty)::after { display: none; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: none; box-shadow: none; }
.task-list { list-style-type: none; }
.task-list-item { position: relative; padding-left: 1em; }
.task-list-item input { position: absolute; top: 0px; left: 0px; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc::after, .md-toc-content::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); text-decoration: none; }
.md-toc-inner:hover { }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: bold; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
.md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
.md-toc-h4 .md-toc-inner { margin-left: 5em; }
.md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
.md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: '.'; }
.md-tag { opacity: 0.5; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: monospace; }
code { text-align: left; }
h1 .md-tag, h2 .md-tag, h3 .md-tag, h4 .md-tag, h5 .md-tag, h6 .md-tag { font-weight: initial; opacity: 0.35; }
a.md-print-anchor { border: none !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: none !important; background-color: transparent !important; text-shadow: initial !important; background-position: initial initial !important; background-repeat: initial initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.mathjax-block .MathJax_SVG_Display { text-align: center; margin: 1em 0em; position: relative; text-indent: 0px; max-width: none; max-height: none; min-height: 0px; min-width: 100%; width: auto; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: monospace; }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: normal; line-height: normal; zoom: 90%; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { -webkit-transition: none; transition: none; }
@include-when-export url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
/**
* css forked from https://github.com/GitbookIO/gitbook
* www.gitbook.com
* Apache License
* https://github.com/GitbookIO/gitbook/blob/master/LICENSE
**/
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: normal;
src: local('Open Sans Regular'),url('file:///Users/ivanistomin/Library/Application%20Support/abnerworks.Typora/themes/github/400.woff') format('woff')
}
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: normal;
src: local('Open Sans Italic'),url('file:///Users/ivanistomin/Library/Application%20Support/abnerworks.Typora/themes/github/400i.woff') format('woff')
}
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: bold;
src: local('Open Sans Bold'),url('file:///Users/ivanistomin/Library/Application%20Support/abnerworks.Typora/themes/github/700.woff') format('woff')
}
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: bold;
src: local('Open Sans Bold Italic'),url('file:///Users/ivanistomin/Library/Application%20Support/abnerworks.Typora/themes/github/700i.woff') format('woff')
}
html {
font-size: 16px;
}
body {
font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
color: rgb(51, 51, 51);
line-height: 1.6;
}
#write{
max-width: 860px;
margin: 0 auto;
padding: 20px 30px 40px 30px;
padding-top: 20px;
padding-bottom: 100px;
}
#write > ul:first-child,
#write > ol:first-child{
margin-top: 30px;
}
body > *:first-child {
margin-top: 0 !important;
}
body > *:last-child {
margin-bottom: 0 !important;
}
a {
color: #4183C4;
}
h1,
h2,
h3,
h4,
h5,
h6 {
position: relative;
margin-top: 1rem;
margin-bottom: 1rem;
font-weight: bold;
line-height: 1.4;
cursor: text;
}
h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
/*background: url("file:///Users/ivanistomin/Library/Application%20Support/images/modules/styleguide/para.png") no-repeat 10px center;*/
text-decoration: none;
}
h1 tt,
h1 code {
font-size: inherit;
}
h2 tt,
h2 code {
font-size: inherit;
}
h3 tt,
h3 code {
font-size: inherit;
}
h4 tt,
h4 code {
font-size: inherit;
}
h5 tt,
h5 code {
font-size: inherit;
}
h6 tt,
h6 code {
font-size: inherit;
}
h1 {
padding-bottom: .3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
h2 {
padding-bottom: .3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
h3 {
font-size: 1.5em;
line-height: 1.43;
}
h4 {
font-size: 1.25em;
}
h5 {
font-size: 1em;
}
h6 {
font-size: 1em;
color: #777;
}
p,
blockquote,
ul,
ol,
dl,
table{
margin: 0.8em 0;
}
li>ol,
li>ul {
margin: 0 0;
}
hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
overflow: hidden;
box-sizing: content-box;
border-bottom: 1px solid #ddd;
}
body > h2:first-child {
margin-top: 0;
padding-top: 0;
}
body > h1:first-child {
margin-top: 0;
padding-top: 0;
}
body > h1:first-child + h2 {
margin-top: 0;
padding-top: 0;
}
body > h3:first-child,
body > h4:first-child,
body > h5:first-child,
body > h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1,
a:first-child h2,
a:first-child h3,
a:first-child h4,
a:first-child h5,
a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1 p,
h2 p,
h3 p,
h4 p,
h5 p,
h6 p {
margin-top: 0;
}
li p.first {
display: inline-block;
}
ul,
ol {
padding-left: 30px;
}
ul:first-child,
ol:first-child {
margin-top: 0;
}
ul:last-child,
ol:last-child {
margin-bottom: 0;
}
blockquote {
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777;
}
blockquote blockquote {
padding-right: 0;
}
table {
padding: 0;
word-break: initial;
}
table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
table tr th {
font-weight: bold;
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px;
}
table tr td {
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px;
}
table tr th:first-child,
table tr td:first-child {
margin-top: 0;
}
table tr th:last-child,
table tr td:last-child {
margin-bottom: 0;
}
.CodeMirror-gutters {
border-right: 1px solid #ddd;
}
.md-fences,
code,
tt {
border: 1px solid #ddd;
background-color: #f8f8f8;
border-radius: 3px;
padding: 0;
font-family: Consolas, "Liberation Mono", Courier, monospace;
padding: 2px 4px 0px 4px;
font-size: 0.9em;
}
.md-fences {
margin-bottom: 15px;
margin-top: 15px;
padding: 0.2em 1em;
padding-top: 8px;
padding-bottom: 6px;
}
.task-list{
padding-left: 0;
}
.task-list-item {
padding-left:32px;
}
.task-list-item input {
top: 3px;
left: 8px;
}
@media screen and (min-width: 914px) {
/*body {
width: 854px;
margin: 0 auto;
}*/
}
@media print {
html {
font-size: 13px;
}
table,
pre {
page-break-inside: avoid;
}
pre {
word-wrap: break-word;
}
}
.md-fences {
background-color: #f8f8f8;
}
#write pre.md-meta-block {
padding: 1rem;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border: 0;
border-radius: 3px;
color: #777777;
margin-top: 0 !important;
}
.mathjax-block>.code-tooltip {
bottom: .375rem;
}
#write>h3.md-focus:before{
left: -1.5625rem;
top: .375rem;
}
#write>h4.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h5.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h6.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
.md-image>.md-meta {
border: 1px solid #ddd;
border-radius: 3px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
padding: 2px 4px 0px 4px;
font-size: 0.9em;
color: inherit;
}
.md-tag{
color: inherit;
}
.md-toc {
margin-top:20px;
padding-bottom:20px;
}
#typora-quick-open {
border: 1px solid #ddd;
background-color: #f8f8f8;
}
#typora-quick-open-item {
background-color: #FAFAFA;
border-color: #FEFEFE #e5e5e5 #e5e5e5 #eee;
border-style: solid;
border-width: 1px;
}
#md-notification:before {
top: 10px;
}
/** focus mode */
.on-focus-mode blockquote {
border-left-color: rgba(85, 85, 85, 0.12);
}
header, .context-menu, .megamenu-content, footer{
font-family: "Segoe UI", "Arial", sans-serif;
}
</style>
<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter44762863 = new Ya.Metrika({ id:44762863, clickmap:true, trackLinks:true, accurateTrackBounce:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/44762863" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter -->
</head>
<body class='typora-export' >
<div id='write' class = 'is-mac'><div class='md-toc' mdtype='toc'><p class="md-toc-content"><span class="md-toc-item md-toc-h2" data-ref="c1219"><a class="md-toc-inner" style="" href="#header-c1219">Алгоритмы и структура данных</a></span><span class="md-toc-item md-toc-h3" data-ref="c1201"><a class="md-toc-inner" style="" href="#header-c1201">std::deque и его представление</a></span><span class="md-toc-item md-toc-h5" data-ref="c631"><a class="md-toc-inner" style="" href="#header-c631">Пример</a></span><span class="md-toc-item md-toc-h3" data-ref="c637"><a class="md-toc-inner" style="" href="#header-c637">Stack как адаптер стандартного контейнера std::deque</a></span><span class="md-toc-item md-toc-h3" data-ref="c653"><a class="md-toc-inner" style="" href="#header-c653">Циклический буфер (кольцо). Стандартная библиотека boost</a></span><span class="md-toc-item md-toc-h4" data-ref="c660"><a class="md-toc-inner" style="" href="#header-c660">Как он устроен</a></span><span class="md-toc-item md-toc-h4" data-ref="c691"><a class="md-toc-inner" style="" href="#header-c691">Библиотека Boost</a></span><span class="md-toc-item md-toc-h3" data-ref="c700"><a class="md-toc-inner" style="" href="#header-c700">Шаблон структуры std::pair</a></span><span class="md-toc-item md-toc-h5" data-ref="c704"><a class="md-toc-inner" style="" href="#header-c704">Структура pair определяется следующим образом:</a></span><span class="md-toc-item md-toc-h5" data-ref="c706"><a class="md-toc-inner" style="" href="#header-c706">Более рабочий пример</a></span><span class="md-toc-item md-toc-h3" data-ref="c1270"><a class="md-toc-inner" style="" href="#header-c1270">Шаблон std::unordered_map. Bucket и chaining</a></span><span class="md-toc-item md-toc-h5" data-ref="c719"><a class="md-toc-inner" style="" href="#header-c719">Пример</a></span><span class="md-toc-item md-toc-h4" data-ref="c725"><a class="md-toc-inner" style="" href="#header-c725">Метод цепочек</a></span><span class="md-toc-item md-toc-h3" data-ref="c1283"><a class="md-toc-inner" style="" href="#header-c1283">Фактор нагрузки, рехеширование и использование функции reserve</a></span><span class="md-toc-item md-toc-h4" data-ref="c741"><a class="md-toc-inner" style="" href="#header-c741">Фактор нагрузки</a></span><span class="md-toc-item md-toc-h4" data-ref="c761"><a class="md-toc-inner" style="" href="#header-c761">Метод повторного хеширования (рехеширование)</a></span><span class="md-toc-item md-toc-h4" data-ref="c794"><a class="md-toc-inner" style="" href="#header-c794">Функции reserve</a></span><span class="md-toc-item md-toc-h3" data-ref="c824"><a class="md-toc-inner" style="" href="#header-c824">Хеширование: линейное, двойное, квадратичное пробирование, folding</a></span><span class="md-toc-item md-toc-h3" data-ref="c1317"><a class="md-toc-inner" style="" href="#header-c1317">Coalesced hashing</a></span><span class="md-toc-item md-toc-h5" data-ref="c871"><a class="md-toc-inner" style="" href="#header-c871">Производительность</a></span><span class="md-toc-item md-toc-h3" data-ref="c1332"><a class="md-toc-inner" style="" href="#header-c1332">Понимание алгоритмов сортировки</a></span><span class="md-toc-item md-toc-h4" data-ref="c881"><a class="md-toc-inner" style="" href="#header-c881">Пузырьковая сортировка (Bubble sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c884"><a class="md-toc-inner" style="" href="#header-c884">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c889"><a class="md-toc-inner" style="" href="#header-c889">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c894"><a class="md-toc-inner" style="" href="#header-c894">Сортировка расчёской (Comb sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c899"><a class="md-toc-inner" style="" href="#header-c899">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c906"><a class="md-toc-inner" style="" href="#header-c906">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c911"><a class="md-toc-inner" style="" href="#header-c911">Сортировка подсчётом (Counting sort)</a></span><span class="md-toc-item md-toc-h4" data-ref="c915"><a class="md-toc-inner" style="" href="#header-c915">Сортировка кучей (Heapsort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c920"><a class="md-toc-inner" style="" href="#header-c920">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c950"><a class="md-toc-inner" style="" href="#header-c950">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c955"><a class="md-toc-inner" style="" href="#header-c955">Сортировка вставками (Insertion sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c958"><a class="md-toc-inner" style="" href="#header-c958">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c963"><a class="md-toc-inner" style="" href="#header-c963">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c969"><a class="md-toc-inner" style="" href="#header-c969">Сортировка слиянием (Merge sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c972"><a class="md-toc-inner" style="" href="#header-c972">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c999"><a class="md-toc-inner" style="" href="#header-c999">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c1004"><a class="md-toc-inner" style="" href="#header-c1004">Быстрая сортировка (Quicksort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c1009"><a class="md-toc-inner" style="" href="#header-c1009">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c1049"><a class="md-toc-inner" style="" href="#header-c1049">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c1054"><a class="md-toc-inner" style="" href="#header-c1054">Поразрядная сортировка (Radix sort)</a></span><span class="md-toc-item md-toc-h4" data-ref="c1058"><a class="md-toc-inner" style="" href="#header-c1058">Сортировка выбором (Selection sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c1061"><a class="md-toc-inner" style="" href="#header-c1061">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c1078"><a class="md-toc-inner" style="" href="#header-c1078">Реализация на C++</a></span><span class="md-toc-item md-toc-h4" data-ref="c1083"><a class="md-toc-inner" style="" href="#header-c1083">Сортировка Шелла (Shell sort)</a></span><span class="md-toc-item md-toc-h5" data-ref="c1095"><a class="md-toc-inner" style="" href="#header-c1095">Алгоритм</a></span><span class="md-toc-item md-toc-h5" data-ref="c1136"><a class="md-toc-inner" style="" href="#header-c1136">Пример</a></span><span class="md-toc-item md-toc-h5" data-ref="c1146"><a class="md-toc-inner" style="" href="#header-c1146">Реализация на C++</a></span><span class="md-toc-item md-toc-h3" data-ref="c1347"><a class="md-toc-inner" style="" href="#header-c1347">Хеширование. Метод Брента</a></span><span class="md-toc-item md-toc-h2" data-ref="c1161"><a class="md-toc-inner" style="" href="#header-c1161">Ответы по прошлым темам</a></span><span class="md-toc-item md-toc-h3" data-ref="c1162"><a class="md-toc-inner" style="" href="#header-c1162">1. Как бы вы определили понятие «структура данных»</a></span><span class="md-toc-item md-toc-h3" data-ref="c1165"><a class="md-toc-inner" style="" href="#header-c1165">6. Объясните отличие класса (class) от структуры (struct)</a></span><span class="md-toc-item md-toc-h6" data-ref="c1378"><a class="md-toc-inner" style="" href="#header-c1378">Created by Ivan Istomin &</a></span><span class="md-toc-item md-toc-h6" data-ref="c1384"><a class="md-toc-inner" style="" href="#header-c1384">View on GitHub</a></span></p></div><h2><a name='header-c1219' class='md-header-anchor '></a>Алгоритмы и структура данных</h2><h3><a name='header-c1201' class='md-header-anchor '></a>std::deque и его представление</h3><p><strong>Двусторонняя очередь</strong> (англ. <strong>deque</strong>) — структура данных, в которой элементы можно добавлять и удалять как в начало, так и в конец, то есть дисциплинами обслуживания являются одновременно FIFO (First In, First Out — «первым пришёл — первым ушёл») и LIFO (Last In, First Out, «последним пришёл — первым ушёл»).</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/e/e5/Deque.svg?uselang=ru' alt='' /></p><h5><a name='header-c631' class='md-header-anchor '></a>Пример</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">deque</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span><span class="cm-operator">></span> <span class="cm-variable">Q</span>;</span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">Q</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">3</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">Q</span>.<span class="cm-variable">push_front</span>(<span class="cm-number">1</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">Q</span>.<span class="cm-variable">insert</span>(<span class="cm-variable">Q</span>.<span class="cm-variable">begin</span>() <span class="cm-operator">+</span> <span class="cm-number">1</span>, <span class="cm-number">2</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">Q</span>[<span class="cm-number">2</span>] <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">copy</span>(<span class="cm-variable">Q</span>.<span class="cm-variable">begin</span>(), <span class="cm-variable">Q</span>.<span class="cm-variable">end</span>(), <span class="cm-variable">ostream_iterator</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span><span class="cm-operator">></span>(<span class="cm-variable">cout</span>, <span class="cm-string">" "</span>));</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Результатом будет - 1 2 0</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 154px;"></div></div></div></pre><p><a href='http://ru.cppreference.com/w/cpp/container/deque'>Ссылка на документацию</a><br/>
<a href='https://ru.wikipedia.org/wiki/%D0%94%D0%B2%D1%83%D1%85%D1%81%D1%82%D0%BE%D1%80%D0%BE%D0%BD%D0%BD%D1%8F%D1%8F_%D0%BE%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D1%8C'>Ссылка на Википедию</a></p><hr /><h3><a name='header-c637' class='md-header-anchor '></a>Stack как адаптер стандартного контейнера std::deque</h3><p>Что же такое адаптер-контейнера? Это, по существу, устоявшийся паттерн, который приходит к нам из реального мира. Мы берём одну сущность и адаптируем её к новым условиям через другую сущность.</p><p>Почему они адапторы? Потому что внутри себя используют полноценный контейнеры, такие как <code>std::vector</code> и <code>std::deque</code>, и адаптируют их интерфейс под другой интерфейс. К примеру, <code>std::vector</code> имеет методы <code>push_back</code>, <code>insert</code> и <code>pop_back</code>, но такие операции для стека не нужны, стеку нужны 3 операции (основные) <code>top</code>, <code>pop</code> и <code>push</code>. Но все эти операции реализованы через соответсвующие операции <code>std::vector</code>, который скрывается в недрах <code>std::stack</code>. Поэтому stack не выделяют как самостоятельный контейнер — он есть адаптер для <code>std::vector</code>.</p><p>Итак, любая последовательность, поддерживающая операции <code>back</code>, <code>push_back</code> и <code>pop_back</code>, может использоваться для модификации stack. В частности, могут использоваться <code>vector</code>, <code>list</code> и <code>deque</code>.</p><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">Container</span><span class="cm-operator">></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">class</span> <span class="cm-def">stack</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">friend</span> <span class="cm-variable-3">bool</span> <span class="cm-keyword">operator</span><span class="cm-operator">==</span>(<span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">х</span>, <span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">y</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">friend</span> <span class="cm-variable-3">bool</span> <span class="cm-keyword">operator</span><span class="cm-operator"><</span>(<span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">х</span>, <span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">y</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">public</span>:</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">typedef</span> <span class="cm-variable">Container::value_type</span> <span class="cm-variable">value_type</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">typedef</span> <span class="cm-variable">Container::size_type</span> <span class="cm-variable">size_type</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">protected</span>:</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">Container</span> <span class="cm-variable">c</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">public</span>:</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">bool</span> <span class="cm-variable">empty</span>() <span class="cm-keyword">const</span> { <span class="cm-keyword">return</span> <span class="cm-variable">c</span>.<span class="cm-variable">empty</span>(); }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">size_type</span> <span class="cm-variable">size</span>() <span class="cm-keyword">const</span> { <span class="cm-keyword">return</span> <span class="cm-variable">c</span>.<span class="cm-variable">size</span>(); }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">value_type</span><span class="cm-operator">&</span> <span class="cm-variable">top</span>() { <span class="cm-keyword">return</span> <span class="cm-variable">c</span>.<span class="cm-variable">back</span>(); }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">const</span> <span class="cm-variable">value_type</span><span class="cm-operator">&</span> <span class="cm-variable">top</span>() <span class="cm-keyword">const</span> { <span class="cm-keyword">return</span> <span class="cm-variable">c</span>.<span class="cm-variable">back</span>(); }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">void</span> <span class="cm-variable">push</span>(<span class="cm-keyword">const</span> <span class="cm-variable">value_type</span><span class="cm-operator">&</span> <span class="cm-variable">х</span>) { <span class="cm-variable">с</span>.<span class="cm-variable">push_back</span>(<span class="cm-variable">х</span>); }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">void</span> <span class="cm-variable">pop</span>() { <span class="cm-variable">c</span>.<span class="cm-variable">pop_back</span>(); }</span></pre><pre class=""><span style="padding-right: 0.1px;"> };</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">Container</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">bool</span> <span class="cm-keyword">operator</span><span class="cm-operator">==</span>(<span class="cm-keyword">const</span> <span class="cm-variable">stack</span> <span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">х</span>, <span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">y</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{ <span class="cm-keyword">return</span> <span class="cm-variable">х</span>.<span class="cm-variable">с</span> <span class="cm-operator">==</span> <span class="cm-variable">у</span>.<span class="cm-variable">с</span>;}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">Container</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">bool</span> <span class="cm-keyword">operator</span><span class="cm-operator"><</span>(<span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">х</span>, <span class="cm-keyword">const</span> <span class="cm-variable">stack</span><span class="cm-operator"><</span><span class="cm-variable">Container</span><span class="cm-operator">>&</span> <span class="cm-variable">y</span>) </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{ <span class="cm-keyword">return</span> <span class="cm-variable">х</span>.<span class="cm-variable">с</span> <span class="cm-operator"><</span> <span class="cm-variable">у</span>.<span class="cm-variable">с</span>; }</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 550px;"></div></div></div></pre><p>Например, <code>stack<vector<int>></code> - целочисленный стек, сделанный из vector, а <code>stack<deque<char>></code> - символьный стек, сделанный из <code>deque</code>.</p><p><a href='http://cpp.com.ru/stl/11.html#11.1'>Ссылка на руководство</a><br/>
<a href='http://ru.stackoverflow.com/questions/479987/%D0%A7%D1%82%D0%BE-%D1%82%D0%B0%D0%BA%D0%BE%D0%B5-%D0%B0%D0%B4%D0%B0%D0%BF%D1%82%D0%B5%D1%80'>Ссылка на StackOverflow</a></p><hr /><h3><a name='header-c653' class='md-header-anchor '></a>Циклический буфер (кольцо). Стандартная библиотека boost</h3><p><strong>Кольцевой буфер</strong>, или <strong>циклический буфер</strong> — это структура данных, использующая единственный буфер фиксированного размера, как будто бы после последнего элемента сразу же снова идет первый. Такая структура легко предоставляет возможность буферизации потоков данных.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/b/b7/Circular_buffer.svg' alt='' /></p><p>Кольцевой буфер. Иллюстрация визуально показывает, что у буфера нет настоящего конца. Тем не менее, поскольку физическая память никогда не делается закольцованной, обычно используется линейное представление, как показано ниже.</p><h4><a name='header-c660' class='md-header-anchor '></a>Как он устроен</h4><p>Кольцевой буфер создается пустым, с некоторой заранее определенной длиной. Например, это семиэлементный буфер:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/f/f7/Circular_buffer_-_empty.svg?uselang=ru' alt='' /></p><p>Предположим, что в середину буфера записывается 1 (в кольцевом буфере точная начальная ячейка не имеет значения):</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/8/89/Circular_buffer_-_XX1XXXX.svg?uselang=ru' alt='' /></p><p>Затем предположим, что после единицы были добавлены ещё два элемента — 2 и 3:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/d/d7/Circular_buffer_-_XX123XX.svg?uselang=ru' alt='' /></p><p>Если после этого два элемента должны быть удалены из буфера, то выбираются два наиболее старых элемента. В нашем случае удаляются элементы 1 и 2, в буфере остается только 3:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/1/11/Circular_buffer_-_XXXX3XX.svg?uselang=ru' alt='' /></p><p>Если в буфере находится 7 элементов, то он заполнен:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/6/67/Circular_buffer_-_6789345.svg?uselang=ru' alt='' /></p><p>Если продолжить запись в буфер, не принимая во внимание его заполненность, то новые данные начнут перезаписывать старые данные. В нашем случае, добавляя элементы A и B, мы перезапишем 3 и 4:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/b/ba/Circular_buffer_-_6789AB5.svg?uselang=ru' alt='' /></p><p>В другом варианте реализации процедуры, обслуживающие буфер, могут предотвратить перезапись данных и вернуть ошибку или выбросить исключение. Перезапись или её отсутствие оставляется на усмотрение обслуживающих процедур буфера или приложения, использующего кольцевой буфер.</p><p>Наконец, если теперь удалить из буфера два элемента, то удалены будут не 3 и 4, а 5 и 6, потому что A и B перезаписали элементы 3 и 4; буфер придет в состояние:</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/4/43/Circular_buffer_-_X789ABX.svg?uselang=ru' alt='' /></p><h4><a name='header-c691' class='md-header-anchor '></a>Библиотека Boost</h4><p>circular_buffer специально разработана, чтобы обеспечить фиксированную емкость.</p><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <boost/circular_buffer.hpp></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Создать кольцевой буфер с емкостью для 3-х int'ов.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">boost::circular_buffer</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span><span class="cm-operator">></span> <span class="cm-def">cb</span>(<span class="cm-number">3</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Положим 3 элемента в буфер.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">1</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">2</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">3</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">a</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">0</span>]; <span class="cm-comment">// a == 1</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">1</span>]; <span class="cm-comment">// b == 2</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">2</span>]; <span class="cm-comment">// c == 3</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Сейчас буфер заполнен, при последующем добавленнии</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// элементов более старые перезаписываются.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">4</span>); <span class="cm-comment">// Перезаписываем 1 добавляя 4.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">5</span>); <span class="cm-comment">// Перезаписываем 2 добавляя 5.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Сейчас буфер содержит 3, 4 и 5.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">a</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">0</span>]; <span class="cm-comment">// a == 3</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">1</span>]; <span class="cm-comment">// b == 4</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">2</span>]; <span class="cm-comment">// c == 5</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Элементы могут быть удалены с конца.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">pop_back</span>(); <span class="cm-comment">// 5 удален.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">cb</span>.<span class="cm-variable">pop_front</span>(); <span class="cm-comment">// 3 удален.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// Оставив только один элемент со значением = 4.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">d</span> <span class="cm-operator">=</span> <span class="cm-variable">cb</span>[<span class="cm-number">0</span>]; <span class="cm-comment">// d == 4</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 682px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D0%BB%D1%8C%D1%86%D0%B5%D0%B2%D0%BE%D0%B9_%D0%B1%D1%83%D1%84%D0%B5%D1%80'>Ссылка на Википедию</a><br/>
<a href='http://www.boost.org/doc/libs/1_61_0/doc/html/circular_buffer.html'>Ссылка на документацию кольцевого буфера в Boost</a></p><hr /><h3><a name='header-c700' class='md-header-anchor '></a>Шаблон структуры std::pair</h3><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">T1</span>,</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">T2</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-operator">></span> <span class="cm-keyword">struct</span> <span class="cm-def">pair</span>;</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 88px;"></div></div></div></pre><p><em>std::pair</em> является шаблоном структуры, который предоставляет возможность хранить два разнородных объекта, как единое целое.</p><h5><a name='header-c704' class='md-header-anchor '></a>Структура pair определяется следующим образом:</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">namespace</span> <span class="cm-def">std</span></span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T1</span>, <span class="cm-keyword">class</span> <span class="cm-def">T2</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">struct</span> <span class="cm-def">pair</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// ...</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// здесь опущены определения типов, </span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// реализации различных версий конструкторов</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// и метода swap</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// ...</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">T1</span> <span class="cm-variable">first</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">T2</span> <span class="cm-variable">second</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">//Реализуем метод создания pair </span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T1</span>, <span class="cm-keyword">class</span> <span class="cm-def">T2</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">pair</span><span class="cm-operator"><</span><span class="cm-variable">T1</span>, <span class="cm-variable">T2</span><span class="cm-operator">></span> <span class="cm-def">make_pair</span>(<span class="cm-keyword">const</span> <span class="cm-variable">T1</span><span class="cm-operator">&</span>, <span class="cm-keyword">const</span> <span class="cm-variable">T2</span><span class="cm-operator">&</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">return</span> <span class="cm-variable">pair</span><span class="cm-operator"><</span><span class="cm-variable">T1</span>, <span class="cm-variable">T2</span><span class="cm-operator">></span>(<span class="cm-variable">x</span>, <span class="cm-variable">y</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable">string</span><span class="cm-operator">></span> <span class="cm-variable">p</span> <span class="cm-operator">=</span> <span class="cm-variable">make_pair</span>(<span class="cm-number">22</span>, <span class="cm-string">"Moscow"</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">//Или</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">//Хранит пары "имя - средний балл аттестата"</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">std::map</span><span class="cm-operator"><</span><span class="cm-variable">string</span>, <span class="cm-variable-3">double</span><span class="cm-operator">></span> <span class="cm-variable">pupils</span>; </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">pupils</span>.<span class="cm-variable">insert</span>(<span class="cm-variable">make_pair</span>(<span class="cm-string">"Ivanov"</span>, <span class="cm-number">4.5</span>));</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">pupils</span>.<span class="cm-variable">insert</span>(<span class="cm-variable">make_pair</span>(<span class="cm-string">"Petrov"</span>, <span class="cm-number">5.0</span>));</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 660px;"></div></div></div></pre><h5><a name='header-c706' class='md-header-anchor '></a>Более рабочий пример</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <utility></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <complex></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <tuple></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable-3">float</span><span class="cm-operator">></span> <span class="cm-variable">p1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Value-initialized: "</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-variable">p1</span>.<span class="cm-variable">first</span> <span class="cm-operator"><<</span> <span class="cm-string">", "</span> <span class="cm-operator"><<</span> <span class="cm-variable">p1</span>.<span class="cm-variable">second</span> <span class="cm-operator"><<</span> <span class="cm-string">'\n'</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable-3">double</span><span class="cm-operator">></span> <span class="cm-variable">p2</span>(<span class="cm-number">42</span>, <span class="cm-number">0.123</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Initialized with two values: "</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-variable">p2</span>.<span class="cm-variable">first</span> <span class="cm-operator"><<</span> <span class="cm-string">", "</span> <span class="cm-operator"><<</span> <span class="cm-variable">p2</span>.<span class="cm-variable">second</span> <span class="cm-operator"><<</span> <span class="cm-string">'\n'</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable-3">char</span>, <span class="cm-variable-3">int</span><span class="cm-operator">></span> <span class="cm-variable">p4</span>(<span class="cm-variable">p2</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Implicitly converted: "</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-variable">p4</span>.<span class="cm-variable">first</span> <span class="cm-operator"><<</span> <span class="cm-string">", "</span> <span class="cm-operator"><<</span> <span class="cm-variable">p4</span>.<span class="cm-variable">second</span> <span class="cm-operator"><<</span> <span class="cm-string">'\n'</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable">std::complex</span><span class="cm-operator"><</span><span class="cm-variable-3">double</span><span class="cm-operator">></span>, <span class="cm-variable">std::string</span><span class="cm-operator">></span> <span class="cm-variable">p6</span>(</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::piecewise_construct</span>, </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::forward_as_tuple</span>(<span class="cm-number">0.123</span>, <span class="cm-number">7.7</span>),</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::forward_as_tuple</span>(<span class="cm-number">10</span>, <span class="cm-string">'a'</span>));</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Piecewise constructed: "</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-variable">p6</span>.<span class="cm-variable">first</span> <span class="cm-operator"><<</span> <span class="cm-string">", "</span> <span class="cm-operator"><<</span> <span class="cm-variable">p6</span>.<span class="cm-variable">second</span> <span class="cm-operator"><<</span> <span class="cm-string">'\n'</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 594px;"></div></div></div></pre><p><a href='http://ru.cppreference.com/w/cpp/utility/pair'>Ссылка на документацию</a><br/>
<a href='http://cs.mipt.ru/wiki/index.php/Pair'>Ссылка на примеры</a></p><hr /><h3><a name='header-c1270' class='md-header-anchor '></a>Шаблон std::unordered_map. Bucket и chaining</h3><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">Key</span>,</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">T</span>,</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">Hash</span> <span class="cm-operator">=</span> <span class="cm-variable">std::hash</span><span class="cm-operator"><</span><span class="cm-variable">Key</span><span class="cm-operator">></span>,</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">KeyEqual</span> <span class="cm-operator">=</span> <span class="cm-variable">std::equal_to</span><span class="cm-operator"><</span><span class="cm-variable">Key</span><span class="cm-operator">></span>,</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">class</span> <span class="cm-def">Allocator</span> <span class="cm-operator">=</span> <span class="cm-variable">std::allocator</span><span class="cm-operator"><</span> <span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-keyword">const</span> <span class="cm-variable">Key</span>, <span class="cm-variable">T</span><span class="cm-operator">></span> <span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-operator">></span> <span class="cm-keyword">class</span> <span class="cm-def">unordered_map</span>;</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 154px;"></div></div></div></pre><p><em>std::unordered_map</em> является ассоциативным контейнером, который содержит пары ключ-значение с уникальными ключами. Поиск, вставка и удаление выполняются за константное время.</p><p>Внутри, элементы не отсортированы в каком-либо определенном порядке, но организованы в блоки (buckets). Каждый блок элемента находится в полной зависимости от хэш-ключа. Это дает быстрый доступ к отдельным элементам, так как вычисляется хэш-код.</p><h5><a name='header-c719' class='md-header-anchor '></a>Пример</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <unordered_map></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <vector></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <bitset></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <utility></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">Key</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::string</span> <span class="cm-variable">first</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::string</span> <span class="cm-variable">second</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">};</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">KeyHash</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::size_t</span> <span class="cm-keyword">operator</span>()(<span class="cm-keyword">const</span> <span class="cm-variable">Key</span><span class="cm-operator">&</span> <span class="cm-variable">k</span>) <span class="cm-keyword">const</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">std::hash</span><span class="cm-operator"><</span><span class="cm-variable">std::string</span><span class="cm-operator">></span>()(<span class="cm-variable">k</span>.<span class="cm-variable">first</span>) <span class="cm-variable">^</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> (<span class="cm-variable">std::hash</span><span class="cm-operator"><</span><span class="cm-variable">std::string</span><span class="cm-operator">></span>()(<span class="cm-variable">k</span>.<span class="cm-variable">second</span>) <span class="cm-operator"><<</span> <span class="cm-number">1</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">};</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">KeyEqual</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">bool</span> <span class="cm-keyword">operator</span>()(<span class="cm-keyword">const</span> <span class="cm-variable">Key</span><span class="cm-operator">&</span> <span class="cm-variable">lhs</span>, <span class="cm-keyword">const</span> <span class="cm-variable">Key</span><span class="cm-operator">&</span> <span class="cm-variable">rhs</span>) <span class="cm-keyword">const</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">lhs</span>.<span class="cm-variable">first</span> <span class="cm-operator">==</span> <span class="cm-variable">rhs</span>.<span class="cm-variable">first</span> <span class="cm-operator">&&</span> <span class="cm-variable">lhs</span>.<span class="cm-variable">second</span> <span class="cm-operator">==</span> <span class="cm-variable">rhs</span>.<span class="cm-variable">second</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">};</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// default constructor: empty map</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable">std::string</span>, <span class="cm-variable">std::string</span><span class="cm-operator">></span> <span class="cm-variable">m1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// list constructor</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable">std::string</span><span class="cm-operator">></span> <span class="cm-variable">m2</span> <span class="cm-operator">=</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> {<span class="cm-number">1</span>, <span class="cm-string">"foo"</span>},</span></pre><pre class=""><span style="padding-right: 0.1px;"> {<span class="cm-number">3</span>, <span class="cm-string">"bar"</span>},</span></pre><pre class=""><span style="padding-right: 0.1px;"> {<span class="cm-number">2</span>, <span class="cm-string">"baz"</span>},</span></pre><pre class=""><span style="padding-right: 0.1px;"> };</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// copy constructor</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable">std::string</span><span class="cm-operator">></span> <span class="cm-variable">m3</span> <span class="cm-operator">=</span> <span class="cm-variable">m2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// move constructor</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>, <span class="cm-variable">std::string</span><span class="cm-operator">></span> <span class="cm-variable">m4</span> <span class="cm-operator">=</span> <span class="cm-variable">std::move</span>(<span class="cm-variable">m2</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// range constructor</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::vector</span><span class="cm-operator"><</span><span class="cm-variable">std::pair</span><span class="cm-operator"><</span><span class="cm-variable">std::bitset</span><span class="cm-operator"><</span><span class="cm-number">8</span><span class="cm-operator">></span>, <span class="cm-variable-3">int</span><span class="cm-operator">>></span> <span class="cm-variable">v</span> <span class="cm-operator">=</span> { {<span class="cm-number">0x12</span>, <span class="cm-number">1</span>}, {<span class="cm-number">0x01</span>,<span class="cm-operator">-</span><span class="cm-number">1</span>} };</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable">std::bitset</span><span class="cm-operator"><</span><span class="cm-number">8</span><span class="cm-operator">></span>, <span class="cm-variable-3">double</span><span class="cm-operator">></span> <span class="cm-variable">m5</span>(<span class="cm-variable">v</span>.<span class="cm-variable">begin</span>(), <span class="cm-variable">v</span>.<span class="cm-variable">end</span>());</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// constructor for a custom type</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::unordered_map</span><span class="cm-operator"><</span><span class="cm-variable">Key</span>, <span class="cm-variable">std::string</span>, <span class="cm-variable">KeyHash</span>, <span class="cm-variable">KeyEqual</span><span class="cm-operator">></span> <span class="cm-variable">m6</span> <span class="cm-operator">=</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> { {<span class="cm-string">"John"</span>, <span class="cm-string">"Doe"</span>}, <span class="cm-string">"example"</span>},</span></pre><pre class=""><span style="padding-right: 0.1px;"> { {<span class="cm-string">"Mary"</span>, <span class="cm-string">"Sue"</span>}, <span class="cm-string">"another"</span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"> };</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 1210px;"></div></div></div></pre><p><strong>Коллизией хеш-функции</strong> <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-5-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="1.994ex" viewBox="0 -755.9 888.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E5-MJMATHI-48" d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 219 683Q260 681 355 681Q389 681 418 681T463 682T483 682Q499 682 499 672Q499 670 497 658Q492 641 487 638H485Q483 638 480 638T473 638T464 637T455 637Q416 636 405 634T387 623Q384 619 355 500Q348 474 340 442T328 395L324 380Q324 378 469 378H614L615 381Q615 384 646 504Q674 619 674 627T617 637Q594 637 587 639T580 648Q580 650 582 660Q586 677 588 679T604 682Q609 682 646 681T740 680Q802 680 835 681T871 682Q888 682 888 672Q888 645 876 638H874Q872 638 869 638T862 638T853 637T844 637Q805 636 794 634T776 623Q773 618 704 340T634 58Q634 51 638 51Q646 48 692 46H723Q729 38 729 37T726 19Q722 6 716 0H701Q664 2 567 2Q533 2 504 2T458 2T437 1Q420 1 420 10Q420 15 423 24Q428 43 433 45Q437 46 448 46H454Q481 46 514 49Q520 50 522 50T528 55T534 64T540 82T547 110T558 153Q565 181 569 198Q602 330 602 331T457 332H312L279 197Q245 63 245 58Q245 51 253 49T303 46H334Q340 38 340 37T337 19Q333 6 327 0H312Q275 2 178 2Q144 2 115 2T69 2T48 1Q31 1 31 10Q31 12 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E5-MJMATHI-48" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-5">H</script> называется два различных входных блока данных <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-2-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.33ex" height="1.41ex" viewBox="0 -504.6 572.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E2-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E2-MJMATHI-78" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-2">x</script> и <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-3-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.155ex" height="1.877ex" viewBox="0 -504.6 497.5 808.1" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E3-MJMATHI-79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E3-MJMATHI-79" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-3">y</script> таких, что <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-4-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="13.329ex" height="2.577ex" viewBox="0 -806.1 5739.1 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E4-MJMATHI-48" d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 219 683Q260 681 355 681Q389 681 418 681T463 682T483 682Q499 682 499 672Q499 670 497 658Q492 641 487 638H485Q483 638 480 638T473 638T464 637T455 637Q416 636 405 634T387 623Q384 619 355 500Q348 474 340 442T328 395L324 380Q324 378 469 378H614L615 381Q615 384 646 504Q674 619 674 627T617 637Q594 637 587 639T580 648Q580 650 582 660Q586 677 588 679T604 682Q609 682 646 681T740 680Q802 680 835 681T871 682Q888 682 888 672Q888 645 876 638H874Q872 638 869 638T862 638T853 637T844 637Q805 636 794 634T776 623Q773 618 704 340T634 58Q634 51 638 51Q646 48 692 46H723Q729 38 729 37T726 19Q722 6 716 0H701Q664 2 567 2Q533 2 504 2T458 2T437 1Q420 1 420 10Q420 15 423 24Q428 43 433 45Q437 46 448 46H454Q481 46 514 49Q520 50 522 50T528 55T534 64T540 82T547 110T558 153Q565 181 569 198Q602 330 602 331T457 332H312L279 197Q245 63 245 58Q245 51 253 49T303 46H334Q340 38 340 37T337 19Q333 6 327 0H312Q275 2 178 2Q144 2 115 2T69 2T48 1Q31 1 31 10Q31 12 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z"></path><path stroke-width="1" id="E4-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E4-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path><path stroke-width="1" id="E4-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E4-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E4-MJMATHI-79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E4-MJMATHI-48" x="0" y="0"></use><use xlink:href="#E4-MJMAIN-28" x="888" y="0"></use><use xlink:href="#E4-MJMATHI-78" x="1278" y="0"></use><use xlink:href="#E4-MJMAIN-29" x="1850" y="0"></use><use xlink:href="#E4-MJMAIN-3D" x="2517" y="0"></use><use xlink:href="#E4-MJMATHI-48" x="3574" y="0"></use><use xlink:href="#E4-MJMAIN-28" x="4462" y="0"></use><use xlink:href="#E4-MJMATHI-79" x="4852" y="0"></use><use xlink:href="#E4-MJMAIN-29" x="5349" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-4">H(x)=H(y)</script>.</p><p>То есть, говоря своими словами, возможна такая ситуация, что хеш-фукнция может сгенерировать одинаковые хэш-ключи.</p><h4><a name='header-c725' class='md-header-anchor '></a>Метод цепочек</h4><p>Каждая ячейка массива <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-5-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="1.994ex" viewBox="0 -755.9 888.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E5-MJMATHI-48" d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 219 683Q260 681 355 681Q389 681 418 681T463 682T483 682Q499 682 499 672Q499 670 497 658Q492 641 487 638H485Q483 638 480 638T473 638T464 637T455 637Q416 636 405 634T387 623Q384 619 355 500Q348 474 340 442T328 395L324 380Q324 378 469 378H614L615 381Q615 384 646 504Q674 619 674 627T617 637Q594 637 587 639T580 648Q580 650 582 660Q586 677 588 679T604 682Q609 682 646 681T740 680Q802 680 835 681T871 682Q888 682 888 672Q888 645 876 638H874Q872 638 869 638T862 638T853 637T844 637Q805 636 794 634T776 623Q773 618 704 340T634 58Q634 51 638 51Q646 48 692 46H723Q729 38 729 37T726 19Q722 6 716 0H701Q664 2 567 2Q533 2 504 2T458 2T437 1Q420 1 420 10Q420 15 423 24Q428 43 433 45Q437 46 448 46H454Q481 46 514 49Q520 50 522 50T528 55T534 64T540 82T547 110T558 153Q565 181 569 198Q602 330 602 331T457 332H312L279 197Q245 63 245 58Q245 51 253 49T303 46H334Q340 38 340 37T337 19Q333 6 327 0H312Q275 2 178 2Q144 2 115 2T69 2T48 1Q31 1 31 10Q31 12 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E5-MJMATHI-48" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-5">H</script> является указателем на связный список (цепочку) пар ключ-значение, соответствующих одному и тому же хеш-значению ключа. Коллизии просто приводят к тому, что появляются цепочки длиной более одного элемента.</p><p>Операции поиска или удаления элемента требуют просмотра всех элементов соответствующей ему цепочки, чтобы найти в ней элемент с заданным ключом. Для добавления элемента нужно добавить элемент в конец или начало соответствующего списка, и, в случае, если коэффициент заполнения станет слишком велик, увеличить размер массива H и перестроить таблицу.</p><p>При предположении, что каждый элемент может попасть в любую позицию таблицы H с равной вероятностью и независимо от того, куда попал любой другой элемент, среднее время работы операции поиска элемента составляет <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-6-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.073ex" height="2.577ex" viewBox="0 -806.1 3906.4 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E6-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E6-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E6-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E6-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E6-MJMATHI-3B1" d="M34 156Q34 270 120 356T309 442Q379 442 421 402T478 304Q484 275 485 237V208Q534 282 560 374Q564 388 566 390T582 393Q603 393 603 385Q603 376 594 346T558 261T497 161L486 147L487 123Q489 67 495 47T514 26Q528 28 540 37T557 60Q559 67 562 68T577 70Q597 70 597 62Q597 56 591 43Q579 19 556 5T512 -10H505Q438 -10 414 62L411 69L400 61Q390 53 370 41T325 18T267 -2T203 -11Q124 -11 79 39T34 156ZM208 26Q257 26 306 47T379 90L403 112Q401 255 396 290Q382 405 304 405Q235 405 183 332Q156 292 139 224T121 120Q121 71 146 49T208 26Z"></path><path stroke-width="1" id="E6-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E6-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E6-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E6-MJMAIN-31" x="1153" y="0"></use><use xlink:href="#E6-MJMAIN-2B" x="1875" y="0"></use><use xlink:href="#E6-MJMATHI-3B1" x="2876" y="0"></use><use xlink:href="#E6-MJMAIN-29" x="3516" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-6">O(1 + \alpha)</script>, где <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-7-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.488ex" height="1.41ex" viewBox="0 -504.6 640.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E7-MJMATHI-3B1" d="M34 156Q34 270 120 356T309 442Q379 442 421 402T478 304Q484 275 485 237V208Q534 282 560 374Q564 388 566 390T582 393Q603 393 603 385Q603 376 594 346T558 261T497 161L486 147L487 123Q489 67 495 47T514 26Q528 28 540 37T557 60Q559 67 562 68T577 70Q597 70 597 62Q597 56 591 43Q579 19 556 5T512 -10H505Q438 -10 414 62L411 69L400 61Q390 53 370 41T325 18T267 -2T203 -11Q124 -11 79 39T34 156ZM208 26Q257 26 306 47T379 90L403 112Q401 255 396 290Q382 405 304 405Q235 405 183 332Q156 292 139 224T121 120Q121 71 146 49T208 26Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E7-MJMATHI-3B1" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-7">\alpha</script> — коэффициент заполнения таблицы.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/d/d0/Hash_table_5_0_1_1_1_1_1_LL.svg' alt='' /></p><p><a href='http://ru.cppreference.com/w/cpp/container/unordered_map'>Ссылка на документацию</a><br/>
<a href='http://neerc.ifmo.ru/wiki/index.php?title=%D0%A0%D0%B0%D0%B7%D1%80%D0%B5%D1%88%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BA%D0%BE%D0%BB%D0%BB%D0%B8%D0%B7%D0%B8%D0%B9'>Ссылка на статью «Решение коллизий»</a><br/>
<a href='https://ru.wikipedia.org/wiki/%D0%A5%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D0%B0'>Ссылка на Википедию</a></p><hr /><h3><a name='header-c1283' class='md-header-anchor '></a>Фактор нагрузки, рехеширование и использование функции reserve</h3><h4><a name='header-c741' class='md-header-anchor '></a>Фактор нагрузки</h4><p>Критическая статистика для хэш-таблицы - коэффициент нагрузки (<strong>фактор нагрузки</strong>), определяемый как</p><p><img src='https://wikimedia.org/api/rest_v1/media/math/render/svg/4a62e704b51552cd390099fee5a7c14d113c4a9a' alt='' /></p><p>где</p><ul><li><span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script> это число entries (записей);</li><li><span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-9-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.211ex" height="1.994ex" viewBox="0 -755.9 521.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E9-MJMATHI-6B" d="M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E9-MJMATHI-6B" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-9">k</script> это число buckets (блоков).</li></ul><p>По мере того как коэффициент нагрузки становится больше, хэш-таблица становится медленнее, и это может привести к остановке работы (в зависимости от используемого метода). Ожидаемое константное время свойство хэш-таблицы предполагает, что коэффициент нагрузки поддерживается ниже некоторой границы. При фиксированном числе блоков (buckets), время для поиска растет с числом записей (entries) и, следовательно, желаемое котное время не достигается.</p><p>Второе, что можно исследовать, дисперсию числа записей в каждый блок. Например, две таблицы, обе имеют 1000 записей и 1000 блоков; ровно один вход в каждый блок, а другой имеет все записи в один и тот же блок. Очевидно, что хеширование не работает во втором блоке.</p><p>Низкий коэффициент нагрузки не очень полезен. Когда коэффициент нагрузки приближается к 0, доля неиспользуемых площадей в хэш-таблице увеличивается, но это не обязательно любое снижение «стоимости» поиска. Это приводит к потере памяти.</p><h4><a name='header-c761' class='md-header-anchor '></a>Метод повторного хеширования (рехеширование)</h4><p>Пусть результатом вычисления хеш-функции для некоторого имени <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-28-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.11ex" viewBox="0 -806.1 645.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E28-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E28-MJMATHI-53" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-28">S</script> является число <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-12-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.339ex" height="1.994ex" viewBox="0 -755.9 576.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E12-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E12-MJMATHI-68" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-12">h</script>. Пусть элемент с этим инд-м <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-12-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.339ex" height="1.994ex" viewBox="0 -755.9 576.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E12-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E12-MJMATHI-68" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-12">h</script> уже занят, т.е. является не пустым, возникает коллизия, которую надо устранить путём выбора другой ячейки таблицы для имени <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-28-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.11ex" viewBox="0 -806.1 645.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E28-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E28-MJMATHI-53" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-28">S</script>.
Выбор такой ячейки производится:
<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-14-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="23.255ex" height="2.577ex" viewBox="0 -806.1 10012.6 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E14-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E14-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E14-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E14-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E14-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E14-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E14-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E14-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E14-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E14-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E14-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E14-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E14-MJMAIN-31" x="815" y="-213"></use><use xlink:href="#E14-MJMAIN-3D" x="1308" y="0"></use><use xlink:href="#E14-MJMAIN-28" x="2364" y="0"></use><use xlink:href="#E14-MJMATHI-68" x="2753" y="0"></use><use xlink:href="#E14-MJMAIN-2B" x="3552" y="0"></use><g transform="translate(4553,0)"><use xlink:href="#E14-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E14-MJMAIN-31" x="712" y="-213"></use></g><use xlink:href="#E14-MJMAIN-29" x="5510" y="0"></use><g transform="translate(6733,0)"><use xlink:href="#E14-MJMAIN-6D"></use><use xlink:href="#E14-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E14-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E14-MJMATHI-4E" x="9124" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-14">h_1 = (h + p_1) \mod N</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-15-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.313ex" height="1.76ex" viewBox="-38.5 -504.6 995.9 757.9" role="img" focusable="false" style="vertical-align: -0.588ex; margin-left: -0.089ex;"><defs><path stroke-width="1" id="E15-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E15-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E15-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E15-MJMAIN-31" x="712" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-15">p_1</script> – некоторое приращение<br/>
Если элемент таблицы <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-16-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.393ex" height="2.227ex" viewBox="0 -755.9 1030.4 958.9" role="img" focusable="false" style="vertical-align: -0.472ex;"><defs><path stroke-width="1" id="E16-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E16-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E16-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E16-MJMAIN-31" x="815" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-16">h_1</script> тоже не пустой, то рассматривается новый элемент:
<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-17-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="23.255ex" height="2.577ex" viewBox="0 -806.1 10012.6 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E17-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E17-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E17-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E17-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E17-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E17-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E17-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E17-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E17-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E17-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E17-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E17-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E17-MJMAIN-32" x="815" y="-213"></use><use xlink:href="#E17-MJMAIN-3D" x="1308" y="0"></use><use xlink:href="#E17-MJMAIN-28" x="2364" y="0"></use><use xlink:href="#E17-MJMATHI-68" x="2753" y="0"></use><use xlink:href="#E17-MJMAIN-2B" x="3552" y="0"></use><g transform="translate(4553,0)"><use xlink:href="#E17-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E17-MJMAIN-32" x="712" y="-213"></use></g><use xlink:href="#E17-MJMAIN-29" x="5510" y="0"></use><g transform="translate(6733,0)"><use xlink:href="#E17-MJMAIN-6D"></use><use xlink:href="#E17-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E17-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E17-MJMATHI-4E" x="9124" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-17">h_2 = (h + p_2) \mod N</script></p><hr /><p><span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-18-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="22.746ex" height="2.577ex" viewBox="0 -806.1 9793.4 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E18-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E18-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E18-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E18-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E18-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E18-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E18-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E18-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E18-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E18-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E18-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E18-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E18-MJMATHI-69" x="815" y="-213"></use><use xlink:href="#E18-MJMAIN-3D" x="1198" y="0"></use><use xlink:href="#E18-MJMAIN-28" x="2254" y="0"></use><use xlink:href="#E18-MJMATHI-68" x="2644" y="0"></use><use xlink:href="#E18-MJMAIN-2B" x="3443" y="0"></use><g transform="translate(4443,0)"><use xlink:href="#E18-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E18-MJMATHI-69" x="712" y="-213"></use></g><use xlink:href="#E18-MJMAIN-29" x="5291" y="0"></use><g transform="translate(6514,0)"><use xlink:href="#E18-MJMAIN-6D"></use><use xlink:href="#E18-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E18-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E18-MJMATHI-4E" x="8904" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-18">h_i = (h + p_i) \mod N</script>, до тех пор пока не будет найден элемент таблицы, что:</p><ol start='' ><li>элемент пустой, тогда имя <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-28-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.11ex" viewBox="0 -806.1 645.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E28-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E28-MJMATHI-53" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-28">S</script> в таблице отсутствует и записывается в таблице под инд. <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-29-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.139ex" height="2.344ex" viewBox="0 -755.9 920.8 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E29-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E29-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E29-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E29-MJMATHI-69" x="815" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-29">h_i</script>.</li><li>элемент с индексом <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-29-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.139ex" height="2.344ex" viewBox="0 -755.9 920.8 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E29-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E29-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E29-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E29-MJMATHI-69" x="815" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-29">h_i</script> является не пустым и содержит имя, совпадающее с именем <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-22-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.631ex" height="2.344ex" viewBox="0 -755.9 1132.9 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E22-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E22-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E22-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E22-MJMATHI-53" x="815" y="-219"></use></g></svg></span><script type="math/tex" id="MathJax-Element-22">h_S</script> , в этом случае хешир-е имя уже есть в таблице и не должно быть записано в таблице.</li><li><span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-23-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.576ex" height="2.344ex" viewBox="0 -755.9 2831.4 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E23-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E23-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E23-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E23-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E23-MJMATHI-69" x="815" y="-213"></use><use xlink:href="#E23-MJMAIN-3D" x="1198" y="0"></use><use xlink:href="#E23-MJMATHI-68" x="2254" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-23">h_i = h</script>, т.е. таблица имен заполнена, т.е. нет пустых ячеек.
В этом случае <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-28-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.11ex" viewBox="0 -806.1 645.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E28-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E28-MJMATHI-53" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-28">S</script> нельзя записать в таблицу и процесс трансляции прекращён.</li></ol><p>Операция деления по <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-25-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.164ex" height="1.994ex" viewBox="0 -755.9 3945.7 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E25-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E25-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E25-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E25-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g transform="translate(666,0)"><use xlink:href="#E25-MJMAIN-6D"></use><use xlink:href="#E25-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E25-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E25-MJMATHI-4E" x="3057" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-25">\mod N</script> при вычислении <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-29-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.139ex" height="2.344ex" viewBox="0 -755.9 920.8 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E29-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E29-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E29-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E29-MJMATHI-69" x="815" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-29">h_i</script> обеспечивает циклический просмотр адресов. С точки зрения эффективности организации хеш-табл. следует отметить, что время поиска элемента определяется количеством возникших коллизий. Время вычисления хеш-функции является постоянной величиной, а количество коллизий должно быть уменьшено путем выбора соответствующего способа <strong>рехеширования</strong>. Чтобы уменьшить количество возникших коллизий приращение <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-32-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.059ex" height="1.76ex" viewBox="-38.5 -504.6 886.3 757.9" role="img" focusable="false" style="vertical-align: -0.588ex; margin-left: -0.089ex;"><defs><path stroke-width="1" id="E32-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E32-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E32-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E32-MJMATHI-69" x="712" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-32">p_i</script> должно вычисляться с учётом 2-х условий:</p><ul><li>ожидаемое число сравнения элемента <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-28-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.499ex" height="2.11ex" viewBox="0 -806.1 645.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E28-MJMATHI-53" d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E28-MJMATHI-53" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-28">S</script> др. элементами таблицы должно быть минимальным.</li><li>значение адресов <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-29-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.139ex" height="2.344ex" viewBox="0 -755.9 920.8 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E29-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E29-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E29-MJMATHI-68" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E29-MJMATHI-69" x="815" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-29">h_i</script> должно равномерно распределяться по таблице.
В идеал. случае значение <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-32-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.059ex" height="1.76ex" viewBox="-38.5 -504.6 886.3 757.9" role="img" focusable="false" style="vertical-align: -0.588ex; margin-left: -0.089ex;"><defs><path stroke-width="1" id="E32-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E32-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E32-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E32-MJMATHI-69" x="712" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-32">p_i</script> должно охватывать целые числа из <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-31-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.557ex" height="2.577ex" viewBox="0 -806.1 4114.6 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E31-MJMAIN-5B" d="M118 -250V750H255V710H158V-210H255V-250H118Z"></path><path stroke-width="1" id="E31-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E31-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E31-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E31-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><path stroke-width="1" id="E31-MJMAIN-5D" d="M22 710V750H159V-250H22V-210H119V710H22Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E31-MJMAIN-5B" x="0" y="0"></use><use xlink:href="#E31-MJMAIN-31" x="278" y="0"></use><use xlink:href="#E31-MJMAIN-2C" x="779" y="0"></use><use xlink:href="#E31-MJMATHI-4E" x="1224" y="0"></use><use xlink:href="#E31-MJMAIN-2212" x="2334" y="0"></use><use xlink:href="#E31-MJMAIN-31" x="3335" y="0"></use><use xlink:href="#E31-MJMAIN-5D" x="3836" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-31">[1,N-1]</script> строго 1 раз.
Различ. варианты повторного хеширования, отличается способом вычисления <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-32-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.059ex" height="1.76ex" viewBox="-38.5 -504.6 886.3 757.9" role="img" focusable="false" style="vertical-align: -0.588ex; margin-left: -0.089ex;"><defs><path stroke-width="1" id="E32-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path><path stroke-width="1" id="E32-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E32-MJMATHI-70" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E32-MJMATHI-69" x="712" y="-213"></use></g></svg></span><script type="math/tex" id="MathJax-Element-32">p_i</script>.</li></ul><h4><a name='header-c794' class='md-header-anchor '></a>Функции reserve</h4><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">reserve</span>( <span class="cm-variable">size_type</span> <span class="cm-variable">size</span> );</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 22px;"></div></div></div></pre><p>Задает емкость контейнера, по крайней мере <code>size</code>. Новая память выделяется при необходимости. </p><p>В описании контейнера <code>vector</code> можно встретить такие функции как <code>size</code> и <code>resize</code>, <code>capacity</code> и <code>reserve</code>. С первого взгляда кажется, что половина явно лишняя, ведь размер у вектора может быть только один.
Почему так? Потому что память для вектора выделяется "про запас", и надо уметь управлять и количеством элементов вектора, и количеством памяти, которое он занимает. <code>size</code> и <code>resize</code> - нужны для работы с реальным числом элементов вектора, <code>capacity</code> и <code>reserve</code> - для работы с памятью.</p><p><code>size</code> - выдает количество элементов в векторе<br/>
<code>resize</code> - изменяет количество элементов в векторе<br/>
<code>capacity</code> - выдает под сколько элементов выделена память<br/>
<code>reserve</code> - резервиует память</p><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">vector</span> <span class="cm-operator"><</span><span class="cm-variable-3">int</span><span class="cm-operator">></span> <span class="cm-variable">v</span>;</span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">v</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">1</span>); <span class="cm-comment">//size==1, capacity==1</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">v</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">17</span>); <span class="cm-comment">//size==2, capacity==2</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">v</span>.<span class="cm-variable">push_back</span>(<span class="cm-number">23</span>); <span class="cm-comment">//size==3, capacity==4</span></span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 88px;"></div></div></div></pre><p><code>vector</code> будет выглядеть вот так:</p><p><img src='http://www.softwaremaniacs.org/Images/alenacpp/vector/vector.png' alt='' /></p><p>Зачем нужен этот запас?
Допустим, у нас есть вектор из <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script> элементов. Что происходит, когда программист добавляет еще один? Когда есть запасная память, элемент пишется туда. Когда ее нет, выделяется непрерывный кусок памяти достаточный для <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-34-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.655ex" height="1.994ex" viewBox="0 -755.9 2434.9 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E34-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E34-MJMAIN-2217" d="M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z"></path><path stroke-width="1" id="E34-MJMATHI-4B" d="M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E34-MJMATHI-6E" x="0" y="0"></use><use xlink:href="#E34-MJMAIN-2217" x="822" y="0"></use><use xlink:href="#E34-MJMATHI-4B" x="1545" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-34">n*K</script> элементов, где <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-35-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.066ex" height="1.994ex" viewBox="0 -755.9 889.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E35-MJMATHI-4B" d="M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E35-MJMATHI-4B" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-35">K</script> - коэффицент. В него копируются предыдущие <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script>, добавляется наш новый элемент, старый кусок размером <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script> освобождается. Если бы запаса не было, то память бы выделялась каждый раз при добавлении нового элемента, что страшно неэффективно.
Зачем нужен <code>reserve</code>, если все и без участия программиста так хорошо работает? Это может быть полезно в некоторых ситуациях. Например, знание того, как выделяется память под вектор, можно использовать и в начале, при его задании. Допустим, я точно знаю, что в векторе будет где-то 100-110 элементов. Я сразу же создам вектор размером 110, это поможет избежать перевыделений памяти, что положительно скажется на производительности.</p><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">vector</span> <span class="cm-operator"><</span><span class="cm-variable-3">int</span><span class="cm-operator">></span> <span class="cm-variable">v</span>;</span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable">v</span>.<span class="cm-variable">reserve</span>(<span class="cm-number">110</span>);</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 44px;"></div></div></div></pre><p>Это вовсе не означает, что зарезервировано место для 110-ти элементов ровно. Зарезервировано место как минимум для 110 элементов, возможно больше.</p><p><a href='https://en.wikipedia.org/wiki/Hash_table#Key_statistics'>Link on Wikipedia</a><br/>
<a href='http://alenacpp.blogspot.com/2005/06/vector_30.html'>Хорошее объяснение reserve</a><br/>
<a href='http://ru.cppreference.com/w/cpp/container/vector/reserve'>Ссылка на документацию по reserve</a><br/>
<a href='http://codingrus.ru/readarticle.php?article_id=2179'>Ссылка про рехеширование</a></p><hr /><h3><a name='header-c824' class='md-header-anchor '></a>Хеширование: линейное, двойное, квадратичное пробирование, folding</h3><p>Ниже приведены некоторые распространенные типы последовательностей проб. Сразу оговорим, что нумерация элементов последовательности проб и ячеек хеш-таблицы ведётся от нуля, а <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-47-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="1.994ex" viewBox="0 -755.9 888.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E47-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E47-MJMATHI-4E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-47">N</script> — размер хеш-таблицы (и, как замечено выше, также и длина последовательности проб).</p><ul><li><strong>Линейное пробирование</strong>: ячейки хеш-таблицы последовательно просматриваются с некоторым фиксированным интервалом k между ячейками (обычно <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-39-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.472ex" height="1.994ex" viewBox="0 -755.9 2356.1 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E39-MJMATHI-6B" d="M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z"></path><path stroke-width="1" id="E39-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E39-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E39-MJMATHI-6B" x="0" y="0"></use><use xlink:href="#E39-MJMAIN-3D" x="799" y="0"></use><use xlink:href="#E39-MJMAIN-31" x="1855" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-39">k = 1</script>), то есть <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-40-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="0.802ex" height="1.994ex" viewBox="0 -755.9 345.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E40-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E40-MJMATHI-69" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-40">i</script>-й элемент последовательности проб — это ячейка с номером <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-41-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="24.352ex" height="2.577ex" viewBox="0 -806.1 10484.8 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E41-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E41-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E41-MJMATHI-61" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path><path stroke-width="1" id="E41-MJMATHI-73" d="M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z"></path><path stroke-width="1" id="E41-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path><path stroke-width="1" id="E41-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E41-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E41-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E41-MJMATHI-6B" d="M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z"></path><path stroke-width="1" id="E41-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E41-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E41-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E41-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E41-MJMAIN-28" x="0" y="0"></use><use xlink:href="#E41-MJMATHI-68" x="389" y="0"></use><use xlink:href="#E41-MJMATHI-61" x="966" y="0"></use><use xlink:href="#E41-MJMATHI-73" x="1495" y="0"></use><use xlink:href="#E41-MJMATHI-68" x="1965" y="0"></use><use xlink:href="#E41-MJMAIN-28" x="2541" y="0"></use><use xlink:href="#E41-MJMATHI-78" x="2931" y="0"></use><use xlink:href="#E41-MJMAIN-29" x="3503" y="0"></use><use xlink:href="#E41-MJMAIN-2B" x="4115" y="0"></use><use xlink:href="#E41-MJMATHI-69" x="5115" y="0"></use><use xlink:href="#E41-MJMATHI-6B" x="5461" y="0"></use><use xlink:href="#E41-MJMAIN-29" x="5982" y="0"></use><g transform="translate(7205,0)"><use xlink:href="#E41-MJMAIN-6D"></use><use xlink:href="#E41-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E41-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E41-MJMATHI-4E" x="9596" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-41">(hash(x) + ik) \mod N</script>. Для того, чтобы все ячейки оказались просмотренными по одному разу, необходимо, чтобы k было взаимно-простым с размером хеш-таблицы.</li><li><strong>Квадратичное пробирование</strong>: интервал между ячейками с каждым шагом увеличивается на константу. Если размер хеш-таблицы равен степени двойки (<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-42-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="7.494ex" height="2.344ex" viewBox="0 -755.9 3226.6 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E42-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E42-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E42-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E42-MJMATHI-70" d="M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E42-MJMATHI-4E" x="0" y="0"></use><use xlink:href="#E42-MJMAIN-3D" x="1166" y="0"></use><use xlink:href="#E42-MJMAIN-32" x="2222" y="0"></use><use xlink:href="#E42-MJMATHI-70" x="2723" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-42">N = 2p</script>), то одним из примеров последовательности, при которой каждый элемент будет просмотрен по одному разу, является:
<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-43-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="91.292ex" height="2.577ex" viewBox="0 -806.1 39306.2 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E43-MJMATHI-68" d="M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z"></path><path stroke-width="1" id="E43-MJMATHI-61" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path><path stroke-width="1" id="E43-MJMATHI-73" d="M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z"></path><path stroke-width="1" id="E43-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E43-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path><path stroke-width="1" id="E43-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E43-MJMAIN-6D" d="M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z"></path><path stroke-width="1" id="E43-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E43-MJMAIN-64" d="M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z"></path><path stroke-width="1" id="E43-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E43-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E43-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E43-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E43-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E43-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E43-MJMATHI-68" x="0" y="0"></use><use xlink:href="#E43-MJMATHI-61" x="576" y="0"></use><use xlink:href="#E43-MJMATHI-73" x="1106" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="1575" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="2152" y="0"></use><use xlink:href="#E43-MJMATHI-78" x="2541" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="3114" y="0"></use><g transform="translate(4336,0)"><use xlink:href="#E43-MJMAIN-6D"></use><use xlink:href="#E43-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E43-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E43-MJMATHI-4E" x="6727" y="0"></use><use xlink:href="#E43-MJMAIN-2C" x="7615" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="8061" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="8450" y="0"></use><use xlink:href="#E43-MJMATHI-61" x="9027" y="0"></use><use xlink:href="#E43-MJMATHI-73" x="9556" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="10026" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="10602" y="0"></use><use xlink:href="#E43-MJMATHI-78" x="10992" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="11564" y="0"></use><use xlink:href="#E43-MJMAIN-2B" x="12176" y="0"></use><use xlink:href="#E43-MJMAIN-31" x="13176" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="13677" y="0"></use><g transform="translate(14900,0)"><use xlink:href="#E43-MJMAIN-6D"></use><use xlink:href="#E43-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E43-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E43-MJMATHI-4E" x="17290" y="0"></use><use xlink:href="#E43-MJMAIN-2C" x="18179" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="18624" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="19013" y="0"></use><use xlink:href="#E43-MJMATHI-61" x="19590" y="0"></use><use xlink:href="#E43-MJMATHI-73" x="20119" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="20589" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="21165" y="0"></use><use xlink:href="#E43-MJMATHI-78" x="21555" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="22127" y="0"></use><use xlink:href="#E43-MJMAIN-2B" x="22739" y="0"></use><use xlink:href="#E43-MJMAIN-33" x="23740" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="24240" y="0"></use><g transform="translate(25463,0)"><use xlink:href="#E43-MJMAIN-6D"></use><use xlink:href="#E43-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E43-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E43-MJMATHI-4E" x="27854" y="0"></use><use xlink:href="#E43-MJMAIN-2C" x="28742" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="29187" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="29577" y="0"></use><use xlink:href="#E43-MJMATHI-61" x="30153" y="0"></use><use xlink:href="#E43-MJMATHI-73" x="30683" y="0"></use><use xlink:href="#E43-MJMATHI-68" x="31152" y="0"></use><use xlink:href="#E43-MJMAIN-28" x="31729" y="0"></use><use xlink:href="#E43-MJMATHI-78" x="32118" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="32691" y="0"></use><use xlink:href="#E43-MJMAIN-2B" x="33303" y="0"></use><use xlink:href="#E43-MJMAIN-36" x="34303" y="0"></use><use xlink:href="#E43-MJMAIN-29" x="34804" y="0"></use><g transform="translate(36027,0)"><use xlink:href="#E43-MJMAIN-6D"></use><use xlink:href="#E43-MJMAIN-6F" x="833" y="0"></use><use xlink:href="#E43-MJMAIN-64" x="1334" y="0"></use></g><use xlink:href="#E43-MJMATHI-4E" x="38417" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-43">hash(x) \mod N, (hash(x) + 1) \mod N, (hash(x) + 3) \mod N, (hash(x) + 6) \mod N</script>, …</li><li><strong>Двойное хеширование</strong>: интервал между ячейками фиксирован, как при линейном пробировании, но, в отличие от него, размер интервала вычисляется второй, вспомогательной хеш-функцией, а значит, может быть различным для разных ключей. Значения этой хеш-функции должны быть ненулевыми и взаимно-простыми с размером хеш-таблицы, что проще всего достичь, взяв простое число в качестве размера, и потребовав, чтобы вспомогательная хеш-функция принимала значения от <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-44-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.162ex" height="1.994ex" viewBox="0 -755.9 500.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E44-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E44-MJMAIN-31" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-44">1</script> до <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-45-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.066ex" height="1.994ex" viewBox="0 -755.9 2611.9 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E45-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E45-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><path stroke-width="1" id="E45-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E45-MJMATHI-4E" x="0" y="0"></use><use xlink:href="#E45-MJMAIN-2212" x="1110" y="0"></use><use xlink:href="#E45-MJMAIN-31" x="2111" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-45">N - 1</script>.</li></ul><p>Другим методом создания хеш-функции называется сверткой (<strong>folding</strong>) и основан на выполнении некоторых арифметических действий над различными частями поля хеширования. При этом символьные строки преобразуются в целые числа с использованием некоторой кодировки (на основе расположения букв в алфавите или кодов символов ASCII). Например, можно преобразовать в целое число первые два символа поля табельного номера сотрудника (атрибут staffNo), а затем сложить полученное значение с остальными цифрами этого номера. Вычисленная сумма используется в качестве адреса дисковой страницы, на которой будет храниться данная запись. Более популярный альтернативный метод основан на хешировании с применением остатка от деления. В этом методе используется функция MOD, которой передается значение поля. Функция делит полученное значение на некоторое заранее заданное целое число, после чего остаток от деления используется в качестве адреса на диске.</p><p><a href='http://neerc.ifmo.ru/wiki/index.php?title=%D0%A0%D0%B0%D0%B7%D1%80%D0%B5%D1%88%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BA%D0%BE%D0%BB%D0%BB%D0%B8%D0%B7%D0%B8%D0%B9'>Ссылка на статью «Решение коллизий»</a><br/>
<a href='http://aliev.me/runestone/SortSearch/Hashing.html'>Ссылка на неплохое объяснение</a><br/>
<a href='https://ru.wikipedia.org/wiki/%D0%A5%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D0%B0'>Ссылка на Википедию</a></p><hr /><h3><a name='header-c1317' class='md-header-anchor '></a>Coalesced hashing</h3><p><strong>Coalesced hashing</strong>, также называемая <strong>coalesced chaining</strong>, это стратегия решения коллизий в хеш-таблицах, что образует смесь <em>раздельных цепочек</em> и <em>открытой адресации</em>. В хеш-таблице <em>раздельных цепочек</em>, элементы этого хеша размещены по тому же адресу в списке или "цепочке" по этому адресу. Этот метод может привести к большой потери памяти, потому что сама хеш-таблица должена быть достаточно большой чтобы поддерживать коэффициент нагрузки (фактор нагрузки), который также выполняется (обычно в два раза ожидаемого числа элементов), и дополнительная память должна быть использована для всех, но с первого пункта в цепочке (за исключением списка используемых заголовков, в случае выделения дополнительной памяти должны применяться для всех элементов в цепи).</p><p>Дана случайно сгенерированные трех-буквенные последовательности строк "qrj," "aty," "qur," "dim," "ofu," "gcl," "rhv," "clq," "ecd," "qsu", в следую бщей таудут генерироваться (используя алгоритм Боба Дженкинса) таблица с размером 10:</p><p><img src='https://istomin.im/gc/coalesced_hashing_exp.png' alt='' /></p><p><img src='https://upload.wikimedia.org/wikipedia/commons/4/4c/CoalescedHash.jpg' alt='' /></p><p><em>Пример Coalesced Hashing. Для целей этого примера, коллизии блоков распределяются в порядке возрастания, начиная с блока 0.</em></p><p>Данная стратегия эффективна, и очень легко реализовывается. Однако, иногда использование дополнительной памяти может быть запрещено, а самая распространенная альтернатива, открытая адресация, имеет неудобные недостатки, снижающие производительность. Основной недостаток открытой адресации является первичная и вторичная кластеризация, в которых поиски могут открыть длинные последовательности используемых сегментов, содержащих элементы с различными хеш-адресами; таким образом, элементы с хеш-адресами могут увеличить время поисков предметов с другими хеш-адресоми.</p><p>Одно такое решение и есть coalesced hashing. Coalesced hashing использует похожую технику с <em>раздельными цепочками</em>, but instead of allocating new nodes for the linked list, buckets in the actual table are used. The first empty bucket in the table at the time of a collision is considered the collision bucket. When a collision occurs anywhere in the table, the item is placed in the collision bucket and a link is made between the chain and the collision bucket. It is possible for a newly inserted item to collide with items with a different hash address, such as the case in the example above when item "clq" is inserted. The chain for "clq" is said to "coalesce" with the chain of "qrj," hence the name of the algorithm. However, the extent of coalescing is minor compared with the clustering exhibited by open addressing. For example, when coalescing occurs, the length of the chain grows by only 1, whereas in open addressing, search sequences of arbitrary length may combine.</p><p>Важная оптимизация, чтобы уменьшить влияние объединения, нужно ограничить адресное пространство хэш-функции только подмножества хеш-таблицы. Для примера, если таблица имеет размер <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-48-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.442ex" height="1.994ex" viewBox="0 -755.9 1051.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E48-MJMATHI-4D" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E48-MJMATHI-4D" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-48">M</script> with buckets numbered from 0 to M − 1, we can restrict the address space so that the hash function only assigns addresses to the first N locations in the table. The remaining M − N buckets, called the cellar, are used exclusively for storing items that collide during insertion. No coalescing can occur until the cellar is exhausted.</p><p>Оптимальный выбор <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-47-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.064ex" height="1.994ex" viewBox="0 -755.9 888.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E47-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E47-MJMATHI-4E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-47">N</script> относительно <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-48-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.442ex" height="1.994ex" viewBox="0 -755.9 1051.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E48-MJMATHI-4D" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E48-MJMATHI-4D" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-48">M</script> depends upon the load factor (or fullness) of the table. A careful analysis shows that the value <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-49-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="14.579ex" height="1.994ex" viewBox="0 -755.9 6277 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E49-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E49-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E49-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path><path stroke-width="1" id="E49-MJMAIN-2E" d="M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z"></path><path stroke-width="1" id="E49-MJMAIN-38" d="M70 417T70 494T124 618T248 666Q319 666 374 624T429 515Q429 485 418 459T392 417T361 389T335 371T324 363L338 354Q352 344 366 334T382 323Q457 264 457 174Q457 95 399 37T249 -22Q159 -22 101 29T43 155Q43 263 172 335L154 348Q133 361 127 368Q70 417 70 494ZM286 386L292 390Q298 394 301 396T311 403T323 413T334 425T345 438T355 454T364 471T369 491T371 513Q371 556 342 586T275 624Q268 625 242 625Q201 625 165 599T128 534Q128 511 141 492T167 463T217 431Q224 426 228 424L286 386ZM250 21Q308 21 350 55T392 137Q392 154 387 169T375 194T353 216T330 234T301 253T274 270Q260 279 244 289T218 306L210 311Q204 311 181 294T133 239T107 157Q107 98 150 60T250 21Z"></path><path stroke-width="1" id="E49-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path><path stroke-width="1" id="E49-MJMAIN-D7" d="M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z"></path><path stroke-width="1" id="E49-MJMATHI-4D" d="M289 629Q289 635 232 637Q208 637 201 638T194 648Q194 649 196 659Q197 662 198 666T199 671T201 676T203 679T207 681T212 683T220 683T232 684Q238 684 262 684T307 683Q386 683 398 683T414 678Q415 674 451 396L487 117L510 154Q534 190 574 254T662 394Q837 673 839 675Q840 676 842 678T846 681L852 683H948Q965 683 988 683T1017 684Q1051 684 1051 673Q1051 668 1048 656T1045 643Q1041 637 1008 637Q968 636 957 634T939 623Q936 618 867 340T797 59Q797 55 798 54T805 50T822 48T855 46H886Q892 37 892 35Q892 19 885 5Q880 0 869 0Q864 0 828 1T736 2Q675 2 644 2T609 1Q592 1 592 11Q592 13 594 25Q598 41 602 43T625 46Q652 46 685 49Q699 52 704 61Q706 65 742 207T813 490T848 631L654 322Q458 10 453 5Q451 4 449 3Q444 0 433 0Q418 0 415 7Q413 11 374 317L335 624L267 354Q200 88 200 79Q206 46 272 46H282Q288 41 289 37T286 19Q282 3 278 1Q274 0 267 0Q265 0 255 0T221 1T157 2Q127 2 95 1T58 0Q43 0 39 2T35 11Q35 13 38 25T43 40Q45 46 65 46Q135 46 154 86Q158 92 223 354T289 629Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E49-MJMATHI-4E" x="0" y="0"></use><use xlink:href="#E49-MJMAIN-3D" x="1166" y="0"></use><g transform="translate(2222,0)"><use xlink:href="#E49-MJMAIN-30"></use><use xlink:href="#E49-MJMAIN-2E" x="500" y="0"></use><use xlink:href="#E49-MJMAIN-38" x="779" y="0"></use><use xlink:href="#E49-MJMAIN-36" x="1279" y="0"></use></g><use xlink:href="#E49-MJMAIN-D7" x="4224" y="0"></use><use xlink:href="#E49-MJMATHI-4D" x="5225" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-49">N = 0.86 × M</script> yields near-optimum performance for most load factors. Other variants for insertion are also possible that have improved search time. Deletion algorithms have been developed that preserve randomness, and thus the average search time analysis still holds after deletions.
Вставки в C:</p><pre class="md-fences md-end-block" lang="c"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">/* htab это хеш-таблица,</span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">N это размер адресного пространства хеш-функции, и</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">M is the size of the entire table including the cellar.</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">Collision buckets are allocated in decreasing order, starting with bucket M-1. */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">insert</span> ( <span class="cm-variable-3">char</span> <span class="cm-variable">key</span>[] )</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">unsigned</span> <span class="cm-variable">h</span> <span class="cm-operator">=</span> <span class="cm-variable">hash</span> ( <span class="cm-variable">key</span>, <span class="cm-variable">strlen</span> ( <span class="cm-variable">key</span> ) ) <span class="cm-operator">%</span> <span class="cm-variable">N</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> ( <span class="cm-variable">htab</span>[<span class="cm-variable">h</span>] <span class="cm-operator">==</span> <span class="cm-variable">NULL</span> ) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">/* Создает новую цепь */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">htab</span>[<span class="cm-variable">h</span>] <span class="cm-operator">=</span> <span class="cm-variable">make_node</span> ( <span class="cm-variable">key</span>, <span class="cm-variable">NULL</span> );</span></pre><pre class=""><span style="padding-right: 0.1px;"> } <span class="cm-keyword">else</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">struct</span> <span class="cm-def">node</span> <span class="cm-operator">*</span><span class="cm-variable">it</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">cursor</span> <span class="cm-operator">=</span> <span class="cm-variable">M</span><span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">/* Находит первый пустой блок */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">while</span> ( <span class="cm-variable">cursor</span> <span class="cm-operator">>=</span> <span class="cm-number">0</span> <span class="cm-operator">&&</span> <span class="cm-variable">htab</span>[<span class="cm-variable">cursor</span>] <span class="cm-operator">!=</span> <span class="cm-variable">NULL</span> )</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-operator">--</span><span class="cm-variable">cursor</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">/* Таблица заполнена, неудачное завершение */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> ( <span class="cm-variable">cursor</span> <span class="cm-operator">==</span> <span class="cm-operator">-</span><span class="cm-number">1</span> )</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">htab</span>[<span class="cm-variable">cursor</span>] <span class="cm-operator">=</span> <span class="cm-variable">make_node</span> ( <span class="cm-variable">key</span>, <span class="cm-variable">NULL</span> );</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">/* Нахождение последнего узла в цепочке и указатель на него */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">it</span> <span class="cm-operator">=</span> <span class="cm-variable">htab</span>[<span class="cm-variable">h</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">while</span> ( <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">next</span> <span class="cm-operator">!=</span> <span class="cm-variable">NULL</span> )</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">it</span> <span class="cm-operator">=</span> <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">next</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">next</span> <span class="cm-operator">=</span> <span class="cm-variable">htab</span>[<span class="cm-variable">cursor</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 814px;"></div></div></div></pre><p>Одно из преимуществ этой стратегии является то, что алгоритм поиска для разделеных цепочек может использоваться без изменений в объединенной хэш-таблице.</p><pre class="md-fences md-end-block" lang="c"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">char</span> <span class="cm-variable-3">*</span><span class="cm-def">find</span> ( <span class="cm-variable-3">char</span> <span class="cm-variable">key</span>[] )</span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">unsigned</span> <span class="cm-variable">h</span> <span class="cm-operator">=</span> <span class="cm-variable">hash</span> ( <span class="cm-variable">key</span>, <span class="cm-variable">strlen</span> ( <span class="cm-variable">key</span> ) ) <span class="cm-operator">%</span> <span class="cm-variable">N</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> ( <span class="cm-variable">htab</span>[<span class="cm-variable">h</span>] <span class="cm-operator">!=</span> <span class="cm-variable">NULL</span> ) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">struct</span> <span class="cm-def">node</span> <span class="cm-operator">*</span><span class="cm-variable">it</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">/* Поиск цепочки с индексом h */</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> ( <span class="cm-variable">it</span> <span class="cm-operator">=</span> <span class="cm-variable">htab</span>[<span class="cm-variable">h</span>]; <span class="cm-variable">it</span> <span class="cm-operator">!=</span> <span class="cm-variable">NULL</span>; <span class="cm-variable">it</span> <span class="cm-operator">=</span> <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">next</span> ) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> ( <span class="cm-variable">strcmp</span> ( <span class="cm-variable">key</span>, <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">data</span> ) <span class="cm-operator">==</span> <span class="cm-number">0</span> )</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">it</span><span class="cm-operator">-></span><span class="cm-variable">data</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">NULL</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 352px;"></div></div></div></pre><h5><a name='header-c871' class='md-header-anchor '></a>Производительность</h5><p>Coalesced chaining avoids the effects of primary and secondary clustering, and as a result can take advantage of the efficient search algorithm for separate chaining. If the chains are short, this strategy is very efficient and can be highly condensed, memory-wise. As in open addressing, deletion from a coalesced hash table is awkward and potentially expensive, and resizing the table is terribly expensive and should be done rarely, if ever.</p><p><a href='https://en.wikipedia.org/wiki/Coalesced_hashing'>Link on Wikipedia</a></p><hr /><h3><a name='header-c1332' class='md-header-anchor '></a>Понимание алгоритмов сортировки</h3><p><a href='http://algo-visualizer.jasonpark.me/'>Визуализатор алгоритмов</a></p><h4><a name='header-c881' class='md-header-anchor '></a>Пузырьковая сортировка (Bubble sort)</h4><p><strong>Пузырьковая сортировка</strong> — простой алгоритм сортировки. Для понимания и реализации этот алгоритм — простейший, но эффективен он лишь для небольших массивов. Сложность алгоритма: <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-50-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.032ex" height="2.811ex" viewBox="0 -906.7 2596.9 1210.2" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E50-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E50-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E50-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E50-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E50-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E50-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E50-MJMAIN-28" x="763" y="0"></use><g transform="translate(1153,0)"><use xlink:href="#E50-MJMATHI-6E" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E50-MJMAIN-32" x="849" y="513"></use></g><use xlink:href="#E50-MJMAIN-29" x="2207" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-50"> O(n^{2})</script>.</p><h5><a name='header-c884' class='md-header-anchor '></a>Алгоритм</h5><p>Алгоритм состоит из повторяющихся проходов по сортируемому массиву. За каждый проход элементы последовательно сравниваются попарно и, если порядок в паре неверный, выполняется обмен элементов. Проходы по массиву повторяются <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-51-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.066ex" height="1.994ex" viewBox="0 -755.9 2611.9 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E51-MJMATHI-4E" d="M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z"></path><path stroke-width="1" id="E51-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><path stroke-width="1" id="E51-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E51-MJMATHI-4E" x="0" y="0"></use><use xlink:href="#E51-MJMAIN-2212" x="1110" y="0"></use><use xlink:href="#E51-MJMAIN-31" x="2111" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-51">N-1</script> раз или до тех пор, пока на очередном проходе не окажется, что обмены больше не нужны, что означает — массив отсортирован. При каждом проходе алгоритма по внутреннему циклу, очередной наибольший элемент массива ставится на своё место в конце массива рядом с предыдущим «наибольшим элементом», а наименьший элемент перемещается на одну позицию к началу массива («всплывает» до нужной позиции, как пузырёк в воде, отсюда и название алгоритма).</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif' alt='' /></p><h5><a name='header-c889' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">bubble_sort</span>(<span class="cm-variable-3">int</span> <span class="cm-variable-3">*</span><span class="cm-variable">a</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">length</span>)</span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">length</span><span class="cm-operator">-</span><span class="cm-number">1</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">bool</span> <span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">false</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">j</span> <span class="cm-operator"><</span> <span class="cm-variable">length</span><span class="cm-operator">-</span><span class="cm-variable">i</span><span class="cm-operator">-</span><span class="cm-number">1</span>; <span class="cm-variable">j</span><span class="cm-operator">++</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">a</span>[<span class="cm-variable">j</span>] <span class="cm-operator">></span> <span class="cm-variable">a</span>[<span class="cm-variable">j</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>]) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-variable">j</span>]; </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">a</span>[<span class="cm-variable">j</span>] <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-variable">j</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">a</span>[<span class="cm-variable">j</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>] <span class="cm-operator">=</span> <span class="cm-variable">b</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> </span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-operator">!</span><span class="cm-variable">swapped</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">break</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 374px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%BF%D1%83%D0%B7%D1%8B%D1%80%D1%8C%D0%BA%D0%BE%D0%BC'>Ссылка на Википедию</a></p><h4><a name='header-c894' class='md-header-anchor '></a>Сортировка расчёской (Comb sort)</h4><p><strong>Сортировка расчёской</strong> улучшает сортировку пузырьком, и конкурирует с алгоритмами, подобными быстрой сортировке. Основная идея — устранить <em>черепах</em>, или маленькие значения в конце списка, которые крайне замедляют сортировку пузырьком (<em>кролики</em>, большие значения в начале списка, не представляют проблемы для сортировки пузырьком).</p><p>В сортировке пузырьком, когда сравниваются два элемента, промежуток (расстояние друг от друга) равен 1. Основная идея сортировки расчёской в том, что этот промежуток может быть гораздо больше, чем единица (сортировка Шелла также основана на этой идее, но она является модификацией сортировки вставками, а не сортировки пузырьком).</p><h5><a name='header-c899' class='md-header-anchor '></a>Алгоритм</h5><p>В «пузырьке», «шейкере» и «чёт-нечете» при переборе массива сравниваются соседние элементы. Основная идея «расчёски» в том, чтобы первоначально брать достаточно большое расстояние между сравниваемыми элементами и по мере упорядочивания массива сужать это расстояние вплоть до минимального. Таким образом, мы как бы причёсываем массив, постепенно разглаживая на всё более аккуратные пряди. Первоначальный разрыв между сравниваемыми элементами лучше брать с учётом специальной величины, называемой фактором уменьшения, оптимальное значение которой равно примерно <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-52-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.684ex" height="2.344ex" viewBox="0 -755.9 2447.2 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E52-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E52-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E52-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E52-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E52-MJMAIN-37" d="M55 458Q56 460 72 567L88 674Q88 676 108 676H128V672Q128 662 143 655T195 646T364 644H485V605L417 512Q408 500 387 472T360 435T339 403T319 367T305 330T292 284T284 230T278 162T275 80Q275 66 275 52T274 28V19Q270 2 255 -10T221 -22Q210 -22 200 -19T179 0T168 40Q168 198 265 368Q285 400 349 489L395 552H302Q128 552 119 546Q113 543 108 522T98 479L95 458V455H55V458Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E52-MJMAIN-31" x="0" y="0"></use><use xlink:href="#E52-MJMAIN-2C" x="500" y="0"></use><g transform="translate(945,0)"><use xlink:href="#E52-MJMAIN-32"></use><use xlink:href="#E52-MJMAIN-34" x="500" y="0"></use><use xlink:href="#E52-MJMAIN-37" x="1001" y="0"></use></g></g></svg></span><script type="math/tex" id="MathJax-Element-52">1,247</script>. Сначала расстояние между элементами равно размеру массива, разделённого на фактор уменьшения (результат округляется до ближайшего целого). Затем, пройдя массив с этим шагом, необходимо поделить шаг на фактор уменьшения и пройти по списку вновь. Так продолжается до тех пор, пока разность индексов не достигнет единицы. В этом случае массив досортировывается обычным пузырьком.</p><p>Оптимальное значение фактора уменьшения <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-53-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="7.624ex" height="2.344ex" viewBox="0 -755.9 3282.7 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E53-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E53-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E53-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E53-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E53-MJMAIN-37" d="M55 458Q56 460 72 567L88 674Q88 676 108 676H128V672Q128 662 143 655T195 646T364 644H485V605L417 512Q408 500 387 472T360 435T339 403T319 367T305 330T292 284T284 230T278 162T275 80Q275 66 275 52T274 28V19Q270 2 255 -10T221 -22Q210 -22 200 -19T179 0T168 40Q168 198 265 368Q285 400 349 489L395 552H302Q128 552 119 546Q113 543 108 522T98 479L95 458V455H55V458Z"></path><path stroke-width="1" id="E53-MJMAIN-2E" d="M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E53-MJMAIN-31" x="0" y="0"></use><use xlink:href="#E53-MJMAIN-2C" x="500" y="0"></use><g transform="translate(945,0)"><use xlink:href="#E53-MJMAIN-32"></use><use xlink:href="#E53-MJMAIN-34" x="500" y="0"></use><use xlink:href="#E53-MJMAIN-37" x="1001" y="0"></use><use xlink:href="#E53-MJMAIN-2E" x="1501" y="0"></use><use xlink:href="#E53-MJMAIN-2E" x="1780" y="0"></use><use xlink:href="#E53-MJMAIN-2E" x="2058" y="0"></use></g></g></svg></span><script type="math/tex" id="MathJax-Element-53">1,247...</script> можно представить формулой в следующем виде <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-54-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="9.46ex" height="4.445ex" viewBox="0 -956.9 4073.1 1913.9" role="img" focusable="false" style="vertical-align: -2.223ex;"><defs><path stroke-width="1" id="E54-MJMAIN-2248" d="M55 319Q55 360 72 393T114 444T163 472T205 482Q207 482 213 482T223 483Q262 483 296 468T393 413L443 381Q502 346 553 346Q609 346 649 375T694 454Q694 465 698 474T708 483Q722 483 722 452Q722 386 675 338T555 289Q514 289 468 310T388 357T308 404T224 426Q164 426 125 393T83 318Q81 289 69 289Q55 289 55 319ZM55 85Q55 126 72 159T114 210T163 238T205 248Q207 248 213 248T223 249Q262 249 296 234T393 179L443 147Q502 112 553 112Q609 112 649 141T694 220Q694 249 708 249T722 217Q722 153 675 104T555 55Q514 55 468 76T388 123T308 170T224 192Q164 192 125 159T83 84Q80 55 69 55Q55 55 55 85Z"></path><path stroke-width="1" id="E54-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E54-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><path stroke-width="1" id="E54-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E54-MJMATHI-3D5" d="M409 688Q413 694 421 694H429H442Q448 688 448 686Q448 679 418 563Q411 535 404 504T392 458L388 442Q388 441 397 441T429 435T477 418Q521 397 550 357T579 260T548 151T471 65T374 11T279 -10H275L251 -105Q245 -128 238 -160Q230 -192 227 -198T215 -205H209Q189 -205 189 -198Q189 -193 211 -103L234 -11Q234 -10 226 -10Q221 -10 206 -8T161 6T107 36T62 89T43 171Q43 231 76 284T157 370T254 422T342 441Q347 441 348 445L378 567Q409 686 409 688ZM122 150Q122 116 134 91T167 53T203 35T237 27H244L337 404Q333 404 326 403T297 395T255 379T211 350T170 304Q152 276 137 237Q122 191 122 150ZM500 282Q500 320 484 347T444 385T405 400T381 404H378L332 217L284 29Q284 27 285 27Q293 27 317 33T357 47Q400 66 431 100T475 170T494 234T500 282Z"></path><path stroke-width="1" id="E54-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E54-MJMAIN-2248" x="0" y="0"></use><g transform="translate(778,0)"><g transform="translate(397,0)"><rect stroke="none" width="2776" height="60" x="0" y="220"></rect><use transform="scale(0.707)" xlink:href="#E54-MJMAIN-31" x="1713" y="572"></use><g transform="translate(60,-629)"><use transform="scale(0.707)" xlink:href="#E54-MJMAIN-31" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E54-MJMAIN-2212" x="500" y="0"></use><g transform="translate(904,0)"><text font-family="STIXGeneral,'Arial Unicode MS',serif" stroke="none" transform="scale(35.539) matrix(1 0 0 -1 0 0)">е</text><use transform="scale(0.5)" xlink:href="#E54-MJMAIN-28" x="478" y="697"></use></g><use transform="scale(0.707)" xlink:href="#E54-MJMAIN-2212" x="1992" y="0"></use><use transform="scale(0.707)" xlink:href="#E54-MJMATHI-3D5" x="2771" y="0"></use><use transform="scale(0.707)" xlink:href="#E54-MJMAIN-29" x="3367" y="0"></use></g></g></g></g></svg></span><script type="math/tex" id="MathJax-Element-54">≈ \frac{1}{1-е^(-\phi)}</script>, где <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-55-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="0.786ex" height="2.928ex" viewBox="0 -856.4 338.5 1260.5" role="img" focusable="false" style="vertical-align: -0.938ex;"><defs></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><text font-family="STIXGeneral,'Arial Unicode MS',serif" stroke="none" transform="scale(50.259) matrix(1 0 0 -1 0 0)">е</text></g></svg></span><script type="math/tex" id="MathJax-Element-55">е</script> - экспонента; <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-56-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.385ex" height="2.461ex" viewBox="0 -755.9 596.5 1059.4" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E56-MJMATHI-3D5" d="M409 688Q413 694 421 694H429H442Q448 688 448 686Q448 679 418 563Q411 535 404 504T392 458L388 442Q388 441 397 441T429 435T477 418Q521 397 550 357T579 260T548 151T471 65T374 11T279 -10H275L251 -105Q245 -128 238 -160Q230 -192 227 -198T215 -205H209Q189 -205 189 -198Q189 -193 211 -103L234 -11Q234 -10 226 -10Q221 -10 206 -8T161 6T107 36T62 89T43 171Q43 231 76 284T157 370T254 422T342 441Q347 441 348 445L378 567Q409 686 409 688ZM122 150Q122 116 134 91T167 53T203 35T237 27H244L337 404Q333 404 326 403T297 395T255 379T211 350T170 304Q152 276 137 237Q122 191 122 150ZM500 282Q500 320 484 347T444 385T405 400T381 404H378L332 217L284 29Q284 27 285 27Q293 27 317 33T357 47Q400 66 431 100T475 170T494 234T500 282Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E56-MJMATHI-3D5" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-56">\phi</script> - «золотое» число.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/4/46/Comb_sort_demo.gif' alt='' /></p><h5><a name='header-c906' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">comb</span>(<span class="cm-variable">vector</span><span class="cm-operator"><</span><span class="cm-variable-3">double</span><span class="cm-operator">></span> <span class="cm-variable">sort</span>)</span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">n</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-comment">// количество перестановок</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">double</span> <span class="cm-variable">fakt</span> <span class="cm-operator">=</span> <span class="cm-number">1.2473309</span>; <span class="cm-comment">// фактор уменьшения</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">step</span> <span class="cm-operator">=</span> <span class="cm-variable">sort</span>.<span class="cm-variable">size</span>() <span class="cm-operator">-</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">bool</span> <span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">while</span> (<span class="cm-variable">step</span> <span class="cm-operator">></span> <span class="cm-number">1</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">false</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">i</span> <span class="cm-operator">+</span> <span class="cm-variable">step</span> <span class="cm-operator"><</span> <span class="cm-variable">sort</span>.<span class="cm-variable">size</span>(); <span class="cm-operator">++</span><span class="cm-variable">i</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">if</span> (<span class="cm-variable">sort</span>[<span class="cm-variable">i</span>] <span class="cm-operator">></span> <span class="cm-variable">sort</span>[<span class="cm-variable">i</span> <span class="cm-operator">+</span> <span class="cm-variable">step</span>])</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">swap</span>(<span class="cm-variable">sort</span>[<span class="cm-variable">i</span>], <span class="cm-variable">sort</span>[<span class="cm-variable">i</span> <span class="cm-operator">+</span> <span class="cm-variable">step</span>]);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">n</span><span class="cm-operator">++</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">step</span> <span class="cm-operator">/=</span> <span class="cm-variable">fakt</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-comment">// сортировка пузырьком</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">sort</span>.<span class="cm-variable">size</span>() <span class="cm-operator">-</span> <span class="cm-number">1</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable-3">bool</span> <span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">false</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">j</span> <span class="cm-operator"><</span> <span class="cm-variable">sort</span>.<span class="cm-variable">size</span>() <span class="cm-operator">-</span> <span class="cm-variable">i</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>; <span class="cm-variable">j</span><span class="cm-operator">++</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">if</span> (<span class="cm-variable">sort</span>[<span class="cm-variable">j</span>] <span class="cm-operator">></span> <span class="cm-variable">sort</span>[<span class="cm-variable">j</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>]) {</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">swap</span>(<span class="cm-variable">sort</span>[<span class="cm-variable">j</span>], <span class="cm-variable">sort</span>[<span class="cm-variable">j</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>]);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">swapped</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-operator">++</span><span class="cm-variable">n</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">if</span> (<span class="cm-operator">!</span><span class="cm-variable">swapped</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">break</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">return</span> <span class="cm-variable">n</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 880px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D1%80%D0%B0%D1%81%D1%87%D1%91%D1%81%D0%BA%D0%BE%D0%B9'>Ссылка на Википедию</a></p><h4><a name='header-c911' class='md-header-anchor '></a>Сортировка подсчётом (Counting sort)</h4><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%BF%D0%BE%D0%B4%D1%81%D1%87%D1%91%D1%82%D0%BE%D0%BC'>Ссылка на Википедию</a></p><h4><a name='header-c915' class='md-header-anchor '></a>Сортировка кучей (Heapsort)</h4><p><strong>Сортировка кучей</strong> (или «Пирамидальная сортировка») — алгоритм сортировки, работающий в худшем, в среднем и в лучшем случае (то есть гарантированно) за <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-57-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="10.118ex" height="2.577ex" viewBox="0 -806.1 4356.3 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E57-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E57-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E57-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E57-MJMAIN-6C" d="M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z"></path><path stroke-width="1" id="E57-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E57-MJMAIN-67" d="M329 409Q373 453 429 453Q459 453 472 434T485 396Q485 382 476 371T449 360Q416 360 412 390Q410 404 415 411Q415 412 416 414V415Q388 412 363 393Q355 388 355 386Q355 385 359 381T368 369T379 351T388 325T392 292Q392 230 343 187T222 143Q172 143 123 171Q112 153 112 133Q112 98 138 81Q147 75 155 75T227 73Q311 72 335 67Q396 58 431 26Q470 -13 470 -72Q470 -139 392 -175Q332 -206 250 -206Q167 -206 107 -175Q29 -140 29 -75Q29 -39 50 -15T92 18L103 24Q67 55 67 108Q67 155 96 193Q52 237 52 292Q52 355 102 398T223 442Q274 442 318 416L329 409ZM299 343Q294 371 273 387T221 404Q192 404 171 388T145 343Q142 326 142 292Q142 248 149 227T179 192Q196 182 222 182Q244 182 260 189T283 207T294 227T299 242Q302 258 302 292T299 343ZM403 -75Q403 -50 389 -34T348 -11T299 -2T245 0H218Q151 0 138 -6Q118 -15 107 -34T95 -74Q95 -84 101 -97T122 -127T170 -155T250 -167Q319 -167 361 -139T403 -75Z"></path><path stroke-width="1" id="E57-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E57-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E57-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E57-MJMATHI-6E" x="1153" y="0"></use><g transform="translate(1920,0)"><use xlink:href="#E57-MJMAIN-6C"></use><use xlink:href="#E57-MJMAIN-6F" x="278" y="0"></use><use xlink:href="#E57-MJMAIN-67" x="779" y="0"></use></g><use xlink:href="#E57-MJMATHI-6E" x="3366" y="0"></use><use xlink:href="#E57-MJMAIN-29" x="3966" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-57">O(n \log n)</script> операций при сортировке n элементов. Количество применяемой служебной памяти не зависит от размера массива (то есть, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-58-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="4.745ex" height="2.577ex" viewBox="0 -806.1 2043 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E58-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E58-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E58-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E58-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E58-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E58-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E58-MJMAIN-31" x="1153" y="0"></use><use xlink:href="#E58-MJMAIN-29" x="1653" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-58">O(1)</script>).</p><p>Может рассматриваться как усовершенствованная сортировка пузырьком, в которой элемент всплывает (min-heap) / тонет (max-heap) по многим путям.</p><h5><a name='header-c920' class='md-header-anchor '></a>Алгоритм</h5><p>Сортировка пирамидой использует бинарное сортирующее дерево. Сортирующее дерево — это такое дерево, у которого выполнены условия:</p><ol start='' ><li>Каждый лист имеет глубину либо <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script>, либо <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-60-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.219ex" height="1.994ex" viewBox="0 -755.9 2246.9 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E60-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path><path stroke-width="1" id="E60-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path><path stroke-width="1" id="E60-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E60-MJMATHI-64" x="0" y="0"></use><use xlink:href="#E60-MJMAIN-2212" x="745" y="0"></use><use xlink:href="#E60-MJMAIN-31" x="1746" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-60">d-1</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script> — максимальная глубина дерева.
Значение в любой вершине не меньше (другой вариант — не больше) значения её потомков.</li><li>Удобная структура данных для сортирующего дерева — такой массив <code>Array</code>, что <code>Array[1]</code> — элемент в корне, а потомки элемента <code>Array[i]</code> являются <code>Array[2i+1]</code> и <code>Array[2i+2]</code>.</li></ol><p>Алгоритм сортировки будет состоять из двух основных шагов:</p><ul><li>Выстраиваем элементы массива в виде сортирующего дерева:<br/>
<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-62-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="24.369ex" height="2.577ex" viewBox="0 -806.1 10492 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E62-MJMAIN-41" d="M255 0Q240 3 140 3Q48 3 39 0H32V46H47Q119 49 139 88Q140 91 192 245T295 553T348 708Q351 716 366 716H376Q396 715 400 709Q402 707 508 390L617 67Q624 54 636 51T687 46H717V0H708Q699 3 581 3Q458 3 437 0H427V46H440Q510 46 510 64Q510 66 486 138L462 209H229L209 150Q189 91 189 85Q189 72 209 59T259 46H264V0H255ZM447 255L345 557L244 256Q244 255 345 255H447Z"></path><path stroke-width="1" id="E62-MJMAIN-72" d="M36 46H50Q89 46 97 60V68Q97 77 97 91T98 122T98 161T98 203Q98 234 98 269T98 328L97 351Q94 370 83 376T38 385H20V408Q20 431 22 431L32 432Q42 433 60 434T96 436Q112 437 131 438T160 441T171 442H174V373Q213 441 271 441H277Q322 441 343 419T364 373Q364 352 351 337T313 322Q288 322 276 338T263 372Q263 381 265 388T270 400T273 405Q271 407 250 401Q234 393 226 386Q179 341 179 207V154Q179 141 179 127T179 101T180 81T180 66V61Q181 59 183 57T188 54T193 51T200 49T207 48T216 47T225 47T235 46T245 46H276V0H267Q249 3 140 3Q37 3 28 0H20V46H36Z"></path><path stroke-width="1" id="E62-MJMAIN-61" d="M137 305T115 305T78 320T63 359Q63 394 97 421T218 448Q291 448 336 416T396 340Q401 326 401 309T402 194V124Q402 76 407 58T428 40Q443 40 448 56T453 109V145H493V106Q492 66 490 59Q481 29 455 12T400 -6T353 12T329 54V58L327 55Q325 52 322 49T314 40T302 29T287 17T269 6T247 -2T221 -8T190 -11Q130 -11 82 20T34 107Q34 128 41 147T68 188T116 225T194 253T304 268H318V290Q318 324 312 340Q290 411 215 411Q197 411 181 410T156 406T148 403Q170 388 170 359Q170 334 154 320ZM126 106Q126 75 150 51T209 26Q247 26 276 49T315 109Q317 116 318 175Q318 233 317 233Q309 233 296 232T251 223T193 203T147 166T126 106Z"></path><path stroke-width="1" id="E62-MJMAIN-79" d="M69 -66Q91 -66 104 -80T118 -116Q118 -134 109 -145T91 -160Q84 -163 97 -166Q104 -168 111 -168Q131 -168 148 -159T175 -138T197 -106T213 -75T225 -43L242 0L170 183Q150 233 125 297Q101 358 96 368T80 381Q79 382 78 382Q66 385 34 385H19V431H26L46 430Q65 430 88 429T122 428Q129 428 142 428T171 429T200 430T224 430L233 431H241V385H232Q183 385 185 366L286 112Q286 113 332 227L376 341V350Q376 365 366 373T348 383T334 385H331V431H337H344Q351 431 361 431T382 430T405 429T422 429Q477 429 503 431H508V385H497Q441 380 422 345Q420 343 378 235T289 9T227 -131Q180 -204 113 -204Q69 -204 44 -177T19 -116Q19 -89 35 -78T69 -66Z"></path><path stroke-width="1" id="E62-MJMAIN-5B" d="M118 -250V750H255V710H158V-210H255V-250H118Z"></path><path stroke-width="1" id="E62-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E62-MJMAIN-5D" d="M22 710V750H159V-250H22V-210H119V710H22Z"></path><path stroke-width="1" id="E62-MJMAIN-2265" d="M83 616Q83 624 89 630T99 636Q107 636 253 568T543 431T687 361Q694 356 694 346T687 331Q685 329 395 192L107 56H101Q83 58 83 76Q83 77 83 79Q82 86 98 95Q117 105 248 167Q326 204 378 228L626 346L360 472Q291 505 200 548Q112 589 98 597T83 616ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path><path stroke-width="1" id="E62-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E62-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path stroke-width="1" id="E62-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E62-MJMAIN-41"></use><use xlink:href="#E62-MJMAIN-72" x="750" y="0"></use><use xlink:href="#E62-MJMAIN-72" x="1143" y="0"></use><use xlink:href="#E62-MJMAIN-61" x="1535" y="0"></use><use xlink:href="#E62-MJMAIN-79" x="2036" y="0"></use><use xlink:href="#E62-MJMAIN-5B" x="2564" y="0"></use><use xlink:href="#E62-MJMATHI-69" x="2843" y="0"></use><use xlink:href="#E62-MJMAIN-5D" x="3188" y="0"></use><use xlink:href="#E62-MJMAIN-2265" x="3744" y="0"></use><g transform="translate(4801,0)"><use xlink:href="#E62-MJMAIN-41"></use><use xlink:href="#E62-MJMAIN-72" x="750" y="0"></use><use xlink:href="#E62-MJMAIN-72" x="1143" y="0"></use><use xlink:href="#E62-MJMAIN-61" x="1535" y="0"></use><use xlink:href="#E62-MJMAIN-79" x="2036" y="0"></use></g><use xlink:href="#E62-MJMAIN-5B" x="7365" y="0"></use><use xlink:href="#E62-MJMAIN-32" x="7644" y="0"></use><use xlink:href="#E62-MJMATHI-69" x="8144" y="0"></use><use xlink:href="#E62-MJMAIN-2B" x="8712" y="0"></use><use xlink:href="#E62-MJMAIN-31" x="9713" y="0"></use><use xlink:href="#E62-MJMAIN-5D" x="10213" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-62">{\text{Array}}[i]\geq {\text{Array}}[2i+1]</script><br/>
<span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-63-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="24.369ex" height="2.577ex" viewBox="0 -806.1 10492 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E63-MJMAIN-41" d="M255 0Q240 3 140 3Q48 3 39 0H32V46H47Q119 49 139 88Q140 91 192 245T295 553T348 708Q351 716 366 716H376Q396 715 400 709Q402 707 508 390L617 67Q624 54 636 51T687 46H717V0H708Q699 3 581 3Q458 3 437 0H427V46H440Q510 46 510 64Q510 66 486 138L462 209H229L209 150Q189 91 189 85Q189 72 209 59T259 46H264V0H255ZM447 255L345 557L244 256Q244 255 345 255H447Z"></path><path stroke-width="1" id="E63-MJMAIN-72" d="M36 46H50Q89 46 97 60V68Q97 77 97 91T98 122T98 161T98 203Q98 234 98 269T98 328L97 351Q94 370 83 376T38 385H20V408Q20 431 22 431L32 432Q42 433 60 434T96 436Q112 437 131 438T160 441T171 442H174V373Q213 441 271 441H277Q322 441 343 419T364 373Q364 352 351 337T313 322Q288 322 276 338T263 372Q263 381 265 388T270 400T273 405Q271 407 250 401Q234 393 226 386Q179 341 179 207V154Q179 141 179 127T179 101T180 81T180 66V61Q181 59 183 57T188 54T193 51T200 49T207 48T216 47T225 47T235 46T245 46H276V0H267Q249 3 140 3Q37 3 28 0H20V46H36Z"></path><path stroke-width="1" id="E63-MJMAIN-61" d="M137 305T115 305T78 320T63 359Q63 394 97 421T218 448Q291 448 336 416T396 340Q401 326 401 309T402 194V124Q402 76 407 58T428 40Q443 40 448 56T453 109V145H493V106Q492 66 490 59Q481 29 455 12T400 -6T353 12T329 54V58L327 55Q325 52 322 49T314 40T302 29T287 17T269 6T247 -2T221 -8T190 -11Q130 -11 82 20T34 107Q34 128 41 147T68 188T116 225T194 253T304 268H318V290Q318 324 312 340Q290 411 215 411Q197 411 181 410T156 406T148 403Q170 388 170 359Q170 334 154 320ZM126 106Q126 75 150 51T209 26Q247 26 276 49T315 109Q317 116 318 175Q318 233 317 233Q309 233 296 232T251 223T193 203T147 166T126 106Z"></path><path stroke-width="1" id="E63-MJMAIN-79" d="M69 -66Q91 -66 104 -80T118 -116Q118 -134 109 -145T91 -160Q84 -163 97 -166Q104 -168 111 -168Q131 -168 148 -159T175 -138T197 -106T213 -75T225 -43L242 0L170 183Q150 233 125 297Q101 358 96 368T80 381Q79 382 78 382Q66 385 34 385H19V431H26L46 430Q65 430 88 429T122 428Q129 428 142 428T171 429T200 430T224 430L233 431H241V385H232Q183 385 185 366L286 112Q286 113 332 227L376 341V350Q376 365 366 373T348 383T334 385H331V431H337H344Q351 431 361 431T382 430T405 429T422 429Q477 429 503 431H508V385H497Q441 380 422 345Q420 343 378 235T289 9T227 -131Q180 -204 113 -204Q69 -204 44 -177T19 -116Q19 -89 35 -78T69 -66Z"></path><path stroke-width="1" id="E63-MJMAIN-5B" d="M118 -250V750H255V710H158V-210H255V-250H118Z"></path><path stroke-width="1" id="E63-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E63-MJMAIN-5D" d="M22 710V750H159V-250H22V-210H119V710H22Z"></path><path stroke-width="1" id="E63-MJMAIN-2265" d="M83 616Q83 624 89 630T99 636Q107 636 253 568T543 431T687 361Q694 356 694 346T687 331Q685 329 395 192L107 56H101Q83 58 83 76Q83 77 83 79Q82 86 98 95Q117 105 248 167Q326 204 378 228L626 346L360 472Q291 505 200 548Q112 589 98 597T83 616ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path><path stroke-width="1" id="E63-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E63-MJMAIN-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E63-MJMAIN-41"></use><use xlink:href="#E63-MJMAIN-72" x="750" y="0"></use><use xlink:href="#E63-MJMAIN-72" x="1143" y="0"></use><use xlink:href="#E63-MJMAIN-61" x="1535" y="0"></use><use xlink:href="#E63-MJMAIN-79" x="2036" y="0"></use><use xlink:href="#E63-MJMAIN-5B" x="2564" y="0"></use><use xlink:href="#E63-MJMATHI-69" x="2843" y="0"></use><use xlink:href="#E63-MJMAIN-5D" x="3188" y="0"></use><use xlink:href="#E63-MJMAIN-2265" x="3744" y="0"></use><g transform="translate(4801,0)"><use xlink:href="#E63-MJMAIN-41"></use><use xlink:href="#E63-MJMAIN-72" x="750" y="0"></use><use xlink:href="#E63-MJMAIN-72" x="1143" y="0"></use><use xlink:href="#E63-MJMAIN-61" x="1535" y="0"></use><use xlink:href="#E63-MJMAIN-79" x="2036" y="0"></use></g><use xlink:href="#E63-MJMAIN-5B" x="7365" y="0"></use><use xlink:href="#E63-MJMAIN-32" x="7644" y="0"></use><use xlink:href="#E63-MJMATHI-69" x="8144" y="0"></use><use xlink:href="#E63-MJMAIN-2B" x="8712" y="0"></use><use xlink:href="#E63-MJMAIN-32" x="9713" y="0"></use><use xlink:href="#E63-MJMAIN-5D" x="10213" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-63">{\text{Array}}[i]\geq {\text{Array}}[2i+2]</script><br/>
при <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-64-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="11.881ex" height="2.577ex" viewBox="0 -806.1 5115.6 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E64-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E64-MJMAIN-2264" d="M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z"></path><path stroke-width="1" id="E64-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E64-MJMAIN-3C" d="M694 -11T694 -19T688 -33T678 -40Q671 -40 524 29T234 166L90 235Q83 240 83 250Q83 261 91 266Q664 540 678 540Q681 540 687 534T694 519T687 505Q686 504 417 376L151 250L417 124Q686 -4 687 -5Q694 -11 694 -19Z"></path><path stroke-width="1" id="E64-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E64-MJMAIN-2F" d="M423 750Q432 750 438 744T444 730Q444 725 271 248T92 -240Q85 -250 75 -250Q68 -250 62 -245T56 -231Q56 -221 230 257T407 740Q411 750 423 750Z"></path><path stroke-width="1" id="E64-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E64-MJMAIN-31" x="0" y="0"></use><use xlink:href="#E64-MJMAIN-2264" x="778" y="0"></use><use xlink:href="#E64-MJMATHI-69" x="1834" y="0"></use><use xlink:href="#E64-MJMAIN-3C" x="2457" y="0"></use><use xlink:href="#E64-MJMATHI-6E" x="3514" y="0"></use><use xlink:href="#E64-MJMAIN-2F" x="4114" y="0"></use><use xlink:href="#E64-MJMAIN-32" x="4615" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-64">1\leq i<n/2</script>.</li></ul><p>Этот шаг требует <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-65-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="4.977ex" height="2.577ex" viewBox="0 -806.1 2143 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E65-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E65-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E65-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E65-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E65-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E65-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E65-MJMATHI-6E" x="1153" y="0"></use><use xlink:href="#E65-MJMAIN-29" x="1753" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-65">O(n)</script> операций.</p><ul><li>Будем удалять элементы из корня по одному за раз и перестраивать дерево. То есть на первом шаге обмениваем Array[1] и Array[n], преобразовываем <code>Array[1]</code>, <code>Array[2]</code>, … , <code>Array[n-1]</code> в сортирующее дерево. Затем переставляем <code>Array[1]</code> и <code>Array[n-1]</code>, преобразовываем <code>Array[1]</code>, <code>Array[2]</code>, … , <code>Array[n-2]</code> в сортирующее дерево. Процесс продолжается до тех пор, пока в сортирующем дереве не останется один элемент. Тогда <code>Array[1]</code>, <code>Array[2]</code>, … , <code>Array[n]</code> — упорядоченная последовательность.</li></ul><p>Этот шаг требует <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-68-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="10.118ex" height="2.577ex" viewBox="0 -806.1 4356.3 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E68-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E68-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E68-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E68-MJMAIN-6C" d="M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z"></path><path stroke-width="1" id="E68-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E68-MJMAIN-67" d="M329 409Q373 453 429 453Q459 453 472 434T485 396Q485 382 476 371T449 360Q416 360 412 390Q410 404 415 411Q415 412 416 414V415Q388 412 363 393Q355 388 355 386Q355 385 359 381T368 369T379 351T388 325T392 292Q392 230 343 187T222 143Q172 143 123 171Q112 153 112 133Q112 98 138 81Q147 75 155 75T227 73Q311 72 335 67Q396 58 431 26Q470 -13 470 -72Q470 -139 392 -175Q332 -206 250 -206Q167 -206 107 -175Q29 -140 29 -75Q29 -39 50 -15T92 18L103 24Q67 55 67 108Q67 155 96 193Q52 237 52 292Q52 355 102 398T223 442Q274 442 318 416L329 409ZM299 343Q294 371 273 387T221 404Q192 404 171 388T145 343Q142 326 142 292Q142 248 149 227T179 192Q196 182 222 182Q244 182 260 189T283 207T294 227T299 242Q302 258 302 292T299 343ZM403 -75Q403 -50 389 -34T348 -11T299 -2T245 0H218Q151 0 138 -6Q118 -15 107 -34T95 -74Q95 -84 101 -97T122 -127T170 -155T250 -167Q319 -167 361 -139T403 -75Z"></path><path stroke-width="1" id="E68-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E68-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E68-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E68-MJMATHI-6E" x="1153" y="0"></use><g transform="translate(1920,0)"><use xlink:href="#E68-MJMAIN-6C"></use><use xlink:href="#E68-MJMAIN-6F" x="278" y="0"></use><use xlink:href="#E68-MJMAIN-67" x="779" y="0"></use></g><use xlink:href="#E68-MJMATHI-6E" x="3366" y="0"></use><use xlink:href="#E68-MJMAIN-29" x="3966" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-68">O(n\log n)</script> операций.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif' alt='' /></p><h5><a name='header-c950' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">T</span><span class="cm-operator">></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">ShiftDown</span>(<span class="cm-variable">T</span> <span class="cm-variable">a</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">i</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">j</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">MaxNodeId</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">bool</span> <span class="cm-variable">ShiftDone</span> <span class="cm-operator">=</span> <span class="cm-atom">false</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">while</span> (((<span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>) <span class="cm-operator"><</span> <span class="cm-variable">j</span>) <span class="cm-operator">&&</span> <span class="cm-operator">!</span><span class="cm-variable">ShiftDone</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">if</span> (<span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">1</span> <span class="cm-operator">==</span> <span class="cm-variable">j</span> <span class="cm-operator">-</span> <span class="cm-number">1</span> <span class="cm-operator">||</span> <span class="cm-variable">a</span>[<span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>] <span class="cm-operator">></span> <span class="cm-variable">a</span>[<span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">2</span>])</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">MaxNodeId</span> <span class="cm-operator">=</span> <span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">else</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">MaxNodeId</span> <span class="cm-operator">=</span> <span class="cm-variable">i</span> <span class="cm-operator">*</span> <span class="cm-number">2</span> <span class="cm-operator">+</span> <span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">if</span> (<span class="cm-variable">a</span>[<span class="cm-variable">i</span>] <span class="cm-operator"><</span> <span class="cm-variable">a</span>[<span class="cm-variable">MaxNodeId</span>])</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">std::swap</span>(<span class="cm-variable">a</span>[<span class="cm-variable">i</span>], <span class="cm-variable">a</span>[<span class="cm-variable">MaxNodeId</span>]);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-variable">MaxNodeId</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">else</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">ShiftDone</span> <span class="cm-operator">=</span> <span class="cm-atom">true</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">T</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">HeapSort</span>(<span class="cm-variable">T</span> <span class="cm-variable">a</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">l</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">i</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-comment">//Строим дерево поиска</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">for</span> (<span class="cm-variable">i</span> <span class="cm-operator">=</span> (<span class="cm-variable">l</span> <span class="cm-operator">/</span> <span class="cm-number">2</span>) <span class="cm-operator">-</span> <span class="cm-number">1</span>; <span class="cm-variable">i</span> <span class="cm-operator">></span> <span class="cm-operator">-</span><span class="cm-number">1</span>; <span class="cm-variable">i</span><span class="cm-operator">--</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">ShiftDown</span>(<span class="cm-variable">a</span>, <span class="cm-variable">i</span>, <span class="cm-variable">l</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-comment">//Забираем максимальный (0) элемент дерева в i-ю позицию</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-comment">//Перемещаем новый 0 элемент на правильную позицию в дереве</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">for</span> (<span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-variable">l</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>; <span class="cm-variable">i</span> <span class="cm-operator">></span> <span class="cm-number">0</span>; <span class="cm-variable">i</span><span class="cm-operator">--</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">std::swap</span>(<span class="cm-variable">a</span>[<span class="cm-number">0</span>], <span class="cm-variable">a</span>[<span class="cm-variable">i</span>]);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">ShiftDown</span>(<span class="cm-variable">a</span>, <span class="cm-number">0</span>, <span class="cm-variable">i</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 1012px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%9F%D0%B8%D1%80%D0%B0%D0%BC%D0%B8%D0%B4%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0'>Ссылка на Википедию</a></p><h4><a name='header-c955' class='md-header-anchor '></a>Сортировка вставками (Insertion sort)</h4><p><strong>Сортировка вставками</strong> — алгоритм сортировки, в котором элементы входной последовательности просматриваются по одному, и каждый новый поступивший элемент размещается в подходящее место среди ранее упорядоченных элементов. Основным преимуществом алгоритма сортировки вставками является возможность сортировать массив по мере его получения.То есть имея часть массива, можно начинать его сортировать. В параллельном программирование такая особенность играет не маловажную роль. Вычислительная сложность — <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-72-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.032ex" height="2.811ex" viewBox="0 -906.7 2596.9 1210.2" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E72-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E72-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E72-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E72-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E72-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E72-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E72-MJMAIN-28" x="763" y="0"></use><g transform="translate(1153,0)"><use xlink:href="#E72-MJMATHI-6E" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E72-MJMAIN-32" x="849" y="513"></use></g><use xlink:href="#E72-MJMAIN-29" x="2207" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-72">O(n^2)</script>.</p><h5><a name='header-c958' class='md-header-anchor '></a>Алгоритм</h5><p>Сортируемый массив можно разделить на две части — отсортированная часть и неотсортированная. В начале сортировки первый элемент массива считается отсортированным, все остальные — не отсортированные. Начиная со второго элемента массива и заканчивая последним, алгоритм вставляет неотсортированный элемент массива в нужную позицию в отсортированной части массива. Таким образом, за один шаг сортировки отсортированная часть массива увеличивается на один элемент, а неотсортированная часть массива уменьшается на один элемент. Например, когда мы тянем карту из колоды, смотрим на наши разложенные по возрастанию карты и в зависимости от достоинства вытянутой карты помещаем карту в соответствующее место.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif' alt='' /></p><h5><a name='header-c963' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">Sort</span>(<span class="cm-variable-3">int*</span> <span class="cm-variable">arr</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">n</span>)</span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">counter</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-keyword">for</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">n</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-keyword">for</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-variable">i</span>; <span class="cm-variable">j</span> <span class="cm-operator">></span> <span class="cm-number">0</span> <span class="cm-operator">&&</span> <span class="cm-variable">arr</span>[<span class="cm-variable">j</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>] <span class="cm-operator">></span> <span class="cm-variable">arr</span>[<span class="cm-variable">j</span>]; <span class="cm-variable">j</span><span class="cm-operator">--</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">counter</span><span class="cm-operator">++</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable-3">int</span> <span class="cm-variable">tmp</span> <span class="cm-operator">=</span> <span class="cm-variable">arr</span>[<span class="cm-variable">j</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">arr</span>[<span class="cm-variable">j</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>] <span class="cm-operator">=</span> <span class="cm-variable">arr</span>[<span class="cm-variable">j</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-tab"> </span><span class="cm-variable">arr</span>[<span class="cm-variable">j</span>] <span class="cm-operator">=</span> <span class="cm-variable">tmp</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span>}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">counter</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 330px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B2%D1%81%D1%82%D0%B0%D0%B2%D0%BA%D0%B0%D0%BC%D0%B8'>Ссылка на Википедию</a><br/>
<a href='https://habrahabr.ru/post/181271/'>Ссылка на Habrahabr</a></p><h4><a name='header-c969' class='md-header-anchor '></a>Сортировка слиянием (Merge sort)</h4><p><strong>Сортировка слиянием</strong> — алгоритм сортировки, который упорядочивает списки (или другие структуры данных, доступ к элементам которых можно получать только последовательно, например — потоки) в определённом порядке. Эта сортировка — хороший пример использования принципа «разделяй и властвуй». Сначала задача разбивается на несколько подзадач меньшего размера. Затем эти задачи решаются с помощью рекурсивного вызова или непосредственно, если их размер достаточно мал. Наконец, их решения комбинируются, и получается решение исходной задачи.</p><h5><a name='header-c972' class='md-header-anchor '></a>Алгоритм</h5><p>Для решения задачи сортировки эти три этапа выглядят так:</p><ol start='' ><li>Сортируемый массив разбивается на две части примерно одинакового размера;</li><li>Каждая из получившихся частей сортируется отдельно, например — тем же самым алгоритмом;</li><li>Два упорядоченных массива половинного размера соединяются в один.</li></ol><p>1.1. — 2.1. Рекурсивное разбиение задачи на меньшие происходит до тех пор, пока размер массива не достигнет единицы (любой массив длины 1 можно считать упорядоченным).</p><p>3.1. Соединение двух упорядоченных массивов в один.</p><p>Основную идею слияния двух отсортированных массивов можно объяснить на следующем примере. Пусть мы имеем два уже отсортированных по возрастанию подмассива. Тогда:</p><p>3.2. Слияние двух подмассивов в третий результирующий массив.
На каждом шаге мы берём меньший из двух первых элементов подмассивов и записываем его в результирующий массив. Счётчики номеров элементов результирующего массива и подмассива, из которого был взят элемент, увеличиваем на 1.</p><p>3.3. «Прицепление» остатка.
Когда один из подмассивов закончился, мы добавляем все оставшиеся элементы второго подмассива в результирующий массив.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/c/cc/Merge-sort-example-300px.gif' alt='' /></p><h5><a name='header-c999' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">Item</span><span class="cm-operator">></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">Merge</span>(<span class="cm-variable">Item</span> <span class="cm-variable">Mas</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">left</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">right</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">medium</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-variable">left</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">k</span> <span class="cm-operator">=</span> <span class="cm-variable">medium</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">count</span> <span class="cm-operator">=</span> <span class="cm-variable">right</span> <span class="cm-operator">-</span> <span class="cm-variable">left</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">count</span> <span class="cm-operator"><=</span> <span class="cm-number">1</span>) <span class="cm-keyword">return</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">Item</span> <span class="cm-operator">*</span><span class="cm-variable">TmpMas</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Item</span>[<span class="cm-variable">count</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">count</span>; <span class="cm-operator">++</span><span class="cm-variable">i</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">j</span> <span class="cm-operator"><=</span> <span class="cm-variable">medium</span> <span class="cm-operator">&&</span> <span class="cm-variable">k</span> <span class="cm-operator"><=</span> <span class="cm-variable">right</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">Mas</span>[<span class="cm-variable">j</span>] <span class="cm-operator"><</span> <span class="cm-variable">Mas</span>[<span class="cm-variable">k</span>])</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">TmpMas</span>[<span class="cm-variable">i</span>] <span class="cm-operator">=</span> <span class="cm-variable">Mas</span>[<span class="cm-variable">j</span><span class="cm-operator">++</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">TmpMas</span>[<span class="cm-variable">i</span>] <span class="cm-operator">=</span> <span class="cm-variable">Mas</span>[<span class="cm-variable">k</span><span class="cm-operator">++</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> } <span class="cm-keyword">else</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">j</span> <span class="cm-operator"><=</span> <span class="cm-variable">medium</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">TmpMas</span>[<span class="cm-variable">i</span>] <span class="cm-operator">=</span> <span class="cm-variable">Mas</span>[<span class="cm-variable">j</span><span class="cm-operator">++</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">else</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">TmpMas</span>[<span class="cm-variable">i</span>] <span class="cm-operator">=</span> <span class="cm-variable">Mas</span>[<span class="cm-variable">k</span><span class="cm-operator">++</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-variable">left</span>; <span class="cm-variable">i</span> <span class="cm-operator"><=</span> <span class="cm-variable">right</span>; <span class="cm-operator">++</span><span class="cm-variable">i</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">Mas</span>[<span class="cm-variable">i</span>] <span class="cm-operator">=</span> <span class="cm-variable">TmpMas</span>[<span class="cm-variable">j</span><span class="cm-operator">++</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">delete</span>[] <span class="cm-variable">TmpMas</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">Item</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">MergeSort</span>(<span class="cm-variable">Item</span> <span class="cm-variable">a</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">l</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">r</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">m</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// Условие выхода из рекурсии</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">l</span> <span class="cm-operator">>=</span> <span class="cm-variable">r</span>) <span class="cm-keyword">return</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">m</span> <span class="cm-operator">=</span> (<span class="cm-variable">l</span> <span class="cm-operator">+</span> <span class="cm-variable">r</span>) <span class="cm-operator">/</span> <span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// Рекурсивная сортировка полученных массивов</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">MergeSort</span>(<span class="cm-variable">a</span>, <span class="cm-variable">l</span>, <span class="cm-variable">m</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">MergeSort</span>(<span class="cm-variable">a</span>, <span class="cm-variable">m</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>, <span class="cm-variable">r</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">Merge</span>(<span class="cm-variable">a</span>, <span class="cm-variable">l</span>, <span class="cm-variable">r</span>, <span class="cm-variable">m</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 1034px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D1%81%D0%BB%D0%B8%D1%8F%D0%BD%D0%B8%D0%B5%D0%BC'>Ссылка на Википедию</a></p><h4><a name='header-c1004' class='md-header-anchor '></a>Быстрая сортировка (Quicksort)</h4><p><strong>Быстрая сортировка</strong> — широко известный алгоритм сортировки, разработанный английским информатиком Чарльзом Хоаром во время его работы в МГУ в 1960 году.</p><p>Один из самых быстрых известных универсальных алгоритмов сортировки массивов: в среднем <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-68-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="10.118ex" height="2.577ex" viewBox="0 -806.1 4356.3 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E68-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E68-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E68-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E68-MJMAIN-6C" d="M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z"></path><path stroke-width="1" id="E68-MJMAIN-6F" d="M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z"></path><path stroke-width="1" id="E68-MJMAIN-67" d="M329 409Q373 453 429 453Q459 453 472 434T485 396Q485 382 476 371T449 360Q416 360 412 390Q410 404 415 411Q415 412 416 414V415Q388 412 363 393Q355 388 355 386Q355 385 359 381T368 369T379 351T388 325T392 292Q392 230 343 187T222 143Q172 143 123 171Q112 153 112 133Q112 98 138 81Q147 75 155 75T227 73Q311 72 335 67Q396 58 431 26Q470 -13 470 -72Q470 -139 392 -175Q332 -206 250 -206Q167 -206 107 -175Q29 -140 29 -75Q29 -39 50 -15T92 18L103 24Q67 55 67 108Q67 155 96 193Q52 237 52 292Q52 355 102 398T223 442Q274 442 318 416L329 409ZM299 343Q294 371 273 387T221 404Q192 404 171 388T145 343Q142 326 142 292Q142 248 149 227T179 192Q196 182 222 182Q244 182 260 189T283 207T294 227T299 242Q302 258 302 292T299 343ZM403 -75Q403 -50 389 -34T348 -11T299 -2T245 0H218Q151 0 138 -6Q118 -15 107 -34T95 -74Q95 -84 101 -97T122 -127T170 -155T250 -167Q319 -167 361 -139T403 -75Z"></path><path stroke-width="1" id="E68-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E68-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E68-MJMAIN-28" x="763" y="0"></use><use xlink:href="#E68-MJMATHI-6E" x="1153" y="0"></use><g transform="translate(1920,0)"><use xlink:href="#E68-MJMAIN-6C"></use><use xlink:href="#E68-MJMAIN-6F" x="278" y="0"></use><use xlink:href="#E68-MJMAIN-67" x="779" y="0"></use></g><use xlink:href="#E68-MJMATHI-6E" x="3366" y="0"></use><use xlink:href="#E68-MJMAIN-29" x="3966" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-68">O(n\log n)</script> обменов при упорядочении <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script> элементов; из-за наличия ряда недостатков на практике обычно используется с некоторыми доработками.</p><h5><a name='header-c1009' class='md-header-anchor '></a>Алгоритм</h5><p>Быстрая сортировка использует стратегию «разделяй и властвуй». Шаги алгоритма таковы:</p><ol start='' ><li>Выбираем в массиве некоторый элемент, который будем называть опорным элементом. Для корректности алгоритма значение этого элемента должно быть между максимальным и минимальным значениями в массиве (включительно). С точки зрения повышения эффективности алгоритма выгоднее всего выбирать медиану; но без дополнительных сведений о сортируемых данных её обычно невозможно получить. Известные стратегии: выбирать постоянно один и тот же элемент, например, средний или последний по положению; выбирать элемент со случайно выбранным индексом. Часто хороший результат даёт выбор в качестве опорного элемента среднего арифметического между минимальным и максимальным элементами массива, особенно для целых чисел (в этом случае опорный элемент не обязан быть элементом сортируемого массива).</li><li>Операция разделения массива: реорганизуем массив таким образом, чтобы все элементы со значением меньшим или равным опорному элементу, оказались слева от него, а все элементы, превышающие по значению опорный — справа от него. Обычный алгоритм операции:</li><li>Два индекса — l и r, приравниваются к минимальному и максимальному индексу разделяемого массива, соответственно.</li><li>Вычисляется значение опорного элемента m по одной из стратегий.</li><li>Индекс l последовательно увеличивается до тех пор, пока l-й элемент не окажется больше или равен опорному.</li><li>Индекс r последовательно уменьшается до тех пор, пока r-й элемент не окажется меньше или равен опорному.</li><li>Если r = l — найдена середина массива — операция разделения закончена, оба индекса указывают на опорный элемент.</li><li>Если l < r — найденную пару элементов нужно обменять местами и продолжить операцию разделения с тех значений l и r, которые были достигнуты. Следует учесть, что если какая-либо граница (l или r) дошла до опорного элемента, то при обмене значение m изменяется на r-й или l-й элемент соответственно, изменяется именно индекс опорного элемента и алгоритм продолжает своё выполнение.</li><li>Рекурсивно упорядочиваем подмассивы, лежащие слева и справа от опорного элемента.</li><li>Базой рекурсии являются наборы: пустой или состоящий из одного элемента, которые возвращаются в исходном виде. Все такие отрезки уже упорядочены в процессе разделения.</li></ol><p>Поскольку в каждой итерации (на каждом следующем уровне рекурсии) длина обрабатываемого отрезка массива уменьшается, по меньшей мере, на единицу, терминальная ветвь рекурсии будет достигнута обязательно, и обработка гарантированно завершится.</p><p></p><p><img src='https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif' alt='' /></p><h5><a name='header-c1049' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">SortAlgo::quickSort</span>(<span class="cm-variable-3">int*</span> <span class="cm-variable">data</span>, <span class="cm-variable-3">int</span> <span class="cm-keyword">const</span> <span class="cm-variable">len</span>)</span></pre></div><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-keyword">const</span> <span class="cm-variable">lenD</span> <span class="cm-operator">=</span> <span class="cm-variable">len</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">pivot</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">ind</span> <span class="cm-operator">=</span> <span class="cm-variable">lenD</span><span class="cm-operator">/</span><span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">i</span>,<span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>,<span class="cm-variable">k</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">lenD</span> <span class="cm-operator">></span> <span class="cm-number">1</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int*</span> <span class="cm-variable">L</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable-3">int</span>[<span class="cm-variable">lenD</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int*</span> <span class="cm-variable">R</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable-3">int</span>[<span class="cm-variable">lenD</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">pivot</span> <span class="cm-operator">=</span> <span class="cm-variable">data</span>[<span class="cm-variable">ind</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">lenD</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">i</span> <span class="cm-operator">!=</span> <span class="cm-variable">ind</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">data</span>[<span class="cm-variable">i</span>] <span class="cm-operator"><</span> <span class="cm-variable">pivot</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">L</span>[<span class="cm-variable">j</span>] <span class="cm-operator">=</span> <span class="cm-variable">data</span>[<span class="cm-variable">i</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">j</span><span class="cm-operator">++</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">else</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">R</span>[<span class="cm-variable">k</span>] <span class="cm-operator">=</span> <span class="cm-variable">data</span>[<span class="cm-variable">i</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">k</span><span class="cm-operator">++</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">quickSort</span>(<span class="cm-variable">L</span>, <span class="cm-variable">j</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">quickSort</span>(<span class="cm-variable">R</span>, <span class="cm-variable">k</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">cnt</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">cnt</span> <span class="cm-operator"><</span> <span class="cm-variable">lenD</span>; <span class="cm-variable">cnt</span><span class="cm-operator">++</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">cnt</span> <span class="cm-operator"><</span> <span class="cm-variable">j</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">data</span>[<span class="cm-variable">cnt</span>] <span class="cm-operator">=</span> <span class="cm-variable">L</span>[<span class="cm-variable">cnt</span>];;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">else</span> <span class="cm-keyword">if</span>(<span class="cm-variable">cnt</span> <span class="cm-operator">==</span> <span class="cm-variable">j</span>){</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">data</span>[<span class="cm-variable">cnt</span>] <span class="cm-operator">=</span> <span class="cm-variable">pivot</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">else</span>{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">data</span>[<span class="cm-variable">cnt</span>] <span class="cm-operator">=</span> <span class="cm-variable">R</span>[<span class="cm-variable">cnt</span><span class="cm-operator">-</span>(<span class="cm-variable">j</span><span class="cm-operator">+</span><span class="cm-number">1</span>)];</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 814px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%91%D1%8B%D1%81%D1%82%D1%80%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0'>Ссылка на Википедию</a></p><h4><a name='header-c1054' class='md-header-anchor '></a>Поразрядная сортировка (Radix sort)</h4><p><a href='https://ru.wikipedia.org/wiki/%D0%9F%D0%BE%D1%80%D0%B0%D0%B7%D1%80%D1%8F%D0%B4%D0%BD%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0'>Ссылка на Википедию</a></p><h4><a name='header-c1058' class='md-header-anchor '></a>Сортировка выбором (Selection sort)</h4><p><strong>Сортировка выбором</strong> — алгоритм сортировки. Может быть как устойчивый, так и неустойчивый. На массиве из <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-70-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.395ex" height="1.41ex" viewBox="0 -504.6 600.5 607.1" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E70-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E70-MJMATHI-6E" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-70">n</script> элементов имеет время выполнения в худшем, среднем и лучшем случае <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-72-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.032ex" height="2.811ex" viewBox="0 -906.7 2596.9 1210.2" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E72-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E72-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E72-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E72-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E72-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E72-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E72-MJMAIN-28" x="763" y="0"></use><g transform="translate(1153,0)"><use xlink:href="#E72-MJMATHI-6E" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E72-MJMAIN-32" x="849" y="513"></use></g><use xlink:href="#E72-MJMAIN-29" x="2207" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-72">O(n^2)</script>, предполагая что сравнения делаются за постоянное время</p><h5><a name='header-c1061' class='md-header-anchor '></a>Алгоритм</h5><p>Шаги алгоритма:</p><ol start='' ><li>находим номер минимального значения в текущем списке</li><li>производим обмен этого значения со значением первой неотсортированной позиции (обмен не нужен, если минимальный элемент уже находится на данной позиции)</li><li>теперь сортируем хвост списка, исключив из рассмотрения уже отсортированные элементы</li></ol><p>Для реализации устойчивости алгоритма необходимо в пункте 2 минимальный элемент непосредственно вставлять в первую неотсортированную позицию, не меняя порядок остальных элементов.</p><p><img src='https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif' alt='' /></p><h5><a name='header-c1078' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <cstddef></span></span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-meta">#include <utility></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">T</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">selection_sort</span>(<span class="cm-variable">T</span> <span class="cm-variable">array</span>[], <span class="cm-variable">std::size_t</span> <span class="cm-variable">size</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;">{</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable">std::size_t</span> <span class="cm-variable">idx_i</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>; <span class="cm-variable">idx_i</span> <span class="cm-operator"><</span> <span class="cm-variable">size</span> <span class="cm-operator">-</span> <span class="cm-number">1</span>; <span class="cm-variable">idx_i</span><span class="cm-operator">++</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::size_t</span> <span class="cm-variable">min_idx</span> <span class="cm-operator">=</span> <span class="cm-variable">idx_i</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable">std::size_t</span> <span class="cm-variable">idx_j</span> <span class="cm-operator">=</span> <span class="cm-variable">idx_i</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>; <span class="cm-variable">idx_j</span> <span class="cm-operator"><</span> <span class="cm-variable">size</span>; <span class="cm-variable">idx_j</span><span class="cm-operator">++</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">array</span>[<span class="cm-variable">idx_j</span>] <span class="cm-operator"><</span> <span class="cm-variable">array</span>[<span class="cm-variable">min_idx</span>])</span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">min_idx</span> <span class="cm-operator">=</span> <span class="cm-variable">idx_j</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">min_idx</span> <span class="cm-operator">!=</span> <span class="cm-variable">idx_i</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">std::swap</span>(<span class="cm-variable">array</span>[<span class="cm-variable">idx_i</span>], <span class="cm-variable">array</span>[<span class="cm-variable">min_idx</span>]);</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 506px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B2%D1%8B%D0%B1%D0%BE%D1%80%D0%BE%D0%BC'>Ссылка на Википедию</a></p><h4><a name='header-c1083' class='md-header-anchor '></a>Сортировка Шелла (Shell sort)</h4><p><strong>Сортировка Шелла</strong> — алгоритм сортировки, являющийся усовершенствованным вариантом сортировки вставками. Идея метода Дональда Шелла состоит в сравнении элементов, стоящих не только рядом, но и на определённом расстоянии друг от друга; иными словами — это сортировка вставками, но с предварительными «грубыми» проходами.</p><p>Невзирая на то, что сортировка Шелла во многих случаях медленнее, чем быстрая сортировка — она имеет ряд преимуществ:</p><ul><li>Отсутствие потребности в памяти под стек;</li><li>Отсутствие деградации при неудачных наборах данных — быстрая сортировка легко деградирует до <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-72-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="6.032ex" height="2.811ex" viewBox="0 -906.7 2596.9 1210.2" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E72-MJMATHI-4F" d="M740 435Q740 320 676 213T511 42T304 -22Q207 -22 138 35T51 201Q50 209 50 244Q50 346 98 438T227 601Q351 704 476 704Q514 704 524 703Q621 689 680 617T740 435ZM637 476Q637 565 591 615T476 665Q396 665 322 605Q242 542 200 428T157 216Q157 126 200 73T314 19Q404 19 485 98T608 313Q637 408 637 476Z"></path><path stroke-width="1" id="E72-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E72-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path stroke-width="1" id="E72-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E72-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E72-MJMATHI-4F" x="0" y="0"></use><use xlink:href="#E72-MJMAIN-28" x="763" y="0"></use><g transform="translate(1153,0)"><use xlink:href="#E72-MJMATHI-6E" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E72-MJMAIN-32" x="849" y="513"></use></g><use xlink:href="#E72-MJMAIN-29" x="2207" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-72">O(n^2)</script>, что хуже, чем худшее гарантированное время для сортировки Шелла.</li></ul><h5><a name='header-c1095' class='md-header-anchor '></a>Алгоритм</h5><p>Этапы алгоритма:</p><ol start='' ><li><p><strong>Инициализация:</strong> задание начального значения <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script> — которое впоследствии будет уменьшаться;</p></li><li><p><strong>Основная часть:</strong></p></li><li><p>Упорядочение массива:</p><ol start='' ><li>Выбор пары элементов, индексы которых отличаются на <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script>;</li><li>Определение разности элементов выбранной пары;</li><li>Упорядочение элементов в рамках пары согласно разности значений;</li><li>Переход к следующей паре;</li></ol></li><li><p>Уменьшение значения <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script>;</p></li><li><p><strong>Проверка:</strong> если <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-76-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.477ex" height="1.994ex" viewBox="0 -755.9 2358.1 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E76-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path><path stroke-width="1" id="E76-MJMAIN-3E" d="M84 520Q84 528 88 533T96 539L99 540Q106 540 253 471T544 334L687 265Q694 260 694 250T687 235Q685 233 395 96L107 -40H101Q83 -38 83 -20Q83 -19 83 -17Q82 -10 98 -1Q117 9 248 71Q326 108 378 132L626 250L378 368Q90 504 86 509Q84 513 84 520Z"></path><path stroke-width="1" id="E76-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E76-MJMATHI-64" x="0" y="0"></use><use xlink:href="#E76-MJMAIN-3E" x="801" y="0"></use><use xlink:href="#E76-MJMAIN-30" x="1857" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-76">d>0</script> — вернуться к пункту "1" основной части (и если <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-77-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.477ex" height="1.994ex" viewBox="0 -755.9 2358.1 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E77-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path><path stroke-width="1" id="E77-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E77-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E77-MJMATHI-64" x="0" y="0"></use><use xlink:href="#E77-MJMAIN-3D" x="801" y="0"></use><use xlink:href="#E77-MJMAIN-31" x="1857" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-77">d=1</script> — для проведения обычной сортировки вставками);</p></li><li><p><strong>Завершение работы</strong> (например, вывод результатов на экран).</p></li><li><p>Эффективность сортировки Шелла, — в определённых случаях, — обеспечивается тем, что элементы «быстрее» встают на свои места (в простых методах сортировки, — например, пузырьковой, — каждая перестановка двух элементов уменьшает количество инверсий в списке максимум на 1, а при сортировке Шелла — это число может быть больше).</p></li></ol><p><img src='https://upload.wikimedia.org/wikipedia/commons/d/d8/Sorting_shellsort_anim.gif' alt='' /><br/>
Сортировка с шагами 23, 10, 4, 1.</p><h5><a name='header-c1136' class='md-header-anchor '></a>Пример</h5><p><img src='https://upload.wikimedia.org/wikipedia/commons/2/20/Shellsort-ru.svg' alt='' /><br/>
Пусть дан список <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-78-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="52.641ex" height="2.577ex" viewBox="0 -806.1 22664.7 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E78-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E78-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E78-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E78-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E78-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E78-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E78-MJMAIN-39" d="M352 287Q304 211 232 211Q154 211 104 270T44 396Q42 412 42 436V444Q42 537 111 606Q171 666 243 666Q245 666 249 666T257 665H261Q273 665 286 663T323 651T370 619T413 560Q456 472 456 334Q456 194 396 97Q361 41 312 10T208 -22Q147 -22 108 7T68 93T121 149Q143 149 158 135T173 96Q173 78 164 65T148 49T135 44L131 43Q131 41 138 37T164 27T206 22H212Q272 22 313 86Q352 142 352 280V287ZM244 248Q292 248 321 297T351 430Q351 508 343 542Q341 552 337 562T323 588T293 615T246 625Q208 625 181 598Q160 576 154 546T147 441Q147 358 152 329T172 282Q197 248 244 248Z"></path><path stroke-width="1" id="E78-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E78-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E78-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path><path stroke-width="1" id="E78-MJMAIN-38" d="M70 417T70 494T124 618T248 666Q319 666 374 624T429 515Q429 485 418 459T392 417T361 389T335 371T324 363L338 354Q352 344 366 334T382 323Q457 264 457 174Q457 95 399 37T249 -22Q159 -22 101 29T43 155Q43 263 172 335L154 348Q133 361 127 368Q70 417 70 494ZM286 386L292 390Q298 394 301 396T311 403T323 413T334 425T345 438T355 454T364 471T369 491T371 513Q371 556 342 586T275 624Q268 625 242 625Q201 625 165 599T128 534Q128 511 141 492T167 463T217 431Q224 426 228 424L286 386ZM250 21Q308 21 350 55T392 137Q392 154 387 169T375 194T353 216T330 234T301 253T274 270Q260 279 244 289T218 306L210 311Q204 311 181 294T133 239T107 157Q107 98 150 60T250 21Z"></path><path stroke-width="1" id="E78-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E78-MJMAIN-37" d="M55 458Q56 460 72 567L88 674Q88 676 108 676H128V672Q128 662 143 655T195 646T364 644H485V605L417 512Q408 500 387 472T360 435T339 403T319 367T305 330T292 284T284 230T278 162T275 80Q275 66 275 52T274 28V19Q270 2 255 -10T221 -22Q210 -22 200 -19T179 0T168 40Q168 198 265 368Q285 400 349 489L395 552H302Q128 552 119 546Q113 543 108 522T98 479L95 458V455H55V458Z"></path><path stroke-width="1" id="E78-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path><path stroke-width="1" id="E78-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E78-MJMATHI-41" x="0" y="0"></use><use xlink:href="#E78-MJMAIN-3D" x="1028" y="0"></use><use xlink:href="#E78-MJMAIN-28" x="2084" y="0"></use><g transform="translate(2474,0)"><use xlink:href="#E78-MJMAIN-33"></use><use xlink:href="#E78-MJMAIN-32" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="3475" y="0"></use><g transform="translate(3920,0)"><use xlink:href="#E78-MJMAIN-39"></use><use xlink:href="#E78-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="4921" y="0"></use><g transform="translate(5366,0)"><use xlink:href="#E78-MJMAIN-31"></use><use xlink:href="#E78-MJMAIN-36" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="6367" y="0"></use><g transform="translate(6812,0)"><use xlink:href="#E78-MJMAIN-38"></use><use xlink:href="#E78-MJMAIN-32" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="7813" y="0"></use><g transform="translate(8258,0)"><use xlink:href="#E78-MJMAIN-32"></use><use xlink:href="#E78-MJMAIN-34" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="9259" y="0"></use><g transform="translate(9704,0)"><use xlink:href="#E78-MJMAIN-36"></use><use xlink:href="#E78-MJMAIN-36" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="10705" y="0"></use><g transform="translate(11151,0)"><use xlink:href="#E78-MJMAIN-33"></use><use xlink:href="#E78-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="12152" y="0"></use><g transform="translate(12597,0)"><use xlink:href="#E78-MJMAIN-31"></use><use xlink:href="#E78-MJMAIN-39" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="13598" y="0"></use><g transform="translate(14043,0)"><use xlink:href="#E78-MJMAIN-37"></use><use xlink:href="#E78-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="15044" y="0"></use><g transform="translate(15489,0)"><use xlink:href="#E78-MJMAIN-35"></use><use xlink:href="#E78-MJMAIN-34" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="16490" y="0"></use><g transform="translate(16935,0)"><use xlink:href="#E78-MJMAIN-34"></use><use xlink:href="#E78-MJMAIN-30" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="17936" y="0"></use><g transform="translate(18381,0)"><use xlink:href="#E78-MJMAIN-34"></use><use xlink:href="#E78-MJMAIN-33" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="19382" y="0"></use><g transform="translate(19828,0)"><use xlink:href="#E78-MJMAIN-39"></use><use xlink:href="#E78-MJMAIN-33" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-2C" x="20829" y="0"></use><g transform="translate(21274,0)"><use xlink:href="#E78-MJMAIN-36"></use><use xlink:href="#E78-MJMAIN-38" x="500" y="0"></use></g><use xlink:href="#E78-MJMAIN-29" x="22275" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-78">A=(32,95,16,82,24,66,35,19,75,54,40,43,93,68)</script> и выполняется его сортировка методом Шелла, а в качестве значений <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-79-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.216ex" height="1.994ex" viewBox="0 -755.9 523.5 858.4" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E79-MJMATHI-64" d="M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E79-MJMATHI-64" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-79">d</script> выбраны <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-80-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="5.555ex" height="2.344ex" viewBox="0 -755.9 2391.8 1009.2" role="img" focusable="false" style="vertical-align: -0.588ex;"><defs><path stroke-width="1" id="E80-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E80-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E80-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E80-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E80-MJMAIN-35" x="0" y="0"></use><use xlink:href="#E80-MJMAIN-2C" x="500" y="0"></use><use xlink:href="#E80-MJMAIN-33" x="945" y="0"></use><use xlink:href="#E80-MJMAIN-2C" x="1446" y="0"></use><use xlink:href="#E80-MJMAIN-31" x="1891" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-80">5,3,1</script>.</p><p>На первом шаге сортируются подсписки <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-82-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.743ex" height="2.11ex" viewBox="0 -806.1 750.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E82-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E82-MJMATHI-41" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-82">A</script>, составленные из всех элементов <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-82-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.743ex" height="2.11ex" viewBox="0 -806.1 750.5 908.7" role="img" focusable="false" style="vertical-align: -0.238ex;"><defs><path stroke-width="1" id="E82-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E82-MJMATHI-41" x="0" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-82">A</script>, различающихся на 5 позиций, то есть подсписки <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-83-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="18.027ex" height="2.694ex" viewBox="0 -806.1 7761.6 1160" role="img" focusable="false" style="vertical-align: -0.822ex;"><defs><path stroke-width="1" id="E83-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E83-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E83-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E83-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E83-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E83-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E83-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E83-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E83-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path><path stroke-width="1" id="E83-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E83-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path><path stroke-width="1" id="E83-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E83-MJMATHI-41" x="0" y="0"></use><g transform="translate(750,-150)"><use transform="scale(0.707)" xlink:href="#E83-MJMAIN-35" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E83-MJMAIN-2C" x="500" y="0"></use><use transform="scale(0.707)" xlink:href="#E83-MJMAIN-31" x="779" y="0"></use></g><use xlink:href="#E83-MJMAIN-3D" x="2033" y="0"></use><use xlink:href="#E83-MJMAIN-28" x="3089" y="0"></use><g transform="translate(3478,0)"><use xlink:href="#E83-MJMAIN-33"></use><use xlink:href="#E83-MJMAIN-32" x="500" y="0"></use></g><use xlink:href="#E83-MJMAIN-2C" x="4479" y="0"></use><g transform="translate(4924,0)"><use xlink:href="#E83-MJMAIN-36"></use><use xlink:href="#E83-MJMAIN-36" x="500" y="0"></use></g><use xlink:href="#E83-MJMAIN-2C" x="5925" y="0"></use><g transform="translate(6371,0)"><use xlink:href="#E83-MJMAIN-34"></use><use xlink:href="#E83-MJMAIN-30" x="500" y="0"></use></g><use xlink:href="#E83-MJMAIN-29" x="7372" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-83">A_{5,1}=(32,66,40)</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-84-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="18.027ex" height="2.694ex" viewBox="0 -806.1 7761.6 1160" role="img" focusable="false" style="vertical-align: -0.822ex;"><defs><path stroke-width="1" id="E84-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E84-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E84-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E84-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E84-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E84-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E84-MJMAIN-39" d="M352 287Q304 211 232 211Q154 211 104 270T44 396Q42 412 42 436V444Q42 537 111 606Q171 666 243 666Q245 666 249 666T257 665H261Q273 665 286 663T323 651T370 619T413 560Q456 472 456 334Q456 194 396 97Q361 41 312 10T208 -22Q147 -22 108 7T68 93T121 149Q143 149 158 135T173 96Q173 78 164 65T148 49T135 44L131 43Q131 41 138 37T164 27T206 22H212Q272 22 313 86Q352 142 352 280V287ZM244 248Q292 248 321 297T351 430Q351 508 343 542Q341 552 337 562T323 588T293 615T246 625Q208 625 181 598Q160 576 154 546T147 441Q147 358 152 329T172 282Q197 248 244 248Z"></path><path stroke-width="1" id="E84-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E84-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E84-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E84-MJMATHI-41" x="0" y="0"></use><g transform="translate(750,-150)"><use transform="scale(0.707)" xlink:href="#E84-MJMAIN-35" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E84-MJMAIN-2C" x="500" y="0"></use><use transform="scale(0.707)" xlink:href="#E84-MJMAIN-32" x="779" y="0"></use></g><use xlink:href="#E84-MJMAIN-3D" x="2033" y="0"></use><use xlink:href="#E84-MJMAIN-28" x="3089" y="0"></use><g transform="translate(3478,0)"><use xlink:href="#E84-MJMAIN-39"></use><use xlink:href="#E84-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E84-MJMAIN-2C" x="4479" y="0"></use><g transform="translate(4924,0)"><use xlink:href="#E84-MJMAIN-33"></use><use xlink:href="#E84-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E84-MJMAIN-2C" x="5925" y="0"></use><g transform="translate(6371,0)"><use xlink:href="#E84-MJMAIN-34"></use><use xlink:href="#E84-MJMAIN-33" x="500" y="0"></use></g><use xlink:href="#E84-MJMAIN-29" x="7372" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-84">A_{5,2}=(95,35,43)</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-85-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="18.027ex" height="2.694ex" viewBox="0 -806.1 7761.6 1160" role="img" focusable="false" style="vertical-align: -0.822ex;"><defs><path stroke-width="1" id="E85-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E85-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E85-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E85-MJMAIN-33" d="M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z"></path><path stroke-width="1" id="E85-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E85-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E85-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path><path stroke-width="1" id="E85-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path><path stroke-width="1" id="E85-MJMAIN-39" d="M352 287Q304 211 232 211Q154 211 104 270T44 396Q42 412 42 436V444Q42 537 111 606Q171 666 243 666Q245 666 249 666T257 665H261Q273 665 286 663T323 651T370 619T413 560Q456 472 456 334Q456 194 396 97Q361 41 312 10T208 -22Q147 -22 108 7T68 93T121 149Q143 149 158 135T173 96Q173 78 164 65T148 49T135 44L131 43Q131 41 138 37T164 27T206 22H212Q272 22 313 86Q352 142 352 280V287ZM244 248Q292 248 321 297T351 430Q351 508 343 542Q341 552 337 562T323 588T293 615T246 625Q208 625 181 598Q160 576 154 546T147 441Q147 358 152 329T172 282Q197 248 244 248Z"></path><path stroke-width="1" id="E85-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E85-MJMATHI-41" x="0" y="0"></use><g transform="translate(750,-150)"><use transform="scale(0.707)" xlink:href="#E85-MJMAIN-35" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E85-MJMAIN-2C" x="500" y="0"></use><use transform="scale(0.707)" xlink:href="#E85-MJMAIN-33" x="779" y="0"></use></g><use xlink:href="#E85-MJMAIN-3D" x="2033" y="0"></use><use xlink:href="#E85-MJMAIN-28" x="3089" y="0"></use><g transform="translate(3478,0)"><use xlink:href="#E85-MJMAIN-31"></use><use xlink:href="#E85-MJMAIN-36" x="500" y="0"></use></g><use xlink:href="#E85-MJMAIN-2C" x="4479" y="0"></use><g transform="translate(4924,0)"><use xlink:href="#E85-MJMAIN-31"></use><use xlink:href="#E85-MJMAIN-39" x="500" y="0"></use></g><use xlink:href="#E85-MJMAIN-2C" x="5925" y="0"></use><g transform="translate(6371,0)"><use xlink:href="#E85-MJMAIN-39"></use><use xlink:href="#E85-MJMAIN-33" x="500" y="0"></use></g><use xlink:href="#E85-MJMAIN-29" x="7372" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-85">A_{5,3}=(16,19,93)</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-86-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="18.027ex" height="2.694ex" viewBox="0 -806.1 7761.6 1160" role="img" focusable="false" style="vertical-align: -0.822ex;"><defs><path stroke-width="1" id="E86-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E86-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E86-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E86-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E86-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E86-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E86-MJMAIN-38" d="M70 417T70 494T124 618T248 666Q319 666 374 624T429 515Q429 485 418 459T392 417T361 389T335 371T324 363L338 354Q352 344 366 334T382 323Q457 264 457 174Q457 95 399 37T249 -22Q159 -22 101 29T43 155Q43 263 172 335L154 348Q133 361 127 368Q70 417 70 494ZM286 386L292 390Q298 394 301 396T311 403T323 413T334 425T345 438T355 454T364 471T369 491T371 513Q371 556 342 586T275 624Q268 625 242 625Q201 625 165 599T128 534Q128 511 141 492T167 463T217 431Q224 426 228 424L286 386ZM250 21Q308 21 350 55T392 137Q392 154 387 169T375 194T353 216T330 234T301 253T274 270Q260 279 244 289T218 306L210 311Q204 311 181 294T133 239T107 157Q107 98 150 60T250 21Z"></path><path stroke-width="1" id="E86-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E86-MJMAIN-37" d="M55 458Q56 460 72 567L88 674Q88 676 108 676H128V672Q128 662 143 655T195 646T364 644H485V605L417 512Q408 500 387 472T360 435T339 403T319 367T305 330T292 284T284 230T278 162T275 80Q275 66 275 52T274 28V19Q270 2 255 -10T221 -22Q210 -22 200 -19T179 0T168 40Q168 198 265 368Q285 400 349 489L395 552H302Q128 552 119 546Q113 543 108 522T98 479L95 458V455H55V458Z"></path><path stroke-width="1" id="E86-MJMAIN-36" d="M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z"></path><path stroke-width="1" id="E86-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E86-MJMATHI-41" x="0" y="0"></use><g transform="translate(750,-150)"><use transform="scale(0.707)" xlink:href="#E86-MJMAIN-35" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E86-MJMAIN-2C" x="500" y="0"></use><use transform="scale(0.707)" xlink:href="#E86-MJMAIN-34" x="779" y="0"></use></g><use xlink:href="#E86-MJMAIN-3D" x="2033" y="0"></use><use xlink:href="#E86-MJMAIN-28" x="3089" y="0"></use><g transform="translate(3478,0)"><use xlink:href="#E86-MJMAIN-38"></use><use xlink:href="#E86-MJMAIN-32" x="500" y="0"></use></g><use xlink:href="#E86-MJMAIN-2C" x="4479" y="0"></use><g transform="translate(4924,0)"><use xlink:href="#E86-MJMAIN-37"></use><use xlink:href="#E86-MJMAIN-35" x="500" y="0"></use></g><use xlink:href="#E86-MJMAIN-2C" x="5925" y="0"></use><g transform="translate(6371,0)"><use xlink:href="#E86-MJMAIN-36"></use><use xlink:href="#E86-MJMAIN-38" x="500" y="0"></use></g><use xlink:href="#E86-MJMAIN-29" x="7372" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-86">A_{5,4}=(82,75,68)</script>, <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-87-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="14.668ex" height="2.694ex" viewBox="0 -806.1 6315.5 1160" role="img" focusable="false" style="vertical-align: -0.822ex;"><defs><path stroke-width="1" id="E87-MJMATHI-41" d="M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z"></path><path stroke-width="1" id="E87-MJMAIN-35" d="M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z"></path><path stroke-width="1" id="E87-MJMAIN-2C" d="M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z"></path><path stroke-width="1" id="E87-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E87-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E87-MJMAIN-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path stroke-width="1" id="E87-MJMAIN-34" d="M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z"></path><path stroke-width="1" id="E87-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E87-MJMATHI-41" x="0" y="0"></use><g transform="translate(750,-150)"><use transform="scale(0.707)" xlink:href="#E87-MJMAIN-35" x="0" y="0"></use><use transform="scale(0.707)" xlink:href="#E87-MJMAIN-2C" x="500" y="0"></use><use transform="scale(0.707)" xlink:href="#E87-MJMAIN-35" x="779" y="0"></use></g><use xlink:href="#E87-MJMAIN-3D" x="2033" y="0"></use><use xlink:href="#E87-MJMAIN-28" x="3089" y="0"></use><g transform="translate(3478,0)"><use xlink:href="#E87-MJMAIN-32"></use><use xlink:href="#E87-MJMAIN-34" x="500" y="0"></use></g><use xlink:href="#E87-MJMAIN-2C" x="4479" y="0"></use><g transform="translate(4924,0)"><use xlink:href="#E87-MJMAIN-35"></use><use xlink:href="#E87-MJMAIN-34" x="500" y="0"></use></g><use xlink:href="#E87-MJMAIN-29" x="5925" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-87">A_{5,5}=(24,54)</script>.</p><p>В полученном списке на втором шаге вновь сортируются подсписки из отстоящих на 3 позиции элементов.</p><p>Процесс завершается обычной сортировкой вставками получившегося списка.</p><h5><a name='header-c1146' class='md-header-anchor '></a>Реализация на C++</h5><pre class="md-fences md-end-block" lang="cpp"> <div class="CodeMirror cm-s-inner CodeMirror-wrap"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 4px;"></div><div class="CodeMirror-hscrollbar" style="left: 0px; min-height: 18px;"><div style="height: 100%; min-height: 1px; width: 0px;"></div></div><div class="CodeMirror-vscrollbar" style="min-width: 18px;"><div style="min-width: 1px; height: 0px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; min-height: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><div style="width: 50px; height: 50px; overflow-x: scroll;"></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">increment</span>(<span class="cm-variable-3">long</span> <span class="cm-variable">inc</span>[], <span class="cm-variable-3">long</span> <span class="cm-variable">size</span>) {</span></pre></div><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// inc[] массив, в который заносятся инкременты</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// size размерность этого массива</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">p1</span>, <span class="cm-variable">p2</span>, <span class="cm-variable">p3</span>, <span class="cm-variable">s</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">p1</span> <span class="cm-operator">=</span> <span class="cm-variable">p2</span> <span class="cm-operator">=</span> <span class="cm-variable">p3</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">do</span> {<span class="cm-comment">// заполняем массив элементов по формуле Роберта Седжвика</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-operator">++</span><span class="cm-variable">s</span> <span class="cm-operator">%</span> <span class="cm-number">2</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">inc</span>[<span class="cm-variable">s</span>] <span class="cm-operator">=</span> <span class="cm-number">8</span><span class="cm-operator">*</span><span class="cm-variable">p1</span> <span class="cm-operator">-</span> <span class="cm-number">6</span><span class="cm-operator">*</span><span class="cm-variable">p2</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> } <span class="cm-keyword">else</span> {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">inc</span>[<span class="cm-variable">s</span>] <span class="cm-operator">=</span> <span class="cm-number">9</span><span class="cm-operator">*</span><span class="cm-variable">p1</span> <span class="cm-operator">-</span> <span class="cm-number">9</span><span class="cm-operator">*</span><span class="cm-variable">p3</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">p2</span> <span class="cm-operator">*=</span> <span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">p3</span> <span class="cm-operator">*=</span> <span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">p1</span> <span class="cm-operator">*=</span> <span class="cm-number">2</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// заполняем массив, пока текущая инкремента хотя бы в 3 раза меньше количества элементов в массиве</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> } <span class="cm-keyword">while</span>(<span class="cm-number">3</span><span class="cm-operator">*</span><span class="cm-variable">inc</span>[<span class="cm-variable">s</span>] <span class="cm-operator"><</span> <span class="cm-variable">size</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">s</span> <span class="cm-operator">></span> <span class="cm-number">0</span> <span class="cm-operator">?</span> <span class="cm-operator">--</span><span class="cm-variable">s</span> : <span class="cm-number">0</span>;<span class="cm-comment">// возвращаем количество элементов в массиве</span></span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T</span><span class="cm-operator">></span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">shellSort</span>(<span class="cm-variable">T</span> <span class="cm-variable">a</span>[], <span class="cm-variable-3">long</span> <span class="cm-variable">size</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// inc инкремент, расстояние между элементами сравнения</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// i и j стандартные переменные цикла</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// seq[40] массив, в котором хранятся инкременты</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">long</span> <span class="cm-variable">inc</span>, <span class="cm-variable">i</span>, <span class="cm-variable">j</span>, <span class="cm-variable">seq</span>[<span class="cm-number">40</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">s</span>;<span class="cm-comment">//количество элементов в массиве seq[40]</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span></span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-comment">// вычисление последовательности приращений</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-variable">increment</span>(<span class="cm-variable">seq</span>, <span class="cm-variable">size</span>);</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">while</span> (<span class="cm-variable">s</span> <span class="cm-operator">>=</span> <span class="cm-number">0</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-comment">//извлекаем из массива очередную инкременту</span></span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-tab"> </span><span class="cm-variable">inc</span> <span class="cm-operator">=</span> <span class="cm-variable">seq</span>[<span class="cm-variable">s</span><span class="cm-operator">--</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// сортировка вставками с инкрементами inc</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-variable">inc</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-variable">size</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>) {</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">T</span> <span class="cm-variable">temp</span> <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-variable">i</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// сдвигаем элементы до тех пор, пока не дойдем до конца или не упорядочим в нужном порядке</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable">j</span> <span class="cm-operator">=</span> <span class="cm-variable">i</span><span class="cm-operator">-</span><span class="cm-variable">inc</span>; (<span class="cm-variable">j</span> <span class="cm-operator">>=</span> <span class="cm-number">0</span>) <span class="cm-operator">&&</span> (<span class="cm-variable">a</span>[<span class="cm-variable">j</span>] <span class="cm-operator">></span> <span class="cm-variable">temp</span>); <span class="cm-variable">j</span> <span class="cm-operator">-=</span> <span class="cm-variable">inc</span>)</span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">a</span>[<span class="cm-variable">j</span><span class="cm-operator">+</span><span class="cm-variable">inc</span>] <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-variable">j</span>];</span></pre><pre class=""><span style="padding-right: 0.1px;"><span class="cm-comment">// после всех сдвигов ставим на место j+inc элемент, который находился на i месте</span></span></pre><pre class=""><span style="padding-right: 0.1px;"> <span class="cm-variable">a</span>[<span class="cm-variable">j</span><span class="cm-operator">+</span><span class="cm-variable">inc</span>] <span class="cm-operator">=</span> <span class="cm-variable">temp</span>;</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;"> }</span></pre><pre class=""><span style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px; top: 0px;"></div><div class="CodeMirror-gutters" style="display: none; height: 1056px;"></div></div></div></pre><p><a href='https://ru.wikipedia.org/wiki/%D0%A1%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0_%D0%A8%D0%B5%D0%BB%D0%BB%D0%B0'>Ссылка на Википедию</a></p><hr /><h3><a name='header-c1347' class='md-header-anchor '></a>Хеширование. Метод Брента</h3><p>Один класс методов перемещает элементы во время вставки при двойном хешировании, делая успешный поиск более эффективным. Брент (Brent) разработал метод, при использовании которого даже в заполненной таблице среднее время успешного поиска ограничено константой. Такой метод может быть удобным в приложениях, в которых основной операцией является успешный поиск.</p><p><a href='https://en.wikipedia.org/wiki/Brent%27s_method'>Link on Wikipedia</a></p><blockquote><p>Метод Брента применяется для нахождения корня <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-88-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="4.418ex" height="2.577ex" viewBox="0 -806.1 1902 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E88-MJMATHI-66" d="M118 -162Q120 -162 124 -164T135 -167T147 -168Q160 -168 171 -155T187 -126Q197 -99 221 27T267 267T289 382V385H242Q195 385 192 387Q188 390 188 397L195 425Q197 430 203 430T250 431Q298 431 298 432Q298 434 307 482T319 540Q356 705 465 705Q502 703 526 683T550 630Q550 594 529 578T487 561Q443 561 443 603Q443 622 454 636T478 657L487 662Q471 668 457 668Q445 668 434 658T419 630Q412 601 403 552T387 469T380 433Q380 431 435 431Q480 431 487 430T498 424Q499 420 496 407T491 391Q489 386 482 386T428 385H372L349 263Q301 15 282 -47Q255 -132 212 -173Q175 -205 139 -205Q107 -205 81 -186T55 -132Q55 -95 76 -78T118 -61Q162 -61 162 -103Q162 -122 151 -136T127 -157L118 -162Z"></path><path stroke-width="1" id="E88-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E88-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path><path stroke-width="1" id="E88-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E88-MJMATHI-66" x="0" y="0"></use><use xlink:href="#E88-MJMAIN-28" x="550" y="0"></use><use xlink:href="#E88-MJMATHI-78" x="940" y="0"></use><use xlink:href="#E88-MJMAIN-29" x="1512" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-88">f(x)</script> при <span class="MathJax_Preview"></span><span class="MathJax_SVG" id="MathJax-Element-89-Frame" tabindex="-1" style="font-size: 100%; display: inline-block;"><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="8.678ex" height="2.577ex" viewBox="0 -806.1 3736.6 1109.7" role="img" focusable="false" style="vertical-align: -0.705ex;"><defs><path stroke-width="1" id="E89-MJMATHI-66" d="M118 -162Q120 -162 124 -164T135 -167T147 -168Q160 -168 171 -155T187 -126Q197 -99 221 27T267 267T289 382V385H242Q195 385 192 387Q188 390 188 397L195 425Q197 430 203 430T250 431Q298 431 298 432Q298 434 307 482T319 540Q356 705 465 705Q502 703 526 683T550 630Q550 594 529 578T487 561Q443 561 443 603Q443 622 454 636T478 657L487 662Q471 668 457 668Q445 668 434 658T419 630Q412 601 403 552T387 469T380 433Q380 431 435 431Q480 431 487 430T498 424Q499 420 496 407T491 391Q489 386 482 386T428 385H372L349 263Q301 15 282 -47Q255 -132 212 -173Q175 -205 139 -205Q107 -205 81 -186T55 -132Q55 -95 76 -78T118 -61Q162 -61 162 -103Q162 -122 151 -136T127 -157L118 -162Z"></path><path stroke-width="1" id="E89-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path stroke-width="1" id="E89-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path><path stroke-width="1" id="E89-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path><path stroke-width="1" id="E89-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path stroke-width="1" id="E89-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#E89-MJMATHI-66" x="0" y="0"></use><use xlink:href="#E89-MJMAIN-28" x="550" y="0"></use><use xlink:href="#E89-MJMATHI-78" x="940" y="0"></use><use xlink:href="#E89-MJMAIN-29" x="1512" y="0"></use><use xlink:href="#E89-MJMAIN-3D" x="2179" y="0"></use><use xlink:href="#E89-MJMAIN-30" x="3236" y="0"></use></g></svg></span><script type="math/tex" id="MathJax-Element-89">f(x)=0</script></p></blockquote><h2><a name='header-c1161' class='md-header-anchor '></a>Ответы по прошлым темам</h2><h3><a name='header-c1162' class='md-header-anchor '></a>1. Как бы вы определили понятие «структура данных»</h3><p><strong>Структура данных</strong> (англ. <strong>data structure</strong>) — программная единица, позволяющая хранить и обрабатывать множество однотипных и/или логически связанных данных в вычислительной технике. Для добавления, поиска, изменения и удаления данных структура данных предоставляет некоторый набор функций, составляющих её интерфейс.</p><h3><a name='header-c1165' class='md-header-anchor '></a>6. Объясните отличие класса (class) от структуры (struct)</h3><p>В Си++ основная разница между структурой и классом - это модификатор доступа, который используется по умолчанию для их членов. Для классов, по умолчанию используется модификатор private, а для структур - public. Конечно, принципы инкапсуляции структуры таким образом подрывают, но классы, в свою очередь тормозят стадию проектирования, которая затрагивает структурную эволюцию проекта.</p><p>Т.е., к примеру: выделить класс из структуры проще, чем из класса, т.к. для класса придется пересматривать логику взаимодействия свойств, которые ранее были на одном уровне доступа. Этот процеесс выливается в дописывание/переписывание методов, обеспечивающих инкапсуляцию.</p><p>Все было бы хорошо, если бы на какой-то очередной стадии проектирования Вы вдруг не осознаете, что порой ходите кругами, делая пустую работу, прикрывая тылы инкапсуляции.</p><p>С одной стороны, можно конечно занять позицию рецензора Си++ и следовать "букве закона ООП", т.е. смириться с этой неизбежной бюрократией. Но с другой стороны - это ведь Ваш проект, и Вы вправе строить его по своим законам, давая волю свободному проектированию какого-то сложного класса на структурах, а его финальные версии закрепить на классах по всем правилам ООП.</p><p><a href='http://ru.stackoverflow.com/questions/205371/%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D1%8B-%D0%BF%D1%80%D0%BE%D1%82%D0%B8%D0%B2-%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%82%D1%83%D1%80'>Ссылка</a></p><p></p><h6><a name='header-c1378' class='md-header-anchor '></a>Created by Ivan Istomin &<img src='images/etizolam.png' alt='etizolam' /></h6><h6><a name='header-c1384' class='md-header-anchor '></a>View on <a href='https://github.com/Ivan-Istomin/Algorithms'>GitHub</a></h6></div>
</body>
</html>