Self-assessment quiz
Presentation & objectives
The following quizzes are here to help you check that you understood the articles you had to study. At the end of a quiz, you will be given explanations on your answers. If some of them are wrong, you will have the possibility to click on the question you failed to try again.
These quizzes are provided for self-assessment and will not be graded or stored.
Don’t hesitate to reach out on the Discord server for any precision/explanation!
Quizzes
What is a data structure?
# What is a data structure?
- [x] A way of organizing data to make it easier to process
> ✅ A data structure organizes data to make it more manageable and easier to process.
- [ ] A built-in data type
> ❌ A data structure is not necessarily a built-in data type; it can be user-defined.
- [x] A concrete implementation of an abstract data type
> ✅ Data structures provide concrete implementations of abstract data types (ADT).
- [ ] A function that manipulates data
> ❌ A function manipulates data, but it is not a data structure.
- [x] A way to store and retrieve data efficiently
> ✅ Data structures are designed to store and retrieve data efficiently.
# What is an abstract data type (ADT)?
- [x] A data structure that defines operations independently of implementation
> ✅ An ADT defines operations independently of how the data is represented or implemented.
- [ ] A built-in type like `int` or `float`
> ❌ Built-in types are not considered abstract data types.
- [ ] A type of data structure specific to Python
> ❌ ADTs are not language-specific and are a general concept in computer science.
- [x] A data structure that abstracts away the details of implementation
> ✅ ADTs abstract away the underlying implementation details, focusing on the operations that can be performed.
- [ ] A data structure that is always implemented using arrays
> ❌ ADTs can be implemented using a variety of structures, not just arrays.
# Which of the following are examples of abstract data types?
- [x] Linked list
> ✅ A linked list is an abstract data type that can be implemented in various ways.
- [x] Stack
> ✅ A stack is an ADT with Last In First Out (LIFO) behavior.
- [x] Queue
> ✅ A queue is an ADT that operates on a First In First Out (FIFO) basis.
- [ ] Integer
> ❌ An integer is a built-in data type, not an abstract data type.
- [x] Graph
> ✅ A graph is an ADT used to represent relationships between objects.
# What is a tree in data structures?
- [x] A non-linear and hierarchical structure
> ✅ Trees are hierarchical, meaning they have a parent-child relationship between elements.
- [ ] A structure where each element points to exactly two other elements
> ❌ This describes a binary tree, but not all trees follow this structure.
- [x] A structure that has a root node and sub-nodes
> ✅ In a tree, the top element is called the root node, with sub-nodes branching off from it.
- [ ] A structure where all nodes are connected in a cycle
> ❌ Trees are acyclic structures, meaning they do not contain cycles.
- [x] A structure used to perform operations like search and traversal
> ✅ Trees are commonly used for searching and traversal operations like Depth-First and Breadth-First Search.
# What is a graph in data structures?
- [x] A non-linear structure consisting of vertices and edges
> ✅ Graphs are made up of vertices (nodes) connected by edges.
- [x] A structure used to model relationships between objects
> ✅ Graphs are useful for modeling relationships between interconnected objects.
- [ ] A linear structure like a list
> ❌ Graphs are non-linear, unlike lists.
- [x] A structure that can have cycles
> ✅ Unlike trees, graphs can have cycles.
- [ ] A structure where every node is connected to every other node
> ❌ This describes a complete graph, which is a specific type of graph, not a general characteristic.
Built-in data structures
# What is a list in Python?
- [x] A data structure that stores multiple ordered values
> ✅ Lists are ordered collections, meaning the position of elements matters and is based on their index.
- [ ] A data structure that only allows unique values
> ❌ Lists allow duplicate values, unlike sets which only allow unique values.
- [x] A dynamic data structure where elements can be added or removed
> ✅ Lists are dynamic and support adding or removing elements after creation.
- [x] A mutable data structure
> ✅ Lists are mutable, meaning their contents can be changed after they are created.
- [ ] A data structure where elements are accessed using keys
> ❌ Lists are indexed by position, not by keys. This behavior is specific to dictionaries.
# What is a set in Python?
- [x] A data structure that stores unique values
> ✅ Sets only store unique elements, and duplicate entries are not allowed.
- [ ] A data structure where values are indexed by position
> ❌ Sets are unordered, so they do not support indexing by position.
- [x] A mutable data structure
> ✅ Sets in Python are mutable, allowing values to be added or removed.
- [x] A data structure that does not allow duplicates
> ✅ One of the key properties of sets is that they cannot contain duplicate elements.
- [ ] A data structure that supports slicing like lists
> ❌ Sets are unordered and do not support slicing operations like lists.
# What are the properties of a tuple in Python?
- [x] A tuple stores multiple values in an ordered sequence
> ✅ Tuples maintain the order of elements just like lists, but they are immutable.
- [ ] A tuple allows for changing its values
> ❌ Tuples are immutable, meaning that their values cannot be changed after they are created.
- [x] A tuple allows duplicate values
> ✅ Tuples can store duplicate values, unlike sets which require elements to be unique.
- [x] A tuple is a sequence data type
> ✅ Tuples are sequence types, meaning they are indexed by positions starting from zero.
- [ ] A tuple can be dynamically resized
> ❌ Tuples are of fixed size and cannot be dynamically resized after creation.
# What is a dictionary in Python?
- [x] A data structure that stores key-value pairs
> ✅ Dictionaries store data in key-value pairs, allowing for efficient lookups based on keys.
- [x] A mutable data structure
> ✅ Dictionaries are mutable, meaning you can add, modify, or remove key-value pairs.
- [ ] A data structure that allows duplicate keys
> ❌ Dictionaries do not allow duplicate keys; each key must be unique.
- [x] A data structure that dynamically grows as key-value pairs are added
> ✅ Dictionaries are dynamic and can grow as new key-value pairs are added.
- [ ] A data structure where values are accessed by their position
> ❌ Values in a dictionary are accessed using keys, not by their position.
# Which of the following are mutable data structures in Python?
- [x] List
> ✅ Lists are mutable, meaning their elements can be changed.
- [x] Set
> ✅ Sets are mutable, allowing the addition and removal of elements.
- [x] Dictionary
> ✅ Dictionaries are mutable, allowing key-value pairs to be added or changed.
- [ ] Tuple
> ❌ Tuples are immutable, meaning they cannot be modified after creation.
- [ ] String
> ❌ Strings are immutable in Python and cannot be altered after they are created.
Linked lists
# What is a doubly-linked list?
- [x] A data structure where each element is linked to its preceding and succeeding elements
> ✅ In a doubly-linked list, each element contains links to both the previous and next elements in the sequence.
- [ ] A data structure where elements are only linked to the succeeding element
> ❌ This describes a singly-linked list, not a doubly-linked list.
- [x] A structure that maintains pointers to both the head and tail
> ✅ Doubly-linked lists maintain pointers to both the first (head) and last (tail) elements for efficient navigation.
- [ ] A structure that stores elements in a continuous block of memory
> ❌ Linked lists store elements non-contiguously, with links connecting them.
- [x] A data structure used to navigate forwards and backwards through the list
> ✅ The links between elements in a doubly-linked list allow for forward and backward navigation.
# What operations are supported by a doubly-linked list?
- [x] Insertion at the beginning
> ✅ You can insert elements at the beginning of a doubly-linked list.
- [x] Insertion at the end
> ✅ Elements can also be inserted at the end of a doubly-linked list.
- [x] Removing the head element
> ✅ The head element can be removed from a doubly-linked list.
- [x] Removing the tail element
> ✅ You can remove the tail element from a doubly-linked list.
- [ ] Direct access to an element by index
> ❌ Linked lists do not support direct access by index; they require traversal to access elements.
# What are the key components of a node in a doubly-linked list?
- [x] Data
> ✅ Each node stores data along with its links to other nodes.
- [x] Link to the next node
> ✅ Each node has a link to the next node in the sequence.
- [x] Link to the previous node
> ✅ Each node has a link to the previous node, enabling backward navigation.
- [ ] Link to the tail
> ❌ Each node does not link directly to the tail; only the head and tail nodes maintain such links.
- [ ] Key-value pair storage
> ❌ Linked list nodes do not inherently store key-value pairs like dictionaries do.
# What is the advantage of a doubly-linked list over a singly-linked list?
- [x] Ability to traverse the list in both directions
> ✅ Doubly-linked lists allow traversal in both forward and backward directions, unlike singly-linked lists.
- [ ] Simpler to implement
> ❌ Doubly-linked lists are more complex to implement due to the additional links to maintain.
- [x] Efficient removal of elements from both ends
> ✅ With pointers to both the head and tail, removing elements from either end is efficient in doubly-linked lists.
- [ ] Less memory usage
> ❌ Doubly-linked lists require more memory than singly-linked lists due to the extra link for the previous node.
- [x] Improved performance for certain navigation operations
> ✅ The ability to move in both directions improves performance in cases where backward traversal is needed.
# What happens when you insert an element at the beginning of a doubly-linked list?
- [x] The new element becomes the head of the list
> ✅ When an element is inserted at the beginning, it becomes the new head of the list.
- [x] The previous head element's `prev` pointer is updated
> ✅ The previous head element’s `prev` pointer is updated to link to the new head.
- [ ] The tail element is replaced
> ❌ The tail element is not replaced when inserting at the beginning.
- [ ] The list is traversed to find the correct position
> ❌ No traversal is needed when inserting at the beginning; the insertion is immediate.
- [x] The list's `head` pointer is updated
> ✅ The list's `head` pointer is updated to point to the newly inserted element.
Stacks
# What is a stack in computer science?
- [x] A data structure where elements are added and removed from the top
> ✅ Stacks follow the Last In, First Out (LIFO) principle, where elements are added and removed from the same end, the top.
- [ ] A data structure where elements are added to the front and removed from the back
> ❌ This describes a queue, not a stack. Stacks only allow access to the top element.
- [x] A LIFO (Last In, First Out) structure
> ✅ Stacks operate based on the LIFO principle, where the most recent item added is the first one removed.
- [ ] A FIFO (First In, First Out) structure
> ❌ FIFO describes a queue, not a stack. In a stack, the last element added is the first to be removed.
- [x] A structure used for managing function calls in programming
> ✅ Stacks are commonly used to manage function calls and recursive processes in programming.
# What are the main operations performed on a stack?
- [x] Push
> ✅ Push adds an element to the top of the stack.
- [x] Pop
> ✅ Pop removes the top element from the stack.
- [ ] Peek
> ❌ Peek is not a core operation in all stacks, though it can be used in some implementations to view the top element without removing it.
- [x] Initialize
> ✅ Initializing creates an empty stack, ready to hold elements.
- [x] is_empty
> ✅ The `is_empty` function checks if the stack contains any elements.
# In which scenarios is a stack particularly useful?
- [x] Managing function calls in recursive algorithms
> ✅ Stacks are often used to manage function calls in recursive processes, storing return addresses and local variables.
- [ ] Processing data in a FIFO order
> ❌ Stacks use a LIFO order, not FIFO. FIFO is for queues.
- [x] Evaluating arithmetic expressions in postfix notation
> ✅ Stacks are used to evaluate arithmetic expressions in postfix notation, where operators follow operands.
- [x] Backtracking algorithms
> ✅ Stacks are ideal for backtracking algorithms, such as depth-first search, as they allow retracing steps when needed.
- [ ] Searching for elements in a sorted list
> ❌ Stacks are not typically used for searching elements in a sorted list; other data structures are more efficient for this task.
# What is the function of the `push` operation in a stack?
- [x] It adds an element to the top of the stack
> ✅ The push operation adds an element to the top of the stack, following the LIFO principle.
- [ ] It removes an element from the bottom of the stack
> ❌ Push adds elements to the top, not the bottom of the stack.
- [ ] It initializes the stack
> ❌ Push does not initialize the stack; it only adds elements to an already initialized stack.
- [x] It increases the stack's size
> ✅ Each push operation increases the size of the stack by adding a new element.
- [ ] It removes the last element added
> ❌ Push adds elements to the stack; pop removes them.
# What is the `pop` operation in a stack?
- [x] It removes the top element from the stack
> ✅ Pop removes and returns the topmost element in the stack.
- [ ] It adds an element to the bottom of the stack
> ❌ Pop does not add elements; it only removes the top element.
- [x] It decreases the size of the stack by one
> ✅ Each pop operation reduces the stack's size by one element.
- [ ] It retrieves an element from the middle of the stack
> ❌ Pop only works on the top element of the stack, not elements in the middle.
- [x] It is part of the LIFO structure
> ✅ Pop follows the LIFO principle, where the last element added is the first one removed.
Queues
# What is a queue in computer science?
- [x] A data structure where the first element added is the first to be removed
> ✅ Queues follow the First In, First Out (FIFO) principle, meaning elements are removed in the order they were added.
- [ ] A data structure where the last element added is the first to be removed
> ❌ This describes a stack, not a queue. Queues follow FIFO, not LIFO.
- [x] A structure used in situations where order matters, such as managing a line of people
> ✅ Queues are often used in real-world situations like processing a line of people, where the first to arrive is the first to be served.
- [ ] A data structure where elements can be added or removed from both ends
> ❌ A deque allows adding and removing from both ends, not a standard queue.
- [x] A FIFO (First In, First Out) data structure
> ✅ Queues follow FIFO, where the first element added is the first to be removed.
# What are the main operations performed on a queue?
- [x] Enqueue
> ✅ Enqueue adds an element to the end of the queue.
- [x] Dequeue
> ✅ Dequeue removes the first element from the queue.
- [ ] Peek
> ❌ Peek is not a core operation in queues, though some implementations may allow peeking at the first element without removing it.
- [x] Initialize
> ✅ Initialization sets up an empty queue to hold elements.
- [x] is_empty
> ✅ The `is_empty` operation checks whether the queue contains any elements.
# In which scenarios is a queue particularly useful?
- [x] Managing the order of tasks in a print queue
> ✅ Queues are used in print queues to manage tasks in the order they were added, ensuring that the first task submitted is the first one processed.
- [ ] Processing data in a LIFO order
> ❌ Queues use a FIFO order, not LIFO. LIFO is used for stacks.
- [x] Handling processes in operating system scheduling
> ✅ Queues are used in operating systems to manage process scheduling, ensuring that processes are handled in the order they arrive.
- [ ] Evaluating arithmetic expressions in postfix notation
> ❌ Stacks, not queues, are typically used for evaluating postfix expressions.
- [x] Managing a line of customers at a service counter
> ✅ Queues are ideal for managing lines, where the first person in line is the first to be served.
# What are the characteristics of a FIFO data structure?
- [x] The first element added is the first one removed
> ✅ In a FIFO structure, the first element added is the first one to be removed.
- [ ] The last element added is the first one removed
> ❌ This describes LIFO (Last In, First Out), not FIFO.
- [x] The queue is emptied in the same order as elements were added
> ✅ In a queue, elements are removed in the same order they were added, following FIFO.
- [ ] Elements are added and removed from both ends
> ❌ Queues only allow elements to be added at the end and removed from the front. A deque allows operations at both ends.
- [x] It is useful for managing tasks that must be processed in order
> ✅ FIFO structures like queues are useful for processing tasks in the order they arrive.
# What is the function of the `enqueue` operation in a queue?
- [x] It adds an element to the end of the queue
> ✅ The enqueue operation adds an element to the end of the queue, following the FIFO principle.
- [ ] It removes an element from the front of the queue
> ❌ Enqueue adds elements to the queue; dequeue removes them.
- [ ] It initializes the queue
> ❌ Enqueue does not initialize the queue; it only adds elements to an already initialized queue.
- [x] It increases the queue's size
> ✅ Each enqueue operation increases the size of the queue by adding a new element.
- [ ] It removes the last element added
> ❌ Enqueue adds elements to the queue; dequeue removes the first element added.