Total Pageviews

Monday, August 31, 2026

➕ ARRAY INSERTION AT FRONT

➕ ARRAY INSERTION AT FRONT
Insert a new value at index 0 by shifting every existing element one position to the RIGHT

📥 Enter Array and New Value

🎬 Step-by-Step Animation

Enter an array and a new value, then press START INSERTION.

📊 Operation Statistics

Array Size 0
Shifts Completed 0

📝 Step-by-Step Explanation

🧮 Mathematical Representation

Suppose:
A = [10, 20, 30, 40, 50]

New value:
5

To insert at the FRONT, all existing elements must move one position RIGHT.

A[5] ← A[4]

50 moves from index 4 to index 5.

A[4] ← A[3]

40 moves from index 3 to index 4.

A[3] ← A[2]

30 moves from index 2 to index 3.

A[2] ← A[1]

20 moves from index 1 to index 2.

A[1] ← A[0]

10 moves from index 0 to index 1.

Finally:
A[0] = 5

Final Array:
[5, 10, 20, 30, 40, 50]

💻 Algorithm

INSERT_FRONT(A,n,value)

Step 1: Start from the last element.

Step 2: Move each element one position RIGHT.

For: i = n − 1 down to 0

Perform: A[i + 1] = A[i]

Step 3: A[0] = value

Step 4: n = n + 1

⏱️ Time and Space Complexity

Time Complexity O(n)
Number of Shifts n

🎯 Final Result

Result will appear here.

🗑️ ARRAY DELETION AT FRONT

🗑️ ARRAY DELETION AT FRONT
Delete the first element and shift every remaining element one position to the LEFT

📥 Enter Array Values

🎬 Step-by-Step Animation

Enter values and press START DELETE.

📊 Operation Statistics

Array Size 0
Shifts Completed 0

📝 Step-by-Step Explanation

🧮 Mathematical Representation

Original Array
A = [10, 20, 30, 40, 50]

First element is deleted:
DELETE A[0]

Deleted value:
10

Now shift the remaining elements LEFT:

A[0] ← A[1]

20 moves from index 1 to index 0.

A[1] ← A[2]

30 moves from index 2 to index 1.

A[2] ← A[3]

40 moves from index 3 to index 2.

A[3] ← A[4]

50 moves from index 4 to index 3.

Finally:
n = n − 1

Therefore:
[20, 30, 40, 50]

💻 Algorithm

DELETE_FRONT(A,n)

Step 1: Delete the first element.

Step 2: Start from the second element.

Step 3: Move each element one position LEFT.

For: i = 1 to n − 1

Perform: A[i − 1] = A[i]

Step 4: n = n − 1

⏱️ Time and Space Complexity

Time Complexity O(n)
Number of Shifts n − 1

🎯 Final Result

Result will appear here.

⚡ QUICK SORT VISUALIZER

