⚡ TechVani: AI, Technology, Apps, Coding & Digital World
TechVaniAI • Technology • Apps • Coding • Digital World
HomeAI & TechAppsCodingFree AI ToolsStudent TechSecurityAboutContactPrivacy
TECHVANI // LEARN. BUILD. TEST.

Learn the tech. Build the idea.

Clear study notes, tested lab files and practical guides for coding, AI and digital safety.

Explore Latest →
šŸ¤– AI & TechAI news, tools & guides šŸ“± Apps & ToolsUseful apps & websites šŸ’» CodingProgramming & web development šŸŽ“ Student TechStudy & career technology šŸ” Cyber SecuritySafety & awareness

Latest Posts

Circuit Notebook theme

Exam Notes

šŸ“š BTech CSE Exam Notes

Find Semester 1-8 subjects in one place. Choose a semester and open the notes you need. This is a general study guide, not an official syllabus.

Open Exam Notes →🧪 Open Lab Files →

Exam Numericals & Study Series

Practice CPU scheduling and explore OS and DBMS topics in separate, easy-to-follow parts. New topics will appear in the hub as they are published.

Open Numericals Hub →

Start here and stay in touch

New to TechVani? Start with our free AI tools guide for students. It covers which tools to try and what to check before relying on an answer.

For step-by-step videos, visit SiteSudhar on YouTube.

Join TechVani on WhatsApp

Get new AI tools and coding guides in your WhatsApp Updates tab.

Browse Topics

Popular Posts

TechVani

Discrete Structures | Semester 3 Core Notes

Semester 3 - Page 3: Discrete Structures. 36 numbered topics, highlighted definitions, worked examples, answered exam questions, three diagrams and four complete Python 3 checks. General common-core BTech CSE guide, not an official assessed syllabus or past-paper prediction. Compare your assigned outline.

Proof versus computation: finite enumeration checks the cases actually enumerated; it does not prove an unrestricted theorem. State domains and hypotheses before applying a formula. Run each Python block separately. Relation/graph elements must be hashable. The graph block accepts only simple undirected graphs, rejecting loops and duplicate edges.

Topic map

  1. Propositions and connectives
  2. Implication and equivalence
  3. Truth tables and normal forms
  4. Logical laws and inference
  5. Predicates and quantifiers
  6. Proof methods
  7. Sets and operations
  8. Power sets and products
  9. Functions and mappings
  10. Composition, inverse and cardinality
  11. Relations and their properties
  12. Relation matrices and closure
  13. Equivalence and partitions
  14. Partial orders and Hasse diagrams
  15. Lattices and bounds
  16. Boolean algebra
  17. Addition and multiplication rules
  18. Permutations and combinations
  19. Repetition and stars-and-bars
  20. Binomial theorem and identities
  21. Inclusion-exclusion
  22. Pigeonhole principle
  23. Finite probability
  24. Mathematical induction
  25. Strong induction and invariants
  26. Recurrences and solving
  27. Generating functions
  28. Divisibility and Euclidean algorithm
  29. Modular arithmetic
  30. Algebraic structures
  31. Graphs and degree sum
  32. Paths, connectivity and trees
  33. Euler and Hamilton routes
  34. Coloring, bipartite and planarity
  35. Directed graphs and matching
  36. Exam revision and limits

1. Propositions and connectives

A proposition has a truth value. Negation, conjunction, disjunction, implication and biconditional combine propositions.

Worked example: p true, q false: p AND q false, p OR q true, p implies q false.
Exam question: Is an open sentence x>3 a proposition by itself?
Answer: Not until its variable is assigned or quantified over a domain.

2. Implication and equivalence

p implies q is equivalent to NOT p OR q. It is false only for true p and false q. Biconditional requires equal truth values.

Worked example: p false, q false makes p implies q true, not evidence of a causal relation.
Exam question: Does implication prove its converse?
Answer: No. p implies q does not generally imply q implies p.

3. Truth tables and normal forms

A truth table examines every Boolean valuation. A tautology is always true, contradiction always false, contingency sometimes true. DNF is an OR of AND terms; CNF an AND of OR clauses.

Worked example: p OR NOT p is a tautology; p AND NOT p is a contradiction.
Exam question: How many rows for n variables?
Answer: 2 to the power n; avoid omitting valuations.

Truth-table check

from itertools import product

def implies(p, q):
    if type(p) is not bool or type(q) is not bool:
        raise TypeError("Boolean inputs required")
    return (not p) or q

print("p q and implies de_morgan")
for p, q in product([True, False], repeat=2):
    law = (not (p and q)) == ((not p) or (not q))
    print(int(p), int(q), int(p and q), int(implies(p, q)), int(law))
try:
    implies(1, False)
except TypeError:
    print("non-Boolean rejected")

Checked output:

p q and implies de_morgan
1 1 1 1 1
1 0 0 0 1
0 1 0 1 1
0 0 0 1 1
non-Boolean rejected

4. Logical laws and inference

De Morgan swaps AND/OR under negation. Modus ponens uses p and p implies q to conclude q; modus tollens uses NOT q to conclude NOT p.

Worked example: NOT(p AND q) equals NOT p OR NOT q in all four rows.
Exam question: Is affirming the consequent valid?
Answer: No. q and p implies q do not force p.

5. Predicates and quantifiers

Always state the domain. For all x and there exists x are different. Negating a quantifier swaps it and negates its predicate.

Worked example: NOT(for all integers x, x even) means there exists an integer x that is not even; 3 is a witness.
Exam question: May quantified variable order be swapped freely?
Answer: No. For all x there exists y can differ from there exists y for all x.

6. Proof methods

Direct proof starts with hypotheses; contrapositive proves NOT q implies NOT p; contradiction assumes the claim false; a counterexample disproves a universal statement..

Worked example: Even a=2m and b=2n give a+b=2(m+n), proving even plus even is even.
Exam question: Do several examples prove a universal claim?
Answer: No. They support intuition but do not cover all cases.

7. Sets and operations

Union, intersection, difference and complement depend on a stated universe. Empty set and a set containing the empty set differ.

Worked example: A={1,2,3}, B={2,3,4}: union {1,2,3,4}, intersection {2,3}, A-B={1}.
Exam question: Is the empty set a subset of every set?
Answer: Yes. There is no element that violates the subset condition.

8. Power sets and products

An n-element finite set has 2^n subsets. A Cartesian product uses ordered pairs and has size(A)*size(B) elements for finite sets.

Worked example: A={a,b} has four subsets; three-element A and B give nine ordered pairs.
Exam question: Does A times B generally equal B times A?
Answer: No. Ordered coordinates have different roles.

9. Functions and mappings

A function assigns exactly one codomain value to each domain element. Injective means distinct inputs have distinct outputs; surjective means every codomain element is reached.

Worked example: f(x)=x+1 from {1,2,3} to {2,3,4} is bijective.
Exam question: Can changing only the codomain change surjectivity?
Answer: Yes. Extra unreached codomain elements make it non-surjective.

10. Composition, inverse and cardinality

Composition g after f requires f's outputs to lie in g's domain. A two-sided inverse function exists exactly for a bijection. Finite equal cardinality alone does not make a given map bijective.

Worked example: f(x)=x+1, g(x)=2x gives g(f(3))=8; f(g(3))=7.
Exam question: Are all infinite sets the same size?
Answer: No. Integers are countable, while real numbers are uncountable.

11. Relations and their properties

A relation on A is a subset of A times A. Check reflexive, symmetric, antisymmetric and transitive independently.

Worked example: The usual <= on integers is reflexive, antisymmetric and transitive, but not symmetric.
Exam question: Does antisymmetric mean not symmetric?
Answer: No. Equality is both symmetric and antisymmetric.

12. Relation matrices and closure

A finite relation can use a 0/1 matrix. Boolean composition checks intermediate elements. Reflexive closure adds diagonal pairs; transitive closure adds pairs reachable by paths.

Worked example: Edges 0->1 and 1->2 force 0->2 in transitive closure.
Exam question: Does transitive closure always add every diagonal?
Answer: No. Reflexive-transitive closure does; transitive closure adds self-reachability only when a positive-length cycle exists.

