Computer Science 1 Class Notes (Page 1 of 5)
Generated: November 05, 2025
WEEK 1 2 OVERVIEW: What is Computer Science?
CS studies algorithms (step-by-step procedures) and the limits of computation.
Key ideas: correctness, efficiency, data representation, abstraction.
Computer calculator only: it's a general-purpose symbol manipulator.
Bits & Data: binary (0/1), bytes (8 bits), text encodings (ASCII/UTF 8).
Software layers: hardware OS programming language runtime your program.
Compilation vs Interpretation (e.g., C compiles; Python is interpreted).
Program lifecycle: edit run test debug document iterate.
Pseudocode helps plan logic before coding.
PYTHON BASICS (or Java/C++ equivalents):
Variables: names bound to values; types (int, float, bool, str).
Expressions & operators: +, -, *, /, //, %, **; precedence; parentheses.
Input/Output: input(), print(); f-strings or format specifiers.
Style: meaningful names, consistent casing, comments, docstrings.
ERRORS:
Syntax errors (parser catches), runtime errors (exceptions), logic errors (wrong result).
Read tracebacks top-to-bottom; the bottom-most call shows where it blew up.
EXERCISE IDEAS:
1. Convert Celsius Fahrenheit.
2. Compute compound interest.
3. Simple tip calculator with user input.
Computer Science 1 November 05, 2025
Computer Science 1 Class Notes (Page 2 of 5)
Generated: November 05, 2025
CONTROL FLOW:
Conditionals: if / elif / else; nesting; boolean operators and/or/not.
Comparisons: ==, !=, <, <=, >, >=; beware float equality pitfalls.
Truthiness: nonempty strings/lists are True; 0/None/"" are False in Python.
LOOPS:
while loops: repeat until condition fails; mind infinite loops.
for loops: iterate over sequences/ranges; for i in range(n).
Loop control: break, continue; use carefully.
Common patterns: accumulation, searching, counting, maxima/minima.
TRACE & INVARIANTS:
Manually trace with a table of variable values across iterations.
Loop invariants: a statement that remains true each iteration and helps prove correctness.
BASIC ALGORITHMS:
Summing a list, finding max/min, counting occurrences.
Linear search O(n): check each element until found/not found.
PRACTICE:
Write a loop that finds the first index of a target value or returns -1.
FizzBuzz variant; prime check up to sqrt(n).
Computer Science 1 November 05, 2025
Computer Science 1 Class Notes (Page 3 of 5)
Generated: November 05, 2025
FUNCTIONS & SCOPE:
Why functions? Abstraction, reuse, testability, readability.
Defining: def name(params): return result.
Parameters vs arguments; default parameters; keyword args.
Return values vs printing outputs.
Scope: local vs global; avoid global state when possible.
Pure functions (no side effects) are easier to reason about.
RECURSION (intro):
A function calling itself with smaller inputs.
Needs a base case + progress toward base case.
Examples: factorial, Fibonacci (inefficient if naive), summing nested lists.
Compare recursion vs iteration; consider stack depth & complexity.
DOCS & TESTS:
Docstrings: describe inputs, outputs, preconditions.
Unit tests: test typical, edge, and error cases.
Assertions: assert conditions that must hold.
EXERCISES:
Write a function to check palindrome strings (ignore case/punctuation).
Implement gcd(a,b) both iteratively and with Euclid s algorithm (recursive).
Computer Science 1 November 05, 2025
Computer Science 1 Class Notes (Page 4 of 5)
Generated: November 05, 2025
DATA STRUCTURES & COMPLEXITY (BIG O):
Strings: immutable sequences; slicing; common methods (lower(), split()).
Lists/arrays: mutable sequences; append, pop, indexing O(1); search O(n).
Tuples: immutable lists; good for fixed records.
Dicts/maps: key value store; average O(1) get/set; hashing idea.
Sets: unique elements; fast membership tests; set ops (union, inters.).
Choosing structures: depends on operations frequency & constraints.
ALGORITHMS (SEARCH & SORT):
Linear search O(n); Binary search O(log n) on sorted data.
Sorting: selection/insertion (O(n²)), merge sort (O(n log n)), quicksort avg O(n log n).
Stability & in-place properties; when it matters.
BIG O INTUITION:
Constant O(1), log O(log n), linear O(n), n log n, quadratic O(n²), exponential.
Rule of thumb: prioritize reducing the highest-order term.
EXERCISES:
Implement selection sort and analyze swap/compare counts.
Time a Python sort on lists of sizes 1k, 10k, 100k; plot runtime (optional).
Computer Science 1 November 05, 2025
Computer Science 1 Class Notes (Page 5 of 5)
Generated: November 05, 2025
FILES, TESTING & DEBUGGING:
File I/O: open(), with context managers, read()/readlines(), write().
CSV parsing basics; always validate inputs.
Defensive programming: check preconditions; raise ValueError on bad input.
Logging vs printing; basic try/except patterns.
DEBUGGING WORKFLOW:
Reproduce reliably.
Reduce (minimize) the failing case.
Reason about expected vs actual; add assertions.
Use a debugger: breakpoints, step, watch variables.
STYLE & PRACTICES:
PEP 8 (Python): naming, line length, docstrings.
Small functions, single-responsibility; avoid copy paste code.
Version control (git): commit early/often with meaningful messages.
CAPSTONE MINI TASK:
Read a CSV of students {name, grades...}, compute averages, letter grades, and write a summary
report.
Computer Science 1 November 05, 2025