Skip to content

CS50x Harvard's Introduction to Computer Science - Complete lecture notes, code examples, and problem set solutions. Understanding what's underneath the hood! ๐ŸŽ“

Notifications You must be signed in to change notification settings

MostafaMousaaa/CS50x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

68 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽ“ CS50: Introduction to Computer Science

"This is CS50!" - David J. Malan

๐Ÿš€ About This Repository

Welcome to my CS50 journey! This repository contains comprehensive notes, code examples, and implementations from Harvard's CS50: Introduction to Computer Science course, taught by the legendary David J. Malan.

๐Ÿ’ก Understanding What's Underneath the Hood

As David always emphasizes, CS50 isn't just about learning to codeโ€”it's about understanding what's happening underneath the hood. This course teaches us to think computationally and solve problems methodically, building a strong foundation that transcends any single programming language.

๐ŸŽฏ Course Philosophy

David's Key Mantras:

  • ๐Ÿ” "Understanding underneath the hood" - We don't just use tools; we understand how they work
  • ๐Ÿง  "Computational thinking" - Breaking down complex problems into manageable pieces
  • ๐ŸŽจ "Correctness, Design, Style" - The three pillars of good programming
  • ๐ŸŒŸ "This is less comfortable โ†’ more comfortable" - Growth happens outside your comfort zone
  • ๐ŸŽช "Algorithms in pseudocode" - Think first, code second
  • ๐Ÿ”ข "Off by one errors" - Attention to detail matters
  • ๐Ÿ“Š "Big O notation" - Efficiency and scalability are crucial

๐Ÿ“š Course Structure

Week 0: Scratch - Thinking Algorithmically

  • Binary representation - How computers really "think"
  • Pseudocode - Planning before programming
  • Visual programming with Scratch blocks

Week 1: C - Getting Closer to the Machine

  • Low-level programming - Understanding memory and pointers
  • Functions and scope - Building reusable code
  • Data types - Choosing the right tool for the job

Week 2: Arrays - Data Structures Fundamentals

  • Memory layout - How data is actually stored
  • Strings as arrays - Characters under the hood
  • Command-line arguments - Programs that take input

Week 3: Algorithms - Efficiency Matters

  • Big O notation - Measuring algorithmic efficiency
  • Searching algorithms - Linear vs Binary search
  • Sorting algorithms - Selection, Bubble, and Merge sort
  • Recursion - Functions calling themselves

Week 4: Memory - Manual Memory Management

  • Pointers - Direct memory access
  • Dynamic memory allocation - malloc() and free()
  • Memory leaks - What happens when you forget to clean up

Week 5: Data Structures - Abstract Data Types

  • Linked lists - Dynamic memory allocation
  • Trees and binary search trees - Hierarchical data
  • Hash tables - Fast lookups with O(1) average time
  • Tries - Efficient string storage and retrieval
  • Stacks and queues - LIFO and FIFO data structures

Week 6: Python - Higher-Level Programming

  • Python syntax - From C to Python transition
  • Data structures - Lists, dictionaries, sets, tuples
  • File I/O - Reading/writing files, CSV, JSON
  • Libraries - Importing modules and packages
  • Image processing - PIL for image manipulation
  • Face recognition - Computer vision applications

Week 7: Artificial Intelligence - Machine Learning & AI

  • Generative AI - ChatGPT, image generation, and AI applications
  • Decision trees - Classification algorithms and information gain
  • Minimax algorithm - Game-playing AI with alpha-beta pruning
  • Machine learning - Supervised and unsupervised learning concepts
  • Neural networks - Deep learning and large language models
  • Prompt engineering - Crafting effective AI prompts
  • AI ethics - Hallucinations, bias, and responsible AI use

Week 8: SQL - Databases and Data Management

  • Relational databases - Moving beyond flat files to structured data
  • SQL syntax - CREATE, SELECT, INSERT, UPDATE, DELETE operations
  • Database design - Schema creation, normalization, and relationships
  • Primary and foreign keys - Data integrity and table relationships
  • Joins and complex queries - Combining data from multiple tables
  • Indexes - Performance optimization for large datasets
  • Python integration - Using sqlite3 and database APIs
  • Security - SQL injection prevention and parameterized queries
  • Concurrency - Race conditions and transaction management

