I'm trying to explain to non-computer science major student with many questions.
(1)What traverses tree? Is it just logic or actu开发者_如何学运维al on off switch generates 1s and 0s traveling the circuit board? where is this tree and node exists CPU/Memory in between?
(2)If it is 1s and 0s HOW the circuits understand the line for example p=p.getLeft();
I said search the google or wiki.
A tree is an abstraction that we put on top of a certain collection of sequences of 0s and 1s that could be anywhere (in a CPU's registers, in a CPU's cache, in memory, etc.). The traversal of such is a sequence of CPU instructions that encapsulate the logic necessary to traverse the tree.
As for how the circuits understand the line p = p.getLeft();
, the compiler has done the job of translating that instruction to the necessary machine instructions that the CPU understands and executes.
Honestly, it's best to think abstractly here. If you want to understand binary tree traversal think at that level of abstractions. If you want to understand how computers work at the level of 0s and 1s, forget about binary trees and study computer architecture instead.
Finally note that 0s and 1s are also just an abstraction over the true mechanism.
精彩评论