12. C但y B畛 xung (Addition)
C畛ng 21 vo c但y
Ch炭ng t担i c畉n t畛i a h+1 ph辿p so s叩nh
T畉o m畛t node m畛i (th畛i gian l h畉ng s畛)
add l畉y c1(h+1)+c2 ho畉c c log n
V狸 th畉 vi畛c b畛 xung vo m畛t c但y c滴ng chi畉m
th畛i gian l log n
Ignoring
low order
terms
13. C但y - Addition th畛 t畛c
static void AddToTree( Node *t, Node new ) {
Node base = *t;
/* If it's a null tree, just add it here */
if ( base == NULL ) {
*t = new; return; }
else
if( KeyLess(ItemKey(new->item),ItemKey(base->item)) )
AddToTree( &(base->left), new );
else
AddToTree( &(base->right), new );
}
void AddToCollection( collection c, void *item ) {
Node new, node_p;
new = (Node)malloc(sizeof(struct t_node));
/* Attach the item to the node */
new->item = item;
new->left = new->right = (Node)0;
AddToTree( &(c->node), new );
}
14. C但y B畛 xung (Addition)
Find c log n
Add c log n
Delete c log n
Hi畛u qu畉 r畉t 叩ng k畛!
Tuy nhi棚n v畉n b畉t g畉p m畛t s畛 tr動畛ng h畛p
..
15. C但y B畛 xung (Addition)
L畉y danh s叩ch k箪 t畛 ny v h狸nh thnh m畛t
c但y
A B C D E F
??
16. Trees - Addition
Nh畉n danh s叩ch k箪 t畛 ny v h狸nh thnh
m畛t c但y A B C D E F
Trong tr動畛ng h畛p ny:
? Find
? Add
? Delete