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

  • 34Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Abstract Data Types
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is an abstract data type (ADT)?

Tap to flipClick to flipspace

A high-level description of a data structure that offers certain properties and characteristics, with implementation details left to the programmer.

Or swipe the card

34 cards

  1. What is an abstract data type (ADT)?

    A high-level description of a data structure that offers certain properties and characteristics, with implementation details left to the programmer.

  2. What does FIFO stand for and which data structure uses it?

    First In, First Out; used by queues.

  3. What are the two main operations of a queue?

    Enqueue (add to the end) and dequeue (remove from the front).

  4. What does LIFO stand for and which data structure uses it?

    Last In, First Out; used by stacks.

  5. What are the two main operations of a stack?

    Push (add to the top) and pop (remove from the top).

  6. How can a queue be implemented using an array?

    Use an array to store elements and an integer size to track the number of elements. Enqueue adds to the end, dequeue removes from the front.

  7. What is a key limitation of implementing a queue or stack with an array?

    Fixed capacity: if more elements are added than the array size, it overflows.

  8. What is a key property of arrays in memory?

    Arrays store data contiguously in memory.

  9. What happens if you try to add an element to a full array?

    You cannot add it directly; you must allocate a new larger array, copy the old data, and free the old array.

  10. Why is copying an array to a larger one considered inefficient?

    It takes O(n)O(n)O(n) time due to iterating over the array to copy each element.

  11. What is the downside of preallocating a very large array to avoid resizing?

    Wasted memory: you allocate space that may never be used.

  12. What is a linked list?

    A data structure where each element (node) contains data and a pointer to the next node, forming a chain.

  13. What is the C structure definition for a node in a singly linked list?

    c typedef struct node { int number; struct node *next; } node;

  14. How do you prepend a node to a linked list?

    1. Set new node's next to current head.
    2. Update head to point to new node.
  15. What is the time complexity of prepending to a linked list?

    O(1)O(1)O(1) (constant time).

  16. What is the time complexity of appending to a linked list?

    O(n)O(n)O(n) in the worst case, because you must traverse to the end.

  17. What is the time complexity of searching for a value in a linked list?

    O(n)O(n)O(n) (linear time).

  18. Why is binary search not possible on a linked list?

    Because linked list elements are not stored contiguously, so you cannot jump to the middle in constant time.

  19. What is a binary search tree (BST)?

    A tree data structure where each node has at most two children, and for any node, all left subtree values are less and all right subtree values are greater.

  20. What is the typical time complexity for searching in a balanced BST?

    O(log⁡n)O(\log n)O(logn) in the average case.

  21. What is the worst-case time complexity for searching in a BST?

    O(n)O(n)O(n), when the tree becomes skewed (like a linked list).

  22. What is a recursive algorithm to search a BST?

    c bool search(node *tree, int number) { if (tree == NULL) return false; else if (number < tree->number) return search(tree->left, number); else if (number > tree->number) return search(tree->right, number); else return true; }

  23. What is hashing?

    A technique that maps an input of arbitrary size to a fixed-size output (hash value) using a hash function.

  24. What is a hash table?

    A data structure that combines an array with linked lists: an array of buckets, each bucket is a linked list. The hash function determines which bucket a key goes into.

  25. What is a collision in a hash table?

    When two different keys hash to the same bucket (same array index).

  26. How does a simple hash function work for a dictionary of names (first letter only)?

    c unsigned int hash(const char *word) { return toupper(word[0]) - 'A'; }

  27. What is the ideal time complexity for a hash table?

    O(1)O(1)O(1) (constant time) for search, insert, delete.

  28. What is the worst-case time complexity for a hash table?

    O(n)O(n)O(n), when all keys hash to the same bucket, resulting in a single long linked list.

  29. How can you reduce collisions in a hash table?

    Increase the number of buckets (table size) or use a better hash function that distributes keys more uniformly.

  30. What is a trie?

    A tree data structure where each node is an array (typically of size 26 for letters) representing possible next characters. Each path from root to a node spells out a key.

  31. What is the time complexity for searching in a trie?

    O(k)O(k)O(k), where kkk is the length of the key (constant for fixed max length). Hence effectively O(1)O(1)O(1).

  32. What is the main disadvantage of a trie?

    High memory usage: each node contains an array of pointers, many of which may be NULL.

  33. How does a trie handle keys that share a common prefix?

    They share the same path until the diverging character, and then separate nodes are created.

  34. What is the C structure for a node in a trie (for 26 letters)?

    c typedef struct node { struct node *children[26]; char *number; // or other value } node;

Card 1 of 34
Card 1 of 34

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent