avatarSudha Chandran B C

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2588

Abstract

e:fit:800/0*y0REl1dNgwTOv4TG"><figcaption></figcaption></figure><figure id="afeb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*ztwhfRFi1XGDVMAG"><figcaption></figcaption></figure><figure id="466a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*etrbVWlw1D_31uZK"><figcaption></figcaption></figure><h1 id="92da">Doubly linked list (Bi-directional)</h1><p id="2006">These contain a pointer to the next node as well as the previous node.</p><p id="386a">This ensures that the list can be traversed in both directions. A DLL node has three fundamental members:</p><ul><li>The data</li><li>Pointer to the next node</li><li>Pointer to the previous node</li></ul><figure id="0118"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*2s5qwgQ3nKmtwE9_"><figcaption></figcaption></figure><figure id="e363"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*HxwO1C7bA2sFlNXR"><figcaption></figcaption></figure><h1 id="e7ea">Circular linked list</h1><p id="d115">Circular linked lists function circularly: the first element points to the last element, and the last element points to the first. A single linked list and double linked list can be made into a circular linked list. The most important operations for a circular linked list are:</p><ul><li><code>insert</code> − insert elements at the start of the list</li><li><code>display</code> − display the list</li><li><code>delete</code> − delete elements from the start of the list</li></ul><h2 id="e70d">Pros 🔥</h2><ul><li><b>Flexible Size / Distributed:</b> Data does not need to be sequential in memory. We can arbitrarily add/remove items in a linked list as long as we have a way to point to the next item.</li><li><b>Ordered:</b> Linked lists provide order by pointing to the <code>next</code> item in the linked list.</li><li><b>Fast Insert / Delete:</b> If we have access to a node (typically the head or tail), we get fast inserts and deletes because the only thing that is required is updating a pointer.</li><li>Have faster prepends and faster appends than dynamic arrays, but they have slower lookups.</li></ul><h2 id="1632">Cons 🤕</h2><ul><li><b>Slow Lookups:</b> There is no direct access to data (no keys/indexes). We must iterate through the list sequentially to perform a lookup.</li></ul><h1 id="e392">GIFs</h1><h2 id="e561">Prepend</h2><figure id="ce69"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*bzavny6iOZDPcvUB"><figcaption>Credit: VisuAlgo</figcaption></figure><h2 id="fc1b">Append</h2><figure id="d23b"><img src="https://cdn-imag

Options

es-1.readmedium.com/v2/resize:fit:800/0*ygz-wRT1mX9vpeXs"><figcaption>Credit: VisuAlgo</figcaption></figure><p id="c8a2">Note: If we did have access to the tail, we could also append in O(1) time.</p><figure id="2fba"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*EYiKN3VCJE5QC4r3"><figcaption>Credit: VisuAlgo</figcaption></figure><h2 id="505d">Delete a Node</h2><figure id="321a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*AJYzGRafZJ16g6Id"><figcaption>Credit: VisuAlgo</figcaption></figure><h1 id="a1a6">Insert an Item</h1><figure id="4c64"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*weFZ0Em3pr-b1gZB"><figcaption>Credit: VisuAlgo</figcaption></figure><h1 id="e552">Reverse</h1><figure id="7cc9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*zqZiT4KlUy3fS6Zu"><figcaption><a href="https://www.youtube.com/watch?v=TSDl7sRxWdU">https://www.youtube.com/watch?v=TSDl7sRxWdU</a></figcaption></figure><figure id="3ae8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*vL7zhnwDbhYE_80_"><figcaption><a href="https://dailycodingproblems.quora.com/Reverse-a-Linked-List-Most-Popular-Interview-Question">https://dailycodingproblems.quora.com/Reverse-a-Linked-List-Most-Popular-Interview-Question</a></figcaption></figure><h1 id="a40a">Big O Performance Analysis</h1><figure id="4d9a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*bHUJwXUp5W5tINu4FTBRfQ.png"><figcaption></figcaption></figure><h1 id="3e8a">Linked Lists in the Real World</h1><ul><li>Browser back and forward buttons (doubly linked list where each page knows the one you visited before and after)</li><li>Implementing stacks and queues (fast operations at the ends)</li><li>Blockchain (distributed nodes are doubly linked lists that point to the one before and after)</li><li>“Undo” button in your text editor</li></ul><p id="2402">The pattern is that for all these implementations, they simply point to the item before and after the current one.</p><h1 id="f0fe">Linked Lists in Interviews</h1><ul><li>Be comfortable taking an input head node of a singly linked list and iterating from there</li><li>Always keep the runner technique in mind</li><li>Understand how to manage multiple pointers</li><li>Know the different <a href="https://skilled.dev/course/implement-a-linked-list">linked list techniques</a> and operations</li></ul><p id="c17a">Thank you for reading!</p><p id="8fd3">If you liked the article, please share and <b>give some claps</b> so others can find it 👏👏👏👏👏 !!!!</p></article></body>

