Linked Lists Flashcards
Learn
What is a Node in a singly linked list?
A Node stores data and a pointer to the next node.
How do you insert a node at the beginning of a linked list?
Create a new node, point its next to the current head, and update the head.
How do you find the length of a linked list?
Traverse the list while counting nodes until you reach the end.
How do you remove a node with a specific value?
Traverse with two pointers and bypass the node when found.
What’s the difference between singly and doubly linked lists?
Singly has a next pointer only; doubly has both next and previous pointers.
What’s the time complexity to access a node in a linked list?
O(n), because you have to traverse nodes one by one.
How do you reverse a linked list in-place?
Use three pointers to reverse the direction of the links.
How do pointers change during insert/remove?
You update the next pointers to include or exclude specific nodes.
How to merge two sorted linked lists?
Compare elements from each list and build a merged list in order.