CT: Ultimate Pattern Recognition Guide 🎯
IMPORTANT
Purpose: Complete hierarchical map of every Computational Thinking question pattern. Master pseudocode logic with quick recognition strategies.
📊 Pattern Hierarchy Overview
| Week | Pattern Families | Total Patterns |
|---|---|---|
| 1: Flowcharts & Pseudocode | Sequences, Logic, Data Sanity | 7 |
| 2: Variables | Assignment, Swapping, Min/Max | 8 |
| 3: Conditionals | If-Else, Nested, Chained | 10 |
| 4: While Loops | Termination, Aggregation, Infinite | 9 |
| 5: For Loops | Iteration, Nested, Break/Continue | 10 |
| 6: Lists & Strings | Indexing, Slicing, Filtering | 12 |
| 7: Dictionaries | Frequency, Grouping, Key Errors | 10 |
| 8: Procedures | Parameters, Return, Scope | 8 |
Week 1: Flowcharts & Pseudocode
Pattern Family 1.1: Initialization Traps
🟢 Level 1: Counter Initialization
Spot it Fast: “Count cards > 500”
Mental Algorithm:
- Initialize ONCE:
count = 0(BEFORE loop) - Increment:
count = count + 1(INSIDE loop) - NEVER reset inside loop
Common Traps:
- ❌ Step 2: Initialize count = 0
- ❌ Step 5: Increment count
- ❌ Step 6: Repeat from Step 2 ← WRONG! Resets count every time!
- ✅ Correct: Repeat from Step 3 or 4 (after initialization)
🟡 Level 2: Accumulator Pattern
Spot it Fast: “Sum of all values”
Template:
sum = 0
For each value in pile:
sum = sum + value
🔴 Level 3: Multiple Counters
Spot it Fast: “Count A, count B, compare”
Mental Algorithm: Initialize ALL counters before loop
Pattern Family 1.2: Logic Flow
🟢 Level 1: Sequential Steps
Spot it Fast: Steps 1, 2, 3… no conditions
Rule: Execute in order, no branching
🟡 Level 2: Conditional Branches
Spot it Fast: “If … then … else …”
Flowchart: Diamond shape for decision
🔴 Level 3: Nested Logic
Spot it Fast: Multiple IF statements inside each other
Interpretation: AND logic (both conditions must be true)
Week 2: Variables & Assignment
Pattern Family 2.1: Variable Updates
🟢 Level 1: Simple Assignment
Spot it Fast: x = 5
Rule: RIGHT side evaluated first, then stored in LEFT
🟡 Level 2: Self-Update
Spot it Fast: x = x + 1
Mental Algorithm:
- Get current value of
x - Add 1
- Store back in
x
Common Traps:
- ❌ Thinking
x = x + 1is algebra (it’s not!)
🔴 Level 3: Swapping Without Temp
Spot it Fast: “Swap A and B without third variable”
Trick (algebraic):
A = A + B
B = A - B (now B has old A)
A = A - B (now A has old B)
Pattern Family 2.2: Min/Max Tracking
🟢 Level 1: Find Maximum
Spot it Fast: “Store largest value”
Template:
max = -infinity (or first element)
For each value:
If value > max:
max = value
🟡 Level 2: Find Minimum with Condition
Spot it Fast: “Lowest Chemistry marks”
Template:
min = 101 (impossible high value)
For each student:
If Chem < min:
min = Chem
🔴 Level 3: Conditional Updates
Spot it Fast: “Store city with lowest count”
Mental Algorithm: Track BOTH value AND associated item
Week 3: Conditionals
Pattern Family 3.1: If-Else Logic
🟢 Level 1: Simple If
Spot it Fast: One condition
Template:
If condition:
action
🟡 Level 2: If-Else
Spot it Fast: “Otherwise”
Template:
If condition:
action1
Else:
action2
Rule: Exactly ONE branch executes
🔴 Level 3: Nested If-Else
Spot it Fast: Multiple levels of conditions
Mental Algorithm: Work from outermost to innermost
Example:
If LetterCount % 2 == 0:
P = P + 1
Else:
If PartOfSpeech == "Adverb":
Q = Q + 1
Interpretation:
Pcounts words with EVEN letter countQcounts ADVERBS with ODD letter count
Pattern Family 3.2: Chained If-Else
🟢 Level 1: Mutually Exclusive
Spot it Fast: If ... Else If ... Else If ...
Rule: Only FIRST true condition executes
Example:
If score >= 90:
grade = "A"
Else If score >= 80:
grade = "B"
Else If score >= 70:
grade = "C"
🟡 Level 2: Multiple Independent Ifs
Spot it Fast: Separate If statements (NOT Else If)
Rule: ALL are checked
Example:
If Math < 80:
count_low_math = count_low_math + 1
If Physics < 80:
count_low_physics = count_low_physics + 1
Common Traps:
- ❌ Using chained Else If when you want to check multiple conditions
Pattern Family 3.3: Complex Conditions
🟢 Level 1: AND Logic
Spot it Fast: Both conditions required
Syntax: If (A > 0) AND (B < 10):
🟡 Level 2: OR Logic
Spot it Fast: At least one condition
Syntax: If (A < 80) OR (B < 80) OR (C < 80):
Meaning: “Scored < 80 in at least one subject”
🔴 Level 3: NOT Logic
Spot it Fast: Negation
Example: If NOT (x > 5): ≡ If x <= 5:
Week 4: While Loops
Pattern Family 4.1: Loop Termination
🟢 Level 1: Counter-Based
Spot it Fast: while count < 10:
Mental Algorithm: Loop runs until condition becomes FALSE
🟡 Level 2: Sentinel Value
Spot it Fast: while pile not empty: or while x != -1:
Use: When you don’t know iterations in advance
🔴 Level 3: Infinite Loop Detection
Spot it Fast: Condition never becomes false
Example (INFINITE):
X = 0
While X < 10:
Print X
If X == 5:
X = X - 1 ← Goes back to 5!
X = X + 1
Trace:
- 0, 1, 2, 3, 4, 5
- At 5: X becomes 4, then 5
- Loop forever between 4 and 5
Pattern Family 4.2: Aggregation Patterns
🟢 Level 1: Counting
Spot it Fast: “How many …”
Template:
count = 0
While pile not empty:
Read value
If condition:
count = count + 1
🟡 Level 2: Summing
Spot it Fast: “Total of …”
Template:
sum = 0
While pile not empty:
Read value
sum = sum + value
🔴 Level 3: Average with Trap
Spot it Fast: “Average of positive numbers”
Template:
sum = 0
count = 0
While pile not empty:
Read X
If X > 0:
sum = sum + X
count = count + 1
If count > 0: ← CRITICAL CHECK!
avg = sum / count
Common Traps:
- ❌ Division by zero if no positive numbers
Week 5: For Loops
Pattern Family 5.1: Basic Iteration
🟢 Level 1: Range-Based
Spot it Fast: For i = 1 to 10:
Iterations: Exactly 10 times
🟡 Level 2: List-Based
Spot it Fast: For item in list:
Iterations: Once per element
🔴 Level 3: Nested Loops
Spot it Fast: Loop inside loop
Example:
For i = 1 to 3:
For j = 1 to i:
count = count + 1
Trace:
- i=1: j=1 (count=1)
- i=2: j=1,2 (count=3)
- i=3: j=1,2,3 (count=6)
Pattern Family 5.2: All-Pairs Comparison
🟢 Level 1: Brute Force
Spot it Fast: “Find pair with same marks”
Template (checks each pair twice):
For each student A:
For each student B:
If A.Name != B.Name AND A.Marks == B.Marks:
Print "Pair found"
🟡 Level 2: Optimized
Spot it Fast: Avoid duplicate comparisons
Template:
For i = 0 to n-2:
For j = i+1 to n-1:
Compare student[i] with student[j]
Efficiency: instead of
Week 6: Lists & Strings
Pattern Family 6.1: Indexing
🟢 Level 1: Zero-Based Indexing
Spot it Fast: L[0] is first element
Rule: Index ranges from 0 to len-1
Common Traps:
- ❌
L[3]for list[10, 20, 30]→ ERROR!
🟡 Level 2: Negative Indexing
Spot it Fast: L[-1] is last element
Rule: -1 = last, -2 = second-last, etc.
🔴 Level 3: Slicing
Spot it Fast: L[start:end]
Rule: Includes start, excludes end
Example: S = "IIT Madras", extract “Madras”
- Indices: I(0), I(1), T(2), space(3), M(4)…
S[4:]→ “Madras”
Pattern Family 6.2: List Operations
🟢 Level 1: Append
Spot it Fast: Add to end
Syntax: L = L ++ [x] or L.append(x)
🟡 Level 2: Filtering
Spot it Fast: “Create list with only even numbers”
Template:
B = []
For x in A:
If x % 2 == 0:
B = B ++ [x]
🔴 Level 3: List Comprehension
Spot it Fast: Compact filtering syntax
Example: [x for x in A if x % 2 == 0]
Week 7: Dictionaries
Pattern Family 7.1: Frequency Counting
🟢 Level 1: Basic Frequency
Spot it Fast: “Count occurrences of each word”
Template:
D = {}
For word in list:
If isKey(D, word):
D[word] = D[word] + 1
Else:
D[word] = 1
🟡 Level 2: Grouping
Spot it Fast: “Group students by city”
Template:
D = {}
For student in list:
city = student.city
If isKey(D, city):
D[city] = D[city] ++ [student]
Else:
D[city] = [student]
Pattern Family 7.2: Key Operations
🟢 Level 1: Key Lookup
Spot it Fast: D[key]
Common Traps:
- ❌ Accessing non-existent key → ERROR!
- ✅ Always check:
If isKey(D, key):
🟡 Level 2: Inverting Dictionary
Spot it Fast: Swap keys and values
Template:
NewD = {}
For key in keys(D):
val = D[key]
If isKey(NewD, val):
NewD[val] = NewD[val] ++ [key]
Else:
NewD[val] = [key]
Week 8: Procedures
Pattern Family 8.1: Parameters & Return
🟢 Level 1: Return vs Print
Spot it Fast: What’s the difference?
Return: Passes value to caller (usable in calculations) Print: Shows to user (NOT usable by program)
Example:
A = 5 + GetVal()→ Needs RETURNPrint X→ Just displays
🟡 Level 2: Pass by Value vs Reference
Spot it Fast: Does original change?
Rule (common in pseudocode):
- Primitives (int, string): Pass by value (copy)
- Lists: Pass by reference (original modified)
🔴 Level 3: Scope
Spot it Fast: Variable defined inside procedure
Rule: Local variables exist only inside procedure
Quick Reference: CT Pattern Spotting
Week 1-2: Basics
- “Repeat from Step 2” where Step 2 is initialization → BUG!
- Swap without temp → A=A+B, B=A-B, A=A-B
Week 3: Conditionals
- Chained Else If → Only first true executes
- Multiple Ifs → All checked
- “At least one” → Use OR
Week 4-5: Loops
- Infinite loop → Variable doesn’t progress toward condition
- Nested loop count → Trace carefully
- All-pairs → Optimize with j=i+1
Week 6-7: Data Structures
- Indexing → Remember 0-based!
- Frequency → Check if key exists first
- Filtering → New list, loop through old
Week 8: Procedures
- Return → Value goes back to caller
- Print → Just displays
- List parameter → Original modified