Computer Science & Applications (Paper 2) (Code 87) · Unit 1 of 10

Discrete Structures & Optimisation

विविक्त संरचनाएँ

Unit overview: the topics below, with their summaries, are the syllabus for this unit. The comprehensive note further down covers every topic in full — explanations, definitions, worked examples, tables, exam points and practice questions — and the short revision note after it is only a quick recap. Standalone one-topic learning pages are not built yet — every topic on this page is covered in the notes and the practice questions below, and each topic card links to those sections.

Premium chapters for this unit

Sets, relations, logic & proof → premium chapter · free preview · ~18 min · 4 practice questions

Graphs & trees → premium chapter · free preview · ~16 min · 4 practice questions

Combinatorics & probability → premium chapter · free preview · ~16 min · 4 practice questions

Linear programming & optimisation → premium chapter · free preview · ~15 min · 4 practice questions

Topics checklist — with weightage (platform estimate from past-question frequency, not an NTA guarantee)

Sets, relations, logic & proof

High weightage

Propositional logic, predicates, proof by induction — the language of CS.

Graphs & trees

High weightage

Paths, cycles, spanning trees, bipartite graphs.

Combinatorics & probability

Medium

Counting, pigeonhole, recurrence relations.

Linear programming & optimisation

Medium

Simplex intuition, duality, assignment/transportation.

Comprehensive unit note · ~20 min read

Discrete mathematics is the language in which computer science is written. While continuous mathematics deals with smooth change, discrete structures deal with distinct, countable objects: statements that are true or false, sets of elements, relations between pairs, graphs made of vertices and edges, and counting arguments that decide how many possibilities exist. Optimisation adds a second question: among all feasible possibilities, which one is best, and how can it be found efficiently. Together, these topics underpin logic programming, database theory, algorithm design, compiler construction, network analysis, and operations research. This unit begins with logic and proof, because every algorithm correctness argument, every database query condition, and every program specification rests on propositions, quantifiers, and valid inference. You will learn to translate English statements into formal logic, test arguments with truth tables, and build proofs by direct argument, contraposition, contradiction, and mathematical induction. The second strand, sets, relations, and functions, gives you the vocabulary for data modelling: equivalence relations partition data into classes, partial orders describe hierarchies and dependencies, and functions formalise mappings from inputs to outputs, including injectivity, surjectivity, and composition. Graphs and trees then turn relations into pictures with powerful theorems. A graph question in an examination rarely asks you to draw alone; it asks whether an Euler trail exists, whether a Hamiltonian cycle can be guaranteed, whether a graph is planar, how many colours suffice, or what a minimum spanning tree costs. Finally, combinatorics and linear programming provide counting and optimisation machinery: permutations and combinations, the pigeonhole principle, inclusion-exclusion, recurrence relations, and linear programming with its graphical method, simplex intuition, duality, and the transportation and assignment problems. Master the definitions precisely, because most errors in this unit come not from arithmetic but from using a term loosely.

Learning objectives

  • Translate statements between English, propositional logic, and predicate logic, and test validity using truth tables and inference rules.
  • Construct proofs by direct proof, contraposition, contradiction, and mathematical induction.
  • Classify relations as reflexive, symmetric, antisymmetric, transitive, equivalence, or partial order, and work with closures and functions.
  • Apply Euler and Hamiltonian criteria, planarity tests, colouring bounds, and spanning-tree algorithms to graphs and trees.
  • Solve counting problems with permutations, combinations, pigeonhole, inclusion-exclusion, and recurrence relations.
  • Formulate linear programs, solve small cases graphically, explain simplex and duality, and model transportation and assignment problems.

Sets, relations, logic & proof

A proposition is a declarative statement that is either true or false, never both. Compound propositions are built with negation, conjunction, disjunction, implication, and biconditional. Implication deserves special care: p implies q is false only when p is true and q is false; in all other cases it is true. Its contrapositive, not q implies not p, is logically equivalent to it, while its converse, q implies p, and its inverse, not p implies not q, are not. A tautology is always true, a contradiction always false, and a contingency is sometimes true. Two formulas are equivalent when they have identical truth-table columns. De Morgan laws, distributive laws, and absorption laws let you simplify formulas, and a formula in disjunctive normal form is a disjunction of conjunctions of literals, while conjunctive normal form is the dual.

