Week 1: Variables, Datatypes & Flowcharts
3320 words
17 min read
2026-09-12T00:00:00.000Z
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
Computational thinking fundamentals, algorithmic thinking, variables, initialization, datatypes, and flowcharts. # Computational Thinking — Week 1: Variables, Datatypes & Flowcharts IITM’s Computational Thinking Week 1 covers **Variables, Initialization, Iterators, Filtering, Datatypes, Flowcharts, and Sanity of Dat...

Computational Thinking — Week 1: Variables, Datatypes & Flowcharts
IITM’s Computational Thinking Week 1 covers Variables, Initialization, Iterators, Filtering, Datatypes, Flowcharts, and Sanity of Data.
The syllabus gives the topic names rather than every sub-concept, so the detailed explanations below are a standard expansion of those listed ideas.
TL;DR
Week 1 is essentially about learning to describe a computation precisely.
The core mental model is:
textData ↓ Variables store values ↓ Initialize state ↓ Iterate through data ↓ Filter relevant items ↓ Update variables ↓ Check whether the data/result makes sense
The highest-value ideas are:
- variable = named storage/state
- initialization = starting value
- iterator = systematically visiting items
- filtering = keeping only items satisfying a condition
- datatype = what kind of value something is
- flowchart = visual representation of control flow
- sanity check = checking whether input/output is plausible
1. What is Computational Thinking?
Computational thinking is not merely writing code.
It is the process of turning a problem into a precise sequence of steps that can be executed systematically.
Typical structure:
Example:
Given marks of students, find how many scored above 60.
Input:
textmarks
Processing:
- examine each mark
- test whether it exceeds 60
- count qualifying marks
Output:
textnumber of students scoring > 60
2. Algorithm
An algorithm is a finite sequence of well-defined steps for solving a problem.
Example:
text1. Start count at 0 2. Look at each student's mark 3. If mark > 60, increase count by 1 4. After all marks are examined, output count
This already contains several Week 1 concepts:
- initialization
- iteration
- filtering
- variable update
3. Variable
A variable is a named quantity whose value can be stored and possibly changed during computation.
Example:
textcount = 0
Here:
- variable name =
count - current value =
0
Later:
textcount = count + 1
changes its value.
4. Variable as state
A useful mental model:
A variable records the current state of the computation.
Suppose we are processing:
text5, 8, 2, 10
and maintaining the running total.
Initially:
texttotal = 0
After reading
5:texttotal = 5
After reading
8:texttotal = 13
After reading
2:texttotal = 15
After reading
10:texttotal = 25
The variable summarizes everything processed so far.
5. Assignment is not algebraic equality
In pseudocode/programming:
textx = x + 1
does not mean the mathematical equation:
That equation would be impossible over ordinary numbers.
Instead it means:
take the current value of x, add 1, and store the result back into x.
So assignment is directional.
6. Old value → new value
If:
textx = 5
and then:
textx = x + 2
the new value becomes:
text7
Think:
7. Initialization
Initialization means giving a variable its starting value before using it.
Example:
textcount = 0
before counting things.
Or:
texttotal = 0
before accumulating a sum.
8. Why initialization matters
Suppose you want to calculate a total.
Correct:
texttotal = 0 for each value: total = total + value
Without a starting value,
total is undefined.The computation has no valid initial state.
9. Initialization depends on the task
For summation:
texttotal = 0
because:
For multiplication:
textproduct = 1
because:
This is not arbitrary.
The initial value should match the operation.
10. Counting pattern
To count how many items satisfy some condition:
textcount = 0 for each item: if condition: count = count + 1
This is one of the most important computational patterns.
11. Running-sum pattern
To compute a sum:
texttotal = 0 for each value: total = total + value
At the end:
texttotal
contains the sum of all processed values.
12. Iterator
An iterator represents the item currently being processed while moving systematically through a collection or sequence.
Conceptually:
textfor each x in data: process x
Here:
textx
acts as the current item.
13. Iteration
Iteration means repetition.
Example data:
text4, 7, 9
An iteration visits:
text4 then 7 then 9
and performs the same prescribed operation on each.
14. Trace iteration manually
Consider:
texttotal = 0 for each x in [2, 5, 3]: total = total + x
Trace:
| Iteration | x | total before | total after |
|---|---|---|---|
| start | — | — | 0 |
| 1 | 2 | 0 | 2 |
| 2 | 5 | 2 | 7 |
| 3 | 3 | 7 | 10 |
Final:
texttotal = 10
Manual tracing is central to this course.
15. Iterator is temporary
Suppose:
textfor each x in [10, 20, 30]
Then
x successively takes:text10 20 30
It is not all three values simultaneously.
It represents the current element.
16. Filtering
Filtering means selecting only items that satisfy some condition.
Example:
Data:
text2, 7, 3, 10, 8
Condition:
textx > 5
Filtered values:
text7, 10, 8
17. Filtering as a predicate
A filter condition evaluates to something conceptually like:
texttrue / false
Example:
For:
condition is true.
For:
condition is false.
18. Counting filtered items
Example:
textcount = 0 for each x in data: if x > 5: count = count + 1
For:
text[2, 7, 3, 10, 8]
the count becomes:
19. Summing filtered items
Suppose we want the sum of only positive numbers:
texttotal = 0 for each x: if x > 0: total = total + x
For:
text[-2, 5, -1, 8]
result:
Filtering and accumulation commonly appear together.
20. Filter vs transformation
These ideas are different.
Filtering
Choose whether an item survives.
Example:
textkeep x if x > 0
Transformation
Change an item.
Example:
textreplace x with x²
A problem can do both:
textkeep positive values, then square them
21. Datatypes
A datatype describes the kind of value a variable contains and what operations make sense on it.
Typical conceptual datatypes include:
- integer
- real/decimal number
- Boolean
- string/text
- collection
22. Integer
An integer represents whole-number values:
Examples:
- number of students
- number of goals
- number of attempts
23. Real / numerical value
Used for quantities that may include fractional values.
Examples:
- temperature
- height
- average
- probability
Example:
24. Boolean
Boolean data has two logical values:
textTrue False
Example condition:
textage >= 18
evaluates to either true or false.
Boolean values drive decisions and filtering.
25. String / text
A string represents text.
Examples:
text"Ahmedabad" "student" "A12"
Important:
text"123"
may be text, while:
text123
is numerical.
They may look similar but behave differently.
26. Why datatype matters
Consider:
text2 + 3
Numerically:
But if interpreted as text:
text"2" + "3"
could conceptually produce:
text"23"
depending on the language/system.
So algorithms must understand what type of data they are manipulating.
27. Valid operations depend on datatype
For numbers:
text+ - × ÷
make sense.
For Boolean values:
textAND OR NOT
make sense.
For strings:
- concatenate
- compare
- inspect characters
may make sense.
Datatype determines meaningful operations.
28. Flowchart
A flowchart visually represents an algorithm or computation.
Typical elements include:
- start/end
- process
- decision
- arrows showing flow
29. Basic flowchart structure
Conceptually:
textStart | v Initialize count = 0 | v Read next value | v Is value > 5? / \ Yes No | | count++ | \ / v More data? / \ Yes No | | loop Output | v End
30. Decision point
A decision asks a yes/no question.
Example:
textIs x > 10?
Two branches emerge:
textYes No
This is the visual equivalent of:
textif condition
31. Flow of control
A flowchart is not merely a diagram of objects.
The arrows indicate execution order.
That is why the word:
flow
matters.
You should be able to follow arrows and simulate what happens step by step.
32. Loop in a flowchart
Iteration usually appears as an arrow that returns to an earlier step.
Example:
textRead item | Process | More items? / \ Yes No | | +---------+
The backward path creates repetition.
33. Sanity of data
Sanity checking asks:
Does this input or result make basic logical sense?
Examples:
- age = −15
- probability = 1.7
- examination percentage = 240%
- number of students = 3.8
These should trigger suspicion.
34. Sanity check vs full validation
A sanity check is often a quick plausibility test.
It may not prove that the data are correct.
Example:
textage = 25
is plausible.
But that does not prove the recorded age is actually correct.
So:
35. Range checks
A basic sanity check often verifies a valid range.
For probability:
For exam percentage:
For count:
and often:
36. Type sanity
Suppose:
textnumber_of_students = 27.4
Even though:
the value is still suspicious because a student count should usually be an integer.
So sanity checking can involve both:
- range
- datatype
37. Missing data
A dataset may contain missing entries.
Example:
textHeight = missing
An algorithm should not blindly treat missing information as:
text0
unless that encoding is explicitly justified.
Otherwise you introduce false data.
38. Impossible vs unusual
Sanity checks must distinguish:
Impossible
textprobability = -0.2
Unusual but possible
textperson height = 220 cm
The second deserves inspection but is not inherently invalid.
39. Outliers are not automatically errors
A rare observation may be genuine.
So:
textunusual
does not mean:
textdelete
Instead ask:
- was it entered incorrectly?
- was measurement wrong?
- is it actually a legitimate extreme value?
40. Precondition intuition
Many algorithms assume certain things about their input.
Example:
Calculate average exam score.
Possible preconditions:
- dataset is nonempty
- scores are numerical
- each score is in an allowed range
If these assumptions fail, the algorithm may fail or return nonsense.
41. Example algorithm
Problem:
Given a list of temperatures, count how many exceed 30°C.
Algorithm:
textcount = 0 for each temperature t: if t is valid: if t > 30: count = count + 1 output count
This uses:
- initialization
- iterator
- filtering
- datatype expectations
- sanity checking
42. Trace the example
Data:
text28, 34, 29, 40, 31
Start:
textcount = 0
Then:
| t | t>30? | count |
|---|---|---|
| 28 | No | 0 |
| 34 | Yes | 1 |
| 29 | No | 1 |
| 40 | Yes | 2 |
| 31 | Yes | 3 |
Output:
43. State invariant intuition
During the previous algorithm, after each iteration:
countequals the number of values greater than 30 among the items processed so far.
That statement is an invariant.
You may not need formal invariant terminology yet, but this is an important computational-thinking habit.
44. Why manual tracing matters
A simple-looking algorithm can behave differently from what you intuitively expect.
Tracing gives you an exact record of:
- variable values
- current iterator
- branch taken
- output
This is effectively debugging by hand.
Common mistake: initialization inside the loop
Suppose:
textfor each x: count = 0 if x > 5: count = count + 1
Here
count resets on every iteration.You lose previous progress.
Usually the intended structure is:
textcount = 0 for each x: if x > 5: count = count + 1
Common mistake: update every item instead of filtered items
Wanted:
count values greater than 5
Wrong:
textfor each x: count = count + 1
This counts all items.
Correct:
textfor each x: if x > 5: count = count + 1
Common mistake: filter reversed
Wanted:
textx > 5
but using:
textx < 5
produces the complementary set.
Always translate the wording carefully before tracing.
Common mistake: confusing iterator with count
Example:
textfor each x:
x represents the current data item.count represents accumulated state.They serve completely different purposes.
Common mistake: output too early
Suppose output happens inside the loop:
textfor each x: ... output count
Then you may get intermediate outputs.
If the problem asks for the final count, output normally belongs after processing all items.
Common mistake: assuming variables retain original value
If:
textx = 3 x = 8
then the current value is:
not both 3 and 8.
Assignments update state.
Common mistake: treating string as number
Suppose:
textmarks = "85"
This might be textual data.
An algorithm expecting arithmetic may require conversion to a numeric datatype first.
Common mistake: no sanity check on inputs
Suppose average age output becomes:
Even if every computational step executed successfully, the result is clearly suspicious.
Correct execution does not guarantee sensible input.
Common mistake: flowchart branch ambiguity
Every decision should have clearly defined branches.
For:
textx > 10?
both:
textYes No
paths need defined behavior.
Missing one branch can make the algorithm incomplete.
Common mistake: infinite flowchart loop
If execution can return repeatedly to the same point without ever reaching a stopping condition, the algorithm may never terminate.
A loop must eventually have a mechanism to stop.
55. Three core accumulator patterns
Count
textcount = 0 count = count + 1
Sum
texttotal = 0 total = total + x
Product
textproduct = 1 product = product * x
Recognizing these patterns helps tremendously in CT questions.
56. Filter + count pattern
textcount = 0 for each x: if condition(x): count = count + 1
Question answered:
How many items satisfy the condition?
57. Filter + sum pattern
texttotal = 0 for each x: if condition(x): total = total + x
Question answered:
What is the sum of the items satisfying the condition?
58. Boolean flag pattern
Sometimes you only need to know whether an event has occurred.
textfound = False for each x: if condition(x): found = True
At the end:
textfound
represents whether any qualifying item was encountered.
This is a useful extension of Week 1 ideas.
59. Sanity-check pattern
A conceptual validation step might look like:
textif value < minimum_allowed: mark invalid else if value > maximum_allowed: mark invalid else: accept value
Computational thinking often begins by deciding the rules before coding anything.
60. How to trace IITM-style pseudocode
When given an algorithm, create a table.
For example:
textA = 0 for each x in [3, 8, 2, 9]: if x > 5: A = A + x
Trace:
| Step | x | Condition | A before | A after |
|---|---|---|---|---|
| start | — | — | — | 0 |
| 1 | 3 | False | 0 | 0 |
| 2 | 8 | True | 0 | 8 |
| 3 | 2 | False | 8 | 8 |
| 4 | 9 | True | 8 | 17 |
Final:
61. Read pseudocode literally
Do not infer what the algorithm "probably wanted" to do.
Follow what it actually says.
If the algorithm contains an odd update:
textcount = count + 2
then count increases by 2.
Your job in tracing questions is execution, not repair.
62. Week 1 master mental model
textINPUT DATA ↓ Check datatype / sanity ↓ Initialize variables ↓ Iterate over data ↓ Test/filter current item ↓ Update state ↓ Repeat ↓ OUTPUT
That single pipeline captures most of the week.
63. What you should actually master
By the end of CT Week 1, you should be able to:
- Explain what a variable represents.
- Distinguish assignment from mathematical equality.
- Initialize variables correctly.
- Trace variable updates manually.
- Explain iteration and iterators.
- Filter data using conditions.
- Combine filtering with counting and summation.
- Distinguish basic datatypes.
- Understand why datatypes affect valid operations.
- Follow a basic flowchart.
- Recognize loops and decisions in flowcharts.
- Perform basic sanity checks on data.
- Distinguish unusual data from impossible data.
- Build a trace table for pseudocode.
- Read pseudocode literally rather than guessing its intention.
If these are comfortable, Computational Thinking Week 1 is under control.
Quick Recall & Flashcards
Test your active recall before proceeding to practice problems. Format:
Question :: Answer.- Week 1 Diagnostic: In computational thinking, what is the purpose of initializing a variable before entering a loop? :: Answer: B — Initialization gives a variable a well-defined starting value (such as count = 0 or max_val = -inf) so subsequent operations update a reliable baseline.
- Week 1 Diagnostic: In a flowchart, what geometric shape is standard for a decision condition (e.g. checking if X > 0)? :: Answer: C — In standard flowcharts, a Diamond represents a branching decision point with two or more outgoing branches (e.g. Yes/No).
Practice & Self-Check
Attempt these diagnostic questions to verify your operational understanding.
1
Question 1
In computational thinking, what is the purpose of initializing a variable before entering a loop?
MCQ
3 Unit Assessment
A. To allocate operating system memory permanently
B. To establish a known, predictable baseline state before updates occur
C. To convert the variable into a string
D. To prevent the program from reading external input
2
Question 2
In a flowchart, what geometric shape is standard for a decision condition (e.g. checking if X > 0)?
MCQ
3 Unit Assessment
A. Rectangle
B. Oval / Pill
C. Diamond
D. Parallelogram