```
⚡ QUICK SORT VISUALIZER
Choose Pivot • Partition • Compare • Swap • Recursively Sort
```
```

📥 Enter Your Data

```
```

📊 Current Array

Enter values and press START QUICK SORT.
```
```

📈 Live Statistics

Recursion Level 0
Comparisons 0
Swaps 0
Partitions 0
Steps 0
```
```

🔀 Partition Visualization

```
```

📝 Step-by-Step Explanation

1
Quick Sort selects a pivot and rearranges the elements so that smaller values go to the left and larger values go to the right.
```
```

🧮 Quick Sort Mathematics

Choose a pivot:
pivot = A[high]

Start:
i = low − 1

For every element A[j]:
If A[j] ≤ pivot
then:
i = i + 1
and swap:
A[i] ↔ A[j]

Finally:
A[i+1] ↔ A[high]

The pivot is now in its correct position.
```
```

🔢 Complete Mathematical Example

Initial Array:
10, 7, 8, 9, 1, 5

Choose last element as pivot:
pivot = 5

Start:
i = −1

Compare 10 with 5:
10 ≤ 5 → False
No swap.

Compare 7 with 5:
7 ≤ 5 → False
No swap.

Compare 8 with 5:
8 ≤ 5 → False
No swap.

Compare 9 with 5:
9 ≤ 5 → False
No swap.

Compare 1 with 5:
1 ≤ 5 → True
i = 0
Swap A[0] and A[4]:
1, 7, 8, 9, 10, 5

Finally swap pivot 5 with A[1]:
1, 5, 8, 9, 10, 7

Pivot 5 is now in its final position.

Left partition:
[1]

Right partition:
[8,9,10,7]

Quick Sort recursively processes both partitions.
```
```

⚙️ How Quick Sort Works

1
Choose a Pivot: Select one element as the pivot. This visualizer uses the last element.
2
Partition: Move elements smaller than or equal to the pivot toward the left side.
3
Move larger elements toward the right side.
4
Place the pivot between the two partitions.
5
Recursively apply Quick Sort to the left partition.
6
Recursively apply Quick Sort to the right partition.
```
```

⚖️ Advantages & Disadvantages

+
Advantages
• Very fast on average.
• Average time complexity is O(n log n).
• Can be implemented in-place.
• Usually performs well in practical applications.
Disadvantages
• Poor pivot selection can produce O(n²) time.
• Standard Quick Sort is not stable.
• Recursive implementation requires stack space.
```
```

⏱️ Time & Space Complexity

Best Case O(n log n)
Average Case O(n log n)
Worst Case O(n²)
Average Space O(log n)
```
```

🎯 Pivot Concept

A good pivot divides the array into two approximately equal parts.

Example:
[2, 4, 5] | 6 | [7, 8, 9]

This produces approximately balanced partitions and gives:
O(n log n) average performance.

A poor pivot may produce:
[] | 1 | [2,3,4,5,6,7]

Repeated poor partitions can lead to:
O(n²)
```

🏔️ HEAP SORT VISUALIZER

```
🏔️ HEAP SORT VISUALIZER
Build Max Heap • Compare • Swap • Extract Maximum • Sort
```
```

📥 Enter Your Data

```
```

📊 Array Visualization

Enter values and press START HEAP SORT.
```
```

🌳 Max Heap Visualization

```
```

📈 Live Statistics

Phase 0
Comparisons 0
Swaps 0
Heap Size 0
Steps 0
```
```

📝 Step-by-Step Explanation

1
Heap Sort first creates a Max Heap. The largest element is placed at the root.
```
```

🧮 Heap Sort Mathematics

For a node at index i:
Left Child: 2i + 1
Right Child: 2i + 2
Parent: ⌊(i - 1) / 2⌋

For Max Heap:
Parent ≥ Left Child
Parent ≥ Right Child

Root contains the:
Maximum Element
```
```

🔢 Complete Mathematical Example

Initial Array:
4, 10, 3, 5, 1

Start from the last non-leaf node.
Last non-leaf index:
⌊n/2⌋ − 1
For n = 5:
⌊5/2⌋ − 1 = 1

Check index 1:
Parent = 10
Children = 5 and 1
10 is already larger.

Check index 0:
Parent = 4
Children = 10 and 3
Largest = 10
Swap:
10, 4, 3, 5, 1

Now the largest value 10 is at the root.

Extract 10:
Swap root with last element.
1, 4, 3, 5 | 10

Heapify:
5 is larger than 1.
Swap:
5, 4, 3, 1 | 10

Repeat until all elements are extracted.

Final:
1, 3, 4, 5, 10
```
```

⚙️ How Heap Sort Works

1
Build Max Heap: Arrange the array so that every parent is greater than or equal to its children.
2
The largest element is now at the root, index 0.
3
Swap the root with the last element of the unsorted heap.
4
Reduce the heap size by one. The extracted largest element is now sorted.
5
Apply heapify to restore the Max Heap property.
6
Repeat the process until only one element remains.
```
```

⚖️ Advantages & Disadvantages

+
Advantages
• Guaranteed O(n log n) time complexity.
• Does not require an additional array like standard Merge Sort.
• Works efficiently for large datasets.
• Uses O(1) auxiliary space when implemented in-place.
Disadvantages
• Usually not stable.
• Heap operations are more difficult to understand than Bubble Sort or Insertion Sort.
• Often has poorer cache behavior than some other O(n log n) sorting algorithms.
```
```

⏱️ Time & Space Complexity

Build Heap O(n)
Best Case O(n log n)
Average Case O(n log n)
Worst Case O(n log n)
Auxiliary Space:
O(1)
Heap Sort is an in-place sorting algorithm.
```