🧠 AI Computer Institute
Content is AI-generated for educational purposes. Verify critical information independently. A bharath.ai initiative.

UGC NET Computer Science & Applications Complete Guide

exam-prepGrades 126 sections

Discrete Structures & Mathematical Foundations

UGC NET Core: Sets, relations, logic, graph theory, combinatorics, number theory basics.

// Set Theory
Universal set U: All elements under consideration
Subset: A ⊆ B if every element of A in B
Power set P(A): All subsets, |P(A)| = 2^|A|

Operations:
Union: A ∪ B = {x | x ∈ A or x ∈ B}
Intersection: A ∩ B = {x | x ∈ A and x ∈ B}
Complement: A' = {x ∈ U | x ∉ A}
Difference: A - B = A ∩ B'

De Morgan's Laws:
(A ∪ B)' = A' ∩ B'
(A ∩ B)' = A' ∪ B'

Cardinality: |A ∪ B| = |A| + |B| - |A ∩ B|

// Relations
Relation R: Subset of A × B
Domain: All first elements
Range: All second elements
Properties:
- Reflexive: (a,a) ∈ R for all a
- Symmetric: (a,b) ∈ R ⟹ (b,a) ∈ R
- Transitive: (a,b),(b,c) ∈ R ⟹ (a,c) ∈ R
- Antisymmetric: (a,b),(b,a) ∈ R ⟹ a=b

Equivalence: Reflexive + Symmetric + Transitive
Partial order: Reflexive + Antisymmetric + Transitive

// Functions
f: A → B (function from A to B)
Domain: A, Codomain: B
Image: f(A) = {f(a) | a ∈ A}
Injective (one-to-one): f(a₁) = f(a₂) ⟹ a₁ = a₂
Surjective (onto): f(A) = B
Bijective: Both injective and surjective