Week 9: HTML, CSS, JavaScript - Web Development Fundamentals

  • Web protocols - HTTP, DNS, and how the internet works
  • HTML for structure - Semantic markup, forms, tables, and accessibility
  • CSS for style - Selectors, box model, flexbox, and responsive design
  • JavaScript for behavior - DOM manipulation, events, and client-side interactivity
  • Web APIs - Geolocation, local storage, and other browser capabilities
  • Code Organization - The importance of separating structure, style, and behavior into different files

Week 10: Flask - Web Application Development

  • Web programming basics - HTTP, client-server model, request/response cycle
  • Flask microframework - Routing, views, and application structure
  • HTML forms - Handling user input and validation
  • Templates (Jinja2) - Dynamic content and code reuse
  • Sessions and cookies - Maintaining state across requests
  • SQLite integration - Persistent data storage
  • APIs and JSON - Building and consuming web APIs

๐Ÿ› ๏ธ Technologies & Tools

Languages: C, Python, SQL, HTML, CSS, JavaScript
Tools: VS Code, GitHub, Flask, SQLite, MySQL
Libraries: CS50, PIL, face_recognition, sqlite3, csv, json
Web Technologies: HTML5, CSS3, JavaScript ES6+, Responsive Design, DOM Manipulation
Databases: SQLite, relational database concepts
AI Concepts: Machine Learning, Neural Networks, Decision Trees, Minimax

๐Ÿ“ Repository Structure

