🧠 D321 Data Representation β€” Exam Study Guide

ADHD-Friendly β€’ All Questions + Answers from Review Slides β€’ Spring 2026

πŸ“‹ What's on the Exam?

Q1 β€” Fibonacci: Recursive vs Iterative (5 pts) Q2 β€” Circular Doubly Linked List (4 pts) Q3 β€” Min/Max Heap Trees (8 pts) Q4 β€” Hash Table Collisions (8 pts) Q5 β€” Binary Arithmetic (10 pts) Q6 β€” Binary Conversions (10 pts) Q7 β€” Logic Gates (5 pts) Q8 β€” ASCII Encoding (5 pts) Q9 β€” BoW & One-Hot Encoding (10 pts) Q10 β€” Set Relations (10 pts) Q11 β€” Set Algebra Simplification (10 pts) Q12 β€” Complex Numbers & Fourier (15 pts)
πŸ”

Q1 β€” Fibonacci: Recursive vs. Iterative

5 pts
The Question

Discuss the differences between recursive and iterative solutions for Fibonacci in terms of time complexity.

βœ… Iterative β€” O(n)

Uses a loop. Calculates each number once. Linear time β€” scales well.

fib = 0, 1 for i in range(n-1): fib = prev + fib

⚠️ Recursive β€” O(2ⁿ)

Calls itself twice at each step. Exponential time β€” gets incredibly slow fast!

def fib(n): if n<=1: return n return fib(n-1)+fib(n-2)
πŸ“ Key Answer: Iterative is far more efficient β€” O(n) vs O(2ⁿ). As n grows, recursive becomes exponentially slower because it recalculates subproblems repeatedly. Iterative just loops once through.
πŸ”—

Q2 β€” Linked Lists & Memory

4 pts
Part A β€” What type of list is shown?

The diagram shows nodes with arrows going both directions and the last node connects back to the first.

βœ… Answer: Circular Doubly Linked List β€” each node has a NEXT pointer AND a PREVIOUS pointer, and the tail connects back to the head.

The 4 Types of Linked Lists β€” Quick Reference

TypeDirectionLast β†’ First?Real Use
Singly LinkedOne way β†’NoSimple lists
Circular SinglyOne way β†’Yes ↩Chess game turns
Doubly LinkedBoth ↔NoMusic player (fwd/back)
Circular DoublyBoth ↔Yes ↩Mac app switcher (⌘+Tab)
Part B β€” Memory allocation
βœ… Answer: Unlike arrays (contiguous memory), a linked list stores nodes in scattered/random memory locations. Each node holds: (1) the data value, (2) a pointer to the NEXT node, and (3) in doubly linked: a pointer to the PREVIOUS node. The pointers connect the scattered pieces together.
🌲

Q3 β€” Min & Max Heap Trees

8 pts
Part A β€” What are Min/Max Heaps?

πŸ”½ Min Heap

Every parent is smaller than its children. The root = smallest element.

πŸ”Ό Max Heap

Every parent is larger than its children. The root = largest element.

Part B β€” Build a heap from: [1, 4, 8, 48, 12, 15, 22]
πŸ“ Process (Max Heap example):
  1. Insert all elements into a complete binary tree in order
  2. Start at index n/2 (middle), work backwards to root
  3. "Bubble down" each element β€” swap parent with the larger child if parent is smaller
  4. Result: Root = 48 (largest), every parent > its children
πŸ’‘ Remember: A heap is a complete binary tree β€” every level is filled left to right before going to the next level.
πŸ—‚οΈ

Q4 β€” Hash Tables & Collision Resolution

8 pts
Part A β€” What is a collision?
βœ… Answer: A hash collision occurs when two different pieces of data produce the same hash value, mapping them to the same slot in the hash table.
Part B β€” Two Collision Resolution Strategies

1️⃣ Direct Chaining (Linked List)

When two keys collide, create a linked list at that slot. All colliding values go into the same chain.

Think: each table slot is a bucket with a chain hanging from it

2️⃣ Linear Probing (Open Addressing)

If a slot is full, move to the next available slot (decrease index by 1). Wraps around to the end if needed.

Problem: "clustering" β€” slots fill up in groups, slowing things down

πŸ”‘ Also know: Double hashing β€” uses a second hash function to calculate how many slots to jump, solving the clustering problem of linear probing.

For the exam table (PHL=4, ORY=8, GCM=6...):

Apply linear probing: if the target slot is taken, keep decrementing the index until you find an empty slot. Apply chaining: if the slot is taken, add to the linked list at that position.

πŸ”’

Q5 β€” Binary Arithmetic

10 pts
Part A β€” Binary Multiplication: B = 111.0011 Γ— C = 1.00101
πŸ“ Partial Sum Method:
  1. Ignore decimal point, multiply as whole numbers
  2. For each bit in C (right to left): if bit = 1, write B shifted left; if bit = 0, write zeros
  3. Add all partial products in binary
  4. Count total decimal places in both numbers, place the decimal point that many positions from the right
⚠️ B has 4 decimal places + C has 5 decimal places = 9 decimal places in the answer
Part B β€” Binary Addition: B + C
RuleResultCarry
0 + 000
0 + 1 or 1 + 010
1 + 101
1 + 1 + 1 (with carry)11
πŸ“ Steps: Align decimal points. Add bit by bit from right to left, carrying over when needed. The exam answer for 111.0011 + 1.00101 = 1000.10001 (align and carry carefully!). The slide answer shows: 00100.010
πŸ”„

Q6 β€” Number System Conversions from 11011.101

10 pts

Starting number: 11011.101

a) β†’ Hexadecimal

Group bits in sets of 4 from the decimal point outward

Integer: 0001 1011 β†’ 1B

Fraction: .1010 β†’ .A

Answer: 1B.A

b) β†’ Octal

Group bits in sets of 3 from the decimal point outward

Integer: 011 011 β†’ 33

Fraction: .101 β†’ .5

Answer: 33.5

c) β†’ IEEE 754 (32-bit floating point)

  1. Determine the sign bit: positive = 0
  2. Normalize: write as 1.xxxxx Γ— 2ⁿ β†’ 11011.101 = 1.1011101 Γ— 2⁴
  3. Exponent: 4 + 127 (bias) = 131 β†’ 10000011
  4. Mantissa: the bits after the "1." = 1011101, pad to 23 bits with zeros
  5. Combine: 0 | 10000011 | 10111010000000000000000

