Logarithms measure “how many times can I halve (or divide by b) before I reach 1”, which is exactly what binary search and divide-and-conquer do. The mod function gives remainders, used in Euclid’s algorithm, hashing and cyclic counters. This page states the rules correctly and shows a common programming trap with negative remainders.
What a logarithm is
So log28=3 because 23=8, and log101000=3. In algorithm analysis, logn without a base usually means log2n, and lgn is a common short form for log2n.
The rules
For positive a,b,c with the bases a,b=1, and any real n:
By change of base, log10n=log210log2n≈0.301log2n. Logarithms to different bases differ only by a constant factor, and big-O ignores constant factors. So O(log2n)=O(log10n)=O(lnn), and we simply write O(logn).
The second result matters in Unit 4: recurrence solutions often look like alogbn, and the exponent swap turns them into a power of n.
The mod function
42mod11=9, because 42=3×11+9.
−42mod11=2, because −42=(−4)×11+2 and 0≤2<11.
The mathematical mod is never negative. Programming languages do not all agree: in C (since C99) the % operator takes the sign of the dividend, so -42 % 11 is -9, while Python’s % follows the mathematical definition and gives 2.
C · mod_demo.c
#include <stdio.h>/* Mathematical b mod n for n > 0: always gives 0 <= r < n. */int math_mod(int b, int n){ int r = b % n; /* C's %: sign follows b (C99 and later) */ return (r < 0) ? r + n : r;}int main(void){ int values[] = {42, -42, 11, -11, 7}; int n = 11; for (int i = 0; i < 5; i++) { int b = values[i]; printf("b = %3d: b / n = %2d, C b %% n = %3d, b mod n = %2d\n", b, b / n, b % n, math_mod(b, n)); } return 0;}
Output
b = 42: b / n = 3, C b % n = 9, b mod n = 9b = -42: b / n = -3, C b % n = -9, b mod n = 2b = 11: b / n = 1, C b % n = 0, b mod n = 0b = -11: b / n = -1, C b % n = 0, b mod n = 0b = 7: b / n = 0, C b % n = 7, b mod n = 7
C’s integer division truncates towards zero (−42/11=−3), so its remainder must be −42−(−3)(11)=−9. The mathematical mod uses the floor instead: k=⌊−42/11⌋=−4, giving remainder 2.
Key takeaways
logbx=y means by=x; bases must be positive and not 1.
loga(1/b)=−logab and logba=1/logab; the study material’s (iii) and (iv) are misprinted.
Change of base shows all log bases differ by constants, so O(logn) has no base.
bmodn∈{0,…,n−1}; C’s % can be negative, Python’s % cannot (for n>0).
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Using the log rules, show that log2(n3⋅8)=3log2n+3, and find its value for n=4.
Show worked answer
Product rule: log₂(n³ · 8) = log₂ n³ + log₂ 8. Power rule: log₂ n³ = 3 log₂ n, and log₂ 8 = 3. So the expression is 3 log₂ n + 3. For n = 4: 3 × 2 + 3 = 9. Check: 4³ × 8 = 512 = 2⁹.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-211/some-pre-requisites-and-asymptotic-bounds/logarithms-and-the-mod-function/ to read this page.