CS50/
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 0 - Scratch/
โ”‚   โ””โ”€โ”€ Scratch.txt
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 1 - C/
โ”‚   โ”œโ”€โ”€ C_Programming.txt
โ”‚   โ”œโ”€โ”€ hello.c
โ”‚   โ”œโ”€โ”€ calculator.c
โ”‚   โ”œโ”€โ”€ discount.c
โ”‚   โ”œโ”€โ”€ mario.c
โ”‚   โ”œโ”€โ”€ conditions.c
โ”‚   โ”œโ”€โ”€ loops.c
โ”‚   โ””โ”€โ”€ data_types.c
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 2 - Arrays/
โ”‚   โ”œโ”€โ”€ Arrays.txt
โ”‚   โ”œโ”€โ”€ arrays_basic.c
โ”‚   โ”œโ”€โ”€ strings.c
โ”‚   โ”œโ”€โ”€ caesar.c
โ”‚   โ”œโ”€โ”€ readability.c
โ”‚   โ”œโ”€โ”€ substitution.c
โ”‚   โ”œโ”€โ”€ argv.c
โ”‚   โ””โ”€โ”€ scores.c
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 3 - Algorithms/
โ”‚   โ”œโ”€โ”€ Algorithms.txt
โ”‚   โ”œโ”€โ”€ linear_search.c
โ”‚   โ”œโ”€โ”€ binary_search.c
โ”‚   โ”œโ”€โ”€ selection_sort.c
โ”‚   โ”œโ”€โ”€ bubble_sort.c
โ”‚   โ”œโ”€โ”€ merge_sort.c
โ”‚   โ”œโ”€โ”€ recursion.c
โ”‚   โ””โ”€โ”€ phonebook.c
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 4 - Memory/
โ”‚   โ”œโ”€โ”€ Memory.txt
โ”‚   โ”œโ”€โ”€ addresses.c
โ”‚   โ”œโ”€โ”€ copy.c
โ”‚   โ”œโ”€โ”€ memory.c
โ”‚   โ”œโ”€โ”€ swap.c
โ”‚   โ”œโ”€โ”€ phonebook.c
โ”‚   โ”œโ”€โ”€ files.c
โ”‚   โ”œโ”€โ”€ linked_list.c
โ”‚   โ””โ”€โ”€ buffer_overflow.c
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 5 - Data Structures/
โ”‚   โ”œโ”€โ”€ Data_Structures.txt
โ”‚   โ”œโ”€โ”€ linked_lists.c
โ”‚   โ”œโ”€โ”€ binary_tree.c
โ”‚   โ”œโ”€โ”€ hash_table.c
โ”‚   โ”œโ”€โ”€ trie.c
โ”‚   โ”œโ”€โ”€ stack.c
โ”‚   โ””โ”€โ”€ queue.c
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 6 - Python/
โ”‚   โ”œโ”€โ”€ Python.txt
โ”‚   โ”œโ”€โ”€ hello.py
โ”‚   โ”œโ”€โ”€ calculator.py
โ”‚   โ”œโ”€โ”€ mario.py
โ”‚   โ”œโ”€โ”€ phonebook.py
โ”‚   โ”œโ”€โ”€ dna.py
โ”‚   โ”œโ”€โ”€ cash.py
โ”‚   โ”œโ”€โ”€ readability.py
โ”‚   โ”œโ”€โ”€ data_structures.py
โ”‚   โ”œโ”€โ”€ file_io.py
โ”‚   โ””โ”€โ”€ face_recognition.py
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 7 - Artificial Intelligence/
โ”‚   โ”œโ”€โ”€ Artificial_Intelligence.txt
โ”‚   โ”œโ”€โ”€ decision_tree.py
โ”‚   โ”œโ”€โ”€ minimax_tictactoe.py
โ”‚   โ”œโ”€โ”€ simple_chatbot.py
โ”‚   โ””โ”€โ”€ prompt_engineering.py
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 8 - SQL/
โ”‚   โ”œโ”€โ”€ SQL.txt
โ”‚   โ”œโ”€โ”€ create_database.sql
โ”‚   โ”œโ”€โ”€ queries.sql
โ”‚   โ”œโ”€โ”€ python_sql.py
โ”‚   โ”œโ”€โ”€ race_conditions.py
โ”‚   โ””โ”€โ”€ csv_to_sql.py
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 9 - HTML, CSS, JavaScript/
โ”‚   โ”œโ”€โ”€ Web_Development.txt
โ”‚   โ”œโ”€โ”€ bingo.html
โ”‚   โ”œโ”€โ”€ homepage.html
โ”‚   โ”œโ”€โ”€ form_validation.html
โ”‚   โ”œโ”€โ”€ autocomplete.html
โ”‚   โ”œโ”€โ”€ geolocation.html
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ css/
โ”‚   โ”‚   โ”œโ”€โ”€ bingo.css
โ”‚   โ”‚   โ”œโ”€โ”€ homepage.css
โ”‚   โ”‚   โ”œโ”€โ”€ form_validation.css
โ”‚   โ”‚   โ”œโ”€โ”€ autocomplete.css
โ”‚   โ”‚   โ””โ”€โ”€ geolocation.css
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ js/
โ”‚       โ”œโ”€โ”€ bingo.js
โ”‚       โ”œโ”€โ”€ homepage.js
โ”‚       โ”œโ”€โ”€ form_validation.js
โ”‚       โ”œโ”€โ”€ autocomplete.js
โ”‚       โ””โ”€โ”€ geolocation.js
โ”œโ”€โ”€ ๐Ÿ“‚ Lecture 10 - Flask/
โ”‚   โ”œโ”€โ”€ forms_app/
โ”‚   โ”‚   โ”œโ”€โ”€ app.py
โ”‚   โ”‚   โ””โ”€โ”€ templates/
โ”‚   โ”‚       โ””โ”€โ”€ index.html
โ”‚   โ”œโ”€โ”€ frosh_ims_app/
โ”‚   โ”‚   โ”œโ”€โ”€ app.py
โ”‚   โ”‚   โ””โ”€โ”€ templates/
โ”‚   โ”‚       โ””โ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ shows_app/
โ”‚       โ”œโ”€โ”€ app.py
โ”‚       โ””โ”€โ”€ templates/
โ”‚           โ””โ”€โ”€ index.html
โ””โ”€โ”€ README.md

๐ŸŽ“ Key Learning Outcomes

By the end of CS50, students will:

  • โœ… Think computationally and solve problems methodically

  • โœ… Understand computer science fundamentals that transcend programming languages

  • โœ… Write correct, well-designed, and stylish code

  • โœ… Debug effectively using proper techniques and tools

  • โœ… Implement fundamental algorithms and data structures

  • โœ… Manage memory and understand system-level programming

  • โœ… Build web applications from front-end to back-end

  • forms_app/ โ€” A simple app showing how to handle HTML forms, process user input, and display responses. Great for learning about routing, request methods, and templates.

  • frosh_ims_app/ โ€” A registration system for intramural sports, demonstrating form validation, user feedback, and storing submitted data. This mirrors the classic CS50 โ€œFrosh IMsโ€ example.

  • shows_app/ โ€” An app that queries a SQLite database and displays TV show data using templates. Illustrates database integration and dynamic content rendering.

