-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
742 lines (351 loc) · 23.7 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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
<!DOCTYPE HTML>
<html lang="en" >
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>排序与搜索 | 数据结构与算法(Python)</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="generator" content="GitBook 2.6.7">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
<link rel="next" href="../chapter6/section1.html" />
<link rel="prev" href="../chapter5/section3.html" />
</head>
<body>
<div class="book"
data-level="6"
data-chapter-title="排序与搜索"
data-filepath="chapter6/README.md"
data-basepath=".."
data-revision="Fri Mar 31 2017 18:24:30 GMT+0800 (CST)"
data-innerlanguage="">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="0" data-path="index.html">
<a href="../index.html">
<i class="fa fa-check"></i>
数据结构与算法(Python)
</a>
</li>
<li class="chapter " data-level="1" data-path="chapter1/index.html">
<a href="../chapter1/index.html">
<i class="fa fa-check"></i>
<b>1.</b>
引入概念
</a>
<ul class="articles">
<li class="chapter " data-level="1.1" data-path="chapter1/section1.html">
<a href="../chapter1/section1.html">
<i class="fa fa-check"></i>
<b>1.1.</b>
第一次尝试
</a>
</li>
<li class="chapter " data-level="1.2" data-path="chapter1/section2.html">
<a href="../chapter1/section2.html">
<i class="fa fa-check"></i>
<b>1.2.</b>
算法的提出
</a>
</li>
<li class="chapter " data-level="1.3" data-path="chapter1/section3.html">
<a href="../chapter1/section3.html">
<i class="fa fa-check"></i>
<b>1.3.</b>
第二次尝试
</a>
</li>
<li class="chapter " data-level="1.4" data-path="chapter1/section4.html">
<a href="../chapter1/section4.html">
<i class="fa fa-check"></i>
<b>1.4.</b>
算法效率衡量
</a>
</li>
<li class="chapter " data-level="1.5" data-path="chapter1/section5.html">
<a href="../chapter1/section5.html">
<i class="fa fa-check"></i>
<b>1.5.</b>
算法分析
</a>
</li>
<li class="chapter " data-level="1.6" data-path="chapter1/section6.html">
<a href="../chapter1/section6.html">
<i class="fa fa-check"></i>
<b>1.6.</b>
常见时间复杂度
</a>
</li>
<li class="chapter " data-level="1.7" data-path="chapter1/section7.html">
<a href="../chapter1/section7.html">
<i class="fa fa-check"></i>
<b>1.7.</b>
Python内置类型性能分析
</a>
</li>
<li class="chapter " data-level="1.8" data-path="chapter1/section8.html">
<a href="../chapter1/section8.html">
<i class="fa fa-check"></i>
<b>1.8.</b>
数据结构
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2" data-path="chapter2/index.html">
<a href="../chapter2/index.html">
<i class="fa fa-check"></i>
<b>2.</b>
顺序表
</a>
<ul class="articles">
<li class="chapter " data-level="2.1" data-path="chapter2/section1.html">
<a href="../chapter2/section1.html">
<i class="fa fa-check"></i>
<b>2.1.</b>
顺序表的形式
</a>
</li>
<li class="chapter " data-level="2.2" data-path="chapter2/section2.html">
<a href="../chapter2/section2.html">
<i class="fa fa-check"></i>
<b>2.2.</b>
顺序表的结构与实现
</a>
</li>
<li class="chapter " data-level="2.3" data-path="chapter2/section3.html">
<a href="../chapter2/section3.html">
<i class="fa fa-check"></i>
<b>2.3.</b>
顺序表的操作
</a>
</li>
<li class="chapter " data-level="2.4" data-path="chapter2/section4.html">
<a href="../chapter2/section4.html">
<i class="fa fa-check"></i>
<b>2.4.</b>
Python中的顺序表
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="3" data-path="chapter3/index.html">
<a href="../chapter3/index.html">
<i class="fa fa-check"></i>
<b>3.</b>
链表
</a>
<ul class="articles">
<li class="chapter " data-level="3.1" data-path="chapter3/section1.html">
<a href="../chapter3/section1.html">
<i class="fa fa-check"></i>
<b>3.1.</b>
单向链表
</a>
</li>
<li class="chapter " data-level="3.2" data-path="chapter3/section2.html">
<a href="../chapter3/section2.html">
<i class="fa fa-check"></i>
<b>3.2.</b>
单项循环链表
</a>
</li>
<li class="chapter " data-level="3.3" data-path="chapter3/section3.html">
<a href="../chapter3/section3.html">
<i class="fa fa-check"></i>
<b>3.3.</b>
双向链表
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="4" data-path="chapter4/index.html">
<a href="../chapter4/index.html">
<i class="fa fa-check"></i>
<b>4.</b>
栈
</a>
<ul class="articles">
<li class="chapter " data-level="4.1" data-path="chapter4/section1.html">
<a href="../chapter4/section1.html">
<i class="fa fa-check"></i>
<b>4.1.</b>
栈结构实现
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="5" data-path="chapter5/index.html">
<a href="../chapter5/index.html">
<i class="fa fa-check"></i>
<b>5.</b>
队列
</a>
<ul class="articles">
<li class="chapter " data-level="5.1" data-path="chapter5/section1.html">
<a href="../chapter5/section1.html">
<i class="fa fa-check"></i>
<b>5.1.</b>
队列的实现
</a>
</li>
<li class="chapter " data-level="5.2" data-path="chapter5/section3.html">
<a href="../chapter5/section3.html">
<i class="fa fa-check"></i>
<b>5.2.</b>
双端队列
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="6" data-path="chapter6/index.html">
<a href="../chapter6/index.html">
<i class="fa fa-check"></i>
<b>6.</b>
排序与搜索
</a>
<ul class="articles">
<li class="chapter " data-level="6.1" data-path="chapter6/section1.html">
<a href="../chapter6/section1.html">
<i class="fa fa-check"></i>
<b>6.1.</b>
冒泡排序
</a>
</li>
<li class="chapter " data-level="6.2" data-path="chapter6/section2.html">
<a href="../chapter6/section2.html">
<i class="fa fa-check"></i>
<b>6.2.</b>
选择排序
</a>
</li>
<li class="chapter " data-level="6.3" data-path="chapter6/section3.html">
<a href="../chapter6/section3.html">
<i class="fa fa-check"></i>
<b>6.3.</b>
插入排序
</a>
</li>
<li class="chapter " data-level="6.4" data-path="chapter6/section4.html">
<a href="../chapter6/section4.html">
<i class="fa fa-check"></i>
<b>6.4.</b>
快速排序
</a>
</li>
<li class="chapter " data-level="6.5" data-path="chapter6/section5.html">
<a href="../chapter6/section5.html">
<i class="fa fa-check"></i>
<b>6.5.</b>
希尔排序
</a>
</li>
<li class="chapter " data-level="6.6" data-path="chapter6/section6.html">
<a href="../chapter6/section6.html">
<i class="fa fa-check"></i>
<b>6.6.</b>
归并排序
</a>
</li>
<li class="chapter " data-level="6.7" data-path="chapter6/section7.html">
<a href="../chapter6/section7.html">
<i class="fa fa-check"></i>
<b>6.7.</b>
常见排序算法效率比较
</a>
</li>
<li class="chapter " data-level="6.8" data-path="chapter6/section8.html">
<a href="../chapter6/section8.html">
<i class="fa fa-check"></i>
<b>6.8.</b>
搜索
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="7" data-path="chapter7/index.html">
<a href="../chapter7/index.html">
<i class="fa fa-check"></i>
<b>7.</b>
树与树算法
</a>
<ul class="articles">
<li class="chapter " data-level="7.1" data-path="chapter7/section1.html">
<a href="../chapter7/section1.html">
<i class="fa fa-check"></i>
<b>7.1.</b>
二叉树
</a>
</li>
<li class="chapter " data-level="7.2" data-path="chapter7/section2.html">
<a href="../chapter7/section2.html">
<i class="fa fa-check"></i>
<b>7.2.</b>
二叉树的遍历
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Actions Left -->
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../" >数据结构与算法(Python)</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<h1 id="排序与搜索">排序与搜索</h1>
<p>排序算法(英语:Sorting algorithm)是一种能将一串数据依照特定顺序进行排列的一种算法。</p>
<h3 id="排序算法的稳定性">排序算法的稳定性</h3>
<p><strong>稳定性</strong>:稳定排序算法会让原本有相等键值的纪录维持相对次序。也就是如果一个排序算法是稳定的,当有两个相等键值的纪录R和S,且在原本的列表中R出现在S之前,在排序过的列表中R也将会是在S之前。</p>
<p>当相等的元素是无法分辨的,比如像是整数,稳定性并不是一个问题。然而,假设以下的数对将要以他们的第一个数字来排序。</p>
<pre><code>(4, 1) (3, 1) (3, 7)(5, 6)
</code></pre><p>在这个状况下,有可能产生两种不同的结果,一个是让相等键值的纪录维持相对的次序,而另外一个则没有:</p>
<pre><code>(3, 1) (3, 7) (4, 1) (5, 6) (维持次序)
(3, 7) (3, 1) (4, 1) (5, 6) (次序被改变)
</code></pre><p>不稳定排序算法可能会在相等的键值中改变纪录的相对次序,但是稳定排序算法从来不会如此。不稳定排序算法可以被特别地实现为稳定。作这件事情的一个方式是人工扩充键值的比较,如此在其他方面相同键值的两个对象间之比较,(比如上面的比较中加入第二个标准:第二个键值的大小)就会被决定使用在原先数据次序中的条目,当作一个同分决赛。然而,要记住这种次序通常牵涉到额外的空间负担。</p>
</section>
</div>
</div>
</div>
<a href="../chapter5/section3.html" class="navigation navigation-prev " aria-label="Previous page: 双端队列"><i class="fa fa-angle-left"></i></a>
<a href="../chapter6/section1.html" class="navigation navigation-next " aria-label="Next page: 冒泡排序"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="../gitbook/app.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
<script>
require(["gitbook"], function(gitbook) {
var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
gitbook.start(config);
});
</script>
</body>
</html>