You are on page 1of 3

ZAC PUCKETT

1a)
50
20
10
xx
15
40
30
25
39
xx
60
xx
70
65
80
71
xx

b)
IN:
10 15 20 25 30 39 40 50 60 65 70 71 80
PRE:
50 20 10 15 40 30 25 39 60 70 65 80 71
POST:
15 10 25 39 30 40 20 65 71 80 70 60 50

c)
50

10
xx
15

60
40
25
39
70
65
80
71
xx
2a)

struct Node{
Node(string val, int off)
:value(val),offset(off)
{
left = nullptr;
right = nullptr;
}
string value = NULL;
Node* left;
Node* right;
Node* Parent;
int offset;
};
b)
insert(string value, int offset)
{
new_node Node new_node(val,offset);
if head is a nullptr, head = new_node. Return

new_node.parent = node
if (value > (node))
insert(new_node, offset, node);
else
insert(new_ node, offset, node);
return;

insert(Node new_nod, int offset, Node& node)


{

if node is a nullptr,
node = new_node Node new_node(val,offset);
node->parent =
elseif (value > (node))
insert(value, offset, node->left);
else
insert(value, offset, node->right);

}
3a)
7

3
0
2
6
4

3b)
7 3 6 0 2 4

3c)
6 3 4 0 2

4)
a. O[ C + S ]
b. O[ log C + S ]
c. O[ log C + log S ]
d. O[ log S ]
e. O[ 2 ]
f. O[ log C + S ]
g. O[ S log S ]
h. O[ C log S ]

You might also like