Each app is self-contained with its own app.py and templates/ folder. To run an app, navigate to its directory and execute:

python app.py

You can then visit the app in your browser at http://127.0.0.1:5000/.

๐Ÿ† Problem Sets & Projects

Each week includes hands-on problem sets that reinforce the concepts:

  • ๐ŸŽฎ Scratch Project - Interactive game or animation
  • ๐Ÿ”ข Mario Pyramids - ASCII art with nested loops
  • ๐Ÿ” Caesar/Substitution Ciphers - Cryptography fundamentals
  • ๐Ÿ“Š Readability - Text analysis algorithms
  • ๐Ÿ—ณ๏ธ Plurality/Runoff - Election simulation systems
  • ๐Ÿ’พ Filter - Image processing and manipulation
  • ๐Ÿ” Speller - Hash tables and spell checking
  • ๐Ÿง  Memory Recovery - Digital forensics and file systems
  • ๐Ÿ“ž Dynamic Phonebook - Memory management and data structures
  • ๐ŸŒณ Family Trees - Binary search trees and genealogy
  • ๐Ÿ“š Dictionary - Trie implementation for fast word lookup
  • ๐Ÿงฌ DNA Analysis - String processing and pattern matching
  • ๐ŸŽญ Face Recognition - Computer vision and image processing
  • ๐Ÿ’ฐ Cash/Credit - Greedy algorithms and validation
  • ๐ŸŽฏ Tic-Tac-Toe AI - Minimax algorithm implementation
  • ๐Ÿค– Chatbot - Natural language processing basics
  • ๐Ÿ—„๏ธ Movies Database - SQL queries and database design
  • ๐Ÿ  Fiftyville Mystery - SQL detective work with complex queries
  • ๐ŸŒ Homepage Portfolio - Building a personal website with HTML, CSS, and JS
  • โœ… Form Validation Demo - Client-side validation using JavaScript and Regex
  • ๐Ÿ“ Geolocation App - Using browser APIs to get user location

๐Ÿ’ป How to Use This Repository

  1. Clone the repository:

    git clone <repository-url>
    cd CS50
  2. Compile C programs:

    clang -o program program.c -lcs50
    ./program
  3. Run Python programs:

    python program.py
  4. Execute SQL scripts:

    sqlite3 database.db < script.sql
  5. Open HTML files:

    # Simply open in your web browser (e.g., double-click the file).
    # All CSS and JS are linked externally for best practice.
  6. Install Python dependencies (for advanced programs):

    pip install cs50 pillow face-recognition sqlite3
  7. Follow along with lectures using the organized notes and code examples

๐ŸŒŸ David's Inspirational Quotes

"The best way to learn to program is to program."

"Programming is not about what you know; it's about what you can figure out."

"Don't be afraid to break things. That's how you learn."

"In programming, there's often more than one way to solve a problem. Focus on correctness first, then optimize."

"AI is a tool to augment human intelligence, not replace human judgment."

"Understanding what's underneath the hood applies to AI too - know how these systems work."

"Databases are just fancy filing cabinets - but the organization makes all the difference."

"SQL injection is like leaving your front door wide open - always sanitize your inputs!"

"The web is just computers talking to each other. HTML provides the nouns, CSS the adjectives, and JavaScript the verbs."

๐Ÿค Contributing

Feel free to:

  • ๐Ÿ“ Suggest improvements to notes
  • ๐Ÿ› Report errors or typos
  • ๐Ÿ’ก Share alternative implementations
  • ๐ŸŽฏ Add more practice problems

๐Ÿ“ž Connect & Collaborate

  • ๐Ÿ’ฌ Discuss CS50 concepts and problems
  • ๐Ÿค” Ask questions about implementations
  • ๐ŸŽฏ Share learning experiences
  • ๐ŸŒŸ Celebrate coding victories!

๐ŸŽช "This is CS50!"

Building tomorrow's problem solvers, one algorithm at a time.

Happy Coding! ๐Ÿš€โœจ


This repository is a tribute to CS50's incredible teaching methodology and David Malan's inspiring approach to computer science education. Understanding what's underneath the hood has never been more engaging!

About

CS50x Harvard's Introduction to Computer Science - Complete lecture notes, code examples, and problem set solutions. Understanding what's underneath the hood! ๐ŸŽ“

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published