1. Home
  2. Explore
  3. Computer Science
  4. Intro to Data Structures

Study methods

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

Intro to Data Structures

  • 49Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Data Structures Overview

What is a data structure?

49 questions

  1. 1

    What is a data structure?

    1. A

      A method for sorting large datasets

    2. B

      A programming language construct for defining variables

    3. C

      A collection of algorithms for data processing

    4. D

      A way to store and organize data in a computer so that it can be used efficiently

    Correct answer
    D

    A way to store and organize data in a computer so that it can be used efficiently

    Explanation

    A data structure is defined as a way to store and organize data in a computer so that the data can be used efficiently.

  2. 2

    What are the two ways to study data structures?

    1. A

      As primitive and non-primitive types

    2. B

      As static and dynamic structures

    3. C

      As mathematical/logical models and as concrete implementations

    4. D

      As linear and non-linear structures

    Correct answer
    C

    As mathematical/logical models and as concrete implementations

    Explanation

    Data structures are studied as mathematical/logical models (abstract data types) and as concrete implementations.

  3. 3

    What is an Abstract Data Type (ADT)?

    1. A

      A data type that cannot be instantiated

    2. B

      A type of variable used in abstract classes

    3. C

      A definition of data and operations without implementation details

    4. D

      A concrete implementation of a data structure in a programming language

    Correct answer
    C

    A definition of data and operations without implementation details

    Explanation

    An ADT defines data and operations but does not provide implementation details.

  4. 4

    Which of the following is an example of an ADT?

    1. A

      A list that stores elements and allows reading and writing by position

    2. B

      A linked list in C++

    3. C

      An array in C

    4. D

      A struct in C

    Correct answer
    A

    A list that stores elements and allows reading and writing by position

    Explanation

    A list defined with operations like read and write by position is an ADT; arrays and linked lists are implementations.

  5. 5

    What is the primary advantage of using an array for a static list?

    1. A

      Constant-time access to any element using an index

    2. B

      Efficient insertion and deletion at any position

    3. C

      Dynamic resizing capability

    4. D

      No memory overhead for pointers

    Correct answer
    A

    Constant-time access to any element using an index

    Explanation

    Arrays provide constant-time access (O(1)O(1)O(1)) to elements via index because they are stored in contiguous memory.

  6. 6

    What is a major limitation of implementing a dynamic list using a fixed-size array?

    1. A

      The array may become full, requiring creation of a larger array and copying elements

    2. B

      Insertion at the end is always O(n)O(n)O(n)

    3. C

      Memory is wasted because each node stores a pointer

    4. D

      Accessing elements takes time proportional to the list size

    Correct answer
    A

    The array may become full, requiring creation of a larger array and copying elements

    Explanation

    When a fixed-size array fills up, a new larger array must be created and elements copied, which is costly.

  7. 7

    When implementing a dynamic array, what is a common strategy for resizing?

    1. A

      Double the size of the array each time it becomes full

    2. B

      Create a new array of the same size and use a different memory location

    3. C

      Increase the size by half the current size

    4. D

      Increase the size by one element each time

    Correct answer
    A

    Double the size of the array each time it becomes full

    Explanation

    Doubling the array size is a common strategy to amortize the cost of copying over many insertions.

  8. 8

    What is the time complexity of accessing an element by index in an array?

    1. A

      O(n)O(n)O(n)

    2. B

      O(log⁡n)O(\log n)O(logn)

    3. C

      O(1)O(1)O(1)

    4. D

      O(n2)O(n^2)O(n2)

    Correct answer
    C

    O(1)O(1)O(1)

    Explanation

    Array access is constant time because the address is calculated from the base address and index.

  9. 9

    What is the time complexity of inserting an element at the beginning of an array-based list (assuming shifting is required)?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(1)O(1)O(1)

    3. C

      O(log⁡n)O(\log n)O(logn)

    4. D

      O(n)O(n)O(n)

    Correct answer
    D

    O(n)O(n)O(n)

    Explanation

    Inserting at the beginning requires shifting all existing elements, resulting in O(n)O(n)O(n) time.

  10. 10

    What is the time complexity of inserting an element at the end of a dynamic array when the array is not full?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(log⁡n)O(\log n)O(logn)

    3. C

      O(n)O(n)O(n)

    4. D

      O(1)O(1)O(1)

    Correct answer
    D

    O(1)O(1)O(1)

    Explanation

    If there is free space, insertion at the end is constant time by writing to the next available index.

  11. 11

    What is a node in a linked list?

    1. A

      A variable that stores the address of the first element

    2. B

      A contiguous block of memory storing multiple elements

    3. C

      A function used to manage memory allocation

    4. D

      A block of memory containing data and a pointer to the next node

    Correct answer
    D

    A block of memory containing data and a pointer to the next node

    Explanation

    A node contains data and a pointer (link) to the next node, forming the linked list.

  12. 12

    What information is always kept about a linked list?

    1. A

      The address of the head (first) node

    2. B

      The number of nodes currently in the list

    3. C

      The address of the tail (last) node

    4. D

      The size of each node in bytes

    Correct answer
    A

    The address of the head (first) node

    Explanation

    The linked list is identified by the address of the head node; from it, all other nodes can be accessed.

  13. 13

    What is the time complexity of accessing an element by position in a linked list?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(log⁡n)O(\log n)O(logn)

    3. C

      O(n)O(n)O(n)

    4. D

      O(1)O(1)O(1)

    Correct answer
    C

    O(n)O(n)O(n)

    Explanation

    Accessing an element requires traversing from the head, taking time proportional to the position (O(n)O(n)O(n)).

  14. 14

    What is the time complexity of inserting a node at the beginning of a linked list?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(1)O(1)O(1)

    3. C

      O(log⁡n)O(\log n)O(logn)

    4. D

      O(n)O(n)O(n)

    Correct answer
    B

    O(1)O(1)O(1)

    Explanation

    Insertion at the beginning involves creating a node and adjusting the head pointer, both constant time.

  15. 15

    What is a major advantage of a linked list over an array?

    1. A

      Nodes are allocated as needed, so no pre-guessing of size is required

    2. B

      Less memory overhead per element

    3. C

      Accessing any element is faster

    4. D

      Insertion and deletion at the end are always constant time

    Correct answer
    A

    Nodes are allocated as needed, so no pre-guessing of size is required

    Explanation

    Linked lists allocate nodes dynamically, avoiding the need to pre-specify size and allowing efficient memory usage.

  16. 16

    What is a disadvantage of a linked list compared to an array?

    1. A

      It cannot be used to implement a stack

    2. B

      Extra memory is used for storing pointers

    3. C

      Insertion and deletion are always slower

    4. D

      It requires contiguous memory allocation

    Correct answer
    B

    Extra memory is used for storing pointers

    Explanation

    Linked lists use extra memory for pointer fields in each node, increasing per-element memory overhead.

  17. 17

    In a doubly linked list, each node contains:

    1. A

      Two pointers: one to the next node and one to the previous node

    2. B

      One pointer to the next node and one integer field

    3. C

      Two data fields and one pointer

    4. D

      One pointer to the previous node and one pointer to the head

    Correct answer
    A

    Two pointers: one to the next node and one to the previous node

    Explanation

    A doubly linked list node has fields for data, a pointer to the next node, and a pointer to the previous node.

  18. 18

    What is the main advantage of a doubly linked list over a singly linked list?

    1. A

      Insertion at the beginning is faster

    2. B

      It allows traversal in both forward and backward directions

    3. C

      It uses less memory per node

    4. D

      It requires only one pointer to manage the list

    Correct answer
    B

    It allows traversal in both forward and backward directions

    Explanation

    Doubly linked lists have previous pointers, enabling reverse traversal and easier deletion of nodes.

  19. 19

    What is a stack?

    1. A

      A list that allows access to any element in constant time

    2. B

      A list where insertion and deletion occur only at one end, called the top

    3. C

      A list where insertion occurs at one end and deletion at the other

    4. D

      A list where elements are stored in a contiguous block of memory

    Correct answer
    B

    A list where insertion and deletion occur only at one end, called the top

    Explanation

    A stack is a collection with the restriction that insertion (push) and deletion (pop) happen only at the top end. It is LIFO.

  20. 20

    What does LIFO stand for?

    1. A

      First In, Last Out

    2. B

      Last In, Last Out

    3. C

      First In, First Out

    4. D

      Last In, First Out

    Correct answer
    D

    Last In, First Out

    Explanation

    LIFO stands for Last In, First Out, which describes the stack behavior.

  21. 21

    What are the two fundamental operations of a stack?

    1. A

      Enqueue and dequeue

    2. B

      Push and pop

    3. C

      Add and remove

    4. D

      Insert and delete

    Correct answer
    B

    Push and pop

    Explanation

    The fundamental stack operations are push (insert) and pop (remove).

  22. 22

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

    1. A

      O(1)O(1)O(1)

    2. B

      O(n2)O(n^2)O(n2)

    3. C

      O(log⁡n)O(\log n)O(logn)

    4. D

      O(n)O(n)O(n)

    Correct answer
    A

    O(1)O(1)O(1)

    Explanation

    Stack operations are constant time because they involve only the top element.

  23. 23

    Which of the following is a common application of stacks?

    1. A

      Undo operation in editors

    2. B

      Print queue management

    3. C

      Organizing hierarchical data

    4. D

      Network routing

    Correct answer
    A

    Undo operation in editors

    Explanation

    Stacks are used to implement undo operations (Ctrl+Z) by storing previous states.

  24. 24

    What is a queue?

    1. A

      A list that allows constant-time access to any element

    2. B

      A list where elements are stored in sorted order

    3. C

      A list where insertion and deletion occur at the same end

    4. D

      A list where insertion occurs at one end (rear) and deletion occurs at the other end (front)

    Correct answer
    D

    A list where insertion occurs at one end (rear) and deletion occurs at the other end (front)

    Explanation

    A queue is a FIFO structure: insertion at rear, deletion at front.

  25. 25

    What does FIFO stand for?

    1. A

      First In, Last Out

    2. B

      Last In, First Out

    3. C

      First In, First Out

    4. D

      Last In, Last Out

    Correct answer
    C

    First In, First Out

    Explanation

    FIFO stands for First In, First Out, the operating principle of a queue.

  26. 26

    What are the two fundamental operations of a queue?

    1. A

      Enqueue and dequeue

    2. B

      Push and pop

    3. C

      Add and remove

    4. D

      Insert and delete

    Correct answer
    A

    Enqueue and dequeue

    Explanation

    Enqueue inserts at the rear, and dequeue removes from the front.

  27. 27

    What is the time complexity of enqueue and dequeue operations in a queue (assuming efficient implementation)?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(n)O(n)O(n)

    3. C

      O(1)O(1)O(1)

    4. D

      O(log⁡n)O(\log n)O(logn)

    Correct answer
    C

    O(1)O(1)O(1)

    Explanation

    With proper implementation (e.g., circular array or linked list with front/rear pointers), both operations are O(1)O(1)O(1).

  28. 28

    In an array-based queue implementation, what problem can arise if we simply increment front and rear without using a circular array?

    1. A

      Wasted space at the beginning of the array as elements are dequeued

    2. B

      Insertion becomes O(n)O(n)O(n)

    3. C

      The queue cannot store more than one element

    4. D

      Deletion becomes impossible

    Correct answer
    A

    Wasted space at the beginning of the array as elements are dequeued

    Explanation

    Without circular array, after dequeuing, the vacated spaces at the front cannot be reused, wasting memory.

  29. 29

    What is a tree?

    1. A

      A collection of elements stored in contiguous memory

    2. B

      A structure where each node can have at most one parent and many children

    3. C

      A linear data structure where each element has a unique successor

    4. D

      A non-linear hierarchical data structure consisting of nodes connected by edges

    Correct answer
    D

    A non-linear hierarchical data structure consisting of nodes connected by edges

    Explanation

    A tree is a non-linear structure that simulates a hierarchy with nodes and edges.

  30. 30

    What is the root of a tree?

    1. A

      The node that is farthest from the leaves

    2. B

      The topmost node with no parent

    3. C

      The node with the most children

    4. D

      The node that has no children

    Correct answer
    B

    The topmost node with no parent

    Explanation

    The root is the node that has no parent; it is the topmost node in the hierarchy.

  31. 31

    What is a leaf node in a tree?

    1. A

      A node with no children

    2. B

      A node with exactly one child

    3. C

      A node that is a child of the root

    4. D

      The node at the bottom of the tree

    Correct answer
    A

    A node with no children

    Explanation

    A leaf node has zero children.

  32. 32

    What is a binary tree?

    1. A

      A tree where each node has at most two children

    2. B

      A tree where the root has two children

    3. C

      A tree where nodes are arranged in ascending order

    4. D

      A tree where each node has exactly two children

    Correct answer
    A

    A tree where each node has at most two children

    Explanation

    A binary tree allows each node to have zero, one, or two children.

  33. 33

    What is a binary search tree (BST)?

    1. A

      A tree used for efficient searching in a sorted list

    2. B

      A binary tree where for each node, all values in the left subtree are less and all values in the right subtree are greater

    3. C

      A binary tree where all nodes have exactly two children

    4. D

      A tree where each node stores a key and a value

    Correct answer
    B

    A binary tree where for each node, all values in the left subtree are less and all values in the right subtree are greater

    Explanation

    BST property: left subtree values < node value < right subtree values.

  34. 34

    In a BST, what is the time complexity of searching for an element in the average case (balanced tree)?

    1. A

      O(log⁡n)O(\log n)O(logn)

    2. B

      O(n2)O(n^2)O(n2)

    3. C

      O(1)O(1)O(1)

    4. D

      O(n)O(n)O(n)

    Correct answer
    A

    O(log⁡n)O(\log n)O(logn)

    Explanation

    In a balanced BST, each comparison discards half the tree, leading to O(log⁡n)O(\log n)O(logn) time.

  35. 35

    What is the worst-case time complexity of searching in a BST?

    1. A

      O(log⁡n)O(\log n)O(logn)

    2. B

      O(n)O(n)O(n)

    3. C

      O(n2)O(n^2)O(n2)

    4. D

      O(1)O(1)O(1)

    Correct answer
    B

    O(n)O(n)O(n)

    Explanation

    If the BST is skewed (like a linked list), searching becomes O(n)O(n)O(n).

  36. 36

    What is the time complexity of in-order traversal of a binary tree?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(n)O(n)O(n)

    3. C

      O(log⁡n)O(\log n)O(logn)

    4. D

      O(1)O(1)O(1)

    Correct answer
    B

    O(n)O(n)O(n)

    Explanation

    In-order traversal visits each node exactly once, so time is O(n)O(n)O(n).

  37. 37

    What property does an in-order traversal of a BST yield?

    1. A

      The elements in reverse sorted order

    2. B

      The elements in the order they were inserted

    3. C

      The elements grouped by depth

    4. D

      The elements in sorted order

    Correct answer
    D

    The elements in sorted order

    Explanation

    In-order traversal of a BST visits nodes in non-decreasing order.

  38. 38

    What is a graph?

    1. A

      A set of nodes connected in a hierarchical manner

    2. B

      A linear arrangement of elements

    3. C

      A collection of nodes with a fixed number of connections

    4. D

      An ordered pair of a set of vertices and a set of edges

    Correct answer
    D

    An ordered pair of a set of vertices and a set of edges

    Explanation

    A graph is formally defined as G=(V,E)G = (V, E)G=(V,E), where VVV is a set of vertices and EEE is a set of edges.

  39. 39

    What is a directed graph (digraph)?

    1. A

      A graph that has no cycles

    2. B

      A graph with weighted edges

    3. C

      A graph where all edges have a direction (ordered pairs)

    4. D

      A graph where edges are undirected

    Correct answer
    C

    A graph where all edges have a direction (ordered pairs)

    Explanation

    In a directed graph, each edge is an ordered pair, indicating a one-way connection.

  40. 40

    What is an undirected graph?

    1. A

      A graph that is not connected

    2. B

      A graph where every vertex has exactly two edges

    3. C

      A graph that contains no cycles

    4. D

      A graph where edges have no direction (unordered pairs)

    Correct answer
    D

    A graph where edges have no direction (unordered pairs)

    Explanation

    In an undirected graph, edges are unordered pairs, representing bidirectional connections.

  41. 41

    What is a weighted graph?

    1. A

      A graph with a large number of edges

    2. B

      A graph where each edge has an associated numerical value (weight)

    3. C

      A graph where vertices have weights

    4. D

      A graph that is used for machine learning

    Correct answer
    B

    A graph where each edge has an associated numerical value (weight)

    Explanation

    In a weighted graph, edges have costs or weights, often used for shortest path problems.

  42. 42

    What is a simple graph?

    1. A

      A graph with only one edge

    2. B

      A graph with exactly two vertices

    3. C

      A graph that is easy to traverse

    4. D

      A graph with no self-loops and no multiple edges between the same pair of vertices

    Correct answer
    D

    A graph with no self-loops and no multiple edges between the same pair of vertices

    Explanation

    A simple graph prohibits self-loops and multi-edges.

  43. 43

    What is a path in a graph?

    1. A

      A sequence of vertices where each adjacent pair is connected by an edge

    2. B

      A set of edges that form a cycle

    3. C

      The shortest route between two vertices

    4. D

      A collection of disconnected edges

    Correct answer
    A

    A sequence of vertices where each adjacent pair is connected by an edge

    Explanation

    A path is a sequence of vertices linked by edges.

  44. 44

    What is a cycle in a graph?

    1. A

      A path that visits all vertices

    2. B

      A set of edges that form a tree

    3. C

      A walk that repeats edges

    4. D

      A closed walk where no vertices (except start/end) are repeated

    Correct answer
    D

    A closed walk where no vertices (except start/end) are repeated

    Explanation

    A cycle is a closed path with no repeated vertices except the first and last.

  45. 45

    What does it mean for a graph to be connected?

    1. A

      The graph has no cycles

    2. B

      The graph is a tree

    3. C

      There is a path between every pair of vertices

    4. D

      All vertices have the same degree

    Correct answer
    C

    There is a path between every pair of vertices

    Explanation

    A connected graph has a path between any two vertices.

  46. 46

    What is an adjacency matrix?

    1. A

      A matrix used to compute shortest paths

    2. B

      A matrix that stores the coordinates of vertices

    3. C

      A V×VV \times VV×V matrix where entry [i][j][i][j][i][j] indicates an edge from vertex iii to vertex jjj

    4. D

      A list of edges stored as pairs

    Correct answer
    C

    A V×VV \times VV×V matrix where entry [i][j][i][j][i][j] indicates an edge from vertex iii to vertex jjj

    Explanation

    An adjacency matrix is a square matrix used to represent which vertices are adjacent.

  47. 47

    What is an adjacency list?

    1. A

      A linked list of all edges in the graph

    2. B

      An array of lists where each list stores the neighbors of a vertex

    3. C

      A list of all vertices with their degrees

    4. D

      A two-dimensional array with fixed size

    Correct answer
    B

    An array of lists where each list stores the neighbors of a vertex

    Explanation

    An adjacency list maintains a list of neighbors for each vertex, typically using linked lists or dynamic arrays.

  48. 48

    For a sparse graph, which representation is more memory efficient?

    1. A

      Edge list

    2. B

      Adjacency matrix

    3. C

      Incidence matrix

    4. D

      Adjacency list

    Correct answer
    D

    Adjacency list

    Explanation

    Adjacency list uses memory proportional to the number of edges, while adjacency matrix uses V2V^2V2 space, which is wasteful for sparse graphs.

  49. 49

    What is the time complexity of finding all neighbors of a given vertex in an adjacency list (assuming average degree is low)?

    1. A

      O(log⁡V)O(\log V)O(logV)

    2. B

      O(degree of vertex)O(\text{degree of vertex})O(degree of vertex)

    3. C

      O(V)O(V)O(V)

    4. D

      O(E)O(E)O(E)

    Correct answer
    B

    O(degree of vertex)O(\text{degree of vertex})O(degree of vertex)

    Explanation

    Iterating over the adjacency list of a vertex takes time proportional to the number of neighbors.

Question 1 of 49
Question 1 of 49

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent