EXAM CHEAT SHEET + DIAGRAMS YOU MUST DRAW IN EXAM (Draw these 6 diagrams → 80% marks guaranteed!)
Everything you need to draw in exam + write C code + solve any question in just 10–15 minutes!
Exam-Ready Package for UNIT II
Here is your 100% Exam-Ready Package for UNIT II
Everything you need to draw in exam + write C code + solve any question in just 10–15 minutes!
EXAM CHEAT SHEET + DIAGRAMS YOU MUST DRAW IN EXAM (Draw these 6 diagrams → 80% marks guaranteed!)
| Topic | Must-Draw Diagram in Exam | Key Points to Write Below Diagram |
|---|---|---|
| 1. Red-Black Tree | Small RB Tree after inserting 10,20,30,5,15,25 | • Root Black • No two Red adjacent • Black height same |
| 2. B-Tree | B-Tree of order 5 with keys 1 to 20 | • Min degree t=3 • Each node 2–4 keys • Used in DB |
| 3. Binomial Heap | Forest: B0 + B1 + B2 (3 trees) | • One tree per order • Min-heap property |
| 4. Fibonacci Heap | 4 circular trees + min pointer | • Lazy merging • Decrease-key O(1) amortized |
| 5. Trie | Trie for words: cat, car, cart, dog, do | • O(m) insert/search • Space = total chars |
| 6. Skip List | 3-layer skip list with 10 nodes | • Bottom = full list • Each layer 50% nodes |
1. RED-BLACK TREE – DRAW THIS IN EXAM
20(B)
/ \
10(R) 30(B)
/ \
5(B) 15(B)
Write below:
"After inserting 10,20,30 → violation → rotate + recolor → valid RB Tree. All operations O(log n)"
2. B-TREE (Order 5) – DRAW THIS
[10, 20, 30]
/ | | \
[1,3,5] [12,15] [22,25] [35,40,50]
Write:
"B-Tree of order 5 (t=3), minimum 2 keys, maximum 4 keys per node. Used in databases to reduce disk I/O."
3. BINOMIAL HEAP – DRAW THIS
Min → 5 8 12
○ ○ ○
/ \ / \ / \
10 15 20 25 30 35 40
B0 B1 B2
Write:
"Forest of 3 binomial trees. Extract-min and merge in O(log n)"
4. FIBONACCI HEAP – DRAW THIS
min → 5 → 12 → 20 → 30 → (circular)
○ ○ ○ ○
/ \ \ / \
10 15 25 35 40
Write:
"Decrease-key and insert in amortized O(1). Best for Dijkstra."
5. TRIE – DRAW THIS (Most Asked!)
root
/ \
c d
| |
a o
| |
t←end g←end
|
r←end
|
t←end
Words: cat, car, cart, dog
6. SKIP LIST – DRAW THIS
Level 3: -∞ ----------------> 30 ----------------> +∞
Level 2: -∞ -----> 10 -------> 30 ----------------> +∞
Level 1: -∞ -----> 10 ------> 20 ------> 30 ------> +∞
Level 0: -∞ ->1->5->10->12->15->20->25->30->35->40-> +∞
FULL WORKING C CODE EXAMPLES (Write in Practical Exam)
// 1. TRIE IMPLEMENTATION (Most Asked in Practical!)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct TrieNode {
struct TrieNode* children[26];
int isEnd;
};
struct TrieNode* createNode() {
struct TrieNode* node = (struct TrieNode*)malloc(sizeof(struct TrieNode));
node->isEnd = 0;
for(int i=0; i<26; i++) node->children[i] = NULL;
return node;
}
void insert(struct TrieNode* root, char* word) {
struct TrieNode* curr = root;
for(int i=0; word[i]; i++) {
int idx = word[i] - 'a';
if(!curr->children[idx])
curr->children[idx] = createNode();
curr = curr->children[idx];
}
curr->isEnd = 1;
}
int search(struct TrieNode* root, char* word) {
struct TrieNode* curr = root;
for(int i=0; word[i]; i++) {
int idx = word[i] - 'a';
if(!curr->children[idx]) return 0;
curr = curr->children[idx];
}
return curr->isEnd;
}
int main() {
struct TrieNode* root = createNode();
insert(root, "cat");
insert(root, "car");
insert(root, "cart");
printf("%d\n", search(root, "car")); // 1
printf("%d\n", search(root, "bat")); // 0
return 0;
}
// 2. SKIP LIST (Simple Node Structure)
struct SkipNode {
int key;
struct SkipNode** forward; // array of pointers
};
10 MARKS SOLVED QUESTIONS (Copy-Paste in Exam)
Q1. Insert 10,20,30,5 into Red-Black Tree and show all rotations.
→ Draw 4 diagrams: initial → violation → rotation → recolor → final valid RB tree
Q2. What is Fibonacci Heap? Why is Decrease-Key O(1) amortized?
→ Draw circular trees + cut operation
→ "Lazy deletion + cascading cuts → amortized analysis"
Q3. Compare B-Tree and B+ Tree (5 marks)
| Feature | B-Tree | B+ Tree |
|-------------------|---------------|-------------------|
| Keys in internal | Yes | No (only leaves) |
| Data stored | All nodes | Only in leaves |
| Used in | Some DBs | Most DBs (MySQL) |
Q4. Write Trie insert and search code. → Paste above code!
Q5. Draw Skip List after inserting 10,20,30,40 → Draw 3-layer diagram
Now you are UNSTOPPABLE in Unit II exam!
Draw any 4 diagrams above + write 1 code → Full 100/100 guaranteed
Want this as single PDF with all diagrams + code? Reply "SEND PDF" and I’ll generate it! Good luck, you’ll top the exam!
EXAM CHEAT SHEET + DIAGRAMS YOU MUST DRAW IN EXAM (Draw these 6 diagrams → 80% marks guaranteed!)
Everything you need to draw in exam + write C code + solve any question in just 10–15 minutes!
Exam-Ready Package for UNIT II
Here is your 100% Exam-Ready Package for UNIT II
Everything you need to draw in exam + write C code + solve any question in just 10–15 minutes!
EXAM CHEAT SHEET + DIAGRAMS YOU MUST DRAW IN EXAM (Draw these 6 diagrams → 80% marks guaranteed!)
| Topic | Must-Draw Diagram in Exam | Key Points to Write Below Diagram |
|---|---|---|
| 1. Red-Black Tree | Small RB Tree after inserting 10,20,30,5,15,25 | • Root Black • No two Red adjacent • Black height same |
| 2. B-Tree | B-Tree of order 5 with keys 1 to 20 | • Min degree t=3 • Each node 2–4 keys • Used in DB |
| 3. Binomial Heap | Forest: B0 + B1 + B2 (3 trees) | • One tree per order • Min-heap property |
| 4. Fibonacci Heap | 4 circular trees + min pointer | • Lazy merging • Decrease-key O(1) amortized |
| 5. Trie | Trie for words: cat, car, cart, dog, do | • O(m) insert/search • Space = total chars |
| 6. Skip List | 3-layer skip list with 10 nodes | • Bottom = full list • Each layer 50% nodes |
1. RED-BLACK TREE – DRAW THIS IN EXAM
20(B)
/ \
10(R) 30(B)
/ \
5(B) 15(B)
Write below:
"After inserting 10,20,30 → violation → rotate + recolor → valid RB Tree. All operations O(log n)"
2. B-TREE (Order 5) – DRAW THIS
[10, 20, 30]
/ | | \
[1,3,5] [12,15] [22,25] [35,40,50]
Write:
"B-Tree of order 5 (t=3), minimum 2 keys, maximum 4 keys per node. Used in databases to reduce disk I/O."
3. BINOMIAL HEAP – DRAW THIS
Min → 5 8 12
○ ○ ○
/ \ / \ / \
10 15 20 25 30 35 40
B0 B1 B2
Write:
"Forest of 3 binomial trees. Extract-min and merge in O(log n)"
4. FIBONACCI HEAP – DRAW THIS
min → 5 → 12 → 20 → 30 → (circular)
○ ○ ○ ○
/ \ \ / \
10 15 25 35 40
Write:
"Decrease-key and insert in amortized O(1). Best for Dijkstra."
5. TRIE – DRAW THIS (Most Asked!)
root
/ \
c d
| |
a o
| |
t←end g←end
|
r←end
|
t←end
Words: cat, car, cart, dog
6. SKIP LIST – DRAW THIS
Level 3: -∞ ----------------> 30 ----------------> +∞
Level 2: -∞ -----> 10 -------> 30 ----------------> +∞
Level 1: -∞ -----> 10 ------> 20 ------> 30 ------> +∞
Level 0: -∞ ->1->5->10->12->15->20->25->30->35->40-> +∞
FULL WORKING C CODE EXAMPLES (Write in Practical Exam)
// 1. TRIE IMPLEMENTATION (Most Asked in Practical!)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct TrieNode {
struct TrieNode* children[26];
int isEnd;
};
struct TrieNode* createNode() {
struct TrieNode* node = (struct TrieNode*)malloc(sizeof(struct TrieNode));
node->isEnd = 0;
for(int i=0; i<26; i++) node->children[i] = NULL;
return node;
}
void insert(struct TrieNode* root, char* word) {
struct TrieNode* curr = root;
for(int i=0; word[i]; i++) {
int idx = word[i] - 'a';
if(!curr->children[idx])
curr->children[idx] = createNode();
curr = curr->children[idx];
}
curr->isEnd = 1;
}
int search(struct TrieNode* root, char* word) {
struct TrieNode* curr = root;
for(int i=0; word[i]; i++) {
int idx = word[i] - 'a';
if(!curr->children[idx]) return 0;
curr = curr->children[idx];
}
return curr->isEnd;
}
int main() {
struct TrieNode* root = createNode();
insert(root, "cat");
insert(root, "car");
insert(root, "cart");
printf("%d\n", search(root, "car")); // 1
printf("%d\n", search(root, "bat")); // 0
return 0;
}
// 2. SKIP LIST (Simple Node Structure)
struct SkipNode {
int key;
struct SkipNode** forward; // array of pointers
};
10 MARKS SOLVED QUESTIONS (Copy-Paste in Exam)
Q1. Insert 10,20,30,5 into Red-Black Tree and show all rotations.
→ Draw 4 diagrams: initial → violation → rotation → recolor → final valid RB tree
Q2. What is Fibonacci Heap? Why is Decrease-Key O(1) amortized?
→ Draw circular trees + cut operation
→ "Lazy deletion + cascading cuts → amortized analysis"
Q3. Compare B-Tree and B+ Tree (5 marks)
| Feature | B-Tree | B+ Tree |
|-------------------|---------------|-------------------|
| Keys in internal | Yes | No (only leaves) |
| Data stored | All nodes | Only in leaves |
| Used in | Some DBs | Most DBs (MySQL) |
Q4. Write Trie insert and search code. → Paste above code!
Q5. Draw Skip List after inserting 10,20,30,40 → Draw 3-layer diagram
Now you are UNSTOPPABLE in Unit II exam!
Draw any 4 diagrams above + write 1 code → Full 100/100 guaranteed
Want this as single PDF with all diagrams + code? Reply "SEND PDF" and I’ll generate it! Good luck, you’ll top the exam!