Skip to main content

Chapter 2

Discrete Structure

TU BIT past exam questions

Past questions and answers

75 questions set from this chapter; 3 are most repeated (set, or a close variant set, in 3 or more exams). Most repeated first.

  • Most repeated · 4 of 6 exams
  • 2079 · 5 marks

Use mathematical induction to prove that the sum of the first nn odd positive integers is n2n^2.

Similar questions: Prove that the sum of first (2080.1) · Using mathematical induction prove that sum (2082) · Use mathematical induction to show that (2078)

Answer

Claim: 1+3+5+⋯+(2n−1)=n21 + 3 + 5 + \dots + (2n - 1) = n^2 for all n≥1n \ge 1.

Basis (n=1n=1): LHS =1=12= 1 = 1^2.

Inductive step: assume the statement holds for n=kn = k: 1+3+⋯+(2k−1)=k21 + 3 + \dots + (2k-1) = k^2. Then for n=k+1n = k+1:

1+3+⋯+(2k−1)+(2k+1)=k2+2k+1=(k+1)21 + 3 + \dots + (2k-1) + (2k+1) = k^2 + 2k + 1 = (k+1)^2

So it holds for k+1k+1. By mathematical induction the sum of the first nn odd positive integers is n2n^2. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • Most repeated · 3 of 6 exams
  • 2080.1 · 6 marks

Prove that the sum of first NN odd integers is N2N^2 using mathematical induction.

Similar questions: Using mathematical induction prove that sum (2082) · Use mathematical induction to prove that (2079)

Answer

Claim: 1+3+5+⋯+(2N−1)=N21 + 3 + 5 + \dots + (2N-1) = N^2 for all integers N≥1N \ge 1.

Basis (N=1N = 1): the sum is 1=121 = 1^2.

Inductive hypothesis: assume that for some k≥1k \ge 1, 1+3+⋯+(2k−1)=k21 + 3 + \dots + (2k-1) = k^2.

Inductive step: for N=k+1N = k+1, the sum of the first k+1k+1 odd integers is

[1+3+⋯+(2k−1)]+(2k+1)=k2+2k+1=(k+1)2.\big[1 + 3 + \dots + (2k-1)\big] + (2k+1) = k^2 + 2k + 1 = (k+1)^2.

Thus the statement holds for k+1k+1. By the principle of mathematical induction it holds for all N≥1N \ge 1. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • Most repeated · 3 of 6 exams
  • 2082 · 5 marks

Using mathematical induction prove that sum of first NN odd integers is N2N^2.

Similar questions: Prove that the sum of first (2080.1) · Use mathematical induction to prove that (2079)

Answer

Claim: P(N): 1+3+5+⋯+(2N−1)=N2P(N):\ 1+3+5+\cdots+(2N-1)=N^2 for all N≥1N\ge1.

Basis step: N=1N=1: LHS =1=1, RHS =12=1=1^2=1. True.

Inductive step: Assume P(k)P(k): 1+3+⋯+(2k−1)=k21+3+\cdots+(2k-1)=k^2. Then

1+3+⋯+(2k−1)+(2k+1)=k2+2k+1=(k+1)2,1+3+\cdots+(2k-1)+(2k+1)=k^2+2k+1=(k+1)^2,

which is P(k+1)P(k+1).

By the principle of mathematical induction, the sum of the first NN odd integers is N2N^2 for every N≥1N\ge1. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

Use mathematical induction to show that the sum of first nn positive integers is n(n+1)2\frac{n(n+1)}{2}.

Similar questions: Use mathematical induction to prove that (2079)

Answer

Claim: P(n)P(n): 1+2+3+⋯+n=n(n+1)21 + 2 + 3 + \dots + n = \dfrac{n(n+1)}{2} for all positive integers nn.

Basis step: for n=1n = 1, LHS =1= 1 and RHS =1⋅22=1= \frac{1 \cdot 2}{2} = 1. So P(1)P(1) is true.

Inductive step: assume P(k)P(k) is true for some k≥1k \ge 1:

1+2+⋯+k=k(k+1)2.1 + 2 + \dots + k = \frac{k(k+1)}{2}.

Add k+1k + 1 to both sides:

1+2+⋯+k+(k+1)=k(k+1)2+(k+1)=k(k+1)+2(k+1)2=(k+1)(k+2)2.1 + 2 + \dots + k + (k+1) = \frac{k(k+1)}{2} + (k+1) = \frac{k(k+1) + 2(k+1)}{2} = \frac{(k+1)(k+2)}{2}.

This is P(k+1)P(k+1). Since the basis and inductive steps hold, by mathematical induction P(n)P(n) is true for all positive integers nn. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

Write the Dijkstra's algorithm to find the shortest path between two nodes in graph.

Similar questions: Find the shortest path from $a$ (2082)

Answer

Dijkstra's algorithm finds the shortest path from a source vertex ss to all other vertices (or a target tt) in a weighted graph with non-negative weights.

Dijkstra(G, w, s, t):
    for each vertex v:
        dist[v] = infinity
        prev[v] = undefined
    dist[s] = 0
    S = empty set                  // finalised vertices
    Q = all vertices               // priority queue keyed by dist
    while Q is not empty:
        u = vertex in Q with minimum dist[u]
        remove u from Q; add u to S
        if u == t: break
        for each neighbour v of u in Q:
            if dist[u] + w(u, v) < dist[v]:
                dist[v] = dist[u] + w(u, v)
                prev[v] = u
    // path: follow prev[] from t back to s

Idea: repeatedly pick the unvisited vertex with the smallest tentative distance, fix it as final, and relax its outgoing edges. With a binary heap the running time is O((V+E)log⁡V)O((V + E)\log V); with an array it is O(V2)O(V^2).

Example: edges aa-bb 4, aa-cc 1, cc-bb 2, bb-dd 5. From aa: dist(c)=1dist(c) = 1, dist(b)=3dist(b) = 3 (via cc), dist(d)=8dist(d) = 8. Shortest path a→c→b→da \to c \to b \to d has length 8.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

Using direct proof show that the sum of square of even number is even.

Similar questions: Using direct proof show that the (2081)

Answer

Claim: the square of an even number is even, and so the sum of squares of even numbers is even.

Direct proof. Let aa and bb be even integers: a=2ma = 2m and b=2nb = 2n for integers m,nm, n. Then

a2=4m2=2(2m2),b2=4n2=2(2n2)a^2 = 4m^2 = 2(2m^2), \qquad b^2 = 4n^2 = 2(2n^2)

so each square is even. Their sum is

a2+b2=2(2m2)+2(2n2)=2(2m2+2n2)a^2 + b^2 = 2(2m^2) + 2(2n^2) = 2(2m^2 + 2n^2)

which is 2 times an integer, hence even. The same argument works for any number of even terms, since ∑(2mi)2=2∑2mi2\sum (2m_i)^2 = 2\sum 2m_i^2. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Using direct proof show that the sum of odd and even number is odd.

Similar questions: Using direct proof show that the (2080.1)

Answer

Claim: the sum of an odd integer and an even integer is odd.

Direct proof: Let mm be odd and nn be even. By definition, m=2a+1m=2a+1 and n=2bn=2b for some integers a,ba,b. Then

m+n=2a+1+2b=2(a+b)+1.m+n=2a+1+2b=2(a+b)+1.

Since a+ba+b is an integer, m+nm+n has the form 2k+12k+1 with k=a+bk=a+b, so it is odd. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 5 marks

Find the shortest path from aa to zz in following graph using Dijkstra's algorithm.

Similar questions: Write the Dijkstra's algorithm to find (2079)

Answer

Dijkstra's algorithm: keep a distance label d(v)d(v) for every vertex (d(a)=0d(a)=0, others ∞\infty). Repeatedly pick the unvisited vertex with the smallest label, mark it permanent, and relax its neighbours: d(v)=min⁡{d(v), d(u)+w(u,v)}d(v)=\min\{d(v),\,d(u)+w(u,v)\}. Stop when zz is permanent.

Applying it to the graph with edges ab=4, ac=2, bc=1, bd=5, cd=8, ce=10, de=2, dz=6, ez=3ab=4,\ ac=2,\ bc=1,\ bd=5,\ cd=8,\ ce=10,\ de=2,\ dz=6,\ ez=3:

StepPermanent vertexbbccddeezz
0a (0)42∞\infty∞\infty∞\infty
1c (2)3-1012∞\infty
2b (3)--812∞\infty
3d (8)---1014
4e (10)----13
5z (13)

Tracing predecessors back from zz: z←e←d←b←c←az\leftarrow e\leftarrow d\leftarrow b\leftarrow c\leftarrow a.

Shortest path: a→c→b→d→e→za\to c\to b\to d\to e\to z with length 2+1+5+2+3=132+1+5+2+3=13.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 10 marks

Explain direct proof, indirect proof, and proof by contradiction. Use direct proof to show that 'If nn is an odd integer, then n2n^2 is an odd integer'. Also use indirect proof to show that 'If nn is an integer and n2n^2 is odd, then nn is odd'.

Answer

Direct proof: to prove p→qp \rightarrow q, assume pp is true and, using definitions, axioms and known theorems, show directly that qq is true.

Indirect proof (proof by contraposition): to prove p→qp \rightarrow q, prove the equivalent contrapositive ¬q→¬p\neg q \rightarrow \neg p: assume qq is false and show pp is false.

Proof by contradiction: to prove pp, assume ¬p\neg p and derive a contradiction r∧¬rr \wedge \neg r (or an impossible statement). For p→qp \rightarrow q, assume p∧¬qp \wedge \neg q and derive a contradiction. Hence pp must be true.

Direct proof: if nn is odd, then n2n^2 is odd.

Let nn be odd, so n=2k+1n = 2k + 1 for some integer kk. Then

