基礎資料結構-Tree初探

什麼是Tree?

子節點數量沒有限制

什麼是Binary Tree(二元樹)?

又可以分成左子節點/右子節點

什麼是Full Binary Tree?

隊伍滿編

什麼是Complete Binary Tree?

若J節點的位置不在E下面也不為Complete Binary Tree

Binary Search Tree(BST)

Max/Min Heaps

Max:最上層節點數字最大; Min:最上層節點數字最小

Traversal(尋訪)

  1. In-Order Traversal → 演算法會traverse左節點接著node本身最後則是右節點
  2. Pre-Order Traversal → 演算法會traverse node本身接著左節點最後則是右節點
  3. Post-Order Traversal → 演算法會traverse左節點接著右節點最後則是node本身
建立node排列
上面的設定可以產生如圖的tree
輸出 → 1 2 3 5 7 10
輸出 → 5 2 1 3 7 10
輸出 → 1 3 2 10 7 5

--

--

On my way to become an iOS developer!

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store