SID Question

  • SID: this is your TCD student number. It should be an 8-digit number.
  • SID2: this is SID squared; it should be a 15-digit number.
  • d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15: these are the fifteen digits of SID2, from left to right.
  • u1, u2, u3, u4, u5, u6, u7, u8, u9, u10: these are the first 10 unique single-digit numbers of the di sequence, from left to right. If there are less than 10 unique numbers in your di sequence, you should complete the remaining ui sequence with single-digit numbers in ascending order. In the end, the ui sequence should not contain duplicate numbers.

SID Answer

SID: 23373999 SID2:

NumberValue
d15
d24
d36
d43
d54
d63
d78
d82
d99
d102
d115
d122
d130
d140
d151
NumberValue
u15
u24
u36
u43
u58
u62
u79
u80
u91
u107

Tree Question

Give the logical representation of the Left Leaning Red-Black Tree obtained by inserting the sequence from Question 1 to the following Left Leaning Red-Black Tree:

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

If one of the is already in the tree you should not insert it again. Therefore you will need to perform five insertions.

For every insertion you should show:

  • The tree after inserting the key but before any tree transformations are applied.
  • Which transformations should be applied, around which node, and in what order.
  • The tree after each transformation.

Tree Answer

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

5;
graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 5;

Parent is black so we do nothing

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 5;

As per question, is already in the tree so we do nothing

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 5;

As per question, is already in the tree so we do nothing

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 5;

3;
graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

8;
graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

As per question is already in the graph so we can ignore it

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

As per question is already in the graph so we can ignore it

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

0;
graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

1 -- red --> 0;

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

1 -- red --> 0;

As per question, is already in the graph, so we can ignore it

Inserting

graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

1 -- red --> 0;

7;
graph TD;

6 -- red --> 2;
6 -- black --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- red --> 8;
10 -- red --> 9;

4 -- red --> 3;
4 -- red --> 5;

1 -- red --> 0;
8 -- red --> 7;

Here, we have a violation of red red at 8 7, so we look at red black tree rules.

Uncle is red set uncle and parent to black and grandparent to red, then check for other violations.

graph TD;

6 -- red --> 2;
6 -- red --> 10;

2 -- black --> 1;
2 -- black --> 4;

10 -- black --> 8;
10 -- black --> 9;

4 -- red --> 3;
4 -- red --> 5;

1 -- red --> 0;
8 -- red --> 7;

No further violations occur, and all numbers are inserted, hence we are finished.