1. Home
  2. Explore
  3. Computer Science
  4. CS50 Data Structures Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

CS50 Data Structures Overview

Speaker 1Speaker 2

CS50 Data Structures Overview

2:54
0:00-2:54
  1. Michael

    Today we're diving into data structures—how we organize data in memory to solve problems efficiently. We'll distinguish between abstract data types, like queues and stacks, and their actual implementations in C.

  2. Hope

    Queues sound familiar from real life—like lines at a store. What makes them special in computing?

  3. Michael

    Queues follow FIFO: first in, first out. Think of people lining up for cookies. The first person in line gets served first. In code, we enqueue to add and dequeue to remove. That fairness is key for many applications.

  4. Hope

    So queues are great for fairness. But what about stacks? I've heard of push and pop.

  5. Michael

    Stacks are LIFO: last in, first out. Imagine stacking plates—you take the top one first. Your email inbox often works like a stack: newest emails on top, so you see them first. Push adds, pop removes.

  6. Hope

    I can see how that's useful for undo operations or function calls. But implementing these with arrays seems limiting—fixed size.

  7. Michael

    Exactly! Arrays are contiguous and have a fixed capacity. If you need more space, you have to copy everything to a larger array, which is O(n) and wasteful. That's where linked lists come in.

  8. Hope

    Linked lists use pointers to connect nodes, so they can grow dynamically. But they use extra memory for those pointers, right?

  9. Michael

    Right. Each node holds data and a pointer to the next node. Inserting at the beginning is constant time—no copying needed. But searching is O(n) because you have to traverse from the start.

  10. Hope

    So there's a trade-off: you save time on insertion but lose on search. Can we get the best of both?

  11. Michael

    That's where binary search trees come in. Each node has two pointers—left and right—keeping everything sorted. If balanced, search becomes O(log n), like binary search on an array. But if you insert in sorted order, it degenerates into a linked list.

  12. Hope

    So balance matters. What about hash tables? I hear they're used for dictionaries.

  13. Michael

    Hash tables combine arrays and linked lists. You use a hash function to map keys to array indices. Ideally, each index has a short linked list, giving near-constant time search. But in the worst case, all keys collide, and it's just a linked list.

  14. Hope

    So it's all about the hash function. A good one spreads keys evenly. But what about tries? I've heard they're even faster.

  15. Michael

    Tries are trees of arrays. Each node is an array of 26 pointers (for letters). Searching for a word takes time proportional to its length—constant time, regardless of how many words are stored. The catch is memory: lots of null pointers waste space.

  16. Hope

    So tries give incredible speed but at a huge memory cost. Real-world systems often choose hash tables as a compromise. Like at Sweetgreen, they hash salads by first letter—mostly O(1), but busy times cause collisions.

  17. Michael

    Exactly. Every data structure has trade-offs between time and space. Understanding these lets you pick the right tool for your problem. That's the power of data structures.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent