Registry Synced

Week 1: Variables, Datatypes & Flowcharts

3320 words
17 min read
2026-09-12

Reading compass

Now · TL;DR

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:
text
Data
 ↓
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:
Input→Processing→Output\boxed{ \text{Input} \rightarrow \text{Processing} \rightarrow \text{Output} }
Example:
Given marks of students, find how many scored above 60.
Input:
text
marks
Processing:
  • examine each mark
  • test whether it exceeds 60
  • count qualifying marks
Output:
text
number of students scoring > 60

2. Algorithm

An algorithm is a finite sequence of well-defined steps for solving a problem.
Example:
text
1. 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:
text
count = 0
Here:
  • variable name = count
  • current value = 0
Later:
text
count = 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:
text
5, 8, 2, 10
and maintaining the running total.
Initially:
text
total = 0
After reading 5:
text
total = 5
After reading 8:
text
total = 13
After reading 2:
text
total = 15
After reading 10:
text
total = 25
The variable summarizes everything processed so far.

5. Assignment is not algebraic equality

In pseudocode/programming:
text
x = x + 1
does not mean the mathematical equation:
x=x+1.x=x+1.
That equation would be impossible over ordinary numbers.
Instead it means:
take the current value of xx, add 1, and store the result back into xx.
So assignment is directional.

6. Old value → new value

If:
text
x = 5
and then:
text
x = x + 2
the new value becomes:
text
7
Think:
xnew=xold+2.x_{\text{new}} = x_{\text{old}}+2.

7. Initialization

Initialization means giving a variable its starting value before using it.
Example:
text
count = 0
before counting things.
Or:
text
total = 0
before accumulating a sum.

8. Why initialization matters

Suppose you want to calculate a total.
Correct:
text
total = 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:
text
total = 0
because:
0+x=x.0+x=x.
For multiplication:
text
product = 1
because:
1⋅x=x.1\cdot x=x.
This is not arbitrary.
The initial value should match the operation.

10. Counting pattern

To count how many items satisfy some condition:
text
count = 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:
text
total = 0

for each value:
    total = total + value
At the end:
text
total
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:
text
for each x in data:
    process x
Here:
text
x
acts as the current item.

13. Iteration

Iteration means repetition.
Example data:
text
4, 7, 9
An iteration visits:
text
4
then 7
then 9
and performs the same prescribed operation on each.

14. Trace iteration manually

Consider:
text
total = 0

for each x in [2, 5, 3]:
    total = total + x
Trace:
Iterationxtotal beforetotal after
start——0
1202
2527
33710
Final:
text
total = 10
Manual tracing is central to this course.

15. Iterator is temporary

Suppose:
text
for each x in [10, 20, 30]
Then x successively takes:
text
10
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:
text
2, 7, 3, 10, 8
Condition:
text
x > 5
Filtered values:
text
7, 10, 8

17. Filtering as a predicate

A filter condition evaluates to something conceptually like:
text
true / false
Example:
x>5.x>5.
For:
x=7,x=7,
condition is true.
For:
x=3,x=3,
condition is false.

18. Counting filtered items

Example:
text
count = 0

for each x in data:
    if x > 5:
        count = count + 1
For:
text
[2, 7, 3, 10, 8]
the count becomes:
3.3.

19. Summing filtered items

Suppose we want the sum of only positive numbers:
text
total = 0

for each x:
    if x > 0:
        total = total + x
For:
text
[-2, 5, -1, 8]
result:
5+8=13.5+8=13.
Filtering and accumulation commonly appear together.

20. Filter vs transformation

These ideas are different.

Filtering

Choose whether an item survives.
Example:
text
keep x if x > 0

Transformation

Change an item.
Example:
text
replace x with x²
A problem can do both:
text
keep 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:
…,−2,−1,0,1,2,…\dots,-2,-1,0,1,2,\dots
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:
3.75.3.75.

24. Boolean

Boolean data has two logical values:
text
True
False
Example condition:
text
age >= 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:
text
123
is numerical.
They may look similar but behave differently.

26. Why datatype matters

Consider:
text
2 + 3
Numerically:
5.5.
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:
text
AND
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:
text
   Start
     |
     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:
text
Is x > 10?
Two branches emerge:
text
Yes
No
This is the visual equivalent of:
text
if 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:
text
Read 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-15
  • probability = 1.71.7
  • examination percentage = 240%240\%
  • number of students = 3.83.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:
text
age = 25
is plausible.
But that does not prove the recorded age is actually correct.
So:
plausible≠verified\boxed{ \text{plausible}\neq\text{verified} }

35. Range checks

A basic sanity check often verifies a valid range.
For probability:
0≤p≤1.0\leq p\leq1.
For exam percentage:
0≤x≤100.0\leq x\leq100.
For count:
x≥0x\geq0
and often:
x∈Z.x\in\mathbb Z.

36. Type sanity

Suppose:
text
number_of_students = 27.4
Even though:
27.4>0,27.4>0,
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:
text
Height = missing
An algorithm should not blindly treat missing information as:
text
0
unless that encoding is explicitly justified.
Otherwise you introduce false data.

38. Impossible vs unusual

Sanity checks must distinguish:

Impossible

text
probability = -0.2

Unusual but possible

text
person 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:
text
unusual
does not mean:
text
delete
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:
text
count = 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:
text
28, 34, 29, 40, 31
Start:
text
count = 0
Then:
ttt>30t>30?count
28No0
34Yes1
29No1
40Yes2
31Yes3
Output:
3\boxed{3}

43. State invariant intuition

During the previous algorithm, after each iteration:
count equals 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:
text
for 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:
text
count = 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:
text
for each x:
    count = count + 1
This counts all items.
Correct:
text
for each x:
    if x > 5:
        count = count + 1

Common mistake: filter reversed
Wanted:
text
x > 5
but using:
text
x < 5
produces the complementary set.
Always translate the wording carefully before tracing.

Common mistake: confusing iterator with count
Example:
text
for 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:
text
for 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:
text
x = 3
x = 8
then the current value is:
8,8,
not both 3 and 8.
Assignments update state.

Common mistake: treating string as number
Suppose:
text
marks = "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:
−46.-46.
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:
text
x > 10?
both:
text
Yes
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

text
count = 0
count = count + 1

Sum

text
total = 0
total = total + x

Product

text
product = 1
product = product * x
Recognizing these patterns helps tremendously in CT questions.

56. Filter + count pattern

text
count = 0

for each x:
    if condition(x):
        count = count + 1
Question answered:
How many items satisfy the condition?

57. Filter + sum pattern

text
total = 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.
text
found = False

for each x:
    if condition(x):
        found = True
At the end:
text
found
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:
text
if 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:
text
A = 0
for each x in [3, 8, 2, 9]:
    if x > 5:
        A = A + x
Trace:
StepxConditionA beforeA after
start———0
13False00
28True08
32False88
49True817
Final:
A=17\boxed{A=17}

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:
text
count = count + 2
then count increases by 2.
Your job in tracing questions is execution, not repair.

62. Week 1 master mental model

text
INPUT 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:
  1. Explain what a variable represents.
  2. Distinguish assignment from mathematical equality.
  3. Initialize variables correctly.
  4. Trace variable updates manually.
  5. Explain iteration and iterators.
  6. Filter data using conditions.
  7. Combine filtering with counting and summation.
  8. Distinguish basic datatypes.
  9. Understand why datatypes affect valid operations.
  10. Follow a basic flowchart.
  11. Recognize loops and decisions in flowcharts.
  12. Perform basic sanity checks on data.
  13. Distinguish unusual data from impossible data.
  14. Build a trace table for pseudocode.
  15. 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
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.