Tree Search(樹狀搜尋)

一、什麼是 Tree Search(樹狀搜尋)? 在人工智慧(AI)與演算法中,許多問題都可以表示成一棵樹(圖一): 起點(A) / | \ B C D /|\ | / \ E F G H I J 每個節點(Node)代表一種狀態(State)。 例如: 迷宮中的位置 棋局的盤面 路徑規劃中的城市 遊戲中的決策 搜尋演算法的目的: 從起點找到目標節點(Goal Node) 二、Breadth First Search (BFS) 核心思想 先搜尋離起點最近的節點。 一層一層往外擴展。 Level 0: A Level 1: B C D Level 2: E F G H I J 搜尋順序: A B C D E F G H I J 圖一結果: A → B → C → D → E → F → G → H → I → J 使用資料結構 Queue(佇列) FIFO: First In First Out 先進先出 例如: Queue: A 取出A 加入B,C,D Queue: B,C,D BFS特性 優點 如果邊權重相同: BFS一定找到最短路徑。 缺點 需要大量記憶體。 假設每個節點有10個子節點: 深度5: 10^5 = 100000 需要保存很多節點。 時間複雜度 O(V + E) V = Vertex(節點數) E = Edge(邊數) 三、Depth First Search (DFS) 核心思想 一路往下走到底。 不能走才回頭。 A | B | E 然後: A | B | F 搜尋順序 圖一結果: A B E F G C H D I J 使用資料結構 Stack(堆疊) LIFO Last In First Out 後進先出 例如: push(B) push(C) push(D) pop() => D DFS特性 優點 記憶體需求小。 只需保存: 目前路徑 即可。 缺點 可能找到很差的解。 例如: A ├── Goal └── 巨大子樹 DFS可能先跑完整個巨大子樹。 時間複雜度 O(V+E)...

Python in Visual Studio Code

This tutorial will focus on the setting of Python in Visual Studio Code.

Step 1: Download The Required Software

Step 2: Installing Visual Studio Code & Python
By click the installers to install Python and Visual Studio Code. Then choose the default configuration(next, next, and next)



Step 3: Install the Python extension for VS Code.

Click Extension icon. And input "Python extension for VS Code" to search the extension. Then, install(or reload) it.

Step 4: Creating a VS Code project folder
Creating a folder to your preferred path. Open this folder from VS Code.
File ==> Open Folder



Step 5: Checking the Python
Open a New Terminal, 

Type the command "py -V" to check python version. If the version is the installed version from Step 2 (On my PC, it is 3.7.2), then go to the next step.

Step 6: Select a Python interpreter
Open the Command Palette (Ctrl+Shift+P). And type the Python: Select Interpreter command to search. Then, select the command. 

Step 7: Create a Python source file
Click the New File button:

Name it test.py and input the following code, and save the file. 
greetingMsg = "Welcome to python world"
print(greetingMsg)

Step 8: Run the source file
Right-click in the editor and select Run Python File in Terminal(在終端機中執行Python檔案):

And the result will display on the terminal window:

If you see the above result, then your python developing environment is ready. Have a fun with Python programming!.

References:
[1] https://code.visualstudio.com/docs/python/python-tutorial
[2] https://code.visualstudio.com/docs/languages/python

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

留言

這個網誌中的熱門文章