1. Home
  2. Explore
  3. Computer Science
  4. Data Structures Introduction

Study methods

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

Data Structures Introduction

  • 54Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Data Structures Fundamentals

What is a data structure in computer science?

54 questions

  1. 1

    What is a data structure in computer science?

    Model answer

    A data structure is a way to store, organize, and manage data so that it can be accessed or modified efficiently.

    Explanation

    Data structures are fundamental for organizing data in programs, enabling efficient operations.

  2. 2

    What are the four common criteria used to measure the efficiency of a data structure with Big O notation?

    Model answer

    Access, search, insert, and delete.

    Explanation

    These four operations represent the most common functions performed on data structures.

  3. 3

    Why is the worst-case scenario used when evaluating Big O time complexity?

    Model answer

    To prepare for the worst conditions and ensure the data structure performs acceptably in the most demanding situation.

    Explanation

    Worst-case analysis gives an upper bound on time, helping guarantee performance.

  4. 4

    Explain the meaning of O(1) time complexity.

    Model answer

    O(1) means the operation takes constant time, regardless of the data set size; it completes in a single step.

    Explanation

    For example, accessing an array element by index is O(1) because the location is computed directly.

  5. 5

    What does O(log n) time complexity imply about the efficiency relative to data size?

    Model answer

    As data size increases, the number of operations grows logarithmically, so larger data sets give more efficiency per element.

    Explanation

    Logarithmic time, such as binary search, means the number of operations increases slowly even for huge data.

  6. 6

    List the six common Big O time complexity equations from most efficient to least efficient.

    Model answer

    O(1), O(log n), O(n), O(n log n), O(n^2), O(2^n).

    Explanation

    These cover the range from constant to exponential, with O(1) being the best and O(2^n) the worst among those covered.

  7. 7

    What are the three attributes of an array?

    Model answer

    Name, type, and size.

    Explanation

    The name identifies the array, the type specifies the data type of elements, and the size is the fixed capacity.

  8. 8

    Why can the size of an array not be changed after creation?

    Model answer

    Because array elements are stored contiguously in memory; changing size would break this contiguous storage and prevent O(1) access.

    Explanation

    Contiguous storage allows direct computation of element addresses, enabling instant access.

  9. 9

    What is the starting index of an array?

    Model answer

    0

    Explanation

    Indexing begins at zero, so the first element is at index 0.

  10. 10

    What are parallel arrays?

    Model answer

    Two or more arrays with the same number of elements where elements at the same index are related.

    Explanation

    Parallel arrays allow storing different types of data about the same entity, since arrays can only hold one type.

  11. 11

    What is the time complexity for accessing an element in an array?

    Model answer

    O(1)

    Explanation

    Accessing by index is constant time because the memory location is computed directly from the base address and index.

  12. 12

    What are the time complexities for searching, inserting, and deleting in an array?

    Model answer

    All are O(n) in the worst case.

    Explanation

    Search may require scanning all n elements; insert/delete require shifting elements, up to n operations.

  13. 13

    How does an ArrayList differ from an array in terms of size?

    Model answer

    An ArrayList has a dynamic size that can expand as needed, while an array has a fixed size.

    Explanation

    ArrayList automatically grows when elements are added, providing flexibility.

  14. 14

    What is auto-boxing in the context of ArrayLists?

    Model answer

    Auto-boxing is the automatic conversion of a primitive type to its corresponding object wrapper class when adding to an ArrayList that stores objects.

    Explanation

    For example, an int is automatically converted to an Integer object so it can be added to an ArrayList.

  15. 15

    List two differences between an array and an ArrayList regarding memory and built-in methods.

    Model answer

    Arrays are built into most languages and require less memory; ArrayLists are classes that come with pre-built methods but use more memory and space.

    Explanation

    Arrays are primitive and efficient, while ArrayLists offer convenience at a cost.

  16. 16

    What is the time complexity for accessing an element in an ArrayList?

    Model answer

    O(1)

    Explanation

    ArrayList is backed by an array of references, so accessing via index is constant time.

  17. 17

    Why is the time complexity for inserting at the beginning of an ArrayList O(n)?

    Model answer

    Because all elements after the insertion point must be shifted to the right, which requires up to n operations.

    Explanation

    The underlying array of references must be adjusted, leading to linear time.

  18. 18

    What does the LIFO principle mean in the context of a stack?

    Model answer

    Last In, First Out: the last element added to the stack is the first one to be removed.

    Explanation

    Elements are added (pushed) and removed (popped) from the top.

  19. 19

    Name the four methods commonly associated with a stack discussed in the content.

    Model answer

    Push, pop, peek, and contains.

    Explanation

    Push adds to top, pop removes from top, peek returns top without removing, contains checks existence.

  20. 20

    What is the time complexity of push and pop operations on a stack?

    Model answer

    O(1)

    Explanation

    Both operate on the top of the stack, requiring only a single operation regardless of size.

  21. 21

    Give two real-world applications of stacks mentioned in the content.

    Model answer

    Undo/redo functionality in word processors and the back button in web browsers.

    Explanation

    Both use stacks to keep track of recent actions or pages.

  22. 22

    Explain the FIFO principle in queues.

    Model answer

    First In, First Out: the first element added to the queue is the first one to be removed.

    Explanation

    Elements are added at the tail and removed from the head.

  23. 23

    What are the two primary methods for adding and removing elements in a queue?

    Model answer

    Enqueue (add to tail) and dequeue (remove from head).

    Explanation

    Enqueue adds at the back, dequeue removes from the front.

  24. 24

    What is the time complexity of enqueue and dequeue operations?

    Model answer

    O(1)

    Explanation

    Both operate at one end (head or tail) and require constant time.

  25. 25

    Provide an example of queue usage in real-world computing mentioned in the content.

    Model answer

    Job scheduling by the computer's operating system.

    Explanation

    Queues manage tasks in order, like printing jobs or process scheduling.

  26. 26

    What are the two parts of a node in a linked list?

    Model answer

    Data and a pointer (reference) to the next node.

    Explanation

    The data stores the value, and the pointer links to the next node in the sequence.

  27. 27

    What does the tail node of a linked list point to?

    Model answer

    Null (or a null value) to indicate the end of the list.

    Explanation

    The last node has no next node, so its pointer is null.

  28. 28

    Describe the steps to insert a new node at the head of a linked list.

    Model answer

    Set the new node's pointer to point to the current head, then the new node becomes the head.

    Explanation

    This is a simple operation that does not require shifting other elements.

  29. 29

    What is the time complexity for accessing an element in a linked list?

    Model answer

    O(n)

    Explanation

    Access requires traversing from the head through each node until the desired position is reached.

  30. 30

    How does a doubly linked list differ from a singly linked list?

    Model answer

    Each node in a doubly linked list has two pointers: one to the next node and one to the previous node.

    Explanation

    This allows traversal in both directions, forward and backward.

  31. 31

    What is the first step in removing a node from the middle of a doubly linked list?

    Model answer

    Set the next pointer of the node before the one to be removed to point to the node after it.

    Explanation

    This removes the target node from the chain by bypassing it.

  32. 32

    Name one application of a doubly linked list from the content.

    Model answer

    Browser caches that allow going back and forth between webpages.

    Explanation

    The ability to traverse both ways makes it suitable for undo/redo and navigation.

  33. 33

    What is a key-value pair in a dictionary?

    Model answer

    A pair consisting of a unique key and its associated value.

    Explanation

    The key is used to retrieve or modify the value, similar to a social security number linked to a person.

  34. 34

    What two restrictions apply to keys in a dictionary?

    Model answer

    Each key must be unique (no duplicates) and can only map to one value.

    Explanation

    Keys act like identifiers; duplicates would cause ambiguity.

  35. 35

    What is a hash collision and how can it be resolved?

    Model answer

    A hash collision occurs when two different keys hash to the same index; it can be resolved by open addressing (find next empty slot) or closed addressing (chain with linked list).

    Explanation

    Collisions are inevitable with hash tables; these methods ensure all keys can be stored.

  36. 36

    What is the average time complexity for dictionary operations using a good hash function?

    Model answer

    O(1)

    Explanation

    A good hash function distributes keys evenly, allowing constant-time access on average.

  37. 37

    Define the term 'root node' in a tree data structure.

    Model answer

    The topmost node of a tree, from which all other nodes descend.

    Explanation

    Every tree has exactly one root node.

  38. 38

    What is a leaf node in a tree?

    Model answer

    A node that has no children.

    Explanation

    Leaf nodes are the endpoints of the tree structure.

  39. 39

    How is the height of a tree defined?

    Model answer

    The number of edges on the longest path from the root to a leaf.

    Explanation

    Height measures the depth of the tree from top to bottom.

  40. 40

    What is the depth of a node in a tree?

    Model answer

    The number of edges from the root to that node.

    Explanation

    Root has depth 0, its children depth 1, and so on.

  41. 41

    What three restrictions define a binary search tree?

    Model answer

    Each node has at most two children; left child <= parent, right child >= parent; no duplicate values.

    Explanation

    These rules enable efficient searching by comparing values.

  42. 42

    What is the time complexity for searching in a balanced binary search tree?

    Model answer

    O(log n)

    Explanation

    Each comparison narrows the search to half the remaining tree, leading to logarithmic time.

  43. 43

    What type of data do trie nodes store?

    Model answer

    Characters (letters of an alphabet).

    Explanation

    Tries store strings by breaking them into characters along paths.

  44. 44

    How are word endings marked in a trie?

    Model answer

    By flagging nodes (e.g., with a special marker) to indicate the end of a word.

    Explanation

    Flags allow distinguishing between a complete word and a prefix of another word.

  45. 45

    Name one common application of tries mentioned in the content.

    Model answer

    Autocomplete or spellcheck features.

    Explanation

    Tries enable fast retrieval of words by prefix matching.

  46. 46

    In a min-heap, where is the smallest element located?

    Model answer

    At the root node.

    Explanation

    In a min-heap, the root is the minimum value, and each parent is less than or equal to its children.

  47. 47

    Describe the heapify process after deleting the root in a heap.

    Model answer

    Replace the root with the last leaf, then repeatedly swap the new root with its greater child (max-heap) or smaller child (min-heap) until heap property is restored.

    Explanation

    Heapify ensures the tree maintains the heap property after removal.

  48. 48

    What is the primary use of heaps in sorting?

    Model answer

    Heapsort algorithm.

    Explanation

    Heapsort builds a heap and repeatedly extracts the root to produce a sorted list.

  49. 49

    What are the two main components of a graph?

    Model answer

    Nodes (vertices) and edges.

    Explanation

    Nodes represent entities, edges represent connections between them.

  50. 50

    How is a graph represented notationally?

    Model answer

    By a set of vertices and a set of edges, where edges are ordered pairs of vertices.

    Explanation

    For example, V = {1,2,3} and E = {(1,2), (2,3)} describe a graph.

  51. 51

    What is an undirected graph?

    Model answer

    A graph where edges have no direction; traversal can go both ways between nodes.

    Explanation

    Like a Facebook friendship, the relationship is mutual.

  52. 52

    What does it mean for a graph to be acyclic?

    Model answer

    There is no path from any node back to itself (no cycles).

    Explanation

    Acyclic graphs are tree-like and often used in scheduling.

  53. 53

    What is a weighted graph?

    Model answer

    A graph where each edge has a numerical value (weight), representing cost, distance, etc.

    Explanation

    Weights quantify the cost of traversing an edge, used in shortest path algorithms.

  54. 54

    Name one algorithm that uses weighted graphs and its application.

    Model answer

    Dijkstra's shortest path algorithm, used in Google Maps for navigation.

    Explanation

    Dijkstra calculates the minimum cost path from a source to all nodes.

1 of 54
Question 1 of 54

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent