### Problem

Implement quick sort on singly linked list.

### Solution

- Worst case time complexity of quick sort is O(n^2) but it’s rare.
- Quick sort follows divide and conquer approach.
- Quick sort is preferred over merge sort as quick sort is an

Skip to content
# Compute Patterns

## /* Scribbles on design patterns, architectural attributes, programming, best practices, AEMâ€¦ */

#
linked list

# Quick sort implementation on singly linked list in Java

### Problem

### Solution

# Add 2 numbers expressed as singly linked lists

## Problem

## Solution

# Merge 2 sorted singly linked lists

### Problem

### Solution

# Detecting loop in singly linked list

### Problem

### Solution

# Reverse a singly linked list

### Problem

### Solution

# Effective way of finding middle element in a singly linked list

### Problem

# Swap two nodes in a singly linked list

### Problem

### Solution

# Linked list

Implement quick sort on singly linked list.

- Worst case time complexity of quick sort is O(n^2) but it’s rare.
- Quick sort follows divide and conquer approach.
- Quick sort is preferred over merge sort as quick sort is an

Add 2 numbers which are expressed as singly linked lists. Results also should be in a linked list.

- Use recursion to traverse all the way to end and compute sum while returning backwards towards the start.
- Deal with

Merge 2 singly linked lists which are sorted. The resultant one shall also be in sorted order.

- As both the input lists are sorted, traverse through the lists, compare the heads of both the lists and form a

Identifying if there is any loop in singly linked list. Loop meaning any node connecting to one of the previous nodes.

- Best solution involves 2 traversal pointers – slow pointer which hops 1 node at a times and

Reverse a singly linked list in linear time complexity.

- Traverse through the list once and for each node assign the next pointer to the previous node.
- Time complexity O(n).
- Java based implementation along with unit test below

package… read the rest.

Find the middle element in a singly linked list. Obvious solution is traverse through the list once to find the length of list and then find out the middle element. This takes > O(n). Objective here is to Implement … read the rest.

Swap any two nodes in a singly linked list. It’s not swapping the content of the nodes but the nodes itself.

- First find out the previous nodes of nodes to be swapped and then establish the links.
- java

- Linear data structure representing ordered sequence of elements.
- Elements in it are not stored in contiguous location as arrays, rather linked through the pointers.
- Advantage over array
- Dynamic size. Not fixed one as array.
- Ease of insertion or deletion which