Fundamentals of Computer Science Explained

Aug 21, 2024

Computer Science 101 Lecture Notes

Introduction

  • Overview of common coding errors and misconceptions
  • Importance of understanding underlying concepts in computer science

Basic Concepts

  • What is a Computer?

    • A device that processes data using binary (ones and zeros)
    • Conceptually similar to a Turing machine
  • Central Processing Unit (CPU)

    • Core component of modern computers
    • Contains billions of tiny transistors (on/off switches)
    • A bit is the smallest piece of information; a byte (8 bits) represents 256 values

Data Representation

  • Binary System

    • A counting system using only 1 and 0
    • Often simplified for humans using hexadecimal (base 16)
  • Character Encoding

    • Maps keyboard characters to binary values (e.g., ASCII, UTF-8)
  • Machine Code

    • Code that the CPU can decode and execute
    • Applications use Random Access Memory (RAM) to store data temporarily

Input/Output Devices

  • Input: Keyboard, Mouse
  • Output: Monitor
  • Operating System (OS) manages hardware through device drivers
    • Examples: Linux, Mac, Windows

Shell and Programming Languages

  • Shell

    • Program that interacts with the OS via a command line interface
    • Can connect to remote computers using secure shell protocol
  • Programming Languages

    • Tools for writing code with different abstraction levels
    • Interpreted (e.g., Python) vs. Compiled (e.g., C++)

Data Types and Variables

  • Common built-in data types:

    • Integers (int): Whole numbers (signed/unsigned)
    • Floating point numbers (float/double): Numbers with decimals
    • Characters (char) and Strings: Text data
  • Variables

    • Names attached to data points for reuse
    • Dynamic typing (e.g., Python) vs. Static typing (e.g., C)

Memory Management

  • Pointers: Variables that hold memory addresses of other variables
  • Garbage Collection: Automatic memory management system in some languages

Data Structures

  • Arrays/Lists: Ordered collections of items
  • Linked Lists: Items connected by pointers
  • Stacks and Queues: LIFO and FIFO data structures respectively
  • Hash Tables: Key-value pair collections
  • Trees and Graphs: Hierarchical and networked data structures

Algorithms

  • Defined as blocks of code that solve problems
  • Functions: Named blocks of code that take inputs and return outputs
  • Conditional logic (if statements) and loops (while/for)
  • Recursion: Functions calling themselves with base conditions to avoid infinite loops

Algorithm Efficiency

  • Big-O Notation: Measures time and space complexity of algorithms
  • Various types of algorithms:
    • Brute Force: Examining all possible solutions
    • Divide and Conquer: Breaking problems into smaller parts
    • Dynamic Programming: Storing results of solved sub-problems
    • Greedy Algorithms: Making the best immediate choice
    • Backtracking: Incremental approach to find solutions

Programming Paradigms

  • Declarative vs. Imperative: Describes what the program does vs. explicit instructions
  • Object-Oriented Programming (OOP): Classes encapsulating data and behavior
    • Inheritance: Subclass extending behaviors of a parent class

Memory Management in Depth

  • Heap vs. Stack: Dynamic vs. static memory allocation
  • Object references to avoid memory duplication

Multithreading and Concurrency

  • Threads: Allow concurrent execution of code
  • Concurrency Models: Event loops, co-routines for handling multiple jobs

Cloud Computing

  • Virtual Machines: Simulating hardware to run multiple smaller computers
  • Networking: IP addresses, TCP handshake, and APIs for client-server communication

Conclusion

  • The importance of understanding how all components work together in computer science
  • Practical implications, such as troubleshooting printers at home.