Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹...
-
date post
19-Dec-2015 -
Category
Documents
-
view
296 -
download
1
Transcript of Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹...
![Page 1: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/1.jpg)
Algorithms演算法
國立聯合大學 資訊管理學系 陳士杰老師國立聯合大學 資訊管理學系 陳士杰老師
Course 0
課程介紹Introduction
![Page 2: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/2.jpg)
2國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Outline
了解本課程授課重點、目標及課程設計了解本課程評分標準課前重點資料結構 v.s. 演算法資料結構概念基礎複習
![Page 3: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/3.jpg)
3國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
教材 Text Book
蔡宗翰 , 演算法 : 使用 C++ 虛擬碼 , 碁峰圖書 , 2004. 講義下載處 : http://web.nuu.edu.tw/~sjchen
Reference Book R. E. Neapolitan and K. Naimipour,
Foundations of Algorithms: Using C++ Pseudocode, 3/e, Jones,
2004. (Textbook 原文本 )
李家同教授 , Computational Biology, 全文電子書第二章 .
洪逸 , 洪捷 , 演算法 - 名校攻略密笈 , 鼎茂圖書 . 洪逸 , 資料結構 ( 含精選試題 ), 鼎茂圖書 .
![Page 4: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/4.jpg)
4國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
課程重點 前置觀念
演算法:效率,分析與量級 (Algorithms: Efficiency, Analysis, and Order)
遞迴 (Recursion) 排序 (Sort) 搜尋 (Search)
解題策略 Divide-and-Conquer ( 切割與征服 ) Dynamic Programming ( 動態規劃 ) The Greedy Approach ( 貪婪法則 ) Backtracking ( 回溯 ) Branch-and-Bound ( 分枝與限制 )
NP 問題 An Introduction to the Theory of NP
![Page 5: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/5.jpg)
5國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
評分標準期中考: 35% 期末考: 35%平時考: 20%平時成績: 10%加分程式題: 10%~20%
![Page 6: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/6.jpg)
6國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ 資料結構 v.s. 演算法
資料結構 Array Linked List Stack Queue Tree Graph
演算法 Divide-and-Conquer Dynamic Programming The Greedy Approach Backtracking Branch-and-Bound
• 複雜度分析• 搜尋 (Search)• 排序 (Sort)• 高等樹 (Advanced Tre
e)
ADT
Theory of NP:• P Problem• NP Problem• NP Complete Problem• NP Hard Problem
基礎基礎
高階高階
![Page 7: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/7.jpg)
7國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
資料結構概念基礎複習資料結構概念基礎複習
![Page 8: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/8.jpg)
8國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Def: 為表示有序的線性串列之一種方式 其佔用連續性連續性的記憶體空間 各元素型態皆需相同皆需相同 ( 一致 ) 支援 Sequential 及 Random Access 插入、刪除元素較為麻煩
∵ 需挪移其它元素挪移其它元素 不易動態增刪空間大小
▓ Array
![Page 9: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/9.jpg)
9國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Array 種類一維陣列二維陣列三維陣列N 維陣列
![Page 10: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/10.jpg)
10國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ Linked List Def: 由一組節點 節點 (Node)(Node) 所組成的有序串列有序串列,各 Node 除
了 Data 欄之外,另外有 ≥ 1 個 Link 欄 ( 或稱 Pointer) ,用以指向其它 Node 之位址。
有一個指標變數 (Pointer variablePointer variable) 用來指出鏈結串列中的第一個節點之所在。指標變數的名字可用來做為其所指向之鏈結串列的名字。
![Page 11: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/11.jpg)
11國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Linked list 的特質 : 各各 NodeNode 不一定要佔用連續的不一定要佔用連續的 MemoryMemory 空間空間 各各 NodeNode 之型態 之型態 (Data Type) (Data Type) 不一定要相同不一定要相同 僅支援僅支援 Sequential AccessSequential Access Insert/Delete Node Insert/Delete Node 容易容易
![Page 12: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/12.jpg)
12國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
C
nilF
Linked List 種類
![Page 13: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/13.jpg)
13國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ Stack
Def: 具有 LIFO (last in-first out)LIFO (last in-first out) 或 FILO (first iFILO (first in-last out)n-last out) 性質的有序串列。 插入元素的動作稱為 PushPush, 刪除元素的動作稱為 PopPop. Push/Pop 的動作皆發生在同一端,此端稱為 TopTop.
![Page 14: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/14.jpg)
14國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ Queue ( 佇列 )
Def: 具有 FIFO (first in-first out) FIFO (first in-first out) 性質性質的有序串列。其插入元素的動作稱為發生在 Rear (Rear ( 尾尾 )) 端端 , 刪除元素的動作發生在 Front (Front ( 前前 )) 端端 .
![Page 15: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/15.jpg)
15國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Def: Tree是由 1 個以上的 Nodes 所組成的有限集合,滿足 :
至少有一個 Node ,稱為 Root 其餘的 Nodes 分成 T1, T2, …, Tn 個互斥集合,稱為 Su
btree
▓ Tree
![Page 16: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/16.jpg)
16國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ Binary Tree ( 二元樹 )Def:
Binary Tree 為具有 ≥ ≥ 0 0 個個 nodesnodes 所構成的有限集合。 Binary Tree 可以為空的樹空的樹。 若不為空的樹,則具有 Root 及左 , 右子樹,且左 , 右子樹亦是 Binary Tree 。
![Page 17: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/17.jpg)
17國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
二元樹之三個基本定理
[[ 定理一定理一 ]:]: 二元樹中,第 i 個 level 的 node 個數最多有 2i-1 個。
[[ 定理二定理二 ]:]: 高 (深 ) 度為 k 的二元樹,其 node 個數最多有 2k-1 個。
[[ 定理三定理三 ]:]: 非空二元樹若 leaf 個數為 n0 個, degree 為 2 的 node 個數為 n2 個,則 n0 = n2+1 。
![Page 18: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/18.jpg)
18國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
二元樹的種類
Skewed Binary TreeFull Binary TreeComplete Binary Tree
![Page 19: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/19.jpg)
19國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Skewed Binary Tree
Def: 可分為 Left-Skewed Binary Tree: 每個 non-leaf node皆只
有左子集 Right-Skewed Binary Tree: 每個 non-leaf node皆只有右子集
![Page 20: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/20.jpg)
20國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Full Binary Tree
Def: 具有最多最多 NodeNode 個數個數的二元樹稱之
即 : 高度為 d ,其 node 個數必為 22dd-1-1 具有 n 個 nodes 的 Full B.T. ,其高度必為 :
課本將之命名為 : complete binary tree (7.6.1 節 )
)1(log2 n
![Page 21: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/21.jpg)
21國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Complete Binary Tree
Def: 若二元樹高度為 d , node 個數為 n ,則
22d-1d-1-1 < n < 2-1 < n < 2dd-1-1 n 個 node 之編號與高度 d 的 full binary tree 之前的 n 個 no
de編號一一對應,不能跳號。
課本將之命名為 : essentially complete binary tree (7.6.1 節 )
![Page 22: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/22.jpg)
22國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Def: A Graph is a collection of nodes, called
verticesvertices, and a collection of line segments, called edgesedges, that connecting pairs of vertices.
In other words, a graph consists of two sets a set of vertices
a set of lines.
▓ Graph
![Page 23: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/23.jpg)
23國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
Graph may be either directeddirected or undirectedundirected: Directed graph ( 或稱 Digraph)
Each line has a direction to its successor. G = (V, E), 其中 V為頂點集合, E 為邊集合。 <vi, vj> ≠ <vj, vi>。
Undirected graph Each line has no direction. G = (V, E), 其中 V為頂點集合, E 為邊集合。 <vi, vj> = <vj, vi>。
![Page 24: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/24.jpg)
24國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
▓ Data Type and Abstract Data TypeData Type
Def: A data type consists of two parts a set of data data the operationsoperations that can be performed on the data.
For example: Integer
Data: -∞, …, -2, -1, 0, 1, …, ∞ (沒有小數的數值集合 ) Operations: +, -, , , %, , , ==, !=, ++, --, …
Floating point Data: -∞, …, -1.9, …, 0.0, …, ∞ Operations: +, -, , , %, , , ==, !=, …
Character Data: ‘A’, ‘B’, …, ‘a’, ‘b’, … Operations: <, >, …
![Page 25: Algorithms 演算法 國立聯合大學 資訊管理學系 陳士杰老師 Course 0 課程介紹 Introduction.](https://reader033.fdocument.pub/reader033/viewer/2022061503/56649d3e5503460f94a176a0/html5/thumbnails/25.jpg)
25國立聯合大學 資訊管理學系 演算法課程 ( 陳士杰 )
ADT (Abstract Data Type; ADT (Abstract Data Type; 抽象資料型態抽象資料型態 )) DefDef: ADT是一種 Data Type ,且要滿足: “資料的規格資料的規格與
操作的規格操作的規格” 獨立於 “資料的實際表示方式資料的實際表示方式與操作的實際操作的實際製作方式製作方式 .”
User RequestUser Request
Spec. of Spec. of Data ObjectsData Objects
Spec. of Spec. of OperationOperationss
DesignerDesigner
RepresentatioRepresentation ofn ofDataDataEx: a. b. c. …Ex: a. b. c. …ImplementatioImplementation ofn ofOperationsOperationsEx: 1. 2. 3. …Ex: 1. 2. 3. …
Hidden (Hidden ( 隱藏隱藏 ))