Linked Lists - Notes
Linked Lists - Notes
➢ The head in a doubly linked list will point to both null and the next node. The tail in a doubly
linked list will point to null and the previous node.
3. Circular Linked List
➢ The Circular Linked list the next pointer of the last node points back to the first node and this
results in forming a loop.
➢ This type of linked list is simply a singly linked list where the tail, instead of pointing to null
points back to the head node.
4. Doubly Circular Linked List
➢ A doubly circular linked list is a doubly linked list whose head’s previous node will be the tail
instead of null. And the tail’s next node will be the head instead of null.
2. Deletion:
o At the beginning: O(1) - Update head pointer.
o At the end or specific position: O(n) - Traverse to find the node.
o Doubly linked lists make deletion slightly easier due to previous pointers.
3. Traversal:
o O(n) - Visit each node sequentially.
4. Search:
o O(n) - Linear search required as no random access.
2) Polynomial Representation
• Polynomials (e.g., 3x² + 5x + 2) can be represented using linked lists where each node stores a
term’s coefficient and exponent.
• For instance, the polynomial 4x³ + 2x + 1 would have nodes like [4,3] -> [2,1] -> [1,0], with
pointers connecting them.
• This is more efficient than an array (which might store zero coefficients for missing terms)
because only non-zero terms are stored.
3) Addition of Polynomials
• Linked lists simplify adding two polynomials (e.g., 5x² + 4x + 2 and 5x + 5).
• Each polynomial is stored as a linked list of terms (coefficient, exponent).
• To add them, traverse both lists simultaneously, comparing exponents: if they match, add the
coefficients into a new node in the result list; if not, include the term with the higher exponent
and move to the next node.
• Leftover terms from either list are appended to the result. This process is efficient (O(n+m) time,
where n and m are the number of terms) and avoids unnecessary zero-term storage.
• This linked list contains all terms we need to generate the final result. However, it is not sorted by
the powers. Also, it contains duplicate nodes with like terms.
• To generate the final linked list, we can first merge sort the linked list based on each node’s
power.
• After the sorting, the like term nodes are grouped together. Then, we can merge each group of
like terms and get the final multiplication result.