← All notes

CS50

CS50 Week One

excalidraw

Problem Solving

  • The process of developing logical solutions to computational problems.
  • Involves:
    • Understanding the problem
    • Breaking it down into smaller parts
    • Developing algorithms
    • Writing code to implement solutions
  • Essential skill for programming and computer science.

Information Representation

Base-1 / Unary Notation

  • A numbering system that uses only one symbol (e.g., tally marks).
  • Not commonly used in computing but helps in understanding fundamental counting.

Base-2 / Binary System

  • The foundation of all modern computing.
  • Uses only two digits: 0 and 1.

Bit

  • Bit (Binary Digit): The smallest unit of data in computing.
  • Can be either 0 or 1.
  • Represents Off (0) or On (1) in circuits.

Base-8 / Byte

  • A byte consists of 8 bits.
  • A single byte can represent values from 0 to 255.
  • Used for encoding characters, numbers, and other data types.

ASCII (American Standard Code for Information Interchange)

  • A character encoding standard.
  • Maps letters, digits, and symbols to numerical values.
  • Example:
    • 'A' → 65
    • 'B' → 66
    • 'a' → 97
    • '0' → 48

Emoji Representation

  • Uses standardized bits to encode emojis.
  • Similar to ASCII but extended to support a vast range of symbols.
  • Often encoded using Unicode (UTF-8, UTF-16).

Color Representation

  • RGB (Red, Green, Blue) model is used to represent colors in digital systems.
  • Each color is defined by 3 values (ranging from 0 to 255).
  • Example:
    • Black → (0, 0, 0)
    • White → (255, 255, 255)
    • Red → (255, 0, 0)
    • Green → (0, 255, 0)
    • Blue → (0, 0, 255)

Data Structure

Data Structures - Arrays

What is an Array?

An array is a contiguous block of memory that can store multiple elements, either of a single type or various types, depending on the programming language.

Core Concept

The idea behind an array is to store information in a list-like structure with a continuous memory space.
This allows for efficient indexing and quick access to stored values.

Accessing Array Elements

We can access array elements by position (indexing), typically starting from 0.

Type Flexibility

Depending on the programming language:

  • Some languages (Rust) enforce strict typing, meaning all elements must be of the same type.
  • Others (e.g., Python) allow mixed types within an array-like structure.

Important Notes

  • Arrays are immutable by nature, meaning their size cannot change after allocation.
  • Since arrays use contiguous memory, they provide fast access that's O(n) complexity for element retrieval.