Data Structures and Algorithms: “Mastering Linked Lists: From Novice to Node Ninja”

“Demystifying Linked Lists: A Comprehensive Guide to Node Structures”

· Intro: · Singly linked list (Uni-directional) · Doubly linked list (Bi-directional) · Circular linked listPros 🔥Cons 🤕 · GIFsPrependAppendDelete a Node · Insert an Item · Reverse · Big O Performance Analysis · Linked Lists in the Real World · Linked Lists in Interviews

Intro:

A linked list is a common data structure that is made of a chain of nodes. Each node contains a value and a pointer to the next node in the chain.

  • The first node of a linked list is called the head, and the last node is usually called the tail.
  • The head pointer points to the first node, and the last element of the list points to null. When the list is empty, the head pointer points to null.
  • Linked lists can dynamically increase in size.
  • It is easy to insert and delete from a linked list because unlike arrays, as we only need to change the pointers of the previous element and the next element to insert or delete an element.
  • The elements are not stored at contiguous locations.
  • They are commonly used to implement other data structures like Lists, stacks/queues or bucketing for hash tables..

Singly linked list (Uni-directional)

  • A singly linked list is unidirectional, meaning that it can be traversed in only one direction from head to the last node (tail).
  • A singly linked list means that each node will point to the next one in the list. This means you can move forward through the list but not backward.

Doubly linked list (Bi-directional)

These contain a pointer to the next node as well as the previous node.

This ensures that the list can be traversed in both directions. A DLL node has three fundamental members:

  • The data
  • Pointer to the next node
  • Pointer to the previous node

Circular linked list

Circular linked lists function circularly: the first element points to the last element, and the last element points to the first. A single linked list and double linked list can be made into a circular linked list. The most important operations for a circular linked list are:

  • insert − insert elements at the start of the list
  • display − display the list
  • delete − delete elements from the start of the list

Pros 🔥

  • Flexible Size / Distributed: Data does not need to be sequential in memory. We can arbitrarily add/remove items in a linked list as long as we have a way to point to the next item.
  • Ordered: Linked lists provide order by pointing to the next item in the linked list.
  • Fast Insert / Delete: If we have access to a node (typically the head or tail), we get fast inserts and deletes because the only thing that is required is updating a pointer.
  • Have faster prepends and faster appends than dynamic arrays, but they have slower lookups.

Cons 🤕

  • Slow Lookups: There is no direct access to data (no keys/indexes). We must iterate through the list sequentially to perform a lookup.

GIFs

Prepend

Credit: VisuAlgo

Append

Credit: VisuAlgo

Note: If we did have access to the tail, we could also append in O(1) time.

Credit: VisuAlgo

Delete a Node

Credit: VisuAlgo

Insert an Item

Credit: VisuAlgo

Reverse

https://www.youtube.com/watch?v=TSDl7sRxWdU
https://dailycodingproblems.quora.com/Reverse-a-Linked-List-Most-Popular-Interview-Question

Big O Performance Analysis

Linked Lists in the Real World

  • Browser back and forward buttons (doubly linked list where each page knows the one you visited before and after)
  • Implementing stacks and queues (fast operations at the ends)
  • Blockchain (distributed nodes are doubly linked lists that point to the one before and after)
  • “Undo” button in your text editor

The pattern is that for all these implementations, they simply point to the item before and after the current one.

Linked Lists in Interviews

  • Be comfortable taking an input head node of a singly linked list and iterating from there
  • Always keep the runner technique in mind
  • Understand how to manage multiple pointers
  • Know the different linked list techniques and operations

Thank you for reading!

If you liked the article, please share and give some claps so others can find it 👏👏👏👏👏 !!!!

Data Structures
Swift
Interview
Linked Lists
Interview Preparation
Recommended from ReadMedium