Predicate logic adds predicates, variables, and quantifiers. The universal quantifier states that a property holds for every element of a domain, and the existential quantifier states that it holds for at least one element. Order matters: for every x there exists y such that x is less than y is true over the integers, but for every y there exists x with the same property reversed is a different claim. Negating a quantified statement swaps the quantifier and negates the predicate, so the negation of for all x, P(x) is there exists x, not P(x). Arguments are tested by inference rules: modus ponens, modus tollens, hypothetical syllogism, disjunctive syllogism, addition, simplification, and conjunction. An argument is valid when the conclusion must be true whenever all premises are true; validity is not the same as the premises being true in fact.

A set is a collection of distinct objects. Subset, union, intersection, difference, complement, power set, and Cartesian product are the basic operations. A relation from set A to set B is a subset of A cross B. On a single set, a relation may be reflexive (every element relates to itself), irreflexive, symmetric (a related to b implies b related to a), antisymmetric (a related to b and b related to a implies a equals b), or transitive (a related to b and b related to c implies a related to c). An equivalence relation is reflexive, symmetric, and transitive; it partitions the set into disjoint equivalence classes whose union is the whole set, as with congruence modulo n. A partial order is reflexive, antisymmetric, and transitive; its Hasse diagram draws only the covering relations, omitting reflexive loops and transitive edges. The reflexive, symmetric, or transitive closure of a relation is the smallest relation with that property containing the original.

A function f from A to B assigns each element of A exactly one element of B. It is injective (one-to-one) when distinct inputs give distinct outputs, surjective (onto) when every element of B is hit, and bijective when both hold. Composition applies one function after another, and only bijective functions have two-sided inverses. Proof methods build on this foundation. A direct proof assumes the hypothesis and derives the conclusion. Proof by contraposition proves the contrapositive instead. Proof by contradiction assumes the negation of the conclusion and derives an absurdity. Mathematical induction proves a statement P(n) for all natural numbers n by a base case, usually n equals 0 or 1, and an inductive step showing P(k) implies P(k plus 1). Strong induction allows assuming P for all values up to k. Examinations test induction most often on sums, divisibility, and inequalities, and the common failure is a weak inductive step that assumes what must be proved.

Graphs & trees

A graph consists of vertices and edges joining pairs of vertices. In a simple graph there are no loops and no multiple edges. The degree of a vertex is the number of incident edges, with a loop contributing two. The handshaking lemma states that the sum of all degrees equals twice the number of edges, so the number of vertices of odd degree is always even. A path is a sequence of vertices with consecutive pairs joined by edges and no repeated vertex except possibly the endpoints; a cycle is a closed path. A graph is connected when there is a path between every pair of vertices, and a complete graph on n vertices has every pair joined. A bipartite graph has its vertices split into two sets with edges only between sets, never within one set. Two graphs are isomorphic when there is a bijection between their vertex sets preserving adjacency exactly; equal numbers of vertices, edges, and degree sequences are necessary but not sufficient for isomorphism, so a claimed isomorphism must be checked edge by edge.

An Euler path uses every edge exactly once, and an Euler circuit returns to its start. A connected graph has an Euler circuit exactly when every vertex has even degree, and an Euler trail between two distinct vertices exactly when exactly two vertices have odd degree, which must then be the endpoints. A Hamiltonian path visits every vertex exactly once, and a Hamiltonian cycle returns to the start; unlike the Euler case there is no simple necessary and sufficient degree condition, so Hamiltonian questions are usually solved by construction, by exhibiting a cycle, or by a contradiction argument showing no cycle can exist. A planar graph can be drawn in the plane without edge crossings. For a connected planar graph with v vertices, e edges, and f faces, Euler formula gives v minus e plus f equals 2. For a simple planar graph with at least three vertices, e is at most 3v minus 6, and if it is also triangle-free, e is at most 2v minus 4; violating such a bound proves non-planarity. The complete graph K5 and the complete bipartite graph K3,3 are the classic non-planar obstructions.

