Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

GATE CS formula & cheat sheet

25 high-yield formulas, shortcuts and facts, grouped by syllabus chapter. Copy any formula as LaTeX, or switch on Quick Revision Mode to see only the bare equations.

25 cards with explanations. Turn on Quick Revision Mode to hide them.

Regular LanguagesTheory of Computation

  • Pumping lemma for regular languages

    Theorem · Pumping lemma

    ∃p ∀w∈L, ∣w∣≥p: w=xyz,  ∣xy∣≤p,  ∣y∣≥1,  ∀i≥0: xyiz∈L\exists p\ \forall w \in L,\ |w| \ge p:\ w = xyz,\ \ |xy| \le p,\ \ |y| \ge 1,\ \ \forall i \ge 0:\ xy^iz \in L

    Use it only to prove a language is not regular (it is necessary, not sufficient). Pick ww cleverly, e.g. apbpa^pb^p for {anbn}\{a^nb^n\}: yy lies inside the aa's, so pumping breaks the balance.

  • Closure properties of regular languages

    Rule · Closure properties

    Closed under union, intersection, complement, difference, concatenation, Kleene star, reversal, homomorphism and inverse homomorphism.

    Intersection by the product construction (m×nm \times n states); complement by swapping accepting and non-accepting states of a complete DFA. A subset of a regular language need not be regular.

  • Finite automata facts

    Rule · Finite automata

    NFA with n states  ⇒  DFA with at most 2n states\text{NFA with } n \text{ states} \;\Rightarrow\; \text{DFA with at most } 2^n \text{ states}

    NFA, ε\varepsilon-NFA, DFA and regular expressions are equally powerful. The minimal DFA of a regular language is unique up to renaming of states.

Context-Free LanguagesTheory of Computation

  • Pumping lemma for CFLs

    Theorem · Context-free grammars

    w=uvxyz,  ∣vxy∣≤p,  ∣vy∣≥1,  ∀i≥0: uvixyiz∈Lw = uvxyz,\ \ |vxy| \le p,\ \ |vy| \ge 1,\ \ \forall i \ge 0:\ uv^ixy^iz \in L

    Classic non-CFLs: {anbncn}\{a^nb^nc^n\}, {ww}\{ww\}, {an2}\{a^{n^2}\}. Two pumped parts move together, which is why {anbn}\{a^nb^n\} survives but {anbncn}\{a^nb^nc^n\} does not.

  • Closure properties of CFLs and DCFLs

    Rule · Pushdown automata

    CFL: closed under union, concatenation, Kleene star, reversal, homomorphism and intersection with a regular language; not closed under intersection or complement. DCFL: closed under complement; not under union or intersection.

    Counter-example for intersection: {anbncm}∩{ambncn}={anbncn}\{a^nb^nc^m\} \cap \{a^mb^nc^n\} = \{a^nb^nc^n\}, which is not context-free. DPDAs are strictly weaker than NPDAs ({wwR}\{ww^R\} needs non-determinism).

ComputabilityTheory of Computation

  • Chomsky hierarchy

    Rule · Chomsky hierarchy

    Regular⊊CFL⊊CSL⊊Recursive⊊RE\text{Regular} \subsetneq \text{CFL} \subsetneq \text{CSL} \subsetneq \text{Recursive} \subsetneq \text{RE}

    Type 3 regular ↔ finite automaton · Type 2 context-free ↔ PDA · Type 1 context-sensitive ↔ linear bounded automaton · Type 0 unrestricted ↔ Turing machine (RE).

  • Decidability at a glance

    Rule · Undecidability

    Membership: decidable for regular, CFL, CSL and recursive; undecidable for RE. Emptiness: decidable for regular and CFL; undecidable for CSL and above. Equivalence: decidable for regular; undecidable for CFL and above. CFG ambiguity and the halting problem: undecidable.

    Rice's theorem: every non-trivial property of the language accepted by a Turing machine is undecidable. Recursive languages are closed under complement; RE languages are not (L and its complement both RE ⇒ L recursive).

Asymptotic AnalysisAlgorithms

  • Master theorem

    Theorem · Master theorem

    T(n)=aT ⁣(nb)+f(n):{f=O(nlog⁡ba−ε)⇒ Θ(nlog⁡ba)f=Θ(nlog⁡balog⁡kn)⇒ Θ(nlog⁡balog⁡k+1n)f=Ω(nlog⁡ba+ε), af(nb)≤cf(n)⇒ Θ(f(n))T(n) = aT\!\left(\tfrac{n}{b}\right) + f(n):\quad \begin{cases} f = O(n^{\log_b a - \varepsilon}) & \Rightarrow\ \Theta(n^{\log_b a}) \\ f = \Theta(n^{\log_b a}\log^k n) & \Rightarrow\ \Theta(n^{\log_b a}\log^{k+1} n) \\ f = \Omega(n^{\log_b a + \varepsilon}),\ af(\tfrac{n}{b}) \le cf(n) & \Rightarrow\ \Theta(f(n)) \end{cases}

    Compare f(n)f(n) with nlog⁡ban^{\log_b a}. Case 3 needs the regularity condition with c<1c < 1. Examples: 2T(n/2)+n→Θ(nlog⁡n)2T(n/2) + n \to \Theta(n\log n); 4T(n/2)+n2→Θ(n2log⁡n)4T(n/2) + n^2 \to \Theta(n^2\log n); T(n/2)+1→Θ(log⁡n)T(n/2) + 1 \to \Theta(\log n).

  • Common recurrences

    Formula · Recurrences

    T(n)=T(n−1)+1Θ(n)T(n)=T(n−1)+nΘ(n2)T(n)=2T(n−1)+1Θ(2n)T(n)=T(n)+1Θ(log⁡log⁡n)T(n)=2T(n)+log⁡nΘ(log⁡n log⁡log⁡n)\begin{array}{ll} T(n) = T(n-1) + 1 & \Theta(n) \\ T(n) = T(n-1) + n & \Theta(n^2) \\ T(n) = 2T(n-1) + 1 & \Theta(2^n) \\ T(n) = T(\sqrt n) + 1 & \Theta(\log\log n) \\ T(n) = 2T(\sqrt n) + \log n & \Theta(\log n\,\log\log n) \end{array}

    For n\sqrt n recurrences substitute n=2mn = 2^m: T(2m)=S(m)T(2^m) = S(m) turns them into ordinary recurrences in mm.

  • Order of growth and sorting bounds

    Rule · Big-O notation

    1<log⁡log⁡n<log⁡n<n<n<nlog⁡n<n2<2n<n!<nn,log⁡(n!)=Θ(nlog⁡n)1 < \log\log n < \log n < \sqrt n < n < n\log n < n^2 < 2^n < n! < n^n,\qquad \log(n!) = \Theta(n\log n)

    Comparison sorting needs Ω(nlog⁡n)\Omega(n\log n). Merge sort and heap sort: Θ(nlog⁡n)\Theta(n\log n) always. Quick sort: average Θ(nlog⁡n)\Theta(n\log n), worst Θ(n2)\Theta(n^2). Insertion sort: best Θ(n)\Theta(n), worst Θ(n2)\Theta(n^2). Counting sort: O(n+k)O(n + k).

Algorithm DesignAlgorithms

  • BFS and DFS

    Formula · Graph algorithms

    Time: O(V+E) (adjacency list),O(V2) (adjacency matrix);Space: O(V)\text{Time: } O(V + E)\ \text{(adjacency list)},\quad O(V^2)\ \text{(adjacency matrix)};\qquad \text{Space: } O(V)

    BFS gives shortest paths in unweighted graphs. DFS finds cycles, topological order (DAGs) and connected and strongly connected components, all in O(V + E).

  • Shortest-path algorithms

    Formula · Graph algorithms

    Dijkstra O((V+E)log⁡V),Bellman–Ford O(VE),Floyd–Warshall O(V3)\text{Dijkstra } O((V + E)\log V),\qquad \text{Bellman–Ford } O(VE),\qquad \text{Floyd–Warshall } O(V^3)

    Dijkstra (binary heap) fails with negative edge weights. Bellman–Ford handles negative edges and detects negative cycles (V−1V - 1 relaxation rounds, then one check). Floyd–Warshall gives all-pairs shortest paths.

  • Minimum spanning tree

    Formula · Greedy algorithms

    Kruskal O(Elog⁡E),Prim O((V+E)log⁡V) (heap), O(V2) (matrix)\text{Kruskal } O(E\log E),\qquad \text{Prim } O((V + E)\log V)\ \text{(heap)},\ O(V^2)\ \text{(matrix)}

    An MST has V−1V - 1 edges. If all edge weights are distinct, the MST is unique. Both algorithms rely on the cut property: the lightest edge crossing any cut belongs to some MST.

  • Classic dynamic programming problems

    Formula · Dynamic programming

    LCS O(mn),0/1 knapsack O(nW),matrix-chain O(n3),edit distance O(mn)\text{LCS } O(mn),\qquad \text{0/1 knapsack } O(nW),\qquad \text{matrix-chain } O(n^3),\qquad \text{edit distance } O(mn)

    DP applies when a problem has optimal substructure and overlapping subproblems. 0/1 knapsack is pseudo-polynomial: WW is a number, not an input size. Fractional knapsack is solved greedily in O(nlog⁡n)O(n\log n).

Process ManagementOperating Systems

  • Banker's algorithm: safe state

    Rule · Deadlocks

    Needi=Maxi−Allocationi;if Needi≤Work: Work←Work+Allocationi\text{Need}_i = \text{Max}_i - \text{Allocation}_i;\qquad \text{if } \text{Need}_i \le \text{Work}:\ \text{Work} \leftarrow \text{Work} + \text{Allocation}_i

    Start with Work=Available\text{Work} = \text{Available}. Repeatedly pick any unfinished process whose need fits; if all processes can finish, the state is safe and that order is a safe sequence. An unsafe state is not necessarily deadlocked.

  • Minimum resources to avoid deadlock

    Formula · Deadlocks

    n processes, each needing at most k:R≥n(k−1)+1n \text{ processes, each needing at most } k:\qquad R \ge n(k - 1) + 1

    With R=n(k−1)R = n(k-1) every process could hold k−1k-1 and wait forever; one more instance guarantees someone can finish. Four necessary conditions: mutual exclusion, hold and wait, no preemption, circular wait.

  • Scheduling metrics

    Formula · Scheduling

    TAT=CT−AT,WT=TAT−BT,RT=first run−AT\text{TAT} = \text{CT} - \text{AT},\qquad \text{WT} = \text{TAT} - \text{BT},\qquad \text{RT} = \text{first run} - \text{AT}

    SJF minimises average waiting time (when all jobs are available). Round Robin with a very large quantum behaves like FCFS; a very small quantum adds context-switch overhead.

Memory ManagementOperating Systems

  • Effective memory access time with a TLB

    Formula · Page tables

    EMAT=h (t+m)+(1−h) (t+(k+1) m)\text{EMAT} = h\,(t + m) + (1 - h)\,(t + (k + 1)\,m)

    hh = TLB hit ratio, tt = TLB time, mm = memory access time, kk = page-table levels (k=1k = 1 gives t+2mt + 2m on a miss). If TLB lookup is overlapped with memory access, drop tt from the miss term.

  • Effective access time with page faults

    Formula · Virtual memory

    EAT=(1−p) m+p s\text{EAT} = (1 - p)\,m + p\,s

    pp = page-fault rate, ss = page-fault service time (milliseconds, so even a tiny pp dominates). FIFO can show Belady's anomaly; LRU and Optimal cannot.

  • Pages, offset and page-table size

    Formula · Paging

    offset bits=log⁡2(page size),#pages=2logical bitspage size,PT size=#pages×PTE size\text{offset bits} = \log_2(\text{page size}),\qquad \#\text{pages} = \frac{2^{\text{logical bits}}}{\text{page size}},\qquad \text{PT size} = \#\text{pages}\times\text{PTE size}

    Example: 32-bit address, 4 KB pages, 4-byte PTE → 2202^{20} pages, 4 MB4\ \text{MB} page table. Physical frames =physical memorypage size= \dfrac{\text{physical memory}}{\text{page size}}.

Network LayerComputer Networks

  • Subnets and hosts

    Formula · Subnetting

    Usable hosts=2 32−n−2,Subnets from s borrowed bits=2s\text{Usable hosts} = 2^{\,32 - n} - 2,\qquad \text{Subnets from } s \text{ borrowed bits} = 2^{s}

    For a /n/n prefix. The two excluded addresses are the network address (all host bits 0) and the broadcast address (all host bits 1). A /30 gives exactly 2 usable hosts, for point-to-point links.

  • CIDR masks

    Rule · IP addressing

    /24255.255.255.0254/25255.255.255.128126/26255.255.255.19262/27255.255.255.22430/28255.255.255.24014/30255.255.255.2522\begin{array}{lll} /24 & 255.255.255.0 & 254 \\ /25 & 255.255.255.128 & 126 \\ /26 & 255.255.255.192 & 62 \\ /27 & 255.255.255.224 & 30 \\ /28 & 255.255.255.240 & 14 \\ /30 & 255.255.255.252 & 2 \end{array}

    Columns: prefix, mask, usable hosts. Classful ranges (first octet): A 1–126, B 128–191, C 192–223, D (multicast) 224–239. 127.x.x.x is loopback.

Transport LayerComputer Networks

  • TCP window, throughput and BDP

    Formula · Flow control

    Throughput≤WRTT,BDP=bandwidth×RTT\text{Throughput} \le \frac{W}{\text{RTT}},\qquad \text{BDP} = \text{bandwidth} \times \text{RTT}

    The window must be at least the bandwidth-delay product to keep the link full. Without window scaling the advertised window is at most 65,535 bytes. The sender uses min(rwnd, cwnd).

  • TCP congestion control

    Rule · Congestion control

    Slow start: cwnd doubles every RTT (+1 MSS per ACK) until ssthresh. Congestion avoidance: +1 MSS per RTT. Timeout: ssthresh = cwnd/2, cwnd = 1 MSS. 3 duplicate ACKs (Reno fast recovery): ssthresh = cwnd/2, cwnd = ssthresh.

    Slow start is exponential, congestion avoidance is linear (additive increase, multiplicative decrease, AIMD). Tahoe resets cwnd to 1 MSS on both timeout and triple duplicate ACK.

Frequently asked questions

What does the GATE CS cheat sheet cover?
25 revision cards across Regular Languages, Context-Free Languages, Computability, Asymptotic Analysis, Algorithm Design, Process Management, Memory Management, Network Layer, Data Link Layer, Transport Layer, each tied to the GATE CS syllabus.
Can I print it or use it offline?
Yes. Use the Print button for a clean paper copy, and once you have opened the page it stays available offline in the browser or the installed app.
What is Quick Revision Mode?
It hides the explanatory notes so only the formulas and key facts show, for a fast last-minute revision pass.