GATE DA DBMS and Algorithms Formula Sheet with Traps
GATE DA's programming and database sections reward exact counts: comparisons, probes, nodes, edges, keys and cuboids. This sheet collects those formulas for algorithms and data structures, Python, relational databases and data warehousing. Each has its condition, a one-line example of my own and the trap beside it, all checked against the GATE DA 2027 book.
In this guide
Key takeaways
- Selection sort always makes comparisons; insertion sort's shifts equal the number of inversions.
- Dijkstra needs non-negative weights; Bellman–Ford allows negative ones and detects negative cycles.
- Python floor division rounds towards minus infinity, and
roundsends ties to the even integer. - An attribute that never appears on a right-hand side belongs to every candidate key.
- B+ tree order is a floor, never a rounded value.
- dimensions give cuboids, but
ROLLUPforms only groupings.
The terms this sheet uses
is the number of elements and the base-2 logarithm. means "grows exactly like ", and means "at most like ". An inversion is a pair of elements in the wrong order. The load factor of a hash table is , keys over slots.
In a database, a functional dependency says that equal values force equal values. The closure is every attribute that determines. A superkey determines all attributes, and a candidate key is a minimal superkey. A cuboid is one grouping of a data cube.
Searching and sorting
| Formula | Watch out for |
|---|---|
| Binary search worst case: probes | Sorted input with random access |
| Selection sort: comparisons always, at most swaps | Sorted input does not help |
| Insertion sort: comparisons sorted, reverse-sorted | Shifts equal inversions |
| Bubble sort with early exit: best ; swaps equal inversions | Each pass fixes the largest remaining |
| Merging lengths and : at most comparisons | Mergesort needs extra space |
| Quicksort worst: | Sorted input with an end pivot |
| Stable: bubble, insertion, merge | Not stable: selection, quicksort |
Examples: binary search on 100 elements needs at most 7 probes. Selection sort on 10 elements makes 45 comparisons and at most 9 swaps. Insertion sort on makes 2 shifts, one per inversion. Merging lists of 4 and 5 takes at most 8 comparisons.
The master theorem handles . Compare with :
So is , is , and is .
Data structures and hashing
| Formula | Watch out for |
|---|---|
| Chaining: expected search | may exceed 1 |
| Open addressing: unsuccessful at most ; successful at most | Needs |
| Linear probing: | Primary clustering |
| Height in edges: | Edges or levels? Check |
| Leaves (nodes with two children) | Holds for every binary tree |
| Binary tree shapes on nodes: | 1, 2, 5, 14, 42 for to 5 |
| BST operations , | Sorted inserts make a chain |
Examples: at , chaining expects 1.75 probes and open addressing at most 4 for a miss. A tree of height 3 has between 4 and 15 nodes. Six nodes with two children mean 7 leaves.
Trap: Preorder with postorder fixes a binary tree only when it is full. Inorder with either preorder or postorder always fixes it.
Graphs
| Formula | Watch out for |
|---|---|
| The count of odd-degree vertices is even | |
| Simple graph: at most edges; a tree has | A tree has exactly one path between two vertices |
| BFS and DFS: with lists, with a matrix | BFS gives fewest edges, not least weight |
| Back edge in DFS iff a cycle | Topological order iff a DAG |
| Dijkstra with a heap, with an array | Non-negative weights only |
| Bellman–Ford ; Floyd–Warshall | Bellman–Ford detects a reachable negative cycle |
Example: five vertices with degrees summing to 14 have 7 edges. A simple graph on 6 vertices has at most 15 edges.
Python rules that decide answers
These are code, not formulas, but they decide answers just as exactly.
7 / 2is3.5;-7 // 2is-4;-7 % 2is1. The remainder takes the divisor's sign.round(2.5)is2andround(3.5)is4: ties go to the even integer.range(a, b)ands[i:j]stop before the end;s[::-1]reverses.- After
b = a,a += [3]changesbtoo, whilea = a + [3]does not. def f(x, L=[])createsLonce, so calls share and grow the same list.
The book's last-minute sheet covers all seven technical sections like this, with every result's condition beside it. It is part of the GATE DA 2027 book, with 907 questions with worked solutions and 10 full mock tests.
Relational algebra and SQL
| Formula | Watch out for |
|---|---|
| A natural join with no common attribute is a product | |
| Union-compatible relations only | |
| "Paired with every" value of | |
| Safe tuple calculus equals relational algebra |
SQL runs in the order FROM, WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY. Over the values , COUNT(*) is 3, COUNT(col) is 2 and AVG is 6. Any comparison with NULL is unknown, so use IS NULL. NOT IN against a subquery containing NULL returns no rows.
Keys, normal forms and decomposition
| Formula | Watch out for |
|---|---|
| is a superkey iff contains every attribute | Grow until nothing changes |
| 2NF: no non-prime attribute depends on part of a key | Single-attribute keys pass automatically |
| 3NF: for every non-trivial , is a superkey or is prime | Prime means part of some candidate key |
| BCNF: for every non-trivial , is a superkey | BCNF implies 3NF implies 2NF |
| Lossless iff or | BCNF may lose a dependency |
Example: with , and . and appear on no right-hand side, and is every attribute, so is the only key.
Indexing, data preparation and warehousing
| Formula | Watch out for |
|---|---|
| B+ tree order | Take the floor |
| Dense index: one entry per record; sparse: one per block | Sparse needs a sorted file |
| Min-max to : | Use the old range in the fraction |
| z-score: | Divide by the standard deviation, not the variance |
| Decimal scaling: , smallest with every | Choose from the largest absolute value |
| Equal-width bins: width | Equal-frequency bins differ |
| Cuboids: ; with hierarchies | ROLLUP gives groupings |
Examples: , and give . The value 60 on a range 20 to 120 maps to 0.4 on . With mean 50 and standard deviation 8, the value 70 has z-score 2.5. Three dimensions with 3, 2 and 1 levels give cuboids.
Remember: Count, sum, min and max are distributive; average is algebraic; median and mode are holistic. That three-way split decides how a measure rolls up.
Using the sheet in the exam
Count questions are mostly whole numbers, but normalisation answers are decimals; practise both on the GATE virtual calculator. Read the MCQ, MSQ and NAT marking scheme, common to every GATE paper before guessing on an MCQ. If you know the CS syllabus, GATE CS vs GATE DA shows where the database and algorithms core overlaps.
More formula sheets: all of GATE DA · Linear Algebra and Calculus · Machine Learning · Probability and Statistics
Quick revision
- Binary search: probes.
- Selection sort: comparisons always; insertion sort shifts equal inversions.
- Chaining ; open addressing at most for a miss.
- Dijkstra needs non-negative weights.
-7 // 2is-4, andround(2.5)is2.- An attribute on no right-hand side is in every key.
- B+ tree order is .
- Cuboids ;
CUBEgroupings,ROLLUP.
Frequently asked questions
How many comparisons does binary search make in the worst case?
On a sorted array of elements, binary search makes at most probes, from the recurrence . For 100 elements that is . The array must be sorted and allow random access, so binary search on a linked list loses its advantage.
How do you calculate the order of a B+ tree?
An internal node with pointers of bytes and keys of bytes must fit in a block of bytes, so , which gives . With , and , the order is 51. Always take the floor, never round up.
How many cuboids does a data cube have?
With dimensions and no hierarchies, a data cube has cuboids, one for every subset of dimensions. If dimension has levels, not counting the top level all, the count is . In SQL, GROUP BY CUBE over attributes forms groupings, while ROLLUP forms only .
What is the result of -7 // 2 in Python?
In Python 3, -7 // 2 is -4, because floor division rounds towards minus infinity, not towards zero. The remainder -7 % 2 is 1, since the remainder takes the sign of the divisor. True division 7 / 2 gives 3.5. Also note that round(2.5) gives 2, because ties go to the even integer.
When is a decomposition lossless?
Splitting into and is lossless exactly when the common attributes form a key of one side: or holds under the functional dependencies. A 3NF synthesis is always lossless and dependency-preserving. A BCNF decomposition is always lossless but may lose a dependency.
Sources
Dates, fees and the syllabus are set by the GATE 2027 organising institute and can change. Always confirm at gate2027.iitm.ac.in.