Graph colouring assigns colours to vertices so adjacent vertices differ. The chromatic number is the smallest number of colours needed. A bipartite graph needs at most two colours, an odd cycle needs three, and the four-colour theorem says every planar graph needs at most four. Greedy colouring in a bad vertex order can use more colours than optimal, so greedy output is an upper bound, not the chromatic number. A tree is a connected acyclic graph. A tree with n vertices has exactly n minus 1 edges, has a unique simple path between any two vertices, and becomes cyclic if any edge is added or disconnected if any edge is removed. A spanning tree of a connected graph is a tree using all its vertices and a subset of its edges. A minimum spanning tree minimises total edge weight. Kruskal algorithm sorts edges by weight and adds an edge unless it creates a cycle, while Prim algorithm grows a tree from a starting vertex by repeatedly adding the cheapest edge to a new vertex. Both are greedy and both are correct for minimum spanning trees, with running time dominated by sorting or by priority-queue operations. Rooted trees model hierarchies and expression evaluation: binary trees, traversal orders (preorder, inorder, postorder), and binary search tree properties are examined through small worked trees rather than large ones.

Combinatorics & probability

Counting begins with two rules. The product rule multiplies the numbers of independent choices, and the sum rule adds the numbers of mutually exclusive cases. A permutation counts arrangements where order matters: the number of permutations of n distinct objects taken r at a time is n factorial divided by (n minus r) factorial. A combination counts selections where order does not matter: n choose r equals n factorial divided by r factorial times (n minus r) factorial, and n choose r equals n choose (n minus r). Permutations with repetitions, permutations of multiset objects, and combinations with repetition each have their own formula, and the examination trap is choosing the wrong model, for example counting ordered selections when the problem asks for committees. The binomial theorem expands (x plus y) to the power n as a sum of terms with binomial coefficients, and Pascal identity builds the coefficients recursively.

The pigeonhole principle states that if more than n objects are placed into n boxes, some box holds at least two objects. Its generalised form says that placing N objects into n boxes forces some box to hold at least the ceiling of N divided by n objects. This principle proves existence without construction, for instance that among a group of people two share a birth month, or that a sequence of numbers contains a repeated remainder. Inclusion-exclusion corrects overcounting when sets overlap: the size of the union of two sets equals the sum of their sizes minus the size of their intersection, and the three-set formula adds back the triple intersection after subtracting pairwise intersections. It is the standard tool for counting onto functions, derangements, and numbers coprime to a given integer.

A recurrence relation defines a sequence term from earlier terms, together with initial conditions. The Fibonacci recurrence, Tower of Hanoi recurrence, and divide-and-conquer recurrences such as T(n) equals 2 T(n over 2) plus n are standard. Linear homogeneous recurrences with constant coefficients are solved by the characteristic equation: assume a solution of the form r to the power n, solve for r, and combine roots, multiplying by n for repeated roots. Non-homogeneous recurrences add a particular solution matched to the forcing term. Generating functions offer an alternative route but are rarely needed beyond recognition. In probability, the sample space lists all outcomes, an event is a subset of it, and probability is the ratio of favourable to total outcomes in an equally likely model. Conditional probability, independence, Bayes theorem, expectation, and variance are examined through small discrete examples: dice, cards, urns, and coin tosses. Remember that independent events satisfy P(A and B) equals P(A) times P(B), while mutually exclusive events satisfy P(A or B) equals P(A) plus P(B); the two concepts are different and are frequently confused.

Linear programming & optimisation

A linear program optimises a linear objective function subject to linear constraints and non-negativity conditions. Decision variables are the quantities to choose, the objective states profit or cost to maximise or minimise, and constraints encode limited resources, demands, or capacities. A feasible solution satisfies all constraints, the feasible region is the set of all feasible solutions, and an optimal solution is a feasible solution with the best objective value. The fundamental theorem of linear programming says that if an optimal solution exists, one occurs at a corner point, or vertex, of the feasible region, provided the region is a convex polyhedron. This is why the graphical method works for two variables: draw each constraint as a line, shade the feasible region, evaluate the objective at each corner, and pick the best value, checking also for unboundedness and infeasibility when the region is empty or open in the improving direction.

