algos of everything
algos of everything
Start
Input the size of the array, n.
Declare an empty array, arr[].
For i = 0 to n-1, do:
● Input the value for arr[i].
● Assign the value to arr[i].
For i = 0 to n-1, do:
● Display arr[i].
End
Start
Input the size of the array n.
Declare an array arr[] of size n.
For i = 0 to n-1:
● Input the value for arr[i].
● Assign the value to arr[i].
Input the position pos of the element to be deleted (1-based index).
If pos is invalid (i.e., pos < 1 or pos > n):
● Display an error message and exit.
Shift elements to the left to delete the element:
● For i = pos-1 to n-2:
○ Set arr[i] = arr[i+1].
Decrement the size of the array by 1.
Display the new array.
End
Start
Input the size of the array n.
Declare an array arr[] of size n.
For i = 0 to n-1:
● Input the value for arr[i].
For i = 0 to n-1:
● For j = 0 to n-i-2:
○ If arr[j] > arr[j+1], then:
■ Swap arr[j] and arr[j+1].
Display the sorted array.
End
Write a C program to delete a node from the end of a Singly linked list.
⦁ If START = = NULL ( Display Underflow )
⦁ Set PTR = START
⦁ Repeat Until PTR → NEXT != NULL
⦁ Set PREPTR = PTR
⦁ Set PTR = PTR → NEXT
⦁ Set PREPTR → NEXT = NULL
⦁ FREE PTR
⦁ EXIT
Write a C program to insert a node in the beginning of a Circular linked list.
Write a C program to delete a node from the end of a Circular linked list.
⦁ If START = = NULL ( Display Underflow )
⦁ Set PTR = START
⦁ Repeat until PTR NEXT != START
⦁ Set PREPTR = PTR
⦁ Set PTR = PTR NEXT
⦁ Set PREPTR NEXT = START
⦁ FREE PTR
⦁ EXIT
Write a C program to delete a node from the beginning of a Doubly linked list.
⦁ If START = = NULL ( Display Underflow )
⦁ Set PTR = START
⦁ Set START = START PREV
⦁ Set START PREV = NULL
⦁ FREE PTR
⦁ EXIT
⦁ If REAR = MAX – 1
Write Overflow
go to step 4
⦁ If FRONT = -1 and REAR = -1
SET FRONT = REAR = 0
ELSE
SET REAR = REAR + 1
⦁ SET QUEUE[REAR] = NUM
⦁ EXIT
Dequeue:-
⦁ If FRONT = -1
Write Underflow go to step 2
ELSE If FRONT = REAR
SET VAL = QUEUE[FRONT]
SET FRONT = REAR = -1
ELSE
SET VALUE = QUEUE[FRONT]
SET FRONT = FRONT + 1
⦁ EXIT
Enqueue:-
⦁ If (REAR+1)% MAX = FRONT
Write Overflow go to step 4
⦁ If FRONT = -1 and REAR = -1
SET FRONT = REAR = 0
ELSE SET REAR = (REAR + 1)%MAX
⦁ SET QUEUE[REAR] = VALUE
⦁ EXIT
Dequeue:-
⦁ If FRONT = -1
Write Underflow go to step 4
⦁ SET VALUE = OUEUE[FRONT]
⦁ If FRONT = REAR
SET FRONT = REAR = -1
ELSE
SET FRONT = (FRONT + 1)%MAX
⦁ EXIT
If the node to be deleted is a leaf node, simply remove it from the tree.
Step 3: Handle node with one child deletion:
If the node to be deleted has only one child (either left or right), replace the node with its child.
Update the child’s parent pointer to point to the node’s original parent.
Step 4: Handle node with two children deletion:
Find the node’s in-order successor (the smallest node in the right subtree).
Replace the node’s key with the in-order successor’s key.
Recursively delete the in-order successor from the right subtree.
Step 5: Update the node’s children:
If the node’s left child exists, update its parent pointer to point to the node’s original parent.
If the node’s right child exists, update its parent pointer to point to the node’s original parent.
Step 6: Return the updated BST.