d) β†’ First Complement (1's Complement)

Simply flip every bit: 0β†’1 and 1β†’0

11011.101 β†’ 00100.010

Answer: 00100.010 βœ“ (confirmed in slides)
⚑

Q7 β€” Logic Gates Expression

5 pts

The circuit diagram shows: A & B feed into an AND gate, B & C feed into an OR gate, then that feeds into an AND gate, and both AND results feed into a final OR gate.

βœ… Answer from slides:

Q = AB + BC

Read the circuit: AND gate gives A·B, the OR→AND path gives B·C, and the final OR gate combines them.

Logic Gate Quick Reference:

GateSymbolRule
ANDΒ·Output 1 only if ALL inputs are 1
OR+Output 1 if ANY input is 1
NOTA'Flips the input
NAND(AΒ·B)'AND then NOT
NOR(A+B)'OR then NOT
XORβŠ•Output 1 if inputs are DIFFERENT
πŸ”€

Q8 β€” ASCII Decoding

5 pts

Decode: 01001110 01101111 00100001

πŸ’‘ How to use ASCII: Split the 8 bits into two groups of 4. The first 4 bits = the row, the last 4 bits = the column (or just convert each byte to decimal and look up the character).
βœ… How to decode each byte:
  • 01001110 β†’ decimal 78 β†’ N
  • 01101111 β†’ decimal 111 β†’ o
  • 00100001 β†’ decimal 33 β†’ !

Answer: "No!"

(The slide confirms this β€” it literally says "No!" πŸ˜„)

⚠️ Shortcut: Convert each 8-bit byte to decimal, then look up in the ASCII table provided. Binary β†’ decimal: add up powers of 2 for each "1" bit (128, 64, 32, 16, 8, 4, 2, 1 from left to right).
πŸ“¦

Q9 β€” Bag of Words & One-Hot Encoding

10 pts
Part A β€” What is Bag of Words (BoW)?
βœ… Answer: BoW represents a document as a collection of word counts, ignoring grammar and word order. Each unique word in the vocabulary gets a position in a vector, and the value = how many times that word appears.

Example:

Vocabulary: [The, cat, in, hat, sat, on, mat]

β€’ "The cat in the hat" β†’ [2, 1, 1, 1, 0, 0, 0]

β€’ "The cat sat on the mat" β†’ [2, 1, 0, 0, 1, 1, 1]

Part B β€” One-Hot Encoding of [human, animal, world, computer]
βœ… Answer: Each word becomes a vector with a single "1" and all other positions "0":
Wordhumananimalworldcomputer
human1000
animal0100
world0010
computer0001
πŸ”—

Q10 β€” Set Relations

10 pts

Sets: A = Americans, M = Mathematicians, P = Philosophers, Knows = relation where (x,y) means x knows y

Part A β€” "Find people who know an American mathematician"
βœ… Answer:
We need people who Know someone in A ∩ M
π₁(Knows β‹ˆ (A ∩ M))

Plain English: Find all x where there exists a y such that (x Knows y) AND y is in A AND y is in M

Part B β€” "Find philosophers who ONLY know mathematicians"
βœ… Answer:
Philosophers in P where ALL people they know are in M
P βˆ’ π₁(Knows β‹ˆ M')

Plain English: Start with all philosophers, remove any who know at least one non-mathematician

πŸ“

Q11 β€” Set Algebra Simplification

10 pts

Simplify: ((A β†’ B) ∩ A) β†’ B

πŸ’‘ Key rule to remember: A β†’ B = A' βˆͺ B (Implication Law)
βœ… Step-by-step proof:
  1. Rewrite A β†’ B using implication law: (A' βˆͺ B) ∩ A
  2. Distribute ∩ over βˆͺ: (A' ∩ A) βˆͺ (B ∩ A)
  3. A' ∩ A = βˆ… (Complement law): βˆ… βˆͺ (B ∩ A)
  4. βˆ… βˆͺ X = X (Identity law): A ∩ B
  5. Now the full expression is: (A ∩ B) β†’ B
  6. Rewrite using implication: (A ∩ B)' βˆͺ B
  7. De Morgan: (A' βˆͺ B') βˆͺ B
  8. Associativity + Complement: B' βˆͺ B = U β†’ A' βˆͺ U = U
  9. Result = U (always true / tautology)
⚠️ The slides confirm this simplifies using: Complement law (XβˆͺX'=U), Associative law, Implication law, and De Morgan's Law.

Essential Laws Cheat Sheet:

LawFormula
ImplicationA β†’ B = A' βˆͺ B
De Morgan (∩)(A ∩ B)' = A' βˆͺ B'
De Morgan (βˆͺ)(A βˆͺ B)' = A' ∩ B'
ComplementA ∩ A' = βˆ…   |   A βˆͺ A' = U
IdentityA βˆͺ βˆ… = A   |   A ∩ U = A
AbsorptionA ∩ (A βˆͺ B) = A
Abjunction(A β†’ B)' = A ∩ B'
🌊

Q12 β€” Complex Numbers & Fourier Transform

15 pts
Part A β€” Complex number (2, 3i): Magnitude & Angle

πŸ“ Magnitude

Use Pythagorean theorem:
|z| = √(real² + imaginary²)
|z| = √(2² + 3²)
|z| = √(4 + 9) = √13

β‰ˆ 3.606

πŸ“ Angle (ΞΈ)

Use arctangent:
ΞΈ = arctan(imaginary / real)
ΞΈ = arctan(3/2)

β‰ˆ 56.31Β°
Part B β€” Steps to implement the Fourier Transform
βœ… Answer (from slides):
  1. Loop over frequencies (for each frequency you want to analyze):
  2. Create a complex sine wave with the same number of time points as the signal, at the current frequency
  3. Compute the dot product between the complex sine wave and the signal
  4. End loop
  5. The result: each dot product = a Fourier coefficient for that frequency
  6. The magnitude of coefficients = amplitude spectrum
  7. The angle of coefficients = phase spectrum
🎡 Big idea: The Fourier Transform breaks any signal into the sum of sine waves. It answers: "What frequencies make up this signal?" This is how music equalizers, image compression, and signal processing work.

⭐ Last-Minute Power Tips

πŸ” Fibonacci: Iterative = O(n), Recursive = O(2ⁿ)

πŸ”— List type: Circular Doubly Linked List

🌲 Heap: Min = smallest at root, Max = largest at root

πŸ—‚οΈ Collision fix: Chaining = linked lists, Probing = find next empty slot

πŸ“ ASCII decode: "No!" (binary β†’ decimal β†’ letter)

πŸ”„ 1's Complement: Just flip all bits!

πŸ”„ IEEE 754: Sign | Exponent+127 | Mantissa (23 bits)

⚑ Logic gates: Q = AB + BC

πŸ“¦ One-hot: One "1" per row, rest are "0"s

🌊 Fourier: Loop β†’ complex sine wave β†’ dot product

You've got this! πŸš€ Good luck on the exam!