資料結構 上
IDE Code
WEEK_2:正課
9.30實習題_Insertion_Sort
9.30實習題_binary_search
9.30加分題_交集法_DFS
WEEK_3:
10.7實習題_非連續子序列之兩數最大和(Struct & Sort)
10.7延伸題_最大非連續子序列和(DP)
10.7加分題_奇數魔方陣
I/O Stream(課外補充)
I/O 優化(加速輸入輸出 遇TLE可用)
StringStream(好工具)
getline 搭配 stringstream
輸出
四捨五入cout << fixed << setprecision(10); 或是更高精度 (int)10*位數+0.5
寬度 cout << setw(n) << setfill( c ) <<;
參考資料:
https://cp.wiwiho.me/
Swap
Define
Call by address (Call by pointer)
Call by reference
Auto
根據使用型態變化
變數宣告
陣列宣告
函式宣告
參考資料:
https://blog.gtwang.org/programming/cpp-auto-variable-tutorial/
https://docs.microsoft.com/zh-tw/cpp/cpp/auto-cpp?view=msvc-160
For Loop
使用於任何陣列。
for( auto y : x ){…}
y = x.begin() → x.end()。
Call by value
Call by reference
可以修改陣列
參考資料:
https://docs.microsoft.com/zh-tw/cpp/cpp/range-based-for-statement-cpp?view=msvc-160
Dynamic Memory Allocation
Selection sort
從未排序中,選擇最小的放進數列中
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考資料:
https://medium.com/appworks-school/初學者學演算法-排序法入門-選擇排序與插入排序法-23d4bc7085ff
Insertion Sort
插入已排列的數列
題目:http://140.121.198.41:20211/contest/5/problem/2
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考資料:
http://notepad.yehyeh.net/Content/Algorithm/Sort/Insertion/1.php
Bubble Sort
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Merge Sort
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Quick Sort
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Binary_search
只適用於「已排序」的數列
題目:http://140.121.198.41:20211/contest/5/problem/1
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Main
Recursion
Non-Recursion
Binary search tree
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考資料:
https://www.gushiciku.cn/dc_tw/101530793
https://blog.techbridge.cc/2016/09/24/binary-search-introduction/
加分題_交集法(DFS)
題目:http://140.121.198.41:20211/contest/5/problem/a1
作法:
1 1 1 1 0 0 0 0 0 0
1 1 1 1 0 1 0 0 0 0
1 1 1 1 0 1 0 1 1 0 >>解答1 回復上一動
1 1 1 1 0 1 0 0 1 1 >>解答2 回復上一動
1 1 1 1 0 0 1 0 0 0
1 1 1 1 0 0 1 0 1 1 >>解答3 回復上一動
1 1 1 1 0 0 0 1 0 0
1 1 1 1 0 0 0 0 1 0
1 1 1 1 0 0 0 0 0 1
…
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
DFS
Check
Main
Abstraction
透過語意、規範,隱藏實作過程來簡化程式。
Data Abstraction
透過資料型態(規範),來包裝各種元素。
Abstraction Data Type(ADT)
以規範好的行為,去操作資料形態中的物件。
Space Complexity
Total
= float list[ ] + int n + return addres
= 4 + 4 + 4 = 12n
Time Complexity
- assignment
- for loop (n+1)
- return
- conditional
Asymptotic Notation(O, Ω, Θ)
-
Big O
f(n) ≤ cg(n) for all n, n≥n0
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Omega Ω
f(n) ≥ cg(n) for all n, n≥n0
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Theta Θ
c1 g(n) ≤ f(n) ≤ c2 g(n) for all n, n≥n0
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Fibonacci
Recursion
Non-Recursion(DP)
非連續子序列之兩數最大和(Struct & Sort)
Struct
Sort compare
Main
參考資料:範例八 https://shengyu7697.github.io/std-sort/
課外延伸題_最大非連續子序列和(DP)
DP(Dynamic programming)
Main
加分題_奇數魔方陣
題目:http://140.121.198.41:20211/contest/6/problem/a1
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
參考資料:
https://openhome.cc/Gossip/AlgorithmGossip/OddArray.htm
Struct
typedef
Union