-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithmNote.html
More file actions
622 lines (340 loc) · 23.6 KB
/
Copy pathAlgorithmNote.html
File metadata and controls
622 lines (340 loc) · 23.6 KB
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
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>算法 · NOTEBOOK</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<meta name="author" content="STOLENZC">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-code/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-intopic-toc/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-theme-comscore/test.css">
<link rel="stylesheet" href="styles/website.css">
<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="next" href="DataAnalysis.html" />
<link rel="prev" href="./" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="输入并搜索" />
</div>
<nav role="navigation">
<ul class="summary">
<li>
<a href="https://blog.stolenzc.com" target="_blank" class="custom-link">博客主页</a>
</li>
<li>
<a href="https://tools.stolenzc.com" target="_blank" class="custom-link">快捷工具</a>
</li>
<li class="divider"></li>
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
简介
</a>
</li>
<li class="chapter active" data-level="1.2" data-path="AlgorithmNote.html">
<a href="AlgorithmNote.html">
算法
</a>
</li>
<li class="chapter " data-level="1.3" data-path="DataAnalysis.html">
<a href="DataAnalysis.html">
数据分析
</a>
</li>
<li class="chapter " data-level="1.4" data-path="GoNote.html">
<a href="GoNote.html">
Go笔记
</a>
</li>
<li class="chapter " data-level="1.5" data-path="JavaScriptNote.html">
<a href="JavaScriptNote.html">
前端
</a>
</li>
<li class="chapter " data-level="1.6" data-path="KubernetesNote.html">
<a href="KubernetesNote.html">
K8s
</a>
</li>
<li class="chapter " data-level="1.7" data-path="LinuxNote.html">
<a href="LinuxNote.html">
Linux
</a>
</li>
<li class="chapter " data-level="1.8" data-path="MysqlNote.html">
<a href="MysqlNote.html">
MySQL
</a>
</li>
<li class="chapter " data-level="1.9" data-path="Project.html">
<a href="Project.html">
项目
</a>
</li>
<li class="chapter " data-level="1.10" data-path="PythonNote.html">
<a href="PythonNote.html">
Python基础
</a>
</li>
<li class="chapter " data-level="1.11" data-path="RedisNote.html">
<a href="RedisNote.html">
Redis
</a>
</li>
<li class="chapter " data-level="1.12" data-path="SoftManual.html">
<a href="SoftManual.html">
软件使用
</a>
</li>
<li class="chapter " data-level="1.13" >
<span>
读书笔记
</span>
<ul class="articles">
<li class="chapter " data-level="1.13.1" data-path="reading/effective_python.html">
<a href="reading/effective_python.html">
《Effective Python:编写高质量Python代码的90个有效方法》要点文摘
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
本书使用 GitBook 发布
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >算法</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<a href="#算法基础知识" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="算法基础知识"><a name="算法基础知识" class="anchor-navigation-ex-anchor" href="#算法基础知识"><i class="fa fa-link" aria-hidden="true"></i></a>算法基础知识</h1>
<h2 id="big-o"><a name="big-o" class="anchor-navigation-ex-anchor" href="#big-o"><i class="fa fa-link" aria-hidden="true"></i></a>Big O</h2>
<p>时间:随着数据规模的增加,需要进行的时长变化规律</p>
<ul>
<li>不考虑必须要做的操作:循环、赋初值、程序初始化</li>
<li>不考虑常数项:2n -> n</li>
<li>不考虑低次项:n^2 + n -> n^2</li>
</ul>
<p>空间:随着数据规模增加,需要额外开辟的空间</p>
<ul>
<li>遍历使用的临时变量不计算</li>
</ul>
<h1 id="排序算法"><a name="排序算法" class="anchor-navigation-ex-anchor" href="#排序算法"><i class="fa fa-link" aria-hidden="true"></i></a>排序算法</h1>
<table>
<thead>
<tr>
<th>中文名称</th>
<th>英文名称</th>
<th>平均时间复杂度</th>
<th>最坏时间复杂度</th>
<th>最好时间复杂度</th>
<th>空间复杂度</th>
<th>稳定性</th>
</tr>
</thead>
<tbody>
<tr>
<td>选择排序</td>
<td>Selection</td>
<td>n^2</td>
<td>n^2</td>
<td>n^2</td>
<td>1</td>
<td>不稳定</td>
</tr>
<tr>
<td>冒泡排序</td>
<td>Bubble</td>
<td>n^2</td>
<td>n^2</td>
<td>n</td>
<td>1</td>
<td>稳定</td>
</tr>
<tr>
<td>插入排序</td>
<td>Insertion</td>
<td>n^2</td>
<td>n^2</td>
<td>n</td>
<td>1</td>
<td>稳定</td>
</tr>
<tr>
<td>快速排序</td>
<td>Quick</td>
<td>nlog(2, n)</td>
<td>n^2</td>
<td>nlog(2, n)</td>
<td>log(2, n)</td>
<td>不稳定</td>
</tr>
<tr>
<td>归并排序</td>
<td>Merge</td>
<td>nlog(2, n)</td>
<td>nlog(2, n)</td>
<td>nlog(2, n)</td>
<td>n</td>
<td>稳定</td>
</tr>
<tr>
<td>堆排序</td>
<td>Heap</td>
<td>nlog(2, n)</td>
<td>nlog(2, n)</td>
<td>nlog(2, n)</td>
<td>1</td>
<td>不稳定</td>
</tr>
<tr>
<td>希尔排序</td>
<td>Shell</td>
<td>n^1.3</td>
<td>n^2</td>
<td>n</td>
<td>1</td>
<td>不稳定</td>
</tr>
<tr>
<td>桶排序</td>
<td>Bucket</td>
<td>n + k</td>
<td>n^2</td>
<td>n</td>
<td>n + k</td>
<td>稳定</td>
</tr>
<tr>
<td>计数排序</td>
<td>Counting</td>
<td>n + k</td>
<td>n + k</td>
<td>n + k</td>
<td>n + k</td>
<td>稳定</td>
</tr>
<tr>
<td>基数排序</td>
<td>Radix</td>
<td>n * k</td>
<td>n * k</td>
<td>n * k</td>
<td>n + k</td>
<td>稳定</td>
</tr>
</tbody>
</table>
<blockquote>
<p>不稳定:相同的值经过排序后相对位置可能会发送变化</p>
</blockquote>
<p>口诀:选泡插,快归堆希桶计基,恩方老恩恩一三,对恩加k恩乘k,不稳稳稳不稳稳,不稳不稳稳稳稳。</p>
<h2 id="选择排序"><a name="选择排序" class="anchor-navigation-ex-anchor" href="#选择排序"><i class="fa fa-link" aria-hidden="true"></i></a>选择排序</h2>
<p>原理:从第一个数开始,往后遍历,找到最小的数,记录最小值的位置,将该值和第一个位置的值进行交换</p>
<p><img src="book_img/algorithm/selectionSort.gif" alt="选择排序"></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/python/selection_sort.py" target="_blank">python</a></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/go/selection_sort.go" target="_blank">go</a></p>
<h2 id="冒泡排序"><a name="冒泡排序" class="anchor-navigation-ex-anchor" href="#冒泡排序"><i class="fa fa-link" aria-hidden="true"></i></a>冒泡排序</h2>
<p>原理:从第一个数开始,往后遍历,如果遍历的数比后一个位置的数大,则俩数交换位置,使最大的数到之后位置</p>
<p>冒泡排序是从后往前遍历</p>
<p><img src="book_img/algorithm/bubbleSort.gif" alt="冒泡排序"></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/python/bubble_sort.py" target="_blank">python</a></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/go/bubble_sort.go" target="_blank">go</a></p>
<h2 id="插入排序"><a name="插入排序" class="anchor-navigation-ex-anchor" href="#插入排序"><i class="fa fa-link" aria-hidden="true"></i></a>插入排序</h2>
<p>原理:从第二个数开始,往前遍历,如果遍历的数比前一个位置的数小,则将该数与前一个数位置交换</p>
<p><img src="book_img/algorithm/insertionSort.gif" alt="插入排序"></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/python/insertion_sort.py" target="_blank">python</a></p>
<p><a href="https://github.com/stolenzc/book/blob/gh-pages/code/go/insertion_sort.go" target="_blank">go</a></p>
<h2 id="快速排序"><a name="快速排序" class="anchor-navigation-ex-anchor" href="#快速排序"><i class="fa fa-link" aria-hidden="true"></i></a>快速排序</h2>
<h2 id="归并排序"><a name="归并排序" class="anchor-navigation-ex-anchor" href="#归并排序"><i class="fa fa-link" aria-hidden="true"></i></a>归并排序</h2>
<h2 id="堆排序"><a name="堆排序" class="anchor-navigation-ex-anchor" href="#堆排序"><i class="fa fa-link" aria-hidden="true"></i></a>堆排序</h2>
<h2 id="希尔排序"><a name="希尔排序" class="anchor-navigation-ex-anchor" href="#希尔排序"><i class="fa fa-link" aria-hidden="true"></i></a>希尔排序</h2>
<p>原理:希尔排序是基于插入排序的一种排序方法,先将数组分成若干个子数组,每个子数组再进行插入排序</p>
<h2 id="桶排序"><a name="桶排序" class="anchor-navigation-ex-anchor" href="#桶排序"><i class="fa fa-link" aria-hidden="true"></i></a>桶排序</h2>
<h2 id="计数排序"><a name="计数排序" class="anchor-navigation-ex-anchor" href="#计数排序"><i class="fa fa-link" aria-hidden="true"></i></a>计数排序</h2>
<h2 id="基数排序"><a name="基数排序" class="anchor-navigation-ex-anchor" href="#基数排序"><i class="fa fa-link" aria-hidden="true"></i></a>基数排序</h2>
<h1 id="kmp算法"><a name="kmp算法" class="anchor-navigation-ex-anchor" href="#kmp算法"><i class="fa fa-link" aria-hidden="true"></i></a>KMP算法</h1>
<h1 id="动态规划"><a name="动态规划" class="anchor-navigation-ex-anchor" href="#动态规划"><i class="fa fa-link" aria-hidden="true"></i></a>动态规划</h1>
<h1 id="morris遍历"><a name="morris遍历" class="anchor-navigation-ex-anchor" href="#morris遍历"><i class="fa fa-link" aria-hidden="true"></i></a>Morris遍历</h1>
<h1 id="二叉树"><a name="二叉树" class="anchor-navigation-ex-anchor" href="#二叉树"><i class="fa fa-link" aria-hidden="true"></i></a>二叉树</h1>
<h1 id="链表"><a name="链表" class="anchor-navigation-ex-anchor" href="#链表"><i class="fa fa-link" aria-hidden="true"></i></a>链表</h1>
<h1 id="贪心算法"><a name="贪心算法" class="anchor-navigation-ex-anchor" href="#贪心算法"><i class="fa fa-link" aria-hidden="true"></i></a>贪心算法</h1>
<footer class="page-footer"><span class="copyright">Copyright © book.stolenzc.com 2021-2024 all right reserved,powered by Gitbook</span><span class="footer-modification">File Modify:
2024-09-24 02:47:04
</span></footer>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="./" class="navigation navigation-prev " aria-label="Previous page: 简介">
<i class="fa fa-angle-left"></i>
</a>
<a href="DataAnalysis.html" class="navigation navigation-next " aria-label="Next page: 数据分析">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"算法","level":"1.2","depth":1,"next":{"title":"数据分析","level":"1.3","depth":1,"path":"DataAnalysis.md","ref":"DataAnalysis.md","articles":[]},"previous":{"title":"简介","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","search-pro","splitter","code","github","-highlight","prism","anchor-navigation-ex","theme-comscore","intopic-toc","tbfed-pagefooter","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © book.stolenzc.com 2021-2024"},"prism":{},"github":{"url":"https://github.com/stolenzc"},"intopic-toc":{"isCollapsed":true,"isScrollspyActive":true,"label":"目录","maxDepth":6,"mode":"nested","selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","visible":true},"splitter":{},"search-pro":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"","multipleH1":false,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"STOLENZC","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"NOTEBOOK","language":"zh-hans","links":{"sidebar":{"博客主页":"https://blog.stolenzc.com","快捷工具":"https://tools.stolenzc.com"}},"gitbook":"*"},"file":{"path":"AlgorithmNote.md","mtime":"2024-09-24T02:47:04.776Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-09-24T02:47:54.381Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
<script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
<script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
<script src="gitbook/gitbook-plugin-code/plugin.js"></script>
<script src="gitbook/gitbook-plugin-github/plugin.js"></script>
<script src="gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
<script src="gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
<script src="gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
<script src="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="gitbook/gitbook-plugin-theme-comscore/test.js"></script>
</body>
</html>