Quiz 2

Week 1: What is Computational Thinking?

2192 words
11 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Week 1: What is Computational Thinking? > **BSCS1001 — IIT Madras BS Degree** **Prerequisite:** None (this is your first topic!) **Cross-links:** BSCS1002-Python (Week 1), BSCS2002-PDSA (Week 1) ## 1.

Week 1: What is Computational Thinking?

BSCS1001 — IIT Madras BS Degree Prerequisite: None (this is your first topic!) Cross-links: BSCS1002-Python (Week 1), BSCS2002-PDSA (Week 1)

1. Motivation: Why Computational Thinking?

Imagine you are a teacher with a stack of 200 answer sheets. You need to:
  • Find the highest score
  • Calculate the class average
  • Count how many students scored above 80 You could do this manually, but it would take hours and you might make mistakes. Now imagine you could describe the steps so precisely that a computer (which has no common sense) could do it for you in milliseconds. Computational Thinking is exactly this — the art of taking a real-world problem and breaking it down into such precise, step-by-step instructions that a machine can execute them.

Real-World Analogy: A Cooking Recipe

Recipe StepComputational Thinking Concept
"Gather all ingredients"Dataset — the collection of items to process
"Repeat for each onion"Iteration — doing something repeatedly
"If the onion is brown, discard it"Filtering — selective processing
"Keep count of how many onions you chopped"Variable — tracking a value
"Chop until all onions are done"Loop termination — when to stop
Key Insight: Computational thinking is not about computers — it is about thinking in a structured, methodical way. Computers just happen to be very good at executing such structured thinking.

2. What is Computational Thinking?

Formal Definition

Computational Thinking (CT) is the process of formulating problems and expressing their solutions in a way that a computer — human or machine — can effectively carry out. The four pillars of computational thinking are: (Diagram)
Note for absolute beginners: Don't worry if these four pillars seem abstract. By Week 4, every one of them will feel natural. This course focuses mainly on Algorithm Design (the last pillar).

Course Context

In BSCS1001, we focus on:
  1. Procedural approach — describing solutions as sequences of steps
  2. Pattern identification — recognizing that many problems share the same solution structure
  3. Data representation — choosing the right way to store information
  4. Algorithm analysis — understanding which solutions are faster

3. Patterns in Problem Solving

The most important skill you will learn is pattern recognition — noticing that two seemingly different problems can be solved using the same approach.

Example: The "Find the Best" Pattern

Consider these three problems:
ProblemWhat You NeedSame Pattern?
Find the student with highest marksMaximum value in a list✅ Yes
Find the oldest person in a roomMaximum age✅ Yes
Find the most expensive item in a cartMaximum price✅ Yes
All three use the same algorithm: look at each item, remember the best one seen so far, update if current is better.

Example: The "Count Things" Pattern

ProblemWhat You NeedSame Pattern?
Count students in a classTotal number✅ Yes
Count words in a paragraphTotal words✅ Yes
Count items in a shopping billTotal items✅ Yes
All three use: start at 0, add 1 for each item.
💡 Takeaway: Once you learn one pattern, you can reuse it everywhere. This is the superpower of computational thinking.

4. Datasets: The Raw Material

A dataset is just a collection of information. In this course, we work with three main types:

Dataset Examples from the Course

(Diagram)

How We Visualize Datasets

In this course, we imagine data as cards in a pile:
  • Pile 1: Cards we haven't looked at yet (the "unseen" pile)
  • Pile 2: Cards we have already processed (the "seen" pile) We pick cards one by one from Pile 1, process them, and move them to Pile 2.
pseudo
Pile 1 (Unseen)     →  Pick a card  →  Process it  →  Pile 2 (Seen)
   [Card A]
   [Card B]          ──►  Pick Card B  ──►  Read data  ──►  [Card B]
   [Card C]
Why this analogy? Computers don't have "piles" — they have memory. But the pile analogy perfectly captures the idea of sequential processing: one item at a time, in order.

5. Iteration: The Most Powerful Pattern

Iteration means doing the same thing repeatedly. It is the single most used pattern in this course (and in all of programming).

The Iterator Pattern

(Diagram)

The Four Steps of Every Iterator

StepDescriptionExample (Counting Cards)
1. InitializationSet up starting valuesCount = 0
2. Continue or ExitCheck if there's more dataPile 1 has more cards?
3. Repeat StepPick one item, process itPick card, add 1 to Count
4. Go BackReturn to step 2Go back to check condition

Worked Example 1: Counting Cards

Let's trace through the process of counting 3 cards: [A, B, C]
StepWhat HappensPile 1Pile 2Count
StartInitialize Count to 0[A, B, C][]0
CheckPile 1 has cards → continue[A, B, C][]0
PickPick card A[B, C][]0
MoveMove A to Pile 2[B, C][A]0
UpdateIncrement Count: 0+1=1[B, C][A]1
CheckPile 1 has cards → continue[B, C][A]1
PickPick card B[C][A]1
MoveMove B to Pile 2[C][A, B]1
UpdateIncrement Count: 1+1=2[C][A, B]2
CheckPile 1 has cards → continue[C][A, B]2
PickPick card C[][A, B]2
MoveMove C to Pile 2[][A, B, C]2
UpdateIncrement Count: 2+1=3[][A, B, C]3
CheckPile 1 empty → exit[][A, B, C]3
EndReturn Count = 33
🔍 Notice: Every time we go through the loop, Count increases by exactly 1. The process stops when Pile 1 is empty.

Worked Example 2: Sum of Marks

Now let's sum the Maths marks of 4 students. Dataset:
CardNameMaths
1Alice85
2Bob72
3Charlie91
4Diana68
Tracing:
StepCardActionSum
StartSum = 00
Iter 1AliceSum = 0 + 8585
Iter 2BobSum = 85 + 72157
Iter 3CharlieSum = 157 + 91248
Iter 4DianaSum = 248 + 68316
EndReturn 316316

6. Variables: Keeping Track

A variable is a named storage location whose value changes during computation.

Key Properties of Variables

PropertyExplanationExample
NameA label to identify the variableSum, Count, Max
ValueThe data currently storedSum = 157
TypeWhat kind of data it can holdInteger, Boolean, Character
MutableValue can be changed by assignmentSum = Sum + 85

The Assignment Statement

The = sign in computational thinking does not mean equality (like in mathematics). It means assignment — take the value on the right and store it in the variable on the left.
pseudo
Sum = 0          ← "Store the value 0 in the variable named Sum"
Sum = Sum + 85   ← "Take the current value of Sum, add 85, store the result back in Sum"
Math =CT =
x = x + 1 is impossible (no number equals itself plus one)x = x + 1 is normal — it means "increase x by 1"
States a truthGives an instruction
Read as "equals"Read as "becomes" or "gets"
⚠️ Common Pitfall: Beginners often confuse assignment with equality. In pseudocode, = always means assignment. To check equality, we use == (two equals signs).

Common Variable Roles

RoleDescriptionExample
CounterCounts how many items processedCount = Count + 1
AccumulatorAdds up valuesSum = Sum + x.Maths
TrackerRemembers the "best so far"if x.Marks > Max then Max = x.Marks
FlagRecords whether something happenedFound = True

7. Filtering: Selecting What Matters

Filtering means processing only the items that satisfy a condition, ignoring the rest.

The Filtering Pattern

sql
Initialize variables
while (Pile 1 has more cards) {
    Pick a card X from Pile 1
    Move X to Pile 2
    if (condition is true) {
        Update variables with X's data
    }
}

Worked Example: Sum of Boys' Maths Marks Only

Dataset:
CardNameGenderMaths
1AliceF85
2BobM72
3CharlieM91
4DianaF68
Tracing with Filter:
StepCardGenderCondition: M?ActionSum
StartSum = 00
Iter 1AliceFNoSkip0
Iter 2BobMYesSum = 0 + 7272
Iter 3CharlieMYesSum = 72 + 91163
Iter 4DianaFNoSkip163
EndReturn 163163

Types of Filtering Conditions

TypeExampleExplanation
Constant comparisonx.Gender == "M"Compare with a fixed value
Variable comparisonx.Marks > MaxCompare with another variable
Range checkx.Marks >= 0 AND x.Marks <= 100Check if within bounds
Compound conditionx.Gender == "M" AND x.Maths > 80Multiple conditions at once

8. Flowcharts: Visualizing Algorithms

A flowchart is a picture of an algorithm. It uses standard symbols to show the steps and the flow of control.

Standard Flowchart Symbols

(Diagram)
SymbolShapePurpose
Start/EndOval / PillMarks beginning and end of algorithm
ProcessRectangleAny operation that changes variable values
DecisionDiamondA yes/no question that determines which path to take
Input/OutputParallelogramReading data or displaying results
Flow lineArrowShows the direction of execution

Flowchart for Counting Cards

(Diagram)

