4 Lecture

CS301

Midterm & Final Term Short Notes

Methods of Linked List

Linked List is a data structure that stores a sequence of elements in memory. There are several methods to manipulate Linked List, including insertion, deletion, traversal, and searching. These methods involve pointers that point to the next or


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the time complexity of inserting an element at the beginning of a singly linked list? a) O(n) b) O(log n) c) O(1) d) O(n^2) Answer: c) O(1)

  2. Which of the following is not a type of Linked List? a) Singly Linked List b) Doubly Linked List c) Circular Linked List d) Binary Linked List Answer: d) Binary Linked List

  3. What is the time complexity of inserting an element at the end of a singly linked list? a) O(n) b) O(log n) c) O(1) d) O(n^2) Answer: a) O(n)

  4. Which of the following is not a pointer used in Linked List? a) head pointer b) tail pointer c) node pointer d) root pointer Answer: d) root pointer

  5. What is the time complexity of deleting an element from a singly linked list? a) O(n) b) O(log n) c) O(1) d) O(n^2) Answer: a) O(n)

  6. Which of the following Linked List traversal technique involves recursion? a) Linear traversal b) Binary traversal c) Depth First Traversal d) Breadth First Traversal Answer: c) Depth First Traversal

  7. Which of the following is a disadvantage of using a doubly linked list? a) Faster traversal in both directions b) Requires more memory than singly linked list c) More difficult to implement than singly linked list d) Allows insertion and deletion of elements only at the beginning of the list Answer: b) Requires more memory than singly linked list

  8. Which of the following is not a type of node used in Linked List? a) data node b) header node c) sentinel node d) tail node Answer: a) data node

  9. Which of the following Linked List method is used to reverse the order of elements in the list? a) reverse() b) rotate() c) shuffle() d) sort() Answer: a) reverse()

  10. Which of the following is a type of circular linked list? a) Circular doubly linked list b) Circular binary linked list c) Circular balanced linked list d) Circular heap linked list Answer: a) Circular doubly linked list



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a Linked List? Answer: A Linked List is a linear data structure that consists of a sequence of nodes, where each node contains data and a pointer to the next (and possibly the previous) node in the list.

  2. What is the difference between a singly linked list and a doubly linked list? Answer: In a singly linked list, each node has a pointer to the next node in the list, while in a doubly linked list, each node has a pointer to both the next and previous nodes in the list.

  3. What is a head pointer and a tail pointer in a Linked List? Answer: The head pointer points to the first node in the list, while the tail pointer points to the last node in the list.

  4. How is a new node inserted at the beginning of a singly linked list? Answer: To insert a new node at the beginning of a singly linked list, a new node is created and its next pointer is set to the current head of the list. The head pointer is then updated to point to the new node.

  5. How is a new node inserted at the end of a singly linked list? Answer: To insert a new node at the end of a singly linked list, a new node is created and its next pointer is set to NULL. The next pointer of the current last node is updated to point to the new node, and the tail pointer is updated to point to the new node.

  6. How is a node deleted from a singly linked list? Answer: To delete a node from a singly linked list, the next pointer of the previous node is updated to point to the next node in the list. The memory occupied by the deleted node is then freed.

  7. What is a sentinel node in a Linked List? Answer: A sentinel node is a dummy node that is added to the beginning or end of a Linked List to simplify certain operations, such as inserting or deleting nodes at the beginning or end of the list.

  8. What is the time complexity of searching for an element in a Linked List? Answer: The time complexity of searching for an element in a Linked List is O(n), where n is the number of nodes in the list.

  9. How is a Linked List traversed recursively? Answer: A Linked List can be traversed recursively by starting at the head of the list and calling a function that takes the current node as an argument and recursively calls itself with the next node in the list.

  10. What is a circular Linked List? Answer: A circular Linked List is a Linked List where the last node points back to the first node, creating a circular structure. This can be either a singly linked or doubly linked list.

Linked List is a dynamic data structure that is commonly used in computer programming. It is a linear data structure consisting of a sequence of nodes, where each node contains data and a pointer to the next (and possibly the previous) node in the list. In contrast to arrays, Linked Lists can easily expand or contract during runtime, as the size of the list is not fixed. There are two types of Linked Lists: singly linked lists and doubly linked lists. In a singly linked list, each node has a pointer to the next node in the list, while in a doubly linked list, each node has a pointer to both the next and previous nodes in the list. Linked Lists can be easily implemented in programming languages such as C, C++, Java, and Python. In C and C++, nodes in a Linked List are usually implemented as structs with a data field and a pointer field. In Java and Python, nodes are typically implemented as objects with instance variables and a reference to the next node in the list. Insertion and deletion of elements in a Linked List can be performed efficiently, as it only requires updating the pointers of the affected nodes. To insert a new node at the beginning of a singly linked list, a new node is created and its next pointer is set to the current head of the list. The head pointer is then updated to point to the new node. To insert a new node at the end of a singly linked list, a new node is created and its next pointer is set to NULL. The next pointer of the current last node is updated to point to the new node, and the tail pointer is updated to point to the new node. To delete a node from a singly linked list, the next pointer of the previous node is updated to point to the next node in the list. The memory occupied by the deleted node is then freed. In a doubly linked list, deletion of a node also requires updating the previous node's next pointer to point to the next node, and the next node's previous pointer to point to the previous node. Traversing a Linked List involves visiting each node in the list. This can be done iteratively or recursively. Iterative traversal involves using a loop to visit each node in the list, while recursive traversal involves calling a function that takes the current node as an argument and recursively calls itself with the next node in the list. In summary, Linked Lists are a powerful data structure that can be used to store and manipulate collections of data efficiently. They can be easily implemented in various programming languages and can be used in a wide range of applications, from data structures to algorithms.