| BTechibtechi.in |
Loading |
| Free IIT Madras BS notes, PYQs and mock tests at btechi.in |
| BTechibtechi.in |
Loading |
| Free IIT Madras BS notes, PYQs and mock tests at btechi.in |
BSCS1001 · 10 topics · 12 min read
Scores
Words
Shopping Bills
Library, Olympics, others
Boolean
Integer
Character
==, !=, alphabetical orderString
==, joining, lengthSubtypes
| Shape | Meaning |
|---|---|
| Oval / rounded rectangle | Start or End (terminal) |
| Rectangle | Process, e.g. count = count + 1 |
| Diamond | Decision: a condition with Yes and No exits |
| Parallelogram | Input or output |
| Arrow | Flow of control |
count = 0
sum = 0
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Gender == "F"){
count = count + 1
sum = sum + X.Mathematics
}
Move X to Table 2
}
avg = sum / countTraps to avoid
count = 0
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Gender == "F" and X.CityTown == "Chennai"){
count = count + 1
}
Move X to Table 2
}| Write | Means |
|---|---|
a = b | Assign: store the value of b in a |
a == b | Compare: is a equal to b? |
a != b | Not equal |
and | True only when both sides are true |
or | True when at least one side is true |
not | Flips True and False |
a mod b | Remainder: 17 mod 5 = 2 |
Worked example
In Scores, 14 students are female, 12 are from Chennai, and 5 are female and from Chennai. What does an X.Gender == "F" or X.CityTown == "Chennai" filter count?
Answer: 21 students
A = A + 1 counts cards. A = A + X.Marks adds up a field.max = 0
topper = "None"
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Mathematics > max){
max = X.Mathematics
topper = X.Name
}
Move X to Table 2
}min = 100
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Gender == "M" and X.CityTown == "Vellore"){
if(X.Chemistry < min){
min = X.Chemistry
}
}
Move X to Table 2
}| Comparison | On a tie, keeps |
|---|---|
X.M > max | the first card with the maximum |
X.M >= max | the last card with the maximum |
X.M < min | the first card with the minimum |
X.M <= min | the last card with the minimum |
if X > max { second = max; max = X } else if X > second { second = X }.Traps to avoid
Procedure isVowel(c)
if(c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'){
return(True)
}
return(False)
End isVowelisVowel(letter) substitutes the argument for c.return(v) hands v back and exits immediately. Nothing after it runs.i = 1; while(i <= 20){ i = i * 2 } runs for i = 1, 2, 4, 8, 16: five times.| Task | Trick |
|---|---|
| Sum of the two smallest of a, b, c (PYQ Jan 2024) | a + b + c − max(a, b, c) |
| Largest of three | compare a with b, then the winner with c |
| Even or odd | n mod 2 == 0 ⇒ even |
| Last digit / drop it | n mod 10 / floor(n / 10) |
| Sum of digits | repeat s = s + n mod 10, n = floor(n / 10) until n = 0 |
| Reverse a number | repeat r = r × 10 + n mod 10, n = floor(n / 10) |
| GCD (Euclid) | while(b != 0){ t = b; b = a mod b; a = t } → answer a |
| Divisible by k | n mod k == 0 |
Trace the GCD loop
Run the Euclid loop with a = 36, b = 24.
Answer: 12
Worked example
Sum of digits of 4096 with the mod-10 loop?
Answer: 19
if(unit <= 100){
cost = unit * 5
}
else if(unit <= 200){
cost = 100 * 5 + (unit - 100) * 7
}
else{
cost = 100 * 5 + 100 * 7 + (unit - 200) * 10
}PYQ pattern (May 2023)
Using the slabs above, what is the bill for 250 units?
Answer: ₹1700
Traps to avoid
cost = unit * 10 for unit > 200, which charges every unit at the top rate.<=) or slab 2 (<)? Check the comparison sign.sum = 0
n = 0
while(Table 1 has more rows){
Read the first row X in Table 1
sum = sum + X.Total
n = n + 1
Move X to Table 2
}
avg = sum / n
Move all rows from Table 2 to Table 1
count = 0
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Total > avg){
count = count + 1
}
Move X to Table 2
}count = 0
while(Table 1 has more rows){
Read the first row X in Table 1
Move X to Table 2
while(Table 1 has more rows){
Read the first row Y in Table 1
if(X.CityTown == Y.CityTown){
count = count + 1
}
Move Y to Table 3
}
Move all rows from Table 3 to Table 1
}n = 30 ⇒ 435
Worked example
Scores has 30 cards: 10 from Chennai, 8 from Vellore, 12 from Madurai. How many pairs are from the same city? From different cities?
Answer: 139 same-city pairs, 296 different-city pairs
Traps to avoid
Worked example
30 cards split evenly into 3 bins. How many comparisons with and without binning?
Answer: 435 without, 135 with
+ 1 → count; + X.field → sum; = X.field → max, min or 'last seen'.found = False
while(Table 1 has more rows){
Read the first row X in Table 1
if(X.Total > 250){
found = True
}
Move X to Table 2
}Traps to avoid
Exam morning
The 12 things to read on the way to the exam centre.
Now test yourself
Sit a real paper in the exam portal, then come back to the Traps view for whatever you got wrong.
Formulas and conventions follow the IIT Madras BS course material for weeks 1–4. “Every paper” and “Most papers” count how often a topic appears in the qualifier papers on BTechi (January 2023 to May 2024). BTechi is not affiliated with IIT Madras.