Computational Thinking: Complete Theory Notes

IIT Madras BS DS - Foundational Level All 12 Weeks Covered


Week 1-2: Introduction to Data & Algorithms

1.1 What is Computational Thinking?

A problem-solving approach that involves:

  1. Decomposition: Breaking problems into smaller parts
  2. Pattern Recognition: Finding similarities
  3. Abstraction: Focusing on relevant information
  4. Algorithm Design: Creating step-by-step solutions

1.2 Standard Datasets

Words Dataset

ColumnData TypeDescription
Card NumberIntegerUnique ID
WordTextThe actual word
Part of SpeechTextNoun, Verb, Adjective, Adverb
Letter CountIntegerNumber of letters

Scores Dataset

ColumnData TypeDescription
NameTextStudent name
SubjectTextMath, Physics, Chemistry
MarksIntegerScore in subject
GenderTextMale/Female
CityTextHometown
DOBDateDate of birth

Shopping Bills Dataset

ColumnData TypeDescription
Shop NameTextStore name
Customer NameTextBuyer name
ItemTextProduct purchased
PriceNumberCost of item
CategoryTextProduct category

Library Dataset

ColumnData TypeDescription
BookTextBook title
AuthorTextAuthor name
GenreTextFiction, Non-fiction, etc.
YearIntegerPublication year
LanguageTextEnglish, Hindi, etc.

1.3 Data Types & Sanity Checks

TypeValid ExamplesInvalid Examples
Integer1, 42, -5”One”, 3.14, ""
Positive Integer1, 420, -5, 3.14
Text”Hello”, “123”(Usually any text is valid)

Common Errors:

  • Negative letter count
  • Non-integer card number
  • Future dates for historical data

Week 2-3: Pseudocode & Flowcharts

2.1 Standard Pseudocode Structure

Step 1: Arrange all cards in Pile 1
Step 2: Initialize variables (A = 0, B = 0)
Step 3: If Pile 1 is empty, go to Step 7
Step 4: Read top card from Pile 1
Step 5: If <condition> then <action>
Step 6: Move card to Pile 2, repeat from Step 3
Step 7: Output result

2.2 Flowchart Symbols

SymbolShapeMeaning
TerminalOvalStart/End
ProcessRectangleAction/Calculation
DecisionDiamondYes/No Question
Input/OutputParallelogramRead/Print
ArrowArrowFlow direction

2.3 Variables

Declaration: A = 0

Update:

  • Counter: A = A + 1
  • Accumulator: A = A + Value
  • Flag: A = 1 (sets to true)

Week 3-4: Logical Operators

3.1 Boolean Operators

OperatorTrue WhenExample
andBoth conditions truex > 0 and x < 10
orAt least one truex < 0 or x > 10
notCondition is falsenot(x == 0)

3.2 Truth Tables

AND

ABA and B
TTT
TFF
FTF
FFF

OR

ABA or B
TTT
TFT
FTT
FFF

NOT

Anot A
TF
FT

3.3 De Morgan’s Laws

In English:

  • NOT (A and B) = (NOT A) or (NOT B)
  • NOT (A or B) = (NOT A) and (NOT B)

Week 4-5: Common Patterns

4.1 Counting Pattern

count = 0
for each card X:
    if <condition>:
        count = count + 1

Result: Number of items satisfying condition

4.2 Summing Pattern

sum = 0
for each card X:
    sum = sum + X.Value

Result: Total of all values

4.3 Average Pattern

sum = 0
count = 0
for each card X:
    if <condition>:
        sum = sum + X.Value
        count = count + 1
Average = sum / count

4.4 Maximum/Minimum Pattern

max = 0  (or first value)
for each card X:
    if X.Value > max:
        max = X.Value

4.5 Distinct Counting (Flag Pattern)

A = 0, B = 0, C = 0
for each card X:
    if X.Type == "A": A = 1
    if X.Type == "B": B = 1
    if X.Type == "C": C = 1
Result = A + B + C

Key: Use = 1, not = A + 1


Week 5-6: Procedures & Functions

5.1 Procedure Definition

procedure doSomething(X, Y):
    <steps>
    return result

5.2 Calling Procedures

result = doSomething(card1, card2)

5.3 Return Values

procedure compare(A, B):
    if A > B:
        return -1
    else:
        return 1

Week 6-8: Pair Comparisons

6.1 Double Loop Pattern

for each X in Table 1:
    for each Y in Table 1:
        if X != Y:
            if <condition on X and Y>:
                count = count + 1

Note: This counts (A,B) and (B,A) as separate pairs!

6.2 Common Pair Conditions

  • Same Author: X.Author == Y.Author
  • Same Year: X.Year == Y.Year
  • Different Genre: X.Genre != Y.Genre

6.3 Avoiding Double Counting

To count unordered pairs once:

if X.CardNumber < Y.CardNumber:
    if <condition>:
        count = count + 1

Week 8-10: Algorithms

8.1 Searching

  • Check each element one by one
  • Time:
  • Requires sorted data
  • Divide and conquer
  • Time:

8.2 Sorting

Bubble Sort

  • Compare adjacent pairs
  • Swap if out of order
  • Repeat until sorted
  • Time:

Selection Sort

  • Find minimum in unsorted portion
  • Swap to front
  • Time:

Insertion Sort

  • Insert each element into correct position in sorted portion
  • Time:

Week 10-12: Data Structures

10.1 Stack (LIFO)

  • Push: Add to top
  • Pop: Remove from top
  • Use: Backtracking, undo operations

10.2 Queue (FIFO)

  • Enqueue: Add to back
  • Dequeue: Remove from front
  • Use: Task scheduling, BFS

10.3 Arrays

  • Fixed size collection
  • Access by index: A[0], A[1], etc.

Common Traps & Debugging

The Reset Bug

Buggy:

Step 2: count = 0
...
Step 6: Repeat from Step 2

Fixed:

Step 6: Repeat from Step 3

Problem: Repeating from initialization resets variables!

Expression Evaluation

ExpressionResult
2 == 2 or 2 > 3True
2 = 2 and 2 > 3Error (assignment in condition)
not(2 > 2)True
2 + '2'Error (type mismatch)

Nested IF = AND

if A:
    if B:
        action

Is equivalent to:

if A and B:
    action

End of CT Theory. Good luck!