everything.study
COMP 1405

Introduction to Computer Science I

0.5 credit · Undergraduate

Introduction to computer science and programming, for computer science students. Topics include: algorithm design; control structures; variables and types; linear collections; functions; debugging and testing. Special attention is given to procedural programming in a modern language, computational thinking skills, and problem decomposition.

Study notes

Independent, AI-drafted study guide · Public sources linked below · Added November 5, 2026

Independent study guide aligned with the public Fall 2026 outline. Python examples are original. Course materials are linked for scope; these notes are not a reproduction of instructor notes or assignments.

Shared guide for COMP 1005 / COMP 1405.

Turn a problem into a precise algorithm

Before writing syntax, state the inputs, outputs, and rules that connect them. An algorithm is a finite procedure whose steps are unambiguous at the chosen level of detail. Decomposition separates a large task into smaller contracts: read records, validate them, calculate a result, then present it. Trace a tiny example by hand before coding. If you cannot predict the required output for an empty input or a boundary value, the problem specification needs more work. Correctness means satisfying the contract for every allowed input, rather than merely finishing without an exception.

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Values, types, assignment, and state

A variable name refers to a value; assignment updates that binding. In Python, an integer supports exact whole-number arithmetic, while a float approximates real values with finite precision. Strings represent text and require explicit conversion when numerical input is expected. Distinguish equality from identity and from assignment. Evaluate the right side before changing the left side: after x = 4 and x = x + 3, x is 7. A state table listing each variable after every statement is a reliable way to diagnose an incorrect calculation.

distance_m = 1250
time_s = 250
speed_m_per_s = distance_m / time_s
print(speed_m_per_s)  # 5.0

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Branching, loops, and invariants

A conditional chooses a path using a Boolean expression. Test compound expressions with a truth table and remember that the order of overlapping branches matters. A loop repeats an operation while maintaining a useful statement called an invariant. When summing a list, the accumulator equals the sum of all elements already visited. Establish this before the loop, preserve it in each iteration, and use termination to obtain the final result. Watch for off-by-one errors: range(n) produces n indices starting at zero, so its final index is n minus one.

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Lists, strings, dictionaries, and aliasing

Choose a collection according to the operations the program needs. A list preserves position; a dictionary associates keys with values; a string is an immutable sequence of characters. Indexing selects one element, whereas slicing creates a subsequence. Mutating an aliased list is visible through both names: b = a does not copy a. With nested lists, copying only the outer list still shares inner rows. Draw the references when reasoning about such code. Empty collections, absent keys, duplicate values, and uneven row lengths deserve explicit handling.

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Functions, scope, and recursive decomposition

A function gives a name to a calculation and defines an interface through parameters and a return value. Prefer returning a result to printing it when callers must reuse the value. Local variables belong to a call; separate calls have separate local state. A recursive function solves a smaller instance using the same contract. It needs a base case and a measure that decreases toward that case. For a list total, remove one element per recursive call. A missing decrease can cause unbounded recursion even when the base-case code exists.

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Testing, searching, and a worked trace

Consider finding the first reading above 20 in [18, 20, 23, 19]. A linear scan rejects indices 0 and 1, then returns 2. The invariant is that no earlier index qualifies. If nothing qualifies, return a documented sentinel such as None. Linear search takes up to n comparisons; binary search reduces the remaining interval repeatedly but requires sorted input. Sorting first costs time and can change positions. Design tests around the specification: empty input, a match first, a match last, no match, and repeated qualifying values.

def first_above(values, limit):
    for index, value in enumerate(values):
        if value > limit:
            return index
    return None

References: COMP 1405/1005 A/B/C — Fall 2026 course outline · Python Software Foundation — The Python Tutorial

Practice & worked answers

Original exercises for this guide.

1. Why does total = total + value belong inside the loop?

Show worked answer

Each iteration incorporates exactly the current element. Moving the update outside the loop would use only the final element and would also fail for empty input if value was never assigned.

2. What happens after a = [2, 4]; b = a; b.append(6)?

Show worked answer

Both a and b refer to the same mutable list, so both observe [2, 4, 6]. Use a.copy() for an independent shallow copy of this flat list.

3. When is binary search preferable to a single linear scan?

Show worked answer

It is attractive when the input is already sorted or many searches justify an initial sort. For one query on unsorted data, sorting typically adds more work than scanning once.

Public notes & references

Course sources establish the scope above. Reference materials support the explanations; linked lecture notes and books remain with their authors.

2026

Topics

  • design and express simple algorithm using flowcharts and pseudocode
  • create expressions with arithmetic, logical, and comparative operations
  • create branching and repeating control structures, with and without nesting
  • design and implement functions and explain function scope and recursion
  • create, access, and manipulate linear, multidimensional, and associative collections
  • describe and make effective/appropriate use of artificial intelligence-based coding tools

Prerequisites & course information

Also listed as COMP 1005 . Precludes additional credit for BIT 1400 , CGSC 1005 , ECOR 1031 , ECOR 1041 (no longer offered), ECOR 1042 (no longer offered), ECOR 1051 (no longer offered), ECOR 1606 (no longer offered), ITEC 1400 , ITEC 1401 , SYSC 1005 (no longer offered). Prerequisite(s): restricted to students registered in the B.C.S. program, B.Cyber. program, B.D.S. program, combined Honours in Computer Science and Mathematics, Honours Computer Mathematics, and Honours Computer Statistics. Lectures three hours a week, tutorial one and a half hours a week.

Sources