3 Lecture
CS301
Midterm & Final Term Short Notes
Linked List inside Computer Memory
A linked list is a data structure where each element, called a node, contains a value and a reference to the next node in the list. In computer memory, each node is typically represented as a block of memory that contains the value and a pointer
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
In a linked list, each node contains: a. A value and a pointer to the previous node b. A value and a pointer to the next node c. A key and a value d. A key and a pointer to the next node Answer: b
The first node in a linked list is called the: a. Head b. Tail c. Root d. Leaf Answer: a
In computer memory, each node in a linked list is typically represented as: a. A block of memory that contains the value and a pointer to the previous node b. A block of memory that contains the value and a pointer to the next node c. A hash table that contains the key and the value d. An array that contains the key and a pointer to the next node Answer: b
What is the time complexity of inserting a node at the beginning of a linked list? a. O(1) b. O(n) c. O(log n) d. O(n log n) Answer: a
What is the time complexity of inserting a node at the end of a linked list? a. O(1) b. O(n) c. O(log n) d. O(n log n) Answer: b
Deleting a node from a linked list requires updating the: a. Previous node's pointer to the next node b. Next node's pointer to the previous node c. Current node's value to NULL d. None of the above Answer: a
Traversing a linked list means: a. Deleting a node from the list b. Inserting a node into the list c. Moving through the list from the head to the tail d. Sorting the list in ascending order Answer: c
Which of the following is a disadvantage of linked lists compared to arrays? a. Linked lists allow for efficient insertion and deletion of nodes b. Linked lists use memory flexibly c. Linked lists can grow dynamically d. Linked lists have slow access times for specific nodes Answer: d
Which of the following operations can be performed in constant time on a linked list? a. Finding the maximum value in the list b. Inserting a node at the end of the list c. Removing the head node from the list d. Sorting the list in descending order Answer: c
What is the space complexity of a linked list? a. O(n) b. O(log n) c. O(1) d. O(n log n) Answer: a
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a linked list and how is it different from an array? Answer: A linked list is a data structure where each element (node) contains a value and a reference to the next node. The first node in the list is called the head, and each subsequent node is linked to the previous node. In contrast, an array stores a fixed number of elements of the same type in contiguous memory locations.
How are nodes in a linked list allocated in memory? Answer: Each node in a linked list is typically represented as a block of memory that contains the value and a pointer to the next node. The head node is stored in a variable, and each subsequent node is allocated dynamically as needed.
What is the time complexity of inserting a node at the beginning of a linked list? Answer: The time complexity of inserting a node at the beginning of a linked list is O(1), as it involves updating the head node pointer to point to the new node.
How do you traverse a linked list? Answer: To traverse a linked list, start at the head node and follow the next node pointers until the end of the list is reached.
What is the difference between a singly linked list and a doubly linked list? Answer: In a singly linked list, each node contains a reference to the next node, while in a doubly linked list, each node contains references to both the next and previous nodes.
What is the time complexity of inserting a node at the end of a linked list? Answer: The time complexity of inserting a node at the end of a linked list is O(n), as it involves traversing the list to find the last node and updating its next node pointer to point to the new node.
How do you delete a node from a linked list? Answer: To delete a node from a linked list, update the previous node's next node pointer to point to the next node, effectively removing the node from the list.
What is a circular linked list? Answer: A circular linked list is a linked list where the last node's next node pointer points to the head node, creating a circular structure.
What is a sentinel node in a linked list? Answer: A sentinel node is a special node added to the beginning or end of a linked list that acts as a marker to indicate the start or end of the list.
What is the space complexity of a linked list? Answer: The space complexity of a linked list is O(n), where n is the number of nodes in the list. This is because each node requires its own block of memory.