Finite relation properties and transitive closure

def relation_check(domain, relation):
    # Domain elements and pairs must be hashable.
    domain, relation = set(domain), set(relation)
    if any(not isinstance(pair, tuple) or len(pair) != 2 or
           pair[0] not in domain or pair[1] not in domain
           for pair in relation):
        raise ValueError("pairs must stay inside the domain")
    reflexive = all((a, a) in relation for a in domain)
    symmetric = all((b, a) in relation for a, b in relation)
    antisymmetric = all(a == b or (b, a) not in relation
                        for a, b in relation)
    transitive = all((a, c) in relation for a in domain
                     for b in domain for c in domain
                     if (a, b) in relation and (b, c) in relation)
    return reflexive, symmetric, antisymmetric, transitive

def closure(domain, relation):
    domain, result = set(domain), set(relation)
    relation_check(domain, result)  # validate before computing
    for k in domain:
        for i in domain:
            for j in domain:
                if (i, k) in result and (k, j) in result:
                    result.add((i, j))
    return result  # positive-length reachability, not automatic reflexivity

D = {0, 1, 2}
R = {(0, 1), (1, 2)}
print("reflexive symmetric antisymmetric transitive:", relation_check(D, R))
print("closure:", sorted(closure(D, R)))
E = {(a, b) for a in range(6) for b in range(6) if (a - b) % 3 == 0}
print("mod 3 properties:", relation_check(range(6), E))
try:
    relation_check(D, {(0, 9)})
except ValueError:
    print("outside-domain pair rejected")

Checked output:

reflexive symmetric antisymmetric transitive: (False, False, True, False)
closure: [(0, 1), (0, 2), (1, 2)]
mod 3 properties: (True, True, False, True)
outside-domain pair rejected

13. Equivalence and partitions

An equivalence relation is reflexive, symmetric and transitive. Its classes form disjoint nonempty blocks covering the domain.

Worked example: Modulo 3 congruence on {0,1,2,3,4,5} gives classes {0,3},{1,4},{2,5}.
Exam question: Can distinct equivalence classes overlap?
Answer: No. An overlap forces them to be the same class.

14. Partial orders and Hasse diagrams

A partial order is reflexive, antisymmetric and transitive. Hasse diagrams omit loops and transitive edges, drawing larger elements higher under the chosen order.

Worked example: Divisibility on {1,2,3,6}: 1 below 2 and 3, both below 6; 2 and 3 are incomparable.
Exam question: Is every partial order total?
Answer: No. A total order requires every pair to be comparable.
6231
Divisibility on {1,2,3,6}: higher means divisible by the lower element. Loops and the transitive 1-to-6 edge are omitted.

15. Lattices and bounds

A lattice has a unique greatest lower bound and least upper bound for every pair. Minimum/maximum elements differ from merely minimal/maximal elements.

Worked example: Under divisibility on {1,2,3,6}, meet(2,3)=1 and join(2,3)=6.
Exam question: Do all posets form lattices?
Answer: No. Some pairs lack a meet or join within the set.

16. Boolean algebra

Boolean operations obey distributive and complement laws. Power-set union/intersection/complement give a Boolean algebra relative to a universe.

Worked example: Absorption A union (A intersection B)=A; logically p OR (p AND q)=p.
Exam question: Is ordinary arithmetic plus the same as Boolean OR?
Answer: No. Boolean 1 OR 1 is 1, while arithmetic 1+1 is 2.

17. Addition and multiplication rules

Add disjoint alternatives; multiply successive choices when the number of choices per stage is stated. Overlap needs correction.

Worked example: Three shirts and two trousers give six outfits; disjoint three red/two blue pen choices give five.
Exam question: Can overlapping categories simply be added?
Answer: No. Elements in the overlap would be counted twice.

18. Permutations and combinations

For distinct objects, ordered r-selections are n!/(n-r)!; unordered choices are n!/(r!(n-r)!). State repetition and distinguishability.

Worked example: Four books have 24 orders; choose two without order in six ways.
Exam question: Why divide by r factorial?
Answer: Each r-element subset appears in r! different orders.

Counting and recurrence checks

from itertools import combinations, permutations, product
from math import comb, factorial

def fibonacci(count):
    if type(count) is not int or count < 0:
        raise ValueError("nonnegative integer count required")
    result, a, b = [], 0, 1
    for _ in range(count):
        result.append(a)
        a, b = b, a + b
    return result

print("4 books orders:", factorial(4), len(list(permutations(range(4)))))
print("choose 2:", comb(4, 2), len(list(combinations(range(4), 2))))
solutions = [(a, b, c) for a, b, c in product(range(5), repeat=3)
             if a + b + c == 4]
print("three bins, total 4:", len(solutions), comb(6, 2))
print("F0 through F7:", fibonacci(8))
print("sum 1..10:", sum(range(1, 11)), 10 * 11 // 2)
coefficients = [0] * 5
for i in range(3):
    for j in range(3):
        coefficients[i + j] += 1
print("(1+x+x^2)^2:", coefficients)
try:
    fibonacci(-1)
except ValueError:
    print("invalid count rejected")

Checked output:

4 books orders: 24 24
choose 2: 6 6
three bins, total 4: 15 15
F0 through F7: [0, 1, 1, 2, 3, 5, 8, 13]
sum 1..10: 55 55
(1+x+x^2)^2: [1, 2, 3, 2, 1]
invalid count rejected

19. Repetition and stars-and-bars

Length r strings over n symbols number n^r. Nonnegative solutions to x1+...+xk=r number C(r+k-1,k-1). Positive variables first subtract one from each.

Worked example: x1+x2+x3=4 with xi>=0 has C(6,2)=15 solutions.
Exam question: Does stars-and-bars count ordered arrangements of individual identical objects?
Answer: No. It counts distributions among labeled bins under its constraints.

20. Binomial theorem and identities

(x+y)^n has coefficients C(n,k). Pascal identity splits choices by including a distinguished item. Sum of all coefficients is 2^n.

Worked example: Row n=4 is 1,4,6,4,1 and sums to16.
Exam question: Does every binomial identity need algebra?
Answer: No. Many have a combinatorial counting proof.

21. Inclusion-exclusion

Two-set union count is size(A)+size(B)-size(intersection). Three sets subtract pair intersections then add the triple intersection.

Worked example: A has3 elements, B has3 and overlap2 gives union4.
Exam question: Why add the triple intersection back?
Answer: The three-set subtraction removes its membership too many times.

22. Pigeonhole principle

More objects than bins forces a repeated bin. In general n objects in k nonempty available bins force one bin with at least ceiling(n/k) objects.

Worked example: 13 students in12 birth-month bins force two sharing a month.
Exam question: Can it identify the actual shared month?
Answer: No. It guarantees existence, not which bin.

23. Finite probability

For equally likely finite outcomes, probability is favorable/total. Conditional P(A given B)=P(A intersection B)/P(B) for positive P(B); independence means joint probability factors.

Worked example: Two fair coin tosses: exactly one head occurs in2 of4 outcomes, probability1/2.
Exam question: Are disjoint positive-probability events independent?
Answer: No. Their intersection is zero, unlike the positive product.

24. Mathematical induction

State base case, induction hypothesis and step. The hypothesis applies only as stated; the step must establish the next case.

Worked example: Sum1..k=k(k+1)/2; add k+1 to get(k+1)(k+2)/2. Base n=1 gives1.
Exam question: Can you skip the base because the step works?
Answer: No. A working step without an established starting case proves nothing in the intended range.
Base case is establishedAssume statement at kProve statement at k+1Conclude for intended range
Induction structure. The step must follow from valid assumptions, not assume the desired conclusion.

25. Strong induction and invariants

Strong induction assumes earlier cases up to k. An invariant holds initially and is preserved by each allowed transition.

Worked example: For integer n>=2, a composite factors into smaller integers; strong induction builds prime factorization from them.
Exam question: Is checking an invariant on sample runs a proof?
Answer: No. Prove initialization and preservation for all permitted transitions.

26. Recurrences and solving

A recurrence needs base values and index domain. First-order constant-increment recurrences expand to arithmetic progressions; second-order recurrences may require two bases.

Worked example: a0=1, an=an-1+3 gives an=1+3n. F0=0,F1=1,F2..F7=1,2,3,5,8,13.
Exam question: Can one initial value determine every second-order recurrence?
Answer: Not generally; two independent base values are needed.

27. Generating functions

An ordinary generating function packages coefficients as sum an*x^n. Treat formal series identities as coefficient statements, without needing analytic convergence.

Worked example: For a_n=1, series is1/(1-x); coefficient of x^4 in(1+x+x^2)^2 is1.
Exam question: Is a formal power-series identity a numerical claim for every real x?
Answer: No. Formal coefficient algebra and convergence are different questions.

28. Divisibility and Euclidean algorithm

a divides b means b=a*k for an integer k. GCD uses repeated remainders; gcd(a,b)=gcd(b,a mod b). State sign and zero conventions.

Worked example: gcd(84,30): remainders24,6,0, so gcd6. gcd(0,9)=9.
Exam question: Is zero a valid divisor in ordinary divisibility formulas?
Answer: Handle it explicitly; division and modulo by zero are not defined.

29. Modular arithmetic

Congruence mod m means the difference is divisible by positive m. Inverses exist for residues coprime to m; ordinary cancellation may fail.

Worked example: 3 inverse modulo7 is5 because15 congruent1. Modulo6,2*1 and2*4 are equal residues though1 and4 differ.
Exam question: Can every nonzero residue be inverted?
Answer: No. Modulus6 has nonzero nonunits such as2.

30. Algebraic structures

Semigroup: associative closed operation. Monoid adds identity. Group adds inverses; abelian group also commutes. A ring has compatible addition/multiplication; a field is a commutative ring with 1!=0 and every nonzero element invertible.

Worked example: Integers under addition form an abelian group; integers form a ring, not a field. Residues modulo5 form a field, modulo6 do not.
Exam question: Does having an identity automatically make a monoid a group?
Answer: No. Every element also needs an inverse.

31. Graphs and degree sum

State directedness, loops and parallel-edge conventions. In a finite undirected graph degree sum is2*edge_count, counting a loop twice.

Worked example: Path A-B-C-D has degrees1,2,2,1, sum6, edges3.
Exam question: Can an undirected graph have exactly one odd-degree vertex?
Answer: No. The number of odd-degree vertices is even.
ABDC
Undirected cycle A-B-C-D-A: each vertex has degree 2, four edges, bipartite with opposite-vertex groups.

Simple undirected graph checks

from collections import deque

def graph_check(vertices, edges):
    vertices = set(vertices)
    edges = list(edges)
    adjacency = {v: set() for v in vertices}
    seen_edges = set()
    for pair in edges:
        if not isinstance(pair, tuple) or len(pair) != 2:
            raise ValueError("edge pairs required")
        u, v = pair
        key = frozenset((u, v))
        if u not in vertices or v not in vertices or u == v or key in seen_edges:
            raise ValueError("simple undirected edges required")
        seen_edges.add(key)
        adjacency[u].add(v)
        adjacency[v].add(u)
    degrees = {v: len(adjacency[v]) for v in vertices}
    components, bipartite, color = 0, True, {}
    for start in vertices:
        if start in color:
            continue
        components += 1
        color[start] = 0
        queue = deque([start])
        while queue:
            u = queue.popleft()
            for v in adjacency[u]:
                if v not in color:
                    color[v] = 1 - color[u]
                    queue.append(v)
                elif color[v] == color[u]:
                    bipartite = False
    tree = bool(vertices) and components == 1 and len(edges) == len(vertices) - 1
    return degrees, components, bipartite, tree

for label, edges in [
    ("path", [(0, 1), (1, 2), (2, 3)]),
    ("triangle plus isolated", [(0, 1), (1, 2), (2, 0)])
]:
    degrees, components, bipartite, tree = graph_check(range(4), edges)
    print(label, "degrees:", sorted(degrees.items()))
    print("sum:", sum(degrees.values()), "2E:", 2 * len(edges))
    print("components:", components, "bipartite:", bipartite, "tree:", tree)
try:
    graph_check(range(2), [(0, 1), (1, 0)])
except ValueError:
    print("duplicate edge rejected")

Checked output:

path degrees: [(0, 1), (1, 2), (2, 2), (3, 1)]
sum: 6 2E: 6
components: 1 bipartite: True tree: True
triangle plus isolated degrees: [(0, 2), (1, 2), (2, 2), (3, 0)]
sum: 6 2E: 6
components: 2 bipartite: False tree: False
duplicate edge rejected

32. Paths, connectivity and trees

A tree is connected and acyclic; a finite n-vertex nonempty tree has n-1 edges. A forest with n vertices and c components has n-c edges.

Worked example: Path on4 vertices is a tree with3 edges; adding A-C introduces a cycle.
Exam question: Does n-1 edges alone prove a graph is a tree?
Answer: No. Connectivity or acyclicity must also be established under the finite undirected model.

33. Euler and Hamilton routes

Euler uses every edge exactly once; Hamilton visits every vertex exactly once under the stated path/cycle convention. For an undirected graph, connected nonzero-degree vertices and zero/two odd degrees characterize Euler circuit/trail existence.

Worked example: Path A-B-C-D has an Euler trail from A to D, not an Euler circuit.
Exam question: Do Euler degree conditions solve Hamilton cycles?
Answer: No. Hamilton existence is a different problem.

34. Coloring, bipartite and planarity

Proper vertex coloring gives adjacent vertices different colors. Bipartite iff no odd cycle. For a connected planar embedding, V-E+F=2, counting the outer face.

Worked example: Triangle needs3 colors; square needs2. For planar triangle V3,E3,F2 gives2.
Exam question: Does E<=3V-6 prove planarity for every simple graph V>=3?
Answer: No. It is necessary, not sufficient.

35. Directed graphs and matching

Directed reachability respects orientation. A DAG admits a topological order. A matching has disjoint edge endpoints; a maximum matching has largest cardinality, while maximal only means no edge can be added.

Worked example: Edges A->B,A->C,B->D,C->D permit A,B,C,D or A,C,B,D.
Exam question: Is every maximal matching maximum?
Answer: No. A locally non-extendable matching can be smaller than another matching.

36. Exam revision and limits

State domains, models and hypotheses before formulas. Program enumeration verifies finite cases, not a universal theorem. General notes do not certify an assessed syllabus.

Worked example: Implication T,F is false; C(4,2)=6; six-vertex tree has5 edges; union example has4 elements.
Exam question: What makes a useful proof answer?
Answer: A precise claim, assumptions, valid steps and a conclusion covering the requested domain.

Truth-table reference

pqANDORp implies qp iff q
TTTTTT
TFFTFF
FTFTTF
FFFFTT

Checked answer reference

TaskAnswerCondition
Four distinct books, all orders24All distinct, order matters
Choose two of four6No order, no repetition
Three bins, total four15Nonnegative counts, labeled bins
Power set of three elements8Distinct elements
Modulo3 classes on0..5{0,3},{1,4},{2,5}Congruence equivalence
Divisibility meet/join of2,31 and6Domain {1,2,3,6}
Coefficient x^4 in(1+x+x^2)^21Formal polynomial product
GCD84,306Positive integers
Inverse3 modulo75Coprime
Six-vertex tree5 edgesFinite, connected, acyclic
Two fair coin tosses, one head1/2Four equally likely outcomes

Revision checklist

  1. Build all truth-table rows and distinguish converse from contrapositive.
  2. Negate quantified claims with a stated domain.
  3. Check every relation property independently.
  4. State order, repetition and overlap rules before counting.
  5. Give induction base, hypothesis and valid step.
  6. State graph model before degree, tree, Euler and planar formulas.
  7. Distinguish finite test evidence from a universal proof.

Sources

References support definitions and theorem hypotheses. Explanations, fixed examples, diagrams and programs here are original teaching material, not copied textbook sections.

Comments