Binary search tree: insert: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
[[Category:Binary Search Tree]] | [[Category:Binary Search Tree]] | ||
== General Information == | == General Information == | ||
'''Algorithmic problem:''' Sorted sequence: insert | |||
'''Type of algorithm:''' loop | |||
'''Auxiliary data:''' A pointer '''''p''''' of type "pointer to binary search tree node of type <math>\kappa</math>". | |||
== Abstract View == | == Abstract View == |
Revision as of 19:26, 25 September 2014
General Information
Algorithmic problem: Sorted sequence: insert
Type of algorithm: loop
Auxiliary data: A pointer p of type "pointer to binary search tree node of type [math]\displaystyle{ \kappa }[/math]".
Abstract View
Induction Basis
Induction Step
Copmplexity
Pseudocode
TREE-INSERT(T, z)
- y = Null
- x = root(T)
- while x ≠ NULL
- y = x
- if key[z] < key[x]
- then x = left[x]
- then x = right[x]
- p[z] = y
- if y = NULL
- then root[T] = z //Tree was empty
- else if key[z] < key[y]
- then left[y] = z
- else right[y] = z