Blog Posts tagged with 'linkedlist'

Reverse a Linked List is a Popular Technical Interview Question

Reversing a linked list is a popular technical interview question and one I see a lot on popular programming challenge websites. In this linked list tutorial we will create a custom LinkedList Class with a reverse method that will reverse a linked list. We will also create unit tests to test the algorithm using Python's Unit Testing Framework.

Read More

Detect Cycle in Linked List Using Floyd's Cycle-Finding Algorithm

One popular algorithm for detecting cycles in linked lists is Floyd's Cycle-Finding Algorithm, which is often called the tortoise and the hare algorithm. The algorithm uses 2 pointers, a fast pointer and a slow pointer. The fast pointer ( hare ) traverses the linked list 2 nodes at a time while the slow pointer ( tortoise ) traverses the linked list 1 node at a time. If these pointers ever point to the same node in the linked, there is a cycle in the linked list.

Read More

Coding a Queue Abstract Data Type using a Linked List in Python

In this tutorial I will create a Queue Abstract Data Type using a linked list in Python. The queue will implement the two most common operations of enqueue and dequeue to add and remove an item from the queue.

Read More

Coding a Stack Abstract Data Structure Using Linked List in Python

This linked list tutorial will implement a Stack abstract data structure and use a linked list as the underlying data structure for maintain state. The developer will use common stack operations, like push, pop, and peek, and be unaware of the underlying use of a linked list and constant time, O(1), algorithms to perform the operations.

Read More

Inserting New Node in a Linked List Using Python

Let's continue to focus on fundamental data structures in computer science and the linked list. In this tutorial, let's insert new values in a linked list such that the list maintains its list of values in ascending order. Therefore, it's not good enough to add a new value to the linked list at the beginning in O(1). We have to search through the list in O(n) to find the proper location to insert the new node in O(1). It's the popular technical interview question and programming challenge with a twist!

Read More

Linear Search of Linked List in Python

Linked lists are a fundamental data structure in computer science and a common subject of technical job interview questions and programming challenges. One of the simplest challenges is to search a linked list to see if it contains a given value.

Read More