Data Structure
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
Priority queue
- It is backed by
heap sort
. Queue could be implemented by array or list. heap sort
is implemented byComplete binary tree
.
Binary tree
- Binary tree can be considered as a List which has
left
andright
pointing to another List object. Full binary tree
: has 2^depth - 1 leaves.Complete binary tree
: Comparing tofull binary tree
, only the trailing of leaves can be none. The depth - 1 level are full binary tree.- Often, we use
LinkedList
to implement binary tree, but we can also usearray
. - If the storage of
complete binary tree
is byarray
, then the nodes are positioned like this: The root is the smallest. The left and right child should both be greater than the root, recursively. So the first element of the array is the smallest one. the second element of the array is the left node of root, the third element of the array is the right node of the root. The fourth element is at the left node of the second element. The fifth element is at the right node of the second element. If you want to know the left and right children of a node (indexed at i), then just use this formula:2 * i + 1 = left index
,2 * i + 2 = right index
. binary search tree
means all the left nodes are always smaller than current node, and all the right nodes are greater than current node.Balanced
means all the difference of height between left nodes and right nodes is no more than 1.
Traversing a binary tree
- To traverse a binary tree, there are
Depth-First Traversal
andBreadth-First Traversal
. Depth-First Traversal
: traverse till a leaf, then back to previous node and continue doing it.Breadth-First Traversal
: traverse from root layers to leaf layers. Root first.
Three ways of Depth-First Traversal
(middle node first) Pre-order traversal
: Middle first, left subtree second, right subtree the last.(middle node second) In-order traversal
: Left subtree first, Middle second, right subtree the last.(middle node last) Post-order traversal
: Left subtree first, right subtree second, the middle node the last.
Depth-First Traversal
level order traversal.