Flowchart for Sum with Filtering (Boys' Marks)

(Diagram)

Advantages and Disadvantages of Flowcharts

✅ Advantages❌ Disadvantages
Visual and easy to understandBecome very large for complex algorithms
Good for teaching beginnersHard to share and edit (images)
Help catch logical errorsNo standard way to determine level of detail
Excellent for debuggingDifficult to version-control
Why flowcharts first? Before we write pseudocode (Week 2), flowcharts help you see the logic. Once you understand the picture, translating to text is much easier.

9. Putting It All Together

Complete Example: Finding the Maximum Mark

Problem: Find the highest Maths score in a class. Flowchart: (Diagram) Tracing Table (Dataset: [45, 78, 62, 91, 53]):
StepCardX.MathsMax (before)X.Maths > Max?Max (after)
Start00
Iter 1145045 > 0 ✅ Yes45
Iter 22784578 > 45 ✅ Yes78
Iter 33627862 > 78 ❌ No78
Iter 44917891 > 78 ✅ Yes91
Iter 55539153 > 91 ❌ No91
End91
Result: The maximum Maths mark is 91.

The Big Picture: How Week 1 Concepts Fit Together

(Diagram)

10. Practice Questions

Basic Questions

Q1. What is the value of Count after this sequence?
pseudo
Count = 0
Count = Count + 1
Count = Count + 2
Count = Count + 3
Show Answer
StepStatementCount
1Count = 00
2Count = 0 + 1 = 11
3Count = 1 + 2 = 33
4Count = 3 + 3 = 66
Answer: 6 Q2. Trace the following algorithm for dataset [10, 20, 30, 40]:
sql
Sum = 0
while (Pile 1 has more cards) {
    Pick a card X from Pile 1
    Move X to Pile 2
    if (X > 25) {
        Sum = Sum + X
    }
}
Show Answer
IterXX > 25?Sum
110No0
220No0
330Yes30
440Yes70
Answer: 70 Q3. Identify the four steps of every iterator pattern. Show Answer
  1. Initialization — set starting values
  2. Continue or Exit — check if there's more data
  3. Repeat Step — pick and process one item
  4. Go Back — return to step 2 Q4. What is the difference between = in mathematics and = in computational thinking? Show Answer
In mathematics, = states equality (a truth). In computational thinking, = means assignment (an instruction). x = x + 1 is impossible in math but normal in CT — it means "increase x by 1."

Intermediate Questions

Q5. Draw a flowchart for finding the minimum value in a dataset.
Show Answer
Diagram
(Diagram) Q6. Trace the counting algorithm for 6 cards. Show the state of Count and both piles at each step. Show Answer
StepPile 1Pile 2Count
Start[1,2,3,4,5,6][]0
Iter 1[2,3,4,5,6][1]1
Iter 2[3,4,5,6][1,2]2
Iter 3[4,5,6][1,2,3]3
Iter 4[5,6][1,2,3,4]4
Iter 5[6][1,2,3,4,5]5
Iter 6[][1,2,3,4,5,6]6
End[][1,2,3,4,5,6]6
Q7. Write the pseudocode (in words) to find the sum of only those numbers in a dataset that are even.
Show Answer
sql
Sum = 0
while (Pile 1 has more cards) {
    Pick a card X from Pile 1
    Move X to Pile 2
    if (X is even) {
        Sum = Sum + X
    }
}
Return Sum
Where "X is even" means X % 2 == 0 (X divided by 2 leaves remainder 0).

Advanced Questions

Q8. What happens if we initialize Max to 0 but all marks are negative? What should we initialize it to instead?
Show Answer
If Max = 0 and all marks are negative (e.g., [-5, -10, -3]), the algorithm would incorrectly return 0 instead of the actual maximum (-3).
Better initialization: Set Max to the first card's value. Or set it to -INFINITY (a very large negative number) so any real value will be larger.
Alternatively, we can initialize Max = -1 and MaxCard = -1 (invalid card ID), and only update when we see a valid card. Q9. Compare and contrast: constant filtering condition vs. variable filtering condition. Give an example of each. Show Answer
AspectConstant ConditionVariable Condition
Value compared againstFixed, does not changeChanges as algorithm runs
Examplex.Gender == "M"x.Marks > Max
When evaluatedSame check each iterationCheck changes as Max updates
Use caseCounting, summing subgroupsFinding max/min
Q10. Why is the pile analogy used in this course? What real computer memory concept does it represent?
Show Answer
The pile analogy is used because it's intuitive — you can visualize physically picking up cards one by one. It represents sequential access memory where data items are processed one after another in order. This is how computers typically read data from storage or iterate through collections.
The two-pile system (Pile 1 = unseen, Pile 2 = seen) ensures we process each item exactly once, which is the foundation of all iterative algorithms.

📚 Cross-References

CourseTopicConnection
BSCS1002 (Python)Week 1 — Variables & Data TypesPython's = assignment, int, bool types
BSCS2002 (PDSA)Week 1 — Algorithm BasicsThe iteration pattern formalized
BSCS2002 (PDSA)Week 2 — ComplexityHow many steps does iteration take?

Quiz Tip: Practice tracing iteration by hand — it's the most common question type in Quiz 1! Join Discord NextData Types & Representation
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.