// Combinatorics
Permutations: P(n,r) = n!/(n-r)! (order matters)
Combinations: C(n,r) = n!/(r!(n-r)!) (order doesn't matter)
Binomial: (a+b)^n = Σ C(n,k)a^(n-k)b^k

Pigeonhole principle: n+1 items in n boxes ⟹ one box has ≥2
Inclusion-Exclusion: |A ∪ B ∪ C| = |A|+|B|+|C|-|A∩B|-|B∩C|-|A∩C|+|A∩B∩C|

// Number Theory
GCD (Greatest Common Divisor): Largest number dividing both
LCM (Least Common Multiple): Smallest multiple of both
Euclidean algorithm: GCD(a,b) = GCD(b, a mod b)

Modular arithmetic: a ≡ b (mod m) if m | (a-b)
Properties: (a+b) mod m = ((a mod m)+(b mod m)) mod m
Fermat's Little Theorem: a^(p-1) ≡ 1 (mod p) if p prime
Euler's Theorem: a^φ(m) ≡ 1 (mod m) if gcd(a,m)=1

Prime numbers: No divisors except 1 and self
Sieve of Eratosthenes: O(n log log n) to find primes ≤ n

// Propositional Logic
Tautology: Always true
Contradiction: Always false
Contingency: Sometimes true
Logical equivalence: Same truth table

Modus ponens: p, p→q ⟹ q
Modus tollens: ¬q, p→q ⟹ ¬p
Contrapositive: p→q ≡ ¬q→¬p

// First-Order Logic
Predicates: P(x) true for some x
Quantifiers:
∀x P(x): For all x, P(x) is true
∃x P(x): There exists x such that P(x) is true
¬(∀x P(x)) ≡ ∃x ¬P(x)  (De Morgan for quantifiers)
¬(∃x P(x)) ≡ ∀x ¬P(x)

// Proof Techniques
Direct proof: Assume premise, derive conclusion
Proof by contradiction: Assume opposite, derive falsehood
Proof by induction: Base case + inductive step
Proof by contrapositive: Prove ¬q→¬p instead of p→q
Proof by exhaustion: Check all cases

Data Structures & Algorithms Advanced

UGC NET Essential: Complex DS, algorithm design paradigms, advanced analysis.

// Advanced Data Structures

Graph representations:
Adjacency matrix: O(V²) space, O(1) edge check
Adjacency list: O(V+E) space, proportional to edges

Graph algorithms:
DFS: O(V+E) time, uses stack
BFS: O(V+E) time, uses queue

Shortest path:
Dijkstra: O((V+E)log V) with heap, non-negative weights
Floyd-Warshall: O(V³) all-pairs
Bellman-Ford: O(VE) handles negative weights, detects negative cycles

Minimum Spanning Tree:
Kruskal: O(E log E) sort edges, Union-Find
Prim: O(V²) or O((V+E)log V) with heap

// Advanced Tree Structures
AVL tree: Balanced BST, height = O(log n)
Rotation: Single, double to maintain balance

Red-Black tree: Approximate balance
Properties: Color, no two red consecutive, black-height
Operations: O(log n)

B-tree: Generalization of BST for disk
Order m: m-1 keys, m children per node
Use: Databases, file systems

Segment tree: Range queries and updates
Build: O(n), Query: O(log n), Update: O(log n)
Use: Range sum, min/max in interval

Fenwick tree (Binary Indexed Tree):
Prefix sum: O(log n)
Update: O(log n)
Space: O(n)
Simpler than segment tree

Trie: Prefix tree
Operations: O(m) where m = key length
Use: Autocomplete, IP routing, spell checker

// Hashing
Hash function: h(k) = k mod m
Collision handling:
Linear probing: Next slot if occupied
Quadratic probing: Offset by i² where i = attempt
Double hashing: Use second hash function
Chaining: List at each bucket

Load factor λ = n/m
Average time linear probing: 1 + 1/(2(1-λ))
Average time chaining: 1 + λ

// Divide and Conquer
Problem: Break into subproblems
Solve: Recursively solve subproblems
Combine: Merge solutions
Example: Merge sort, quick sort

Master theorem: T(n) = aT(n/b) + f(n)
Case 1: f(n) = O(n^(log_b(a)-ε)) ⟹ T(n) = O(n^log_b(a))
Case 2: f(n) = Θ(n^log_b(a) log n) ⟹ T(n) = O(n^log_b(a) log n)
Case 3: f(n) = Ω(n^(log_b(a)+ε)) ⟹ T(n) = O(f(n))

// Dynamic Programming
Optimal substructure: Optimal solution from optimal subproblems
Overlapping subproblems: Reuse computations
Memoization: Top-down with caching
Tabulation: Bottom-up table building

Fibonacci: O(2^n) recursive ⟹ O(n) DP
Knapsack: O(nW) for n items, capacity W
Edit distance: O(mn) for strings of length m,n
Longest Common Subsequence: O(mn)

// Greedy Algorithms
Local optimal choice at each step
Doesn't always give global optimum
Examples: Activity selection, Huffman coding, Kruskal's MST

Activity selection:
Sort by end time
Greedily pick earliest end
Proof: Greedy optimal by exchange argument

// Backtracking
DFS with pruning
Abandon branch if no solution possible
N-queens: O(N!) worst case
Sudoku solver: Constraint satisfaction

// String Algorithms
Pattern matching:
Naive: O(nm) for pattern m, text n
KMP (Knuth-Morris-Pratt): O(n+m) using failure function
Boyer-Moore: O(n/m) average, fast practical
Rabin-Karp: O(n+m) with hashing

Regular expressions: NFA/DFA matching

// Number Theory Algorithms
GCD: Euclidean O(log min(a,b))
Modular exponentiation: Fast exponentiation O(log n)
Prime checking: Miller-Rabin probabilistic O(k log n)
Factorization: Pollard's rho, quadratic sieve

// Randomized Algorithms
Deterministic: Always correct answer
Las Vegas: Always correct, random time (randomized quicksort)
Monte Carlo: Random time & correctness (probabilistic primality)
Complexity: Expected time analysis

Randomized quicksort: E[T(n)] = O(n log n)
Probability bounds: Markov, Chebyshev inequalities

Programming Languages & Software Engineering

UGC NET Coverage: Paradigms, OOPS, modularity, design patterns, quality metrics.

// Programming Paradigms

Imperative: How to solve (statements)
Declarative: What to solve (expressions)

Procedural: Functions, top-down (C, Pascal)
Object-Oriented: Objects, encapsulation (Java, C++)
Functional: Functions as first-class (Lisp, Haskell)
Logic: Rules and facts (Prolog)

// Object-Oriented Programming
Encapsulation: Hide internal, expose interface
Inheritance: Reuse code, hierarchy
Polymorphism: Same interface, different behavior
Abstraction: Define interface, hide implementation

Classes: Blueprints for objects
Objects: Instances of classes
Methods: Functions on objects
Properties: Data on objects

Access modifiers:
public: Accessible everywhere
private: Only within class
protected: Class and subclasses
package (default): Class and package

// Design Patterns
Creational:
- Singleton: Only one instance
- Factory: Create objects without specifying classes
- Builder: Construct complex objects step-by-step

Structural:
- Adapter: Interface conversion
- Decorator: Add functionality dynamically
- Facade: Simplified interface

Behavioral:
- Observer: Notify multiple listeners
- Strategy: Encapsulate algorithms
- State: Object behavior by state

// Modularity
Module: Self-contained unit
Cohesion: Internal relatedness (high = good)
Coupling: Dependencies between modules (low = good)
Information hiding: Hide internal details

// Code Quality Metrics
Lines of code (LOC): Size (not quality)
Cyclomatic complexity: Number of paths (≤10 good)
Code coverage: % of code executed by tests (>80% good)
Technical debt: Cost of poor practices

// Testing
Unit testing: Individual functions
Integration testing: Modules together
System testing: Entire system
Acceptance testing: Customer requirements

White box (glass box): Know internal structure
Black box: Don't know internal structure
Gray box: Partial knowledge

Test-Driven Development (TDD):
Write test first
Implement code
Refactor
Red-Green-Refactor cycle

// Version Control
Git: Distributed version control
Commit: Save changes with message
Branch: Parallel development
Merge: Combine branches
Conflict: Resolve diverged changes
Tag: Mark releases

// Documentation
Code comments: Why, not what
API documentation: Function signatures, examples
Architecture documentation: System design
User documentation: How to use

// Software Process Models
Waterfall: Sequential phases
Spiral: Iterative with risk analysis
Agile: Incremental, adaptive
DevOps: Automation, continuous deployment

// Refactoring
Improve code structure without changing behavior
Extract method: Move code to function
Rename: Better variable names
Simplify: Reduce complexity
Remove duplication: DRY principle

// Code Smells (Warning signs)
Duplicate code: Extract to function
Long methods: Break into smaller
Large classes: Split responsibility
Long parameter list: Use objects
Too many conditionals: Strategy pattern

Operating Systems & Concurrency

UGC NET Deep Dive: Processes, synchronization, scheduling, memory, file systems.

// Processes & Threads

Process:
- Address space: Stack, heap, data, code
- Process Control Block: pid, state, registers
- Context switch: Save/restore state

Thread:
- Shared address space
- Separate stack per thread
- Lighter weight than process

Multi-threading:
- Concurrency: Parallel execution on single CPU
- Parallelism: True parallel on multiple CPUs
- Thread-safe: Consistent in concurrent access

// Synchronization Primitives

Semaphore:
- Wait (P): Decrement if positive, else wait
- Signal (V): Increment, wake one waiter
- Binary semaphore: Value 0 or 1
- Counting semaphore: Any non-negative value

Mutex: Mutual exclusion lock
- Lock: Acquire, fail if held
- Unlock: Release

Condition variable:
- Wait: Release lock, wait for signal
- Signal: Wake one waiter
- Broadcast: Wake all waiters

Monitor:
- Encapsulates shared data
- Methods mutually exclusive
- Built-in condition variables

// Classic Synchronization Problems

Producer-Consumer:
- Buffer of size n
- Producer: Add if space
- Consumer: Remove if not empty
- Semaphores: empty (n), full (0), mutex (1)

Reader-Writer:
- Multiple readers OK
- Writers exclusive
- Prevent writer starvation
- Use read-write locks

Dining Philosophers:
- 5 philosophers, 5 chopsticks
- Deadlock: All hold one, wait for next
- Solutions: Asymmetric, philosopher picks even first
- Or: Limited diners, waiter coordinates

Sleeping Barber:
- Barber sleeps if no customers
- Customers wait if barber busy
- Chairs in waiting room

// Deadlock

Conditions (all must hold):
1. Mutual exclusion: Resource not shared
2. Hold and wait: Hold while requesting
3. No preemption: Can't force release
4. Circular wait: Cycle in resource graph

Prevention: Break one condition
Avoidance: Check safety before allocation
Detection & recovery: Detect then restart

Banker's algorithm (Avoidance):
- Available: Free resources
- Allocated: Current allocation
- Need: Maximum - current
- Request: Checked for safety

Safe state: No deadlock possible
Algorithm: Find safe sequence

// CPU Scheduling

Preemptive: Timer interrupt, switch
Non-preemptive: Process yields

Algorithms:
FCFS (First Come First Served):
  - Non-preemptive
  - Fair but high average wait
  - Convoy effect: Long process ahead

SJF (Shortest Job First):
  - Optimal average wait
  - Non-preemptive: Don't know duration
  - Preemptive (SRTF): Can switch to shorter

Priority:
  - High priority first
  - Starvation: Low priority never runs
  - Aging: Increase priority over time

Round Robin (Time quantum q):
  - Fair, each process gets time slice
  - q large: Behaves like FCFS
  - q small: High overhead
  - Good for interactive

Multi-level feedback queue:
  - Multiple queues with priorities
  - Process moves between queues
  - Interactive/batch distinction

// Virtual Memory

Paging:
- Divide memory into frames
- Divide address space into pages
- Page table: Logical → Physical
- Page fault: Page not in memory, load from disk

TLB (Translation Lookaside Buffer):
- Cache page table entries
- Hit: 1 cycle, Miss: ~100 cycles
- Hit ratio crucial for performance

Page replacement:
- FIFO: Simple, poor performance
- LRU (Least Recently Used): Good, complex
- Second chance: Approximate LRU
- Clock algorithm: Efficient LRU

Working set:
- Pages actively used
- Memory > working set: Good
- Memory < working set: Thrashing

// File Systems

Inode: File metadata
- Permissions, owner, timestamps
- Block pointers: Direct and indirect

Directory: Name → Inode mapping
Hard link: Same inode, multiple names
Symbolic link: Path to another file

File organization:
- Contiguous: Entire file consecutive
- Linked: Blocks linked with pointers
- Indexed: Index block points to data blocks

Free space management:
- Bitmap: Bit per block
- Linked list: Free blocks linked
- Free list: List of free block ranges

Journaling: Log changes before applying
- Recovery: Replay log after crash
- Atomic: All-or-nothing operations

Database Systems & SQL

UGC NET DBMS: Data modeling, normalization, SQL, transactions, optimization.

// Entity-Relationship Model (ER)

Entity: Real-world object
Attribute: Property of entity
Relationship: Association between entities

Cardinality:
- One-to-one: 1:1
- One-to-many: 1:N
- Many-to-many: M:N

Participation:
- Total: Every entity participates
- Partial: Some entities participate

Weak entity: Depends on another entity
Identifying relationship: Links weak to strong

// Relational Model

Normalization:
1NF: Atomic attributes
  - No multivalued attributes
  - Decompose if needed

2NF: 1NF + no partial dependency
  - Non-prime → part of key not allowed
  - Decompose by partial FD

3NF: 2NF + no transitive dependency
  - Non-prime → non-prime not allowed
  - Decompose by transitive FD

BCNF: Every determinant is candidate key
  - Stricter than 3NF
  - Prevents all anomalies

// Functional Dependencies & Keys

FD: X → Y means X determines Y
Super key: Uniquely identifies tuple
Candidate key: Minimal super key
Primary key: Chosen candidate key

Closure: Set of attributes implied by FD
Armstrong's axioms:
  - Reflexivity: If Y ⊆ X then X → Y
  - Augmentation: If X → Y then XZ → YZ
  - Transitivity: If X → Y and Y → Z then X → Z

Derived:
  - Union: X → Y and X → Z implies X → YZ
  - Decomposition: X → YZ implies X → Y and X → Z
  - Pseudotransitivity: X → Y and YZ → W implies XZ → W

// SQL & Query Processing

SELECT: What columns
FROM: What tables
WHERE: Conditions on rows
GROUP BY: Partition rows
HAVING: Conditions on groups
ORDER BY: Sort result

Joins:
- INNER: Only matching
- LEFT: All left + matching right
- RIGHT: All right + matching left
- FULL OUTER: All from both
- CROSS: Cartesian product

Subqueries:
- Scalar: Returns one value
- Row: Returns one tuple
- Table: Returns multiple rows/columns
- Correlated: References outer query

Indexes:
- Primary key: Unique, not null
- Unique: Unique values allowed
- B-tree: Range queries
- Hash: Exact match only

// Query Optimization

Cost estimation:
- Selectivity: Fraction matching condition
- Cardinality: Number of rows
- I/O cost: Dominant factor

Join order:
- Different orders different costs
- Smaller intermediate result better
- Join algorithms: Nested loop, sort-merge, hash

Optimization strategies:
- Push predicates down (early filtering)
- Use indexes
- Avoid cartesian products
- Parallelize independent operations

// Transaction Management

ACID:
- Atomicity: All or nothing
- Consistency: Valid state to valid state
- Isolation: Concurrent independence
- Durability: Persistent after commit

Anomalies:
- Dirty read: Read uncommitted
- Non-repeatable read: Data changes between reads
- Phantom read: Rows appear/disappear

Isolation levels:
- Read uncommitted: Allows dirty reads
- Read committed: No dirty reads
- Repeatable read: No non-repeatable reads
- Serializable: Full isolation

Concurrency control:
- Locking: Shared, exclusive
- Two-phase locking: Growing, shrinking
- Deadlock detection: Cycle in wait-for graph
- Timestamping: Order transactions by timestamp

Recovery:
- Undo: Revert uncommitted changes
- Redo: Replay committed changes
- Force: Write before commit
- No-steal: Don't write before commit

// Distributed Databases

CAP theorem:
- Consistency: All see same data
- Availability: Always responding
- Partition tolerance: Network failure
- Can guarantee at most 2

Replication:
- Master-slave: One writes, many read
- Multi-master: Multiple write

Sharding:
- Horizontal: Rows split across servers
- Vertical: Columns split

Networking, Security & Emerging Topics

UGC NET Final Topics: Network security, cryptography, web technologies, cloud, blockchain basics.

// Network Security

Threats:
- Eavesdropping: Passive listening
- Modification: Active tampering
- Masquerade: False identity
- Replay: Reuse captured messages
- Denial of service: Overwhelm resource

Security services:
- Authentication: Verify identity
- Authorization: Check permissions
- Confidentiality: Hide content
- Integrity: Prevent tampering
- Non-repudiation: Can't deny

// Cryptography

Symmetric (Secret key):
- DES: 56-bit key, 64-bit blocks (weak now)
- 3DES: Apply DES three times
- AES: 128-bit blocks, 128/192/256-bit keys
- Efficient but key distribution problem

Asymmetric (Public key):
- RSA: Factor n = p×q, c = m^e mod n
- Requires: p, q secret; e, n public
- Decryption: m = c^d mod n where d = e^(-1) mod φ(n)

Hash functions:
- MD5: 128-bit (broken, don't use)
- SHA-1: 160-bit (deprecated)
- SHA-256: 256-bit (secure)
- Collision resistant: Different inputs → different hash

Digital signature:
- Sign: s = h(message)^d mod n (RSA)
- Verify: h(message) = s^e mod n
- Proves authentication and non-repudiation

// Web Security

HTTPS: HTTP over TLS/SSL
- Certificates: Prove website identity
- Session key: Encrypt messages
- Man-in-the-middle: Certificate prevents

Common vulnerabilities:
- SQL injection: Malicious SQL via input
- XSS (Cross-Site Scripting): Inject JavaScript
- CSRF (Cross-Site Request Forgery): Unauthorized action
- XXE (XML External Entity): Process external entities

Protection:
- Input validation: Sanitize user input
- Output encoding: Escape special characters
- CSP (Content Security Policy): Restrict script source
- CORS: Cross-Origin Resource Sharing

// Web Technologies

HTML: Structure
CSS: Style
JavaScript: Interactivity

REST (Representational State Transfer):
- GET: Retrieve
- POST: Create
- PUT: Update
- DELETE: Remove
- Stateless: Each request independent

JSON: Lightweight data format
XML: Structured document format
API: Application Programming Interface

// Cloud Computing

Infrastructure as a Service (IaaS):
- Virtualized computing resources
- AWS EC2, Azure VMs

Platform as a Service (PaaS):
- Runtime environment
- Heroku, Google App Engine

Software as a Service (SaaS):
- Web applications
- Salesforce, Microsoft 365

Advantages: Scalability, flexibility, cost
Challenges: Security, vendor lock-in, latency

// DevOps

Continuous Integration (CI):
- Frequently merge code
- Automated tests
- Early bug detection

Continuous Deployment (CD):
- Automatically deploy to production
- Monitoring, rollback

Containerization:
- Docker: Package with dependencies
- Kubernetes: Orchestrate containers
- Benefits: Portability, isolation

// Blockchain Basics

Distributed ledger: Copy on many nodes
Block: Data + hash of previous block
Chain: Linked blocks
Immutability: Changing past requires recalculating all hashes

Proof of Work: Miners solve puzzle (slow, secure)
Proof of Stake: Validators chosen by stake (fast, less secure)

Smart contracts: Code on blockchain
Applications: Cryptocurrency, supply chain, voting

// Emerging Technologies

Quantum computing:
- Qubits: Superposition 0, 1
- Entanglement: Correlated qubits
- Threat: RSA broken by Shor's algorithm

AI & Machine Learning:
- Neural networks: Deep learning
- NLP: Language understanding
- Computer vision: Image analysis

IoT (Internet of Things):
- Connected devices
- Big data: Processing massive datasets
- Edge computing: Processing at device

More Cheat Sheets