The simplex method generalises the graphical idea to many variables. It starts at a corner point, expressed as a basic feasible solution in a tableau, and moves along an edge to a neighbouring corner that improves the objective, repeating until no improving move exists. Slack variables convert less-than-or-equal constraints into equations, surplus variables handle greater-than-or-equal constraints, and artificial variables with the Big-M method or the two-phase method handle equalities and greater-than constraints. Degeneracy, when a basic variable equals zero, can cause cycling in theory, though examinations usually test one or two tableau steps, pivot choice, and the optimality condition rather than full cycling remedies. Duality pairs every primal maximisation problem with a dual minimisation problem: primal constraints become dual variables, primal variables become dual constraints, and the objective coefficients swap with the right-hand sides. Weak duality says any feasible dual value bounds the primal optimum, and strong duality says the two optima are equal when both are feasible and bounded. Complementary slackness links primal and dual optimal solutions and is a favourite short-answer topic.

The transportation problem ships goods from sources with supplies to destinations with demands at minimum cost, with total supply equal to total demand in the balanced case. An initial basic feasible solution is found by the North-West corner rule, the least-cost method, or Vogel approximation method, and optimality is tested and improved with the stepping-stone method or the MODI (modified distribution) method using dual potentials. The assignment problem is the special case with equal numbers of workers and jobs and one assignment each, solved by the Hungarian method: subtract row minima, subtract column minima, cover zeros with the minimum number of lines, and adjust uncovered elements until an assignment using only zeros exists. Unbalanced problems are balanced with dummy sources, destinations, workers, or jobs at zero cost, and prohibited assignments are handled with a very large cost. In examinations, distinguish these models by their structure: transportation allows split shipments, assignment forbids them, and both are linear programs with totally unimodular structure, so integer solutions arise naturally without integer programming.

Key definitions

  • Proposition: A declarative statement that is exactly one of true or false.
  • Tautology: A compound proposition that is true under every assignment of truth values to its variables.
  • Contrapositive: For implication p implies q, the statement not q implies not p, which is logically equivalent to the original.
  • Equivalence relation: A relation that is reflexive, symmetric, and transitive; it partitions its set into disjoint equivalence classes.
  • Partial order: A relation that is reflexive, antisymmetric, and transitive, modelling hierarchy or precedence.
  • Bijective function: A function that is both injective and surjective, and therefore has a two-sided inverse.
  • Euler circuit: A closed trail that uses every edge of a graph exactly once.
  • Hamiltonian cycle: A cycle that visits every vertex of a graph exactly once before returning to the start.
  • Planar graph: A graph that can be drawn in the plane with no edge crossings.
  • Tree: A connected graph with no cycles; a tree on n vertices has exactly n minus 1 edges.
  • Spanning tree: A tree formed from a subset of a connected graph edges that includes every vertex of the graph.
  • Chromatic number: The smallest number of colours needed to colour vertices so adjacent vertices receive different colours.
  • Pigeonhole principle: If more objects than boxes are distributed among boxes, some box contains at least two objects.
  • Recurrence relation: An equation defining a sequence term from earlier terms, together with initial conditions.
  • Feasible region: The set of all solutions satisfying every constraint of a linear program, including non-negativity.
  • Dual problem: The linear program paired with a primal problem by swapping roles of constraints, variables, and objective coefficients.

Formulas

  • Sum of degrees = 2E, where E is the number of edges; hence the number of odd-degree vertices is even.
  • Permutations P(n, r) = n! / (n - r)!; Combinations C(n, r) = n! / (r! (n - r)!).
  • Inclusion-exclusion for two sets: |A union B| = |A| + |B| - |A intersection B|.
  • Euler formula for a connected planar graph: V - E + F = 2, where V is vertices, E edges, F faces.
  • Tree on n vertices has n - 1 edges; complete graph Kn has n(n - 1)/2 edges.
  • Generalised pigeonhole bound: some box holds at least ceil(N / n) objects when N objects go into n boxes.
  • Primal-dual strong duality: if both primal and dual are feasible and bounded, their optimal objective values are equal.

Worked examples

Example 1: Evaluate the truth value of the implication: if 2 plus 2 equals 5, then Paris is in France. Also give its contrapositive.

The antecedent 2 plus 2 equals 5 is false, and the consequent Paris is in France is true. An implication is false only for true antecedent and false consequent, so this implication is true, vacuously. Its contrapositive is: if Paris is not in France, then 2 plus 2 does not equal 5. The contrapositive has the same truth value, true, and must not be confused with the converse, which would be: if Paris is in France, then 2 plus 2 equals 5.

Example 2: A connected graph has 10 vertices, each of degree 3. Does it have an Euler circuit? How many edges does it have?

Sum of degrees equals 10 times 3 equals 30. By the handshaking lemma, twice the number of edges equals 30, so the graph has 15 edges. Every vertex has odd degree 3, not even degree, so the graph cannot have an Euler circuit, and with more than two odd vertices it cannot have an Euler trail either.

Example 3: Solve the recurrence a(n) = 5 a(n-1) - 6 a(n-2) with a(0) = 1 and a(1) = 2.

Assume a(n) equals r to the power n. The characteristic equation is r squared minus 5r plus 6 equals 0, which factors as (r minus 2)(r minus 3) equals 0, so r equals 2 or 3. The general solution is a(n) equals A times 2 to the power n plus B times 3 to the power n. From a(0) equals 1, A plus B equals 1. From a(1) equals 2, 2A plus 3B equals 2. Subtracting twice the first equation from the second gives B equals 0, hence A equals 1. The solution is a(n) equals 2 to the power n. Check: a(2) should be 5 times 2 minus 6 times 1 equals 4, and 2 squared equals 4, correct.

Example 4: Maximise Z = 3x + 2y subject to x + y at most 4, x at most 2, x at least 0, y at least 0. Find the optimum graphically.

The feasible region is bounded by the axes, the line x equals 2, and the line x plus y equals 4. Its corner points are (0,0), (2,0), (2,2), and (0,4). Evaluate Z: at (0,0), Z equals 0; at (2,0), Z equals 6; at (2,2), Z equals 3 times 2 plus 2 times 2 equals 10; at (0,4), Z equals 8. The maximum is 10 at x equals 2, y equals 2. Note that checking only one corner, or forgetting the intersection (2,2), would miss the optimum.

Proof methods compared

MethodWhat you assumeWhat you showTypical use
Direct proofHypothesis PConclusion Q followsAlgebraic identities, divisibility
ContrapositionNot QNot P followsStatements about parity, divisibility
ContradictionP and not QAn absurdityIrrationality, infinitude of primes
InductionBase case and P(k)P(k + 1)Sums, inequalities, recurrence claims

Euler versus Hamiltonian

FeatureEulerHamiltonian
Uses everyEdge exactly onceVertex exactly once
Simple testDegree parity in a connected graphNo simple necessary and sufficient test
Circuit conditionAll vertices even degreeMust exhibit or rule out a cycle
DifficultyPolynomial, easy to testNP-complete in general

Relation properties at a glance

PropertyDefinitionExample
Reflexivea relates to a for all aEquality, divisibility on positive integers
Symmetrica relates to b implies b relates to aSibling relation, equality
Antisymmetrica relates to b and b relates to a implies a equals bLess-than-or-equal, subset
Transitivea relates to b and b relates to c implies a relates to cLess than, divisibility

Diagrams (described)

Truth-table flowchart: list all assignments of variables in binary order, evaluate innermost connectives first, then outer connectives, and read the final column to classify the formula as tautology, contradiction, or contingency.

Hasse diagram for divisibility on the set containing 1, 2, 3, 6: draw 1 at the bottom, 2 and 3 above it, 6 at the top, with edges 1 to 2, 1 to 3, 2 to 6, and 3 to 6; omit the reflexive loops and the transitive edge 1 to 6.

Kruskal minimum spanning tree walkthrough diagram: sort edges by weight ascending, scan them in order, add an edge only if its endpoints are in different components, otherwise skip it, and stop when n minus 1 edges are chosen.

Graphical linear programming diagram: plot each constraint line, shade the side satisfying the inequality, mark the feasible polygon, label each corner, and evaluate the objective at every corner.

Exam points

  • Implication is false only for true antecedent with false consequent; converse and inverse are not equivalent to the original, but the contrapositive is.
  • An equivalence relation partitions a set; the number of equivalence classes and their sizes are favourite counting questions.
  • Euler circuit needs a connected graph with all even degrees; exactly two odd degrees give an Euler trail, not a circuit.
  • A tree on n vertices has n minus 1 edges, and any two vertices are joined by exactly one simple path.
  • K5 and K3,3 are non-planar; use the edge bounds e at most 3v minus 6, and e at most 2v minus 4 for triangle-free graphs, to prove non-planarity.
  • Greedy colouring gives an upper bound only; the chromatic number of an odd cycle is 3 and of a bipartite graph is at most 2.
  • In linear programming, an optimum, when it exists, occurs at a corner point of the feasible region.
  • Duality: a primal maximisation problem has a dual minimisation problem, and under strong duality their optimal values coincide.
  • The assignment problem is solved by the Hungarian method and forbids split assignments, unlike transportation.