n2=(2k+1)2=4k2+4k+1=2(2k2+2k)+1.n^2 = (2k+1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1.

Since 2k2+2k2k^2 + 2k is an integer, n2n^2 is of the form 2m+12m + 1, so n2n^2 is odd. ■\blacksquare

Indirect proof: if n2n^2 is odd, then nn is odd.

The contrapositive is: if nn is not odd (even), then n2n^2 is not odd (even). Let nn be even, so n=2kn = 2k. Then

n2=4k2=2(2k2),n^2 = 4k^2 = 2(2k^2),

which is even. Thus the contrapositive is true, so the original statement holds: if n2n^2 is odd then nn is odd. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 10 marks

What is linear nonhomogeneous recurrence relation of degree kk with constant coefficients? Find all the solutions of the recurrence relation an=4an−1+na_n = 4a_{n-1} + n. Also find the solution of the relation with initial condition a0=1a_0 = 1.

Answer

Definition: a linear nonhomogeneous recurrence relation of degree kk with constant coefficients has the form

an=c1an−1+c2an−2+⋯+ckan−k+F(n),a_n = c_1 a_{n-1} + c_2 a_{n-2} + \dots + c_k a_{n-k} + F(n),

where c1,…,ckc_1, \dots, c_k are real constants, ck≠0c_k \ne 0, and F(n)≠0F(n) \ne 0 is a function of nn only. The solution is an=an(h)+an(p)a_n = a_n^{(h)} + a_n^{(p)}: the general solution of the associated homogeneous relation plus a particular solution.

Solve an=4an−1+na_n = 4a_{n-1} + n.

Homogeneous part: an=4an−1a_n = 4a_{n-1} has characteristic equation r−4=0r - 4 = 0, so an(h)=α 4na_n^{(h)} = \alpha\, 4^n.

Particular solution: since F(n)=nF(n) = n is linear, try an(p)=cn+da_n^{(p)} = cn + d. Substituting:

cn+d=4(c(n−1)+d)+n=(4c+1)n+(4d−4c).cn + d = 4(c(n-1) + d) + n = (4c + 1)n + (4d - 4c).

Comparing coefficients: c=4c+1c = 4c + 1, so c=−13c = -\tfrac13; and d=4d−4cd = 4d - 4c, so 3d=4c=−433d = 4c = -\tfrac43, giving d=−49d = -\tfrac49.

an(p)=−n3−49.a_n^{(p)} = -\frac{n}{3} - \frac{4}{9}.

All solutions:

an=α 4n−n3−49.a_n = \alpha\, 4^n - \frac{n}{3} - \frac{4}{9}.

With a0=1a_0 = 1: 1=α−491 = \alpha - \tfrac49, so α=139\alpha = \tfrac{13}{9}.

an=139 4n−n3−49.a_n = \frac{13}{9}\,4^n - \frac{n}{3} - \frac{4}{9}.

Check: a1=4(1)+1=5a_1 = 4(1) + 1 = 5 and the formula gives 529−39−49=5\frac{52}{9} - \frac{3}{9} - \frac{4}{9} = 5.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 10 marks

Define spanning tree and minimum spanning tree with suitable example. Use Kruskal's algorithm to find minimum spanning tree in the given graph.

Answer

Spanning tree: a spanning tree of a connected graph GG is a subgraph that is a tree and contains all vertices of GG. For nn vertices it has exactly n−1n - 1 edges and no cycle.

Minimum spanning tree (MST): in a connected weighted graph, a spanning tree whose total edge weight is minimum.

Example: for a triangle with vertices a,b,ca, b, c and edges ab=1ab = 1, bc=2bc = 2, ac=3ac = 3, the spanning trees are {ab,bc}\{ab, bc\} (weight 3), {ab,ac}\{ab, ac\} (4), {bc,ac}\{bc, ac\} (5). The MST is {ab,bc}\{ab, bc\} with weight 3.

Kruskal's algorithm:

  1. Sort the edges in non-decreasing order of weight.
  2. Take the smallest edge; add it to the tree if it does not form a cycle with edges already chosen; otherwise discard it.
  3. Repeat until n−1n - 1 edges are chosen.

Illustration on a graph with vertices a,b,c,d,ea, b, c, d, e and edges bc=1bc = 1, ab=2ab = 2, ac=3ac = 3, bd=4bd = 4, cd=5cd = 5, ce=6ce = 6, de=7de = 7:

EdgeWeightDecision
bcbc1Add
abab2Add
acac3Reject (cycle aa-bb-cc)
bdbd4Add
cdcd5Reject (cycle)
cece6Add (4 edges reached)

MST edges: bc,ab,bd,cebc, ab, bd, ce with total weight 1+2+4+6=131 + 2 + 4 + 6 = 13.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

What is tautology? Show (p∧q)→(p∨q)(p \land q) \rightarrow (p \lor q) is a tautology.

Answer

A tautology is a compound proposition that is true for all possible truth values of its component propositions.

Show (p∧q)→(p∨q)(p \wedge q) \rightarrow (p \vee q) is a tautology.

ppqqp∧qp \wedge qp∨qp \vee q(p∧q)→(p∨q)(p \wedge q) \rightarrow (p \vee q)
TTTTT
TFFTT
FTFTT
FFFFT

The last column is always true, so it is a tautology.

Algebraic check: (p∧q)→(p∨q)≡¬(p∧q)∨(p∨q)≡(¬p∨¬q)∨p∨q≡(¬p∨p)∨(¬q∨q)≡T(p \wedge q) \rightarrow (p \vee q) \equiv \neg(p \wedge q) \vee (p \vee q) \equiv (\neg p \vee \neg q) \vee p \vee q \equiv (\neg p \vee p) \vee (\neg q \vee q) \equiv T.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

Define cartesian product. Find A3A^3 for the set A={a,b,c}A = \{a, b, c\}.

Answer

Cartesian product: for sets AA and BB, the Cartesian product A×BA \times B is the set of all ordered pairs (a,b)(a, b) with a∈Aa \in A and b∈Bb \in B:

A×B={(a,b)∣a∈A, b∈B}.A \times B = \{(a, b) \mid a \in A,\ b \in B\}.

In general A1×A2×⋯×AnA_1 \times A_2 \times \dots \times A_n is the set of ordered nn-tuples (a1,…,an)(a_1, \dots, a_n) with ai∈Aia_i \in A_i, and A3=A×A×AA^3 = A \times A \times A.

For A={a,b,c}A = \{a, b, c\}, ∣A3∣=33=27|A^3| = 3^3 = 27 ordered triples:

A3={(a,a,a),(a,a,b),(a,a,c),(a,b,a),(a,b,b),(a,b,c),(a,c,a),(a,c,b),(a,c,c),A^3 = \{(a,a,a), (a,a,b), (a,a,c), (a,b,a), (a,b,b), (a,b,c), (a,c,a), (a,c,b), (a,c,c), (b,a,a),(b,a,b),(b,a,c),(b,b,a),(b,b,b),(b,b,c),(b,c,a),(b,c,b),(b,c,c),(b,a,a), (b,a,b), (b,a,c), (b,b,a), (b,b,b), (b,b,c), (b,c,a), (b,c,b), (b,c,c), (c,a,a),(c,a,b),(c,a,c),(c,b,a),(c,b,b),(c,b,c),(c,c,a),(c,c,b),(c,c,c)}(c,a,a), (c,a,b), (c,a,c), (c,b,a), (c,b,b), (c,b,c), (c,c,a), (c,c,b), (c,c,c)\}

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

How can you represent relations using matrices? Suppose that A={1,2,3}A = \{1, 2, 3\} and B={1,2}B = \{1, 2\}. Let RR be the relation from AA to BB containing (a,b)(a, b) if a∈Aa \in A, b∈Bb \in B, and a>ba > b. What matrix represents RR if a1=1a_1 = 1, a2=2a_2 = 2, a3=3a_3 = 3, and b1=1b_1 = 1, b2=2b_2 = 2?

Answer

Representing relations by matrices: let RR be a relation from A={a1,…,am}A = \{a_1, \dots, a_m\} to B={b1,…,bn}B = \{b_1, \dots, b_n\}. The zero-one matrix MR=[mij]M_R = [m_{ij}] of size m×nm \times n has

mij={1if (ai,bj)∈R0if (ai,bj)∉R.m_{ij} = \begin{cases} 1 & \text{if } (a_i, b_j) \in R \\ 0 & \text{if } (a_i, b_j) \notin R. \end{cases}

Rows are indexed by elements of AA and columns by elements of BB.

For A={1,2,3}A = \{1,2,3\}, B={1,2}B = \{1,2\} and R={(a,b)∣a>b}R = \{(a,b) \mid a > b\}:

R={(2,1),(3,1),(3,2)}R = \{(2,1), (3,1), (3,2)\}.

MR=[001011]M_R = \begin{bmatrix} 0 & 0 \\ 1 & 0 \\ 1 & 1 \end{bmatrix}

Row 1 is (1>1?,1>2?)=(0,0)(1>1?, 1>2?)=(0,0), row 2 is (2>1,2>2)=(1,0)(2>1, 2>2)=(1,0), row 3 is (3>1,3>2)=(1,1)(3>1, 3>2)=(1,1).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

What is congruent modulo? Determine whether 2020 is congruent to 88 modulo 66 and 2525 is congruent to 1717 modulo 55.

Answer

Congruence modulo: let a,ba, b be integers and mm a positive integer. aa is congruent to bb modulo mm, written a≡b(modm)a \equiv b \pmod m, if mm divides a−ba - b. Equivalently, aa and bb leave the same remainder when divided by mm.

(a) 20−8=1220 - 8 = 12, and 6∣126 \mid 12 (12=6×212 = 6 \times 2). So 20≡8(mod6)20 \equiv 8 \pmod 6: yes, congruent. (Both leave remainder 2.)

(b) 25−17=825 - 17 = 8, and 5∤85 \nmid 8. So 25≢17(mod5)25 \not\equiv 17 \pmod 5: not congruent. (Remainders are 0 and 2.)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

Explain trial division with example? Using trial division, show that 101101 is prime.

Answer

Trial division: to test whether a positive integer n>1n > 1 is prime, divide it by every prime p≤np \le \sqrt{n}. If none divides nn, then nn is prime; if some prime divides it, nn is composite. This works because a composite number has a prime factor not exceeding n\sqrt{n}.

Example: 9191. 91≈9.5\sqrt{91} \approx 9.5; primes up to 9 are 2, 3, 5, 7. Since 91=7×1391 = 7 \times 13, it is composite.

Show 101 is prime: 101≈10.05\sqrt{101} \approx 10.05, so test primes 2,3,5,72, 3, 5, 7.

  • 101÷2101 \div 2: remainder 1.
  • 101÷3101 \div 3: 101=3×33+2101 = 3 \times 33 + 2, remainder 2.
  • 101÷5101 \div 5: remainder 1.
  • 101÷7101 \div 7: 101=7×14+3101 = 7 \times 14 + 3, remainder 3.

No prime up to 101\sqrt{101} divides 101, so 101 is prime.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

Explain product rule. How many strings are there of four lowercase letters that have the letter xx in them?

Answer

Product rule: if a procedure can be broken into two tasks (or a sequence of kk tasks), where there are n1n_1 ways to do the first and n2n_2 ways to do the second after the first is done, then there are n1×n2n_1 \times n_2 ways to do the procedure (in general n1n2⋯nkn_1 n_2 \cdots n_k).

Example: a license code with one letter (26 ways) followed by one digit (10 ways) can be formed in 26×10=26026 \times 10 = 260 ways.

Strings of four lowercase letters containing xx:

Count all strings and subtract those with no xx.

  • Total strings of length 4: 264=45697626^4 = 456976.
  • Strings with no xx (letters from the other 25): 254=39062525^4 = 390625.

264−254=456976−390625=66351.26^4 - 25^4 = 456976 - 390625 = 66351.

There are 6635166351 strings that contain the letter xx at least once.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

What is graph? Explain simple graph and pseudograph with example.

Answer

A graph G=(V,E)G = (V, E) consists of a non-empty set VV of vertices (nodes) and a set EE of edges, each edge connecting a pair of vertices. Graphs model networks such as roads, computer networks and social links.

Simple graph: an undirected graph with no loops (an edge from a vertex to itself) and no multiple (parallel) edges. Each edge is an unordered pair {u,v}\{u, v\} of distinct vertices.

Example: V={a,b,c,d}V = \{a, b, c, d\}, E={{a,b},{b,c},{c,d},{a,d}}E = \{\{a,b\}, \{b,c\}, \{c,d\}, \{a,d\}\} is a simple graph (a 4-cycle).

Pseudograph: an undirected graph that may contain both multiple edges and loops. It is the most general type of undirected graph.

Example: V={a,b,c}V = \{a, b, c\} with two parallel edges between aa and bb, an edge bb-cc, and a loop at cc. A loop adds 2 to the degree of its vertex, so deg⁡(c)=1+2=3\deg(c) = 1 + 2 = 3.

TypeMultiple edgesLoops
Simple graphNoNo
MultigraphYesNo
PseudographYesYes

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2078 · 5 marks

What is Euler path? Compare it with Hamilton path.

Answer

Euler path: a path in a graph that uses every edge exactly once. If it starts and ends at the same vertex it is an Euler circuit.

Hamilton path: a path that visits every vertex exactly once (a Hamilton circuit also returns to the start).

BasisEuler pathHamilton path
VisitsEvery edge exactly onceEvery vertex exactly once
VerticesMay be repeatedNot repeated
EdgesNot repeatedNeed not all be used
Existence testSimple: connected and 0 or 2 odd-degree verticesNo known simple necessary and sufficient condition (NP-complete)
Sufficient conditionEven degrees (circuit)Dirac: deg⁡(v)≥n/2\deg(v) \ge n/2 for all vv (n≥3n \ge 3)
Example useRoute inspection, mail deliveryTravelling salesman problem

Example: in the complete graph K4K_4 every vertex has degree 3 (four odd vertices), so it has no Euler path, but it has a Hamilton circuit.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 10 marks

Give any four examples that are not propositions. Assume the premises, all over smart persons are stupid, children of stupid persons are naughty, John is over smart, Sam is children of John. Using rules of inferences, show that Sam is naughty.

Answer

Four statements that are not propositions (they are not definitely true or false):

  1. What is your name? (question)
  2. Close the door. (command)
  3. x+3=7x + 3 = 7 (truth depends on xx)
  4. How beautiful the Himalayas are! (exclamation)

Predicates: let O(x)O(x): xx is over smart, S(x)S(x): xx is stupid, C(y,x)C(y, x): yy is a child of xx, N(x)N(x): xx is naughty.

Premises:

  1. ∀x (O(x)→S(x))\forall x\,(O(x) \to S(x))
  2. ∀x ∀y (S(x)∧C(y,x)→N(y))\forall x\,\forall y\,(S(x) \wedge C(y, x) \to N(y))
  3. O(John)O(\text{John})
  4. C(Sam,John)C(\text{Sam}, \text{John})

Proof:

StepStatementReason
1∀x (O(x)→S(x))\forall x\,(O(x) \to S(x))Premise
2O(John)→S(John)O(\text{John}) \to S(\text{John})Universal instantiation of 1
3O(John)O(\text{John})Premise
4S(John)S(\text{John})Modus ponens (2, 3)
5C(Sam,John)C(\text{Sam}, \text{John})Premise
6S(John)∧C(Sam,John)S(\text{John}) \wedge C(\text{Sam}, \text{John})Conjunction (4, 5)
7∀x ∀y (S(x)∧C(y,x)→N(y))\forall x\,\forall y\,(S(x) \wedge C(y,x) \to N(y))Premise
8S(John)∧C(Sam,John)→N(Sam)S(\text{John}) \wedge C(\text{Sam}, \text{John}) \to N(\text{Sam})Universal instantiation of 7
9N(Sam)N(\text{Sam})Modus ponens (6, 8)

Hence Sam is naughty.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5+5 marks

Why do we need principle of inclusion and exclusion? How many ways can we express the four character words ending with a digit and beginning three are lowercase alphabets. Be sure that none of the character can be repeated. Using induction, show that 3n−13^n - 1 is multiple of 2 for n≥1n \geq 1.

Answer

Need for the principle of inclusion and exclusion (PIE): when counting elements in a union of sets that overlap, simply adding the sizes counts common elements more than once. PIE corrects this:

∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|

∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣A∩C∣−∣B∩C∣+∣A∩B∩C∣|A \cup B \cup C| = |A|+|B|+|C| - |A\cap B| - |A\cap C| - |B\cap C| + |A\cap B\cap C|

Counting words: the first three characters are distinct lowercase letters and the fourth is a digit (a digit can never equal a letter, so no repetition issue there).

26×25×24×10=15600026 \times 25 \times 24 \times 10 = 156000

There are 156000 such words.

Induction: prove P(n)P(n): 3n−13^n - 1 is a multiple of 2 for n≥1n \ge 1.

Basis: n=1n = 1: 3−1=23 - 1 = 2, which is divisible by 2.

Inductive step: assume 3k−1=2m3^k - 1 = 2m for some integer mm. Then

3k+1−1=3⋅3k−1=3(2m+1)−1=6m+2=2(3m+1)3^{k+1} - 1 = 3\cdot 3^k - 1 = 3(2m + 1) - 1 = 6m + 2 = 2(3m + 1)

which is a multiple of 2. By induction, 3n−13^n - 1 is a multiple of 2 for all n≥1n \ge 1.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 4+6 marks

State necessary and sufficient conditions for a graph to have Euler path and circuit. Find the GCD of 12 and 18 using Extended Euclidian Algorithm.

Answer

Euler circuit: a connected graph (ignoring isolated vertices) has an Euler circuit if and only if every vertex has even degree.

Euler path (not a circuit): a connected graph has an Euler path if and only if it has exactly two vertices of odd degree; the path starts at one odd vertex and ends at the other. (With zero odd vertices an Euler circuit exists, which is also an Euler path.)

GCD of 12 and 18 by the Extended Euclidean Algorithm:

18=1⋅12+618 = 1 \cdot 12 + 6 12=2⋅6+012 = 2 \cdot 6 + 0

The last non-zero remainder is 6, so gcd⁡(12,18)=6\gcd(12, 18) = 6.

Back-substitute:

6=18−1⋅12=(−1)⋅12+1⋅186 = 18 - 1\cdot 12 = (-1)\cdot 12 + 1 \cdot 18

So gcd⁡(12,18)=6=12s+18t\gcd(12,18) = 6 = 12s + 18t with s=−1s = -1, t=1t = 1.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

Show that the sum of two even numbers is even using direct proof.

Answer

Claim: the sum of two even numbers is even.

Direct proof: let aa and bb be even integers. By definition, a=2ma = 2m and b=2nb = 2n for some integers m,nm, n. Then

a+b=2m+2n=2(m+n)a + b = 2m + 2n = 2(m + n)

Since m+nm + n is an integer, a+ba + b is 2 times an integer, so it is even. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

Define power set. What is the power set of the set A={1,2,3,4}A = \{1, 2, 3, 4\}?

Answer

Power set: the power set P(A)P(A) of a set AA is the set of all subsets of AA, including the empty set and AA itself. If ∣A∣=n|A| = n then ∣P(A)∣=2n|P(A)| = 2^n.

For A={1,2,3,4}A = \{1, 2, 3, 4\}, ∣P(A)∣=24=16|P(A)| = 2^4 = 16:

P(A)={∅,{1},{2},{3},{4},{1,2},{1,3},{1,4},{2,3},{2,4},{3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4},{1,2,3,4}}P(A) = \{\emptyset, \{1\}, \{2\}, \{3\}, \{4\}, \{1,2\}, \{1,3\}, \{1,4\}, \{2,3\}, \{2,4\}, \{3,4\}, \{1,2,3\}, \{1,2,4\}, \{1,3,4\}, \{2,3,4\}, \{1,2,3,4\}\}

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

Explain one-to-one correspondence with example. What is identity function?

Answer

One-to-one correspondence (bijection): a function f:A→Bf: A \to B that is both one-to-one (injective: f(a1)=f(a2)⇒a1=a2f(a_1) = f(a_2) \Rightarrow a_1 = a_2) and onto (surjective: every b∈Bb \in B equals f(a)f(a) for some aa). Every element of AA is paired with exactly one element of BB and vice versa, so ∣A∣=∣B∣|A| = |B| for finite sets.

Example: f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=2x+1f(x) = 2x + 1. If 2x1+1=2x2+12x_1 + 1 = 2x_2 + 1 then x1=x2x_1 = x_2 (one-to-one); for any yy, x=(y−1)/2x = (y-1)/2 gives f(x)=yf(x) = y (onto). So ff is a bijection. By contrast f(x)=x2f(x) = x^2 on R\mathbb{R} is neither.

Identity function: IA:A→AI_A : A \to A defined by IA(x)=xI_A(x) = x for all x∈Ax \in A. It is a bijection and is its own inverse.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

What is recursively defined function? Suppose that ff is defined recursively by f(0)=3f(0) = 3, f(n+1)=2f(n)+3f(n+1) = 2f(n) + 3. Find f(1)f(1), f(2)f(2), f(3)f(3), and f(4)f(4).

Answer

A recursively defined function is defined in terms of its own values at smaller arguments: a basis step gives the value(s) at the starting point(s), and a recursive step gives a rule to compute later values from earlier ones.

Given f(0)=3f(0) = 3 and f(n+1)=2f(n)+3f(n+1) = 2f(n) + 3:

f(1)=2(3)+3=9f(1) = 2(3) + 3 = 9 f(2)=2(9)+3=21f(2) = 2(9) + 3 = 21 f(3)=2(21)+3=45f(3) = 2(21) + 3 = 45 f(4)=2(45)+3=93f(4) = 2(45) + 3 = 93

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

What is arithmetic modulo mm? Use the definition of addition and multiplication in Zm\mathbb{Z}_m to find 7+1197 +_{11} 9 and 7∗1197 *_{11} 9.

Answer

Arithmetic modulo mm: on Zm={0,1,…,m−1}\mathbb{Z}_m = \{0, 1, \dots, m-1\}, addition and multiplication are defined by

a+mb=(a+b) mod m,a∗mb=(a⋅b) mod ma +_m b = (a + b) \bmod m, \qquad a *_m b = (a \cdot b) \bmod m

i.e. the remainder after division by mm.

For m=11m = 11:

7+119=16 mod 11=57 +_{11} 9 = 16 \bmod 11 = 5 7∗119=63 mod 11=63−55=87 *_{11} 9 = 63 \bmod 11 = 63 - 55 = 8

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

Define equivalence relation with an example.

Answer

A relation RR on a set AA is an equivalence relation if it is

  1. Reflexive: (a,a)∈R(a, a) \in R for all a∈Aa \in A,
  2. Symmetric: (a,b)∈R⇒(b,a)∈R(a, b) \in R \Rightarrow (b, a) \in R,
  3. Transitive: (a,b)∈R(a, b) \in R and (b,c)∈R⇒(a,c)∈R(b, c) \in R \Rightarrow (a, c) \in R.

Example: on Z\mathbb{Z}, define aRba R b iff a≡b(mod3)a \equiv b \pmod 3 (i.e. 3∣a−b3 \mid a - b).

  • Reflexive: a−a=0a - a = 0 is divisible by 3.
  • Symmetric: if 3∣a−b3 \mid a - b then 3∣b−a3 \mid b - a.
  • Transitive: if 3∣a−b3 \mid a - b and 3∣b−c3 \mid b - c then 3∣(a−b)+(b−c)=a−c3 \mid (a-b)+(b-c) = a - c.

So RR is an equivalence relation; it partitions Z\mathbb{Z} into three equivalence classes (remainders 0, 1, 2).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2079 · 5 marks

What is generalized pigeonhole principle? If a class has 24 students, what is the maximum number of possible grading that must be done to ensure that there at least two students with the same grade.

Answer

Generalized pigeonhole principle: if NN objects are placed into kk boxes, then at least one box contains at least ⌈N/k⌉\lceil N/k \rceil objects.

Application: 24 students, with kk possible grades. At least two students share a grade when ⌈24/k⌉≥2\lceil 24/k \rceil \ge 2, i.e. when k<24k < 24. If there were 24 or more grades, all students could have different grades. Hence the number of distinct grades must be at most k=23k = 23; with 23 grades (the maximum), ⌈24/23⌉=2\lceil 24/23 \rceil = 2, so at least two students are guaranteed the same grade.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 10 marks

Explain how set operations can be represented using venn diagram with example. Convert the following sentences using quantifier: (a) Not all good peoples are heroes. (b) Every peoples in our country are loyal. (c) Some people hate good people.

Answer

Set operations with Venn diagrams: the universal set UU is drawn as a rectangle and each set as a circle inside it. Shading shows the result:

  • Union A∪BA \cup B: shade both circles entirely.
  • Intersection A∩BA \cap B: shade only the overlapping region.
  • Difference A−BA - B: shade the part of AA outside BB.
  • Complement Aˉ\bar{A}: shade everything in UU outside AA.

Example: U={1,…,8}U = \{1,\dots,8\}, A={1,2,3,4}A = \{1,2,3,4\}, B={3,4,5,6}B = \{3,4,5,6\}. Then A∪B={1,…,6}A \cup B = \{1,\dots,6\}, A∩B={3,4}A \cap B = \{3,4\}, A−B={1,2}A - B = \{1,2\}, Aˉ={5,6,7,8}\bar A = \{5,6,7,8\}. In the diagram, 3 and 4 lie in the overlap, 1 and 2 in AA only, 5 and 6 in BB only, and 7 and 8 outside both circles.

Quantifier forms: let G(x)G(x): xx is good, H(x)H(x): xx is a hero, P(x)P(x): xx is a person.

(a) Not all good people are heroes: ¬∀x (G(x)→H(x))≡∃x (G(x)∧¬H(x))\neg\forall x\,\big(G(x) \to H(x)\big) \equiv \exists x\,\big(G(x) \wedge \neg H(x)\big)

(b) Every person in our country is loyal (with L(x)L(x): xx is loyal, domain = people of our country): ∀x L(x)\forall x\, L(x)

(c) Some people hate good people (with Hate(x,y)Hate(x, y): xx hates yy): ∃x ∃y (P(x)∧G(y)∧P(y)∧Hate(x,y))\exists x\,\exists y\,\big(P(x) \wedge G(y) \wedge P(y) \wedge Hate(x, y)\big)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5+5 marks

State ceiling function and floor function with examples. How mathematical induction can be used to prove the correctness of recursive algorithm? Illustrate with an example.

Answer

Floor function ⌊x⌋\lfloor x \rfloor: the greatest integer less than or equal to xx. Examples: ⌊3.7⌋=3\lfloor 3.7 \rfloor = 3, ⌊−2.3⌋=−3\lfloor -2.3 \rfloor = -3, ⌊5⌋=5\lfloor 5 \rfloor = 5.

Ceiling function ⌈x⌉\lceil x \rceil: the least integer greater than or equal to xx. Examples: ⌈3.2⌉=4\lceil 3.2 \rceil = 4, ⌈−2.7⌉=−2\lceil -2.7 \rceil = -2, ⌈5⌉=5\lceil 5 \rceil = 5.

Induction and recursive algorithms: a recursive algorithm solves a problem by calling itself on smaller inputs, with a base case. Its correctness is proved by induction on the input size: show the algorithm is correct for the base case (basis), then assume it is correct for all smaller inputs (inductive hypothesis) and show that the recursive step combines their results into a correct answer for the current input.

Example: recursive power function.

power(a, n):         // a != 0, n >= 0
    if n == 0: return 1
    return a * power(a, n - 1)

Claim: power(a,n)=anpower(a, n) = a^n for all n≥0n \ge 0.

Basis: n=0n = 0 returns 1=a01 = a^0.

Inductive step: assume power(a,k)=akpower(a, k) = a^k. Then power(a,k+1)=a⋅power(a,k)=a⋅ak=ak+1power(a, k+1) = a \cdot power(a, k) = a \cdot a^k = a^{k+1}.

Hence the algorithm is correct for all n≥0n \ge 0 (and terminates since nn decreases each call).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 4+6 marks

What does connectivity in graphs mean? Differentiate between permutation and combination. Solve the recurrence relation an=7an−1−10an−2a_n = 7a_{n-1} - 10a_{n-2} with initial conditions a0=2a_0 = 2 and a1=3a_1 = 3.

Answer

Connectivity in graphs: an undirected graph is connected if there is a path between every pair of distinct vertices; otherwise it is disconnected and splits into connected components. A directed graph is strongly connected if there is a directed path from every vertex to every other, and weakly connected if the underlying undirected graph is connected. Connectivity also measures robustness: a cut vertex or bridge is one whose removal disconnects the graph.

Permutation vs combination:

PermutationCombination
Ordered arrangement of rr objects out of nnUnordered selection of rr objects out of nn
Order mattersOrder does not matter
P(n,r)=n!(n−r)!P(n, r) = \dfrac{n!}{(n-r)!}C(n,r)=n!r!(n−r)!C(n, r) = \dfrac{n!}{r!(n-r)!}
abc≠bacabc \ne bac{a,b,c}={b,a,c}\{a,b,c\} = \{b,a,c\}

Also P(n,r)=r! C(n,r)P(n,r) = r!\,C(n,r).

Recurrence: an=7an−1−10an−2a_n = 7a_{n-1} - 10a_{n-2}, a0=2a_0 = 2, a1=3a_1 = 3.

Characteristic equation: r2−7r+10=0⇒(r−2)(r−5)=0r^2 - 7r + 10 = 0 \Rightarrow (r-2)(r-5) = 0, so r=2,5r = 2, 5.

an=α2n+β5na_n = \alpha 2^n + \beta 5^n

From a0a_0: α+β=2\alpha + \beta = 2. From a1a_1: 2α+5β=32\alpha + 5\beta = 3. Subtracting twice the first: 3β=−13\beta = -1, so β=−13\beta = -\tfrac13 and α=73\alpha = \tfrac73.

an=73 2n−13 5na_n = \frac{7}{3}\,2^n - \frac{1}{3}\,5^n

Check: a1=14/3−5/3=3a_1 = 14/3 - 5/3 = 3. ✓\checkmark

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Describe pre-order, postorder and inorder traversal of a tree with an example.

Answer

A tree traversal visits every vertex of an ordered rooted tree exactly once. For a binary tree with root rr, left subtree LL and right subtree RR:

  • Pre-order: visit root, then LL, then RR (Root-Left-Right).
  • In-order: traverse LL, visit root, then RR (Left-Root-Right).
  • Post-order: traverse LL, then RR, visit root (Left-Right-Root).

Example tree: AA is the root with children BB (left) and CC (right); BB has children DD (left) and EE (right); CC has right child FF.

  • Pre-order: A,B,D,E,C,FA, B, D, E, C, F
  • In-order: D,B,E,A,C,FD, B, E, A, C, F
  • Post-order: D,E,B,F,C,AD, E, B, F, C, A

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Explain one-to-one and onto function with example. What is identity function?

Answer

One-to-one (injective) function: f:A→Bf: A \to B is one-to-one if different inputs give different outputs: f(a1)=f(a2)⇒a1=a2f(a_1) = f(a_2) \Rightarrow a_1 = a_2. Example: f(x)=3x−2f(x) = 3x - 2 on R\mathbb{R}. Counter-example: f(x)=x2f(x) = x^2 on R\mathbb{R} since f(2)=f(−2)f(2) = f(-2).

Onto (surjective) function: f:A→Bf: A \to B is onto if every element of BB is the image of at least one element of AA (range = codomain). Example: f(x)=x3f(x) = x^3 from R\mathbb{R} to R\mathbb{R}. Counter-example: f(x)=x2f(x) = x^2 from R\mathbb{R} to R\mathbb{R} is not onto, since negative numbers are never obtained (it is onto [0,∞)[0, \infty)).

A function that is both is a bijection.

Identity function: IA:A→AI_A: A \to A with IA(x)=xI_A(x) = x for all x∈Ax \in A.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

How can you represent relations using matrices? Explain with suitable example.

Answer

A relation RR from A={a1,…,am}A = \{a_1, \dots, a_m\} to B={b1,…,bn}B = \{b_1, \dots, b_n\} is represented by an m×nm \times n zero-one matrix MR=[mij]M_R = [m_{ij}] where

mij={1if (ai,bj)∈R0otherwise.m_{ij} = \begin{cases} 1 & \text{if } (a_i, b_j) \in R \\ 0 & \text{otherwise.} \end{cases}

Example: A={1,2,3}A = \{1, 2, 3\}, R={(1,1),(1,2),(2,1),(3,3)}R = \{(1,1), (1,2), (2,1), (3,3)\} on AA:

MR=[110100001]M_R = \begin{bmatrix} 1 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix}

Using the matrix to test properties:

  • Reflexive: all diagonal entries are 1.
  • Symmetric: MR=MRTM_R = M_R^{T} (here it is symmetric).
  • Antisymmetric: mij=1m_{ij} = 1 with i≠ji \ne j implies mji=0m_{ji} = 0.

Operations: union MR1∪R2=MR1∨MR2M_{R_1 \cup R_2} = M_{R_1} \vee M_{R_2}, intersection MR1∩R2=MR1∧MR2M_{R_1 \cap R_2} = M_{R_1} \wedge M_{R_2}, and composition MS∘R=MR⊙MSM_{S \circ R} = M_R \odot M_S (Boolean product).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Prove that 2\sqrt{2} is irrational number.

Answer

Claim: 2\sqrt{2} is irrational.

Proof by contradiction. Suppose 2\sqrt{2} is rational. Then 2=ab\sqrt{2} = \dfrac{a}{b} with integers a,ba, b, b≠0b \ne 0, and gcd⁡(a,b)=1\gcd(a, b) = 1 (fraction in lowest terms).

Squaring: 2=a2b22 = \dfrac{a^2}{b^2}, so a2=2b2a^2 = 2b^2. Hence a2a^2 is even, which implies aa is even (the square of an odd number is odd). Write a=2ca = 2c.

Then 4c2=2b24c^2 = 2b^2, so b2=2c2b^2 = 2c^2, hence b2b^2 is even and bb is even.

Now both aa and bb are even, so 2 divides gcd⁡(a,b)\gcd(a,b), contradicting gcd⁡(a,b)=1\gcd(a,b) = 1. Therefore 2\sqrt{2} is irrational. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Solve the system of following congruences using Chinese Remainder theorem: x≡2(mod3)x \equiv 2 \pmod{3}, x≡3(mod5)x \equiv 3 \pmod{5}, x≡2(mod7)x \equiv 2 \pmod{7}

Answer

Solve x≡2(mod3)x \equiv 2 \pmod 3, x≡3(mod5)x \equiv 3 \pmod 5, x≡2(mod7)x \equiv 2 \pmod 7.

The moduli are pairwise coprime, so CRT applies. M=3⋅5⋅7=105M = 3 \cdot 5 \cdot 7 = 105.

M1=105/3=35M_1 = 105/3 = 35, M2=105/5=21M_2 = 105/5 = 21, M3=105/7=15M_3 = 105/7 = 15.

Inverses yiy_i with Miyi≡1(modmi)M_i y_i \equiv 1 \pmod{m_i}:

  • 35≡2(mod3)35 \equiv 2 \pmod 3, and 2⋅2=4≡12 \cdot 2 = 4 \equiv 1, so y1=2y_1 = 2.
  • 21≡1(mod5)21 \equiv 1 \pmod 5, so y2=1y_2 = 1.
  • 15≡1(mod7)15 \equiv 1 \pmod 7, so y3=1y_3 = 1.

x=2⋅35⋅2+3⋅21⋅1+2⋅15⋅1=140+63+30=233x = 2\cdot 35\cdot 2 + 3\cdot 21\cdot 1 + 2\cdot 15\cdot 1 = 140 + 63 + 30 = 233

233 mod 105=23233 \bmod 105 = 23

So x≡23(mod105)x \equiv 23 \pmod{105}. Check: 23=3⋅7+223 = 3\cdot7+2, 23=5⋅4+323 = 5\cdot4+3, 23=7⋅3+223 = 7\cdot3+2. ✓\checkmark

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

What is the pigeonhole principle? Show that (n+1k)=(nk−1)+(nk)\binom{n+1}{k} = \binom{n}{k-1} + \binom{n}{k} where nn and kk are positive integers with n≥kn \geq k.

Answer

Pigeonhole principle: if k+1k+1 or more objects are placed into kk boxes, then at least one box contains two or more objects. (Generalized: NN objects in kk boxes gives some box with at least ⌈N/k⌉\lceil N/k\rceil objects.)

Pascal's identity: (n+1k)=(nk−1)+(nk)\dbinom{n+1}{k} = \dbinom{n}{k-1} + \dbinom{n}{k}.

Algebraic proof:

(nk−1)+(nk)=n!(k−1)!(n−k+1)!+n!k!(n−k)!\binom{n}{k-1} + \binom{n}{k} = \frac{n!}{(k-1)!(n-k+1)!} + \frac{n!}{k!(n-k)!}

Common denominator k!(n−k+1)!k!(n-k+1)!:

=n! k+n! (n−k+1)k! (n−k+1)!=n! (n+1)k! (n+1−k)!=(n+1)!k! (n+1−k)!=(n+1k).■= \frac{n!\,k + n!\,(n-k+1)}{k!\,(n-k+1)!} = \frac{n!\,(n+1)}{k!\,(n+1-k)!} = \frac{(n+1)!}{k!\,(n+1-k)!} = \binom{n+1}{k}. \quad\blacksquare

Combinatorial proof: choose kk items from n+1n+1 items, one of which is a special item xx. Either xx is chosen (then choose k−1k-1 more from the other nn: (nk−1)\binom{n}{k-1} ways) or xx is not chosen (choose all kk from the other nn: (nk)\binom{n}{k} ways).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

What is permutation? What is the next permutation in lexicographic order after 362541?

Answer

A permutation is an ordered arrangement of the objects of a set; rr-permutations of nn objects number P(n,r)=n!(n−r)!P(n,r) = \dfrac{n!}{(n-r)!}, and all nn objects can be arranged in n!n! ways.

Next permutation after 362541 (lexicographic order):

  1. From the right, find the first digit smaller than its right neighbour: the suffix 541541 is decreasing, and 2<52 < 5, so the pivot is 2.
  2. In the suffix 5,4,15, 4, 1 pick the smallest digit larger than 2: it is 4. Swap: 364521364521.
  3. Reverse the part after the pivot's position: 521→125521 \to 125.

Next permutation: 364125.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Explain incidence matrix representation of a graph with example.

Answer

The incidence matrix of an undirected graph GG with vertices v1,…,vnv_1,\dots,v_n and edges e1,…,eme_1,\dots,e_m is an n×mn \times m matrix M=[mij]M = [m_{ij}] with

mij={1if ej is incident with vi0otherwise.m_{ij} = \begin{cases} 1 & \text{if } e_j \text{ is incident with } v_i \\ 0 & \text{otherwise.} \end{cases}

(A loop is shown by a 1 only once in its column; multiple edges give identical columns. For a directed graph, use +1+1 at the tail and −1-1 at the head.)

Example: V={v1,v2,v3,v4}V = \{v_1, v_2, v_3, v_4\}, edges e1=v1v2e_1 = v_1v_2, e2=v2v3e_2 = v_2v_3, e3=v3v4e_3 = v_3v_4, e4=v1v3e_4 = v_1v_3:

M=e1e2e3e4v11001v21100v30111v40010M = \begin{array}{c|cccc} & e_1 & e_2 & e_3 & e_4 \\ \hline v_1 & 1 & 0 & 0 & 1 \\ v_2 & 1 & 1 & 0 & 0 \\ v_3 & 0 & 1 & 1 & 1 \\ v_4 & 0 & 0 & 1 & 0 \end{array}

Each column has exactly two 1s (the two endpoints of the edge), and each row sum equals the degree of the vertex (deg⁡v3=3\deg v_3 = 3). It needs O(nm)O(nm) storage, so it is less compact than an adjacency list for sparse graphs.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080 · 5 marks

Define tree traversal. Explain pre-order traversal with example.

Answer

Tree traversal (tree walk) is the process of visiting every vertex of a rooted tree exactly once in a systematic order.

Pre-order traversal: visit the root first, then recursively traverse each subtree from left to right (Root, Left, Right).

preorder(T):
    visit(root of T)
    for each child subtree in left-to-right order:
        preorder(subtree)

Example: root AA with children BB and CC; BB has children DD and EE; CC has child FF.

Pre-order: start at AA, go to BB, then DD, then EE, back up to CC, then FF.

A,B,D,E,C,FA, B, D, E, C, F

Pre-order is used to copy a tree and to produce prefix (Polish) expressions.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 4 marks

What is Boolean matrix and list its operations?

Answer

A Boolean matrix (zero-one matrix) is a matrix whose entries are only 0 or 1. It is used, for example, to represent relations and graphs.

Operations for A=[aij]A = [a_{ij}] and B=[bij]B = [b_{ij}] of the same size:

  • Join (OR): A∨B=[aij∨bij]A \vee B = [a_{ij} \vee b_{ij}].
  • Meet (AND): A∧B=[aij∧bij]A \wedge B = [a_{ij} \wedge b_{ij}].
  • Boolean product: for AA (m×km \times k) and BB (k×nk \times n), A⊙B=[cij]A \odot B = [c_{ij}] where cij=(ai1∧b1j)∨(ai2∧b2j)∨⋯∨(aik∧bkj)c_{ij} = (a_{i1} \wedge b_{1j}) \vee (a_{i2} \wedge b_{2j}) \vee \dots \vee (a_{ik} \wedge b_{kj}).
  • Boolean power: A[r]=A⊙A⊙⋯⊙AA^{[r]} = A \odot A \odot \cdots \odot A (rr times).
  • Also transpose and complement.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 2 marks

Differentiate between graph and tree.

Answer

GraphTree
May contain cyclesConnected and has no cycles
May be connected or disconnectedAlways connected
Any number of edgesExactly n−1n - 1 edges for nn vertices
Several paths may exist between two verticesExactly one path between any two vertices
No root neededMay be rooted (hierarchical)

Every tree is a graph, but not every graph is a tree.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 8 marks

Describe about the necessary conditions for graphs to be isomorphic with an example.

Answer

Two simple graphs G1=(V1,E1)G_1 = (V_1, E_1) and G2=(V2,E2)G_2 = (V_2, E_2) are isomorphic if there is a bijection f:V1→V2f: V_1 \to V_2 such that u,vu, v are adjacent in G1G_1 if and only if f(u),f(v)f(u), f(v) are adjacent in G2G_2. No simple test is known to prove isomorphism, but there are easy necessary conditions (invariants). If any one fails, the graphs are not isomorphic:

  1. The same number of vertices.
  2. The same number of edges.
  3. The same degree sequence (the multiset of vertex degrees).
  4. The same number of vertices of each degree; a vertex of degree dd must map to a vertex of degree dd.
  5. The same number of cycles of each length (e.g. both have triangles or neither does), and the same circuit structure.
  6. Same connectivity: both connected or both disconnected, with the same number of components.
  7. Adjacency structure preserved: neighbours of a vertex must map to neighbours of its image (e.g. adjacent vertices of degree 3 map to adjacent vertices of degree 3).
  8. Equivalently, adjacency matrices must be identical after suitably relabelling vertices.

These conditions are necessary but not sufficient; after they hold, one must exhibit the mapping ff and check edges.

Example: G1G_1: vertices a,b,c,da,b,c,d with edges ab,bc,cd,daab, bc, cd, da. G2G_2: vertices 1,2,3,41,2,3,4 with edges 12,23,34,4112, 23, 34, 41. Both have 4 vertices, 4 edges and degree sequence (2,2,2,2)(2,2,2,2). Define f(a)=1f(a)=1, f(b)=2f(b)=2, f(c)=3f(c)=3, f(d)=4f(d)=4. Edges map to 12,23,34,4112, 23, 34, 41, exactly the edge set of G2G_2, so G1≅G2G_1 \cong G_2.

Non-example: a 4-cycle C4C_4 and a star K1,3K_{1,3} both have 4 vertices, but C4C_4 has 4 edges and K1,3K_{1,3} only 3, so they are not isomorphic. Also the path P4P_4 (degrees 1,2,2,11,2,2,1) and K1,3K_{1,3} (degrees 3,1,1,13,1,1,1) have the same number of edges (3) but different degree sequences.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 3 marks

Define randomized algorithm with an example.

Answer

A randomized algorithm makes random choices (random numbers) during execution, so its behaviour or running time may differ between runs on the same input. Two kinds: Las Vegas (always correct, running time random) and Monte Carlo (running time fixed, answer correct with high probability).

Example: randomized quicksort. Choose the pivot uniformly at random from the sub-array, partition around it, and recurse on both parts. Because no fixed input can force bad pivots consistently, the expected running time is O(nlog⁡n)O(n \log n) for every input, avoiding the O(n2)O(n^2) worst case on already sorted data. The output is always a correctly sorted array (Las Vegas).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 7 marks

Solve the recurrence relation an=−4an−1−4an−2a_n = -4a_{n-1} - 4a_{n-2} for n≥2n \ge 2, with initial condition a0=0a_0 = 0 and a1=1a_1 = 1.

Answer

an=−4an−1−4an−2a_n = -4a_{n-1} - 4a_{n-2}, a0=0a_0 = 0, a1=1a_1 = 1.

Characteristic equation: r2+4r+4=0⇒(r+2)2=0r^2 + 4r + 4 = 0 \Rightarrow (r+2)^2 = 0, so r=−2r = -2 (repeated root).

General solution:

an=(α+βn)(−2)na_n = (\alpha + \beta n)(-2)^n

Using a0=0a_0 = 0: α=0\alpha = 0.

Using a1=1a_1 = 1: β(−2)=1⇒β=−12\beta(-2) = 1 \Rightarrow \beta = -\tfrac12.

an=−n2(−2)n=n(−2)n−1a_n = -\frac{n}{2}(-2)^n = n(-2)^{n-1}

Check: a2=−4(1)−4(0)=−4a_2 = -4(1) - 4(0) = -4 and the formula gives 2(−2)=−42(-2) = -4. ✓\checkmark

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

List the negations of following statements: (a) He has passed the exam. (b) All dogs are loyal. (c) Some medicine has side effect. (d) If you study then you will pass the exam. (e) Open the door.

Answer

(a) "He has passed the exam." Negation: He has not passed the exam (He failed the exam).

(b) "All dogs are loyal." ∀x (D(x)→L(x))\forall x\,(D(x) \to L(x)). Negation: ∃x (D(x)∧¬L(x))\exists x\,(D(x) \wedge \neg L(x)), i.e. some dog is not loyal.

(c) "Some medicine has side effect." ∃x S(x)\exists x\,S(x). Negation: ∀x ¬S(x)\forall x\,\neg S(x), i.e. no medicine has a side effect.

(d) "If you study then you will pass the exam." p→qp \to q. Negation: p∧¬qp \wedge \neg q, i.e. you study and you will not pass the exam.

(e) "Open the door." This is a command, not a proposition, so it has no truth value and no logical negation. Its opposite instruction is "Do not open the door."

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

How does Kruskal algorithm work? Illustrate with an example.

Answer

Kruskal's algorithm finds a minimum spanning tree of a connected weighted graph by the greedy method.

Steps:

  1. Sort all edges in non-decreasing order of weight.
  2. Start with an empty edge set TT (each vertex is its own component).
  3. Take the next smallest edge; add it to TT if it does not form a cycle with edges already in TT (its endpoints are in different components), otherwise discard it.
  4. Stop when TT has n−1n - 1 edges.

Cycle checks are done with a union-find structure. Time: O(Elog⁡E)O(E \log E).

Example: vertices A,B,C,D,EA, B, C, D, E with edges AB=1AB=1, CD=2CD=2, AC=3AC=3, BC=4BC=4, DE=5DE=5, BD=6BD=6, CE=7CE=7.

EdgeWeightDecision
ABAB1Add
CDCD2Add
ACAC3Add (joins {A,B}\{A,B\} and {C,D}\{C,D\})
BCBC4Reject (cycle)
DEDE5Add (now 4 edges, done)

MST edges: AB,CD,AC,DEAB, CD, AC, DE with total weight 1+2+3+5=111 + 2 + 3 + 5 = 11.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

State generalized Pigeonhole principle. How many ways can we get the 3 digit integers without repeating the digit?

Answer

Generalized pigeonhole principle: if NN objects are placed into kk boxes, then some box contains at least ⌈N/k⌉\lceil N/k \rceil objects.

3-digit integers without repeating a digit: the hundreds digit cannot be 0, so there are 9 choices; the tens digit can be any of the remaining 9 digits (including 0); the units digit has 8 choices.

9×9×8=6489 \times 9 \times 8 = 648

There are 648 such integers.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

Define equivalence relation. How do you represent relation?

Answer

A relation RR on a set AA is an equivalence relation if it is reflexive ((a,a)∈R(a,a)\in R for all aa), symmetric ((a,b)∈R⇒(b,a)∈R(a,b)\in R \Rightarrow (b,a)\in R) and transitive ((a,b),(b,c)∈R⇒(a,c)∈R(a,b),(b,c)\in R \Rightarrow (a,c)\in R). Example: "has the same remainder when divided by 4" on Z\mathbb{Z}; it partitions Z\mathbb{Z} into equivalence classes.

Representing relations:

  1. Roster (set of ordered pairs): R={(1,1),(1,2),(2,1),(2,2),(3,3)}R = \{(1,1), (1,2), (2,1), (2,2), (3,3)\} on A={1,2,3}A = \{1,2,3\}.
  2. Zero-one matrix: entry mij=1m_{ij} = 1 if (ai,aj)∈R(a_i, a_j) \in R: MR=[110110001]M_R = \begin{bmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  3. Directed graph (digraph): each element is a vertex and each pair (a,b)(a, b) is a directed edge from aa to bb; a pair (a,a)(a,a) is a loop. For the relation above: loops on 1, 2, 3 and arrows 1↔21 \leftrightarrow 2.
  4. Rule/set-builder form: R={(a,b)∣a≡b(mod4)}R = \{(a,b) \mid a \equiv b \pmod 4\}.
  5. Table: rows and columns labelled by elements, marked where related.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

How do you solve computer arithmetic with large integers using Chinese remainder theorem? Give an example.

Answer

Chinese Remainder Theorem (CRT): if m1,…,mkm_1, \dots, m_k are pairwise coprime, the system x≡ai(modmi)x \equiv a_i \pmod{m_i} has a unique solution modulo M=m1m2⋯mkM = m_1 m_2 \cdots m_k.

Large-integer arithmetic: choose pairwise coprime moduli whose product exceeds the largest result expected. Represent each large integer by its tuple of remainders (x mod m1,…,x mod mk)(x \bmod m_1, \dots, x \bmod m_k). Addition, subtraction and multiplication are then done component-wise on small numbers (each in its own modulus), with no carries between components, which is fast and parallelisable. Finally, CRT reconstructs the actual result from the remainders.

Example: compute 17+817 + 8 using moduli 3,5,73, 5, 7 (M=105>25M = 105 > 25).

  • 17→(2,2,3)17 \to (2, 2, 3), 8→(2,3,1)8 \to (2, 3, 1).
  • Component-wise sum: (2+2 mod 3, 2+3 mod 5, 3+1 mod 7)=(1,0,4)(2+2 \bmod 3,\ 2+3 \bmod 5,\ 3+1 \bmod 7) = (1, 0, 4).

Solve x≡1(mod3)x \equiv 1 \pmod 3, x≡0(mod5)x \equiv 0 \pmod 5, x≡4(mod7)x \equiv 4 \pmod 7 with M1=35,M2=21,M3=15M_1 = 35, M_2 = 21, M_3 = 15 and inverses y1=2y_1 = 2, y2=1y_2 = 1, y3=1y_3 = 1:

x=1⋅35⋅2+0⋅21⋅1+4⋅15⋅1=70+0+60=130≡25(mod105)x = 1\cdot35\cdot2 + 0\cdot21\cdot1 + 4\cdot15\cdot1 = 70 + 0 + 60 = 130 \equiv 25 \pmod{105}

So 17+8=2517 + 8 = 25, as expected.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

Write Dijkstra's algorithm to find the shortest path from source node to goal node.

Answer

Dijkstra's algorithm computes shortest paths from a source node ss to the other nodes of a weighted graph with non-negative edge weights, and so gives the shortest path to a goal node gg.

Dijkstra(G, w, s, g):
    for each vertex v in G:
        dist[v] = infinity
        prev[v] = none
    dist[s] = 0
    Q = set of all vertices
    while Q is not empty:
        u = vertex in Q with smallest dist[u]
        remove u from Q
        if u == g: break           // shortest path to goal found
        for each neighbour v of u still in Q:
            alt = dist[u] + w(u, v)
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
    path = []
    u = g
    while u is not none:
        insert u at front of path
        u = prev[u]
    return path, dist[g]

Working: the vertex with the smallest tentative distance is permanently labelled, then its neighbours' distances are relaxed (updated if a shorter route is found via it). Repeating this expands outward from ss. Complexity is O(V2)O(V^2) with an array and O((V+E)log⁡V)O((V+E)\log V) with a binary heap.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

How do you plot graph for function f(x)=x+1f(x) = x + 1? Define ceiling, floor and exponential function.

Answer

Plotting f(x)=x+1f(x) = x + 1:

  1. Make a table of values:
xx−2-2−1-1001122
f(x)f(x)−1-100112233
  1. Plot points (x,f(x))(x, f(x)) on the Cartesian plane: (−2,−1)(-2,-1), (−1,0)(-1,0), (0,1)(0,1), (1,2)(1,2), (2,3)(2,3).
  2. Join them with a straight line. It is a line of slope 1 with yy-intercept 1 and xx-intercept −1-1.

Definitions:

  • Floor: ⌊x⌋\lfloor x \rfloor is the largest integer ≤x\le x (e.g. ⌊2.8⌋=2\lfloor 2.8 \rfloor = 2, ⌊−1.2⌋=−2\lfloor -1.2 \rfloor = -2).
  • Ceiling: ⌈x⌉\lceil x \rceil is the smallest integer ≥x\ge x (e.g. ⌈2.1⌉=3\lceil 2.1 \rceil = 3, ⌈−1.8⌉=−1\lceil -1.8 \rceil = -1).
  • Exponential function: f(x)=axf(x) = a^x with base a>0a > 0, a≠1a \ne 1 (commonly 2x2^x or exe^x). It is always positive, passes through (0,1)(0, 1), and grows rapidly for a>1a > 1. Example: 23=82^3 = 8.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2080.1 · 5 marks

List any five rules of inferences.

Answer

Rules of inference are valid argument forms used to derive a conclusion from premises. Five common ones:

  1. Modus ponens: p,  p→q  ∴  qp,\; p\to q \;\therefore\; q
  2. Modus tollens: ¬q,  p→q  ∴  ¬p\neg q,\; p\to q \;\therefore\; \neg p
  3. Hypothetical syllogism: p→q,  q→r  ∴  p→rp\to q,\; q\to r \;\therefore\; p\to r
  4. Disjunctive syllogism: p∨q,  ¬p  ∴  qp\lor q,\; \neg p \;\therefore\; q
  5. Addition: p  ∴  p∨qp \;\therefore\; p\lor q

Other rules are simplification (p∧q∴pp\land q\therefore p), conjunction (p,q∴p∧qp, q \therefore p\land q) and resolution (p∨q, ¬p∨r∴q∨rp\lor q,\ \neg p\lor r \therefore q\lor r).

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5+5 marks

Define graph isomorphism with an example. Using Kruskal's algorithm generate the Minimum Spanning Tree from following graph.

Answer

Graph isomorphism

Two simple graphs G1=(V1,E1)G_1=(V_1,E_1) and G2=(V2,E2)G_2=(V_2,E_2) are isomorphic if there is a one-to-one and onto function f:V1→V2f:V_1\to V_2 such that aa and bb are adjacent in G1G_1 if and only if f(a)f(a) and f(b)f(b) are adjacent in G2G_2. Isomorphic graphs have the same number of vertices, edges, the same degree sequence and the same cycles.

Example: G1G_1 has vertices u1,u2,u3,u4u_1,u_2,u_3,u_4 and edges u1u2, u2u3, u3u4, u4u1u_1u_2,\,u_2u_3,\,u_3u_4,\,u_4u_1 (a 4-cycle). G2G_2 has vertices v1,v2,v3,v4v_1,v_2,v_3,v_4 and edges v1v3, v3v2, v2v4, v4v1v_1v_3,\,v_3v_2,\,v_2v_4,\,v_4v_1. The function f(u1)=v1, f(u2)=v3, f(u3)=v2, f(u4)=v4f(u_1)=v_1,\ f(u_2)=v_3,\ f(u_3)=v_2,\ f(u_4)=v_4 maps every edge of G1G_1 onto an edge of G2G_2 and vice versa, so G1≅G2G_1\cong G_2.

Kruskal's algorithm (Minimum Spanning Tree)

  1. Sort all edges in non-decreasing order of weight.
  2. Start with an empty edge set TT.
  3. Take the next smallest edge; add it to TT if it does not form a cycle with edges already in TT, otherwise discard it.
  4. Stop when TT has n−1n-1 edges (nn = number of vertices).

Illustration (graph with edges ab=1, bc=2, ac=3, cd=4, bd=5, de=6, ce=7ab=1,\ bc=2,\ ac=3,\ cd=4,\ bd=5,\ de=6,\ ce=7):

EdgeWeightAction
ab1accept
bc2accept
ac3reject (cycle a-b-c)
cd4accept
bd5reject (cycle)
de6accept

T={ab,bc,cd,de}T=\{ab,bc,cd,de\} has 4 edges for 5 vertices, so it is the MST with total weight 1+2+4+6=131+2+4+6=13.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 2+8 marks

What are the uses of randomized algorithm? Find the solution to the recurrence relation an=6an−1−11an−2+6an−3a_n = 6a_{n-1} - 11a_{n-2} + 6a_{n-3} with the initial conditions a0=2a_0 = 2, a1=5a_1 = 5 and a2=15a_2 = 15.

Answer

Uses of randomized algorithms

  • They are usually simpler and faster than deterministic ones (e.g. randomized quicksort avoids the worst case on sorted input).
  • They give good expected running time for hard problems such as primality testing (Miller-Rabin), min-cut and hashing.
  • They are used in cryptography (random keys), simulation, Monte Carlo methods and load balancing.

Recurrence

an=6an−1−11an−2+6an−3a_n = 6a_{n-1}-11a_{n-2}+6a_{n-3}

Characteristic equation: r3−6r2+11r−6=0r^3-6r^2+11r-6=0, i.e. (r−1)(r−2)(r−3)=0(r-1)(r-2)(r-3)=0, so r=1,2,3r=1,2,3.

an=A⋅1n+B⋅2n+C⋅3na_n = A\cdot 1^n + B\cdot 2^n + C\cdot 3^n

Using the initial conditions:

A+B+C=2,A+2B+3C=5,A+4B+9C=15A+B+C=2,\qquad A+2B+3C=5,\qquad A+4B+9C=15

Subtracting consecutive equations: B+2C=3B+2C=3 and 2B+6C=102B+6C=10, so B+3C=5B+3C=5. Hence C=2C=2, B=−1B=-1, A=1A=1.

an=1−2n+2⋅3n\boxed{a_n = 1-2^n+2\cdot 3^n}

Check: a0=1−1+2=2a_0=1-1+2=2, a1=1−2+6=5a_1=1-2+6=5, a2=1−4+18=15a_2=1-4+18=15.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 6+4 marks

Define Boolean function, exponential function and partial ordering. List the computer representations for following set over universal set U={0,1,2,3,4,5,6,7,8,9}U=\{0,1,2,3,4,5,6,7,8,9\}: (a) Set that contains even number (b) Set that contains multiple of 5 (c) Set that contains number greater than 7 (d) Set that contains prime number.

Answer

Boolean function: a function f:{0,1}n→{0,1}f:\{0,1\}^n\to\{0,1\} that assigns 0 or 1 to every combination of nn Boolean variables, e.g. f(x,y)=x⋅y+xˉf(x,y)=x\cdot y+\bar{x}.

Exponential function: a function of the form f(x)=axf(x)=a^x with constant base a>0, a≠1a>0,\ a\neq1 (e.g. 2x2^x, exe^x), where the variable appears in the exponent.

Partial ordering: a relation RR on a set SS that is reflexive, antisymmetric and transitive. The pair (S,R)(S,R) is a partially ordered set (poset), e.g. ≤\le on integers or divisibility ∣| on positive integers.

Computer (bit-string) representation over U={0,1,…,9}U=\{0,1,\dots,9\}, where bit ii is 1 if ii is in the set:

(a) Even numbers {0,2,4,6,8}\{0,2,4,6,8\}: 10101010101010101010

(b) Multiples of 5 {0,5}\{0,5\}: 10000100001000010000

(c) Numbers greater than 7 {8,9}\{8,9\}: 00000000110000000011

(d) Primes {2,3,5,7}\{2,3,5,7\}: 00110101000011010100

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Define proposition. Convert the following sentences to predicate: (a) Some kind hearted peoples do still exist. (b) Student who study hard and do the homework get good marks in exam.

Answer

Proposition: a declarative sentence that is either true or false, but not both. For example, "Kathmandu is the capital of Nepal" is a proposition; "Close the door" and "What is your name?" are not.

Predicate forms

(a) Let K(x)K(x): "xx is kind hearted", with the domain of all people. "Some kind hearted people still exist" is

∃x K(x)\exists x\, K(x)

(b) Let S(x)S(x): "xx is a student", H(x)H(x): "xx studies hard", D(x)D(x): "xx does the homework", G(x)G(x): "xx gets good marks in the exam".

∀x [(S(x)∧H(x)∧D(x))→G(x)]\forall x\,\big[(S(x)\land H(x)\land D(x))\to G(x)\big]

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Prove that 13+23+33+⋯+n31^3 + 2^3 + 3^3 + \cdots + n^3 is a perfect square using mathematical induction.

Answer

Claim: P(n): 13+23+⋯+n3=(n(n+1)2)2P(n):\ 1^3+2^3+\cdots+n^3=\left(\dfrac{n(n+1)}{2}\right)^2, which is the square of the integer n(n+1)2\dfrac{n(n+1)}{2}, hence a perfect square.

Basis step: n=1n=1: LHS =1=1, RHS =(1⋅22)2=1=\left(\frac{1\cdot2}{2}\right)^2=1. True.

Inductive step: Assume P(k)P(k) is true:

13+⋯+k3=k2(k+1)241^3+\cdots+k^3=\frac{k^2(k+1)^2}{4}

Then

13+⋯+k3+(k+1)3=k2(k+1)24+(k+1)3=(k+1)2 [k2+4(k+1)]4=(k+1)2(k+2)241^3+\cdots+k^3+(k+1)^3=\frac{k^2(k+1)^2}{4}+(k+1)^3=\frac{(k+1)^2\,[k^2+4(k+1)]}{4}=\frac{(k+1)^2(k+2)^2}{4}

which is ((k+1)(k+2)2)2\left(\frac{(k+1)(k+2)}{2}\right)^2, i.e. P(k+1)P(k+1).

By mathematical induction P(n)P(n) holds for all n≥1n\ge1, so the sum is always a perfect square.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Find the multiplicative inverse of 6 in Z25\mathbb{Z}_{25} using Extended Euclidean Algorithm.

Answer

We need xx with 6x≡1(mod25)6x\equiv1 \pmod{25}. First, gcd⁡(6,25)=1\gcd(6,25)=1, so the inverse exists.

Euclidean steps:

25=4⋅6+125 = 4\cdot6+1 6=6⋅1+06 = 6\cdot1+0

The gcd is 1. Back-substitute:

1=25−4⋅6=25⋅1+6⋅(−4)1 = 25-4\cdot6 = 25\cdot1+6\cdot(-4)

So the coefficient of 6 is −4-4, and −4≡21(mod25)-4\equiv21 \pmod{25}.

6−1≡21(mod25)6^{-1}\equiv 21 \pmod{25}

Check: 6⋅21=126=5⋅25+1≡16\cdot21=126=5\cdot25+1\equiv1.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

State generalized Pigeonhole principle. How many ways can you draw four digits integers without repetition of the digit?

Answer

Generalized pigeonhole principle: if NN objects are placed into kk boxes, then at least one box contains at least ⌈N/k⌉\lceil N/k\rceil objects.

Four-digit integers without repetition of digits

The first digit cannot be 0, so it has 9 choices (1-9). The second digit can be any of the remaining 9 digits (including 0), the third has 8 choices and the fourth has 7.

9×9×8×7=45369\times9\times8\times7=4536

So 4536 such integers can be formed.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Explain any two ways of representing the graph.

Answer

Two common ways to represent a graph G=(V,E)G=(V,E) with nn vertices:

1. Adjacency list: for each vertex store a list of the vertices adjacent to it.

For the graph with edges ab,ac,bc,cdab, ac, bc, cd:

VertexAdjacent vertices
ab, c
ba, c
ca, b, d
dc

It uses O(n+e)O(n+e) space and is efficient for sparse graphs.

2. Adjacency matrix: an n×nn\times n matrix AA where aij=1a_{ij}=1 if there is an edge from viv_i to vjv_j, and 0 otherwise (for weighted graphs, store the weight). For the same graph (order a, b, c, d):

A=(0110101011010010)A=\begin{pmatrix}0&1&1&0\\1&0&1&0\\1&1&0&1\\0&0&1&0\end{pmatrix}

For an undirected graph the matrix is symmetric. It needs O(n2)O(n^2) space but allows checking an edge in O(1)O(1) time.

(Incidence matrix, an n×en\times e matrix of vertex-edge incidence, is a third option.)

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Compute the value of 8 MOD 88 \text{ MOD } 8, −9 MOD 4-9 \text{ MOD } 4, 7 MOD 177 \text{ MOD } 17, 6 MOD 76 \text{ MOD } 7 and −8 MOD 3-8 \text{ MOD } 3.

Answer

a mod ma \bmod m is the remainder rr with a=qm+ra=qm+r and 0≤r<m0\le r<m.

  • 8 mod 8=08 \bmod 8 = 0, since 8=1⋅8+08=1\cdot8+0.
  • −9 mod 4=3-9 \bmod 4 = 3, since −9=(−3)⋅4+3-9=(-3)\cdot4+3.
  • 7 mod 17=77 \bmod 17 = 7, since 7=0⋅17+77=0\cdot17+7.
  • 6 mod 7=66 \bmod 7 = 6, since 6=0⋅7+66=0\cdot7+6.
  • −8 mod 3=1-8 \bmod 3 = 1, since −8=(−3)⋅3+1-8=(-3)\cdot3+1.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Define cut vertices and cut edges. How do you determine whether the graph has Euler path?

Answer

Cut vertex (articulation point): a vertex whose removal (together with its incident edges) increases the number of connected components of the graph.

Cut edge (bridge): an edge whose removal increases the number of connected components.

Euler path: a path that uses every edge of the graph exactly once. For a connected graph:

  • The graph has an Euler path (not closed) if and only if it has exactly two vertices of odd degree; the path starts at one odd vertex and ends at the other.
  • If all vertices have even degree, the graph has an Euler circuit, which is also an Euler path (closed).
  • If it has more than two odd-degree vertices, no Euler path exists.

So count the degrees: 0 or 2 odd-degree vertices (in a connected graph) means an Euler path exists. For a directed graph, at most one vertex has out-degree minus in-degree =1=1, at most one has in-degree minus out-degree =1=1, and all others have equal in- and out-degree.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2081 · 5 marks

Explain about structural induction and recursive definitions with example.

Answer

Recursive definition: defines an object in terms of smaller instances of itself, using a basis (initial) case and a recursive step.

Example (factorial): 0!=10!=1 (basis); n!=n⋅(n−1)!n!=n\cdot(n-1)! for n≥1n\ge1 (recursive step).

Example (set of strings): the set Σ∗\Sigma^* of strings over alphabet Σ\Sigma: the empty string λ∈Σ∗\lambda\in\Sigma^*; if w∈Σ∗w\in\Sigma^* and x∈Σx\in\Sigma then wx∈Σ∗wx\in\Sigma^*.

Structural induction: a proof technique for recursively defined structures (strings, trees, formulas). To prove PP holds for all elements:

  1. Basis step: show PP holds for the elements specified in the basis.
  2. Recursive step: show that if PP holds for the elements used to construct a new element, then PP holds for the new element.

Example: a full binary tree is defined by: a single vertex is a full binary tree (height 0, 1 vertex); if T1,T2T_1,T_2 are full binary trees, joining their roots under a new root gives a full binary tree. Claim n(T)≤2h(T)+1−1n(T)\le 2^{h(T)+1}-1. Basis: one vertex, 1≤21−1=11\le 2^1-1=1. Step: n(T)=1+n(T1)+n(T2)≤1+2(2h+1−1)=2h+2−1n(T)=1+n(T_1)+n(T_2)\le1+2(2^{h+1}-1)=2^{h+2}-1 where h=max⁡(h1,h2)h=\max(h_1,h_2) and h(T)=h+1h(T)=h+1. So the claim holds for all full binary trees.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 2+8 marks

State division theory. Add two integers 1357813578 and 4573045730 using Chinese Remainder Theorem.

Answer

Division theorem: for any integer aa and positive integer dd there exist unique integers qq (quotient) and rr (remainder) with 0≤r<d0\le r<d such that a=dq+ra=dq+r.

Adding with the Chinese Remainder Theorem

The sum is below 6000060000, so choose pairwise coprime moduli whose product exceeds it: m1=99, m2=98, m3=97, m4=95m_1=99,\ m_2=98,\ m_3=97,\ m_4=95, with M=99⋅98⋅97⋅95=89,403,930M=99\cdot98\cdot97\cdot95=89{,}403{,}930.

Residues:

Modulus13578135784573045730Sum mod mm
991591106≡7106\equiv7
985462116≡18116\equiv18
979543138≡41138\equiv41
958835123≡28123\equiv28

So we solve x≡7 (99), x≡18 (98), x≡41 (97), x≡28 (95)x\equiv7\ (99),\ x\equiv18\ (98),\ x\equiv41\ (97),\ x\equiv28\ (95).

With Mk=M/mkM_k=M/m_k and yk=Mk−1 mod mky_k=M_k^{-1}\bmod m_k:

mkm_kMkM_kyky_k
9990307037
9891228533
9792169024
959410944

x=∑akMkyk=7(903070)(37)+18(912285)(33)+41(921690)(24)+28(941094)(4)x=\sum a_kM_ky_k = 7(903070)(37)+18(912285)(33)+41(921690)(24)+28(941094)(4) =233,895,130+541,897,290+906,942,960+105,402,528=1,788,137,908=233{,}895{,}130+541{,}897{,}290+906{,}942{,}960+105{,}402{,}528=1{,}788{,}137{,}908

x mod M=1,788,137,908−20⋅89,403,930=59,308x \bmod M = 1{,}788{,}137{,}908 - 20\cdot 89{,}403{,}930 = 59{,}308

13578+45730=59308\boxed{13578+45730=59308}

Check by direct addition: 13578+45730=5930813578+45730=59308.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 2+3+5 marks

Why do we need quantifiers? List any three rules of inferences. Prove that 2\sqrt{2} is irrational using prove by contradiction.

Answer

Need for quantifiers: propositional logic cannot express statements about all or some members of a domain, such as "every student passes" or "some integer is prime". Quantifiers (∀\forall universal, ∃\exists existential) let a predicate P(x)P(x) be turned into a proposition about a whole domain, which is needed for precise mathematical statements and reasoning.

Three rules of inference

  1. Modus ponens: p, p→q ∴ qp,\ p\to q\ \therefore\ q
  2. Modus tollens: ¬q, p→q ∴ ¬p\neg q,\ p\to q\ \therefore\ \neg p
  3. Hypothetical syllogism: p→q, q→r ∴ p→rp\to q,\ q\to r\ \therefore\ p\to r

Proof that 2\sqrt2 is irrational (by contradiction)

Assume 2\sqrt2 is rational. Then 2=ab\sqrt2=\dfrac ab with integers a,ba,b, b≠0b\ne0, and gcd⁡(a,b)=1\gcd(a,b)=1.

Squaring: 2=a2b22=\dfrac{a^2}{b^2}, so a2=2b2a^2=2b^2. Hence a2a^2 is even, so aa is even; write a=2ca=2c.

Then 4c2=2b24c^2=2b^2, so b2=2c2b^2=2c^2, which makes b2b^2 even and so bb even.

Both aa and bb are even, contradicting gcd⁡(a,b)=1\gcd(a,b)=1. Hence the assumption is false and 2\sqrt2 is irrational. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 2+4+4 marks

List some advantages of randomized algorithm. Given any set of ten natural numbers between 11 and 9999 inclusive, prove that there are two disjoint nonempty subsets of the set with equal sums of their elements. How do you generalize permutations and combinations?

Answer

Advantages of randomized algorithms

  • Simple to design and implement compared with deterministic algorithms for the same problem.
  • Good expected running time; no particular input can force the worst case (e.g. randomized quicksort).
  • Often faster and use less memory for hard problems (primality testing, hashing, min-cut).
  • Useful in cryptography and simulation.

Disjoint subsets with equal sums

Let SS be a set of ten natural numbers from 1 to 99. It has 210−1=10232^{10}-1=1023 nonempty subsets. The sum of any subset is at least 1 and at most the sum of the ten largest allowed numbers:

90+91+⋯+99=945.90+91+\cdots+99=945.

So there are only 945 possible sums for 1023 subsets. By the pigeonhole principle two different subsets A≠BA\ne B have the same sum.

If AA and BB overlap, remove the common elements from both: the sums stay equal. Neither remaining set can be empty: if A∖BA\setminus B were empty then A⊂BA\subset B and B∖AB\setminus A would have sum 0, which is impossible since all numbers are positive. So we get two disjoint nonempty subsets with equal sums. ■\blacksquare

Generalizing permutations and combinations

  • Permutations with repetition: nrn^r ordered selections of rr objects from nn types.
  • Permutations of nn objects with n1,n2,…,nkn_1,n_2,\dots,n_k identical objects of each type: n!n1! n2!⋯nk!\dfrac{n!}{n_1!\,n_2!\cdots n_k!}.
  • Combinations with repetition: C(n+r−1, r)C(n+r-1,\ r) ways to choose rr objects from nn types.

These reduce to P(n,r)=n!(n−r)!P(n,r)=\dfrac{n!}{(n-r)!} and C(n,r)=n!r!(n−r)!C(n,r)=\dfrac{n!}{r!(n-r)!} when repetition is not allowed.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 5 marks

Mention the necessary and sufficient conditions for Euler path and Euler circuit with example.

Answer

An Euler path is a path that uses every edge exactly once; an Euler circuit is such a path that starts and ends at the same vertex.

Euler circuit: a connected multigraph has an Euler circuit if and only if every vertex has even degree.

Euler path (not a circuit): a connected multigraph has an Euler path but no Euler circuit if and only if it has exactly two vertices of odd degree. The path starts at one odd vertex and ends at the other.

Examples

  • A square (4-cycle) a ⁣− ⁣b ⁣− ⁣c ⁣− ⁣d ⁣− ⁣aa\!-\!b\!-\!c\!-\!d\!-\!a: every vertex has degree 2 (even), so it has an Euler circuit a,b,c,d,aa,b,c,d,a.
  • A square with one diagonal acac: degrees are a=3, b=2, c=3, d=2a=3,\ b=2,\ c=3,\ d=2; exactly two odd vertices, so it has an Euler path starting at aa and ending at cc, e.g. a,b,c,a,d,ca,b,c,a,d,c, but no Euler circuit.
  • K4K_4 has all degrees 3 (four odd vertices), so neither exists.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 5 marks

How do you represent set? Explain.

Answer

A set is an unordered collection of distinct objects. It can be represented in several ways:

1. Roster (tabular) method: list the elements inside braces. A={1,2,3,4,5}A=\{1,2,3,4,5\}. For long sets an ellipsis is used: {1,2,3,…,100}\{1,2,3,\dots,100\}.

2. Set-builder (rule) method: describe a property common to all elements. A={x∣x∈Z, 1≤x≤5}A=\{x\mid x\in\mathbb{Z},\ 1\le x\le5\}.

3. Venn diagram: the universal set is drawn as a rectangle and each set as a closed curve (circle) inside it, with elements shown as points.

4. Recursive definition: give initial elements and a rule to generate others, e.g. 3∈S3\in S, and if x∈Sx\in S and y∈Sy\in S then x+y∈Sx+y\in S.

5. Computer (bit-string) representation: for a universal set U={u1,…,un}U=\{u_1,\dots,u_n\} in a fixed order, a subset is a bit string of length nn with bit ii equal to 1 if uiu_i is in the set. For U={1,…,5}U=\{1,\dots,5\}, {1,3,5}\{1,3,5\} is 1010110101. Union, intersection and complement become bitwise OR, AND and NOT.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 5 marks

Solve the recurrence relation an=an−1+an−2a_n = a_{n-1} + a_{n-2} with initial conditions a0=0a_0 = 0 and a1=1a_1 = 1.

Answer

an=an−1+an−2,a0=0, a1=1a_n=a_{n-1}+a_{n-2},\qquad a_0=0,\ a_1=1

Characteristic equation: r2−r−1=0r^2-r-1=0, so

r=1±52.r=\frac{1\pm\sqrt5}{2}.

Let r1=1+52r_1=\frac{1+\sqrt5}{2}, r2=1−52r_2=\frac{1-\sqrt5}{2}. The general solution is an=αr1n+βr2na_n=\alpha r_1^n+\beta r_2^n.

Initial conditions:

  • a0=α+β=0⇒β=−αa_0=\alpha+\beta=0\Rightarrow\beta=-\alpha
  • a1=αr1+βr2=α(r1−r2)=α5=1⇒α=15a_1=\alpha r_1+\beta r_2=\alpha(r_1-r_2)=\alpha\sqrt5=1\Rightarrow\alpha=\dfrac1{\sqrt5}

an=15[(1+52)n−(1−52)n]\boxed{a_n=\frac1{\sqrt5}\left[\left(\frac{1+\sqrt5}{2}\right)^n-\left(\frac{1-\sqrt5}{2}\right)^n\right]}

This gives the Fibonacci numbers 0,1,1,2,3,5,8,…0,1,1,2,3,5,8,\dots

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 2+3 marks

Define Boolean and exponential function. Discuss about partial ordering.

Answer

Boolean function: a function f:{0,1}n→{0,1}f:\{0,1\}^n\to\{0,1\} mapping nn Boolean variables to 0 or 1, built from AND, OR and NOT, e.g. f(x,y)=xyˉ+yf(x,y)=x\bar y+y.

Exponential function: a function f(x)=axf(x)=a^x with constant base a>0, a≠1a>0,\ a\ne1; the variable is in the exponent, e.g. 2x2^x or exe^x.

Partial ordering: a relation RR on a set SS that is reflexive (aRaaRa), antisymmetric (aRbaRb and bRabRa imply a=ba=b) and transitive (aRbaRb and bRcbRc imply aRcaRc). (S,R)(S,R) is called a partially ordered set (poset). Not every pair of elements need be comparable. Examples: ≤\le on the integers; divisibility on positive integers (2 and 3 are incomparable); ⊆\subseteq on subsets of a set. Posets are drawn as Hasse diagrams.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 5 marks

Prove the correctness of following recursive algorithm for computing ana^n using induction:
Power(a, n) {
  if (n = 0) return 1;
  else return a * Power(a, n-1);
}

Answer

Claim: Power(a, n) returns ana^n for every integer n≥0n\ge0.

Proof by induction on nn.

Basis (n=0n=0): the condition n = 0 is true, so the function returns 1=a01=a^0. Correct.

Inductive hypothesis: assume Power(a, k) returns aka^k for some k≥0k\ge0.

Inductive step (n=k+1n=k+1): since k+1≠0k+1\ne0, the else branch runs and returns a * Power(a, k). By the hypothesis this equals a⋅ak=ak+1a\cdot a^k=a^{k+1}.

So the algorithm is correct for n=k+1n=k+1. By induction, Power(a, n) returns ana^n for all n≥0n\ge0. It also terminates, because each call reduces nn by 1 until the base case n=0n=0 is reached. ■\blacksquare

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 2+3 marks

Define spanning and minimum spanning tree? How do you traverse tree?

Answer

Spanning tree: a spanning tree of a connected graph GG is a subgraph that is a tree (connected, no cycles) and contains all the vertices of GG; it has n−1n-1 edges.

Minimum spanning tree (MST): in a weighted connected graph, the spanning tree whose sum of edge weights is the smallest. It can be found with Kruskal's or Prim's algorithm.

Tree traversal means visiting every vertex of a rooted tree exactly once. For an ordered rooted tree there are three standard methods (T = root, with subtrees T1,…,TkT_1,\dots,T_k):

  • Preorder: visit the root, then traverse each subtree in preorder, left to right.
  • Inorder (binary tree): traverse the left subtree, visit the root, then traverse the right subtree.
  • Postorder: traverse the subtrees left to right, then visit the root.

For a binary tree with root AA, left child BB and right child CC: preorder is A,B,CA,B,C; inorder is B,A,CB,A,C; postorder is B,C,AB,C,A.

In general graphs, breadth-first and depth-first search are used.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

  • 2082 · 1+4 marks

What do you mean by connectivity in graph? Discuss about Bipartite and Planar graph.

Answer

Connectivity: an undirected graph is connected if there is a path between every pair of distinct vertices. Otherwise it splits into connected components. (A directed graph is strongly connected if there is a directed path from aa to bb and from bb to aa for all pairs.)

Bipartite graph: a graph whose vertex set can be split into two disjoint sets V1,V2V_1,V_2 such that every edge joins a vertex in V1V_1 to a vertex in V2V_2 (no edge inside a set). Equivalently, its vertices can be coloured with two colours so that adjacent vertices differ, which holds exactly when the graph has no odd cycle. The complete bipartite graph Km,nK_{m,n} has all mnmn edges between the sets. Example: C4C_4 is bipartite, C3C_3 is not.

Planar graph: a graph that can be drawn in the plane with no edges crossing. Properties for a connected planar graph with vv vertices, ee edges and ff regions:

  • Euler's formula: v−e+f=2v-e+f=2.
  • If v≥3v\ge3: e≤3v−6e\le3v-6; if there are no triangles, e≤2v−4e\le2v-4.

K5K_5 and K3,3K_{3,3} are non-planar, and by Kuratowski's theorem a graph is planar iff it contains no subdivision of K5K_5 or K3,3K_{3,3}.

Answer checked by Claude Sonnet · Oct 21, 2026

Test yourself · 2 MCQs

Loading…

Questions from TU BIT 2078 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2078 (BS), via StudyNp), TU BIT 2079 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2079 (BS), via StudyNp), TU BIT 2080 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2080 (BS), via StudyNp), TU BIT 2080.1 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2080.1 (BS), via StudyNp), TU BIT 2081 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2081 (BS), via StudyNp), TU BIT 2082 Second Semester Microprocessor and Computer Architecture (TU IOST semester board exam, 2082 (BS), via StudyNp), TU BIT 2078 Second Semester Discrete Structure (TU IOST semester board exam, 2078 (BS), via StudyNp), TU BIT 2079 Second Semester Discrete Structure (TU IOST semester board exam, 2079 (BS), via StudyNp), TU BIT 2080 Second Semester Discrete Structure (TU IOST semester board exam, 2080 (BS), via StudyNp), TU BIT 2080.1 Second Semester Discrete Structure (TU IOST semester board exam, 2080.1 (BS), via StudyNp), TU BIT 2081 Second Semester Discrete Structure (TU IOST semester board exam, 2081 (BS), via StudyNp), TU BIT 2082 Second Semester Discrete Structure (TU IOST semester board exam, 2082 (BS), via StudyNp), TU BIT 2078 Second Semester Object Oriented Programming (TU IOST semester board exam, 2078 (BS), via StudyNp), TU BIT 2079 Second Semester Object Oriented Programming (TU IOST semester board exam, 2079 (BS), via StudyNp), TU BIT 2080 Second Semester Object Oriented Programming (TU IOST semester board exam, 2080 (BS), via StudyNp), TU BIT 2081 Second Semester Object Oriented Programming (TU IOST semester board exam, 2081 (BS), via StudyNp), TU BIT 2078 Second Semester Economics (TU IOST semester board exam, 2078 (BS), via StudyNp), TU BIT 2079 Second Semester Economics (TU IOST semester board exam, 2079 (BS), via StudyNp), TU BIT 2080 Second Semester Economics (TU IOST semester board exam, 2080 (BS), via StudyNp), TU BIT 2080.1 Second Semester Economics (TU IOST semester board exam, 2080.1 (BS), via StudyNp), TU BIT 2078 Second Semester Basic Statistics (TU IOST semester board exam, 2078 (BS), via StudyNp), TU BIT 2079 Second Semester Basic Statistics (TU IOST semester board exam, 2079 (BS), via StudyNp), TU BIT 2080 Second Semester Basic Statistics (TU IOST semester board exam, 2080 (BS), via StudyNp) and TU BIT 2080.1 Second Semester Basic Statistics (TU IOST semester board exam, 2080.1 (BS), via StudyNp). Answers are written for this site; check them against your class notes.