trees Flashcards
what do trees show
hiearachy
Linear data structure
Array, list, stack queues
Elements are structured in one linear order
Non linear(hierarchal) data structure
No natural order for elements
Tree and graph
how many edges in tree
Tree has N nodes and N-1 edges because edge connects to its parent
External node(leaf)
No children
Internal node
At least one child
path
sequence of nodes such that n1 is parent of n1+1 and so on
path length
number of edges on path
what does each node have
has a data element, parent node pointer and pointers to children nodes
BST operations
Initize new tree
Bool is empty
search(private)- return pointer to node in which key is found, other wise return null ptr
search(public)-return true is key is found
Find min
Find maz
Insert - done at leaf
Remove
display
BST array implemantation pro and con
Pro - easy implementation and fast access
Con - mostly suitable for complete trees
tree preorder traversal
node is visited before its descendants
List the node the first time its passed
what pass does tree in preorder listing list a node
second pass
what pass does tree in postorder listing list a node
last pass
five possible situations for BST deletiong
-ittem not found
-removing leaf
-removing node with one chilg - left
-removing node with one child - right
-