Common mistakes

  • Mistake: treating converse and contrapositive as the same. Correction: only the contrapositive is equivalent to the original implication; the converse may differ in truth value.
  • Mistake: claiming two graphs are isomorphic because they share vertex count, edge count, and degree sequence. Correction: those are necessary, not sufficient; you must exhibit an adjacency-preserving bijection or find a structural difference.
  • Mistake: assuming every graph with an Euler trail has an Euler circuit. Correction: a circuit needs all even degrees; exactly two odd degrees give a trail between those two vertices only.
  • Mistake: confusing independent events with mutually exclusive events. Correction: independent events multiply probabilities, mutually exclusive events add them, and non-trivial mutually exclusive events with positive probability are never independent.
  • Mistake: counting ordered arrangements when the problem asks for unordered selections. Correction: divide by r factorial, that is, use combinations, whenever order does not matter.
  • Mistake: in induction, starting the inductive step by assuming P(k plus 1). Correction: assume P(k) and derive P(k plus 1); assuming the goal is circular reasoning.
  • Mistake: evaluating the linear programming objective at only one corner or at an infeasible point. Correction: list every corner of the feasible region, check feasibility, and compare all objective values.

Practice questions from this note (original practice — not official PYQs)

Checking login…

Quick revision: Logic first: implication truth table, contrapositive equivalence, quantifier negation by swapping the quantifier. Relations next: equivalence gives a partition, partial order gives a Hasse diagram, closures add the smallest missing property. Graphs: handshaking lemma, Euler by degree parity, Hamiltonian by construction or contradiction, planarity by Euler formula and edge bounds, trees by n minus 1 edges, minimum spanning trees by Kruskal or Prim. Counting: permutations for order, combinations for selection, pigeonhole for existence, inclusion-exclusion for overlaps, recurrences by characteristic roots. Optimisation: corner-point theorem for linear programming, simplex moves between corners, duality swaps max and min with equal optima, transportation by MODI, assignment by Hungarian. If you can state each definition without hesitation and re-derive the handshaking lemma, the recurrence solution, and one graphical optimum, the unit is secure.

Unit revision note (quick recap)

Discrete mathematics is the language of computer science: logic for correctness, graphs for networks, counting for complexity, and optimisation for resource decisions.

Learning objectives

  • Use propositional/predicate logic and proof
  • Apply graph and tree facts
  • Solve counting and linear-programming basics

Key concepts

  • Tree: A connected acyclic graph. A tree with n vertices has exactly n − 1 edges.
  • Propositional logic: Statements with AND, OR, NOT, implication; truth tables decide validity.
  • Pigeonhole principle: If n+1 items go into n boxes, some box holds at least two.
  • Recurrence: A sequence defined from earlier terms, e.g. T(n) = 2T(n/2) + n.

Formulas

  • Tree edges = n − 1
  • C(n, k) = n! / (k!(n − k)!)

Worked examples

  • C(5,2) = 10. A tree on 7 vertices has 6 edges — a one-line exam question.

Exam points

  • Induction proves a statement for all n; a counterexample disproves a universal claim.
  • Linear programming: feasible region, objective, optimum at a corner (for LP).

Common mistakes

  • Assuming a graph with n−1 edges is a tree — it must also be connected (or acyclic + connected).

Quick revision: Logic, sets, relations, graphs/trees, counting, recurrences, LP basics.

Practice questions from the whole unit bank (31 in the bank)

This unit's practice bank — the note above has its own smaller practice set drawn from the same bank, so a question can appear in both lists. The list below shows the free sample or the full bank depending on your plan.

Checking login…

Related tests

Unit test for this unit (31 bank questions, 38 min) · Full Mock — CS Paper 2 (100 questions) · Combined 150-question mock (180 min). All +2 per correct, no negative marking.

Revision summary

Logic, sets, relations, graphs/trees, counting, recurrences, LP basics.

After revising, take the unit test above, then check your unit-wise report on the Dashboard to find weak topics.