CodeHub

Algorithms (Step-by-Step)

Bubble Sort
Algorithm: Bubble Sort
1. Start
2. Repeat until no swaps occur
3. Compare adjacent elements
4. If left element is greater than right element, swap them
5. Move to the next pair
6. End when list is sorted
Selection Sort
Algorithm: Selection Sort
1. Start
2. Set the first element as minimum
3. Compare minimum with remaining elements
4. Update minimum if smaller element is found
5. Swap minimum with first element
6. Repeat for remaining list
7. Stop
Insertion Sort
Algorithm: Insertion Sort
1. Start
2. Take the second element
3. Compare it with elements before it
4. Shift larger elements one position to the right
5. Insert element at correct position
6. Repeat for all elements
7. Stop
Linear Search
Algorithm: Linear Search
1. Start
2. Take target value
3. Compare target with each element
4. If match is found, return position
5. If end is reached, report not found
6. Stop
Binary Search
Algorithm: Binary Search
1. Start
2. Set low and high positions
3. Find middle element
4. If middle equals target, return position
5. If target is smaller, search left half
6. If target is larger, search right half
7. Repeat until found or range is empty
8. Stop
Merge Sort
Algorithm: Merge Sort
1. Start
2. Divide the list into two halves
3. Recursively sort the left half
4. Recursively sort the right half
5. Merge the two sorted halves
6. Stop
Quick Sort
Algorithm: Quick Sort
1. Start
2. Choose a pivot element
3. Partition elements smaller than pivot to the left
4. Partition elements greater than pivot to the right
5. Recursively apply steps to both sides
6. Stop
Depth First Search (DFS)
Algorithm: Depth First Search
1. Start
2. Select a starting node
3. Visit the node and mark it as visited
4. Visit an unvisited adjacent node
5. Repeat until no unvisited nodes remain
6. Stop
Breadth First Search (BFS)
Algorithm: Breadth First Search
1. Start
2. Select a starting node
3. Visit the node and enqueue it
4. Visit all adjacent unvisited nodes
5. Dequeue and repeat until queue is empty
6. Stop
Fibonacci Sequence
Algorithm: Fibonacci Sequence
1. Start
2. Set first number to 0 and second number to 1
3. Add the two previous numbers
4. Store the result
5. Repeat until sequence is complete
6. Stop

Pseudocode (Connected to Algorithms)

Bubble Sort Pseudocode
START
SET swapped to true
WHILE swapped is true
  SET swapped to false
  FOR each adjacent pair in list
    IF first number > second number
      SWAP them
      SET swapped to true
END WHILE
STOP
Selection Sort Pseudocode
START
FOR each position in list
  ASSUME current position is minimum
  FOR remaining elements
    IF smaller element is found
      UPDATE minimum
  SWAP minimum with current position
END FOR
STOP
Insertion Sort Pseudocode
START
FOR each element from second position
  STORE current value
  SHIFT larger elements to the right
  INSERT value at correct position
END FOR
STOP
Linear Search Pseudocode
START
FOR each element in list
  IF element equals target
    DISPLAY found
    STOP
END FOR
DISPLAY not found
STOP
Binary Search Pseudocode
START
SET low and high
WHILE low is less than or equal to high
  FIND middle element
  IF middle equals target
    DISPLAY found
    STOP
  ELSE IF target is smaller
    MOVE high left
  ELSE
    MOVE low right
END WHILE
DISPLAY not found
STOP
Merge Sort Pseudocode
START
IF list has more than one element
  DIVIDE list into two halves
  SORT left half
  SORT right half
  MERGE both halves
END IF
STOP
Quick Sort Pseudocode
START
IF list has more than one element
  SELECT a pivot
  MOVE smaller elements to left of pivot
  MOVE larger elements to right of pivot
  APPLY process to both sides
END IF
STOP
DFS Pseudocode
START
VISIT starting node
MARK node as visited
FOR each adjacent node
  IF not visited
    VISIT node
END FOR
STOP
BFS Pseudocode
START
ENQUEUE starting node
WHILE queue is not empty
  DEQUEUE node
  VISIT node
  ENQUEUE all unvisited adjacent nodes
END WHILE
STOP
Fibonacci Pseudocode
START
SET first = 0, second = 1
DISPLAY first and second
WHILE next number is needed
  next = first + second
  DISPLAY next
  UPDATE first and second
END WHILE
STOP

Data Structures (Python Code)

Stack
stack = []

stack.append(10)
stack.append(20)
stack.pop()

print(stack)
[10]
Queue
from collections import deque

queue = deque()
queue.append(1)
queue.append(2)
queue.popleft()

print(queue)
Array
arr = [10, 20, 30, 40]
arr.append(50)
arr.append(50)
arr[1] = 25
arr.remove(30)
print(arr)
Binary Tree Traversal
class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

def preorder(root):
    if root:
        print(root.data)
        preorder(root.left)
        preorder(root.right)

def inorder(root):
    if root:
        inorder(root.left)
        print(root.data)
        inorder(root.right)

def postorder(root):
    if root:
        postorder(root.left)
        postorder(root.right)
        print(root.data)

Group Members in BSIT-2B

  • Abuan, Melissa
  • Coloma, Jake
  • Coloma, Jake
  • De La Cruz, Joelyn
  • Galzote, Margareth
  • Tria, Francine
  • Ubod, Janell Patricia
  • Vendiola, Lady Princess
  • Villanueva, Danica Marie
  • Zarasate, Jennefer