Linked List
Practice Questions
Introduction
Linked lists
Linked lists are an ordered collection of objects. So what makes them different from normal lists? Linked lists differ from lists in the way that they store elements in memory. While lists use a contiguous memory block to store references to their data, linked lists store references as part of their own elements.
Each element of a linked list is called a node, and every node has two different fields:
A linked list is a collection of nodes. The first node is called the head
, and it’s used as the starting point for any iteration through the list. The last node must have its next
reference pointing to None to determine the end of the list. Here’s how it looks:
Some Real Time Applications:
Linked lists serve a variety of purposes in the real world. They can be used to implement (spoiler alert!) queues or stacks as well as graphs. They’re also useful for much more complex tasks, such as lifecycle management for an operating system application.
Linked List in Python:
Python has its own implementation of Linked List , there’s a specific object in the collections
module that you can use for linked lists called deque (pronounced “deck”), which stands for double-ended queue.
collections.deque
uses an implementation of a linked list in which you can access, insert, or remove elements from the beginning or end of a list with constant O(1) performance.
But if you are preparing for job interviews, it is better to understand how to implement your own linked list first. Then we can see a glance of Python's collection.
Try here>>>