Algorithms are a fundamental part of Computer Science and an important topic for Bihar STET Computer Science preparation. An algorithm is a finite sequence of well-defined steps used to solve a problem or perform a computation.
These Bihar STET Computer Science Algorithms Notes 2026 cover algorithm characteristics, complexity analysis, searching, sorting, recursion, divide and conquer, greedy algorithms, dynamic programming, graph algorithms and important MCQs.
What is an Algorithm?
An algorithm is a finite, well-defined sequence of instructions that takes input, processes it and produces the required output to solve a problem.
Example
To find the largest number among three numbers:
Read three numbers.
Compare the first number with the other two.
Identify the largest value.
Display the result.
Characteristics of an Algorithm
A good algorithm generally has the following characteristics:
1. Input
An algorithm may accept zero or more inputs.
2. Output
It should produce at least one result or output.
3. Definiteness
Every step should be clear and unambiguous.
4. Finiteness
The algorithm must terminate after a finite number of steps.
5. Effectiveness
Each operation should be basic enough to be carried out in a finite amount of time.
6. Correctness
The algorithm should produce the correct result for valid inputs.
Algorithm Representation
Algorithms can be represented using:
Natural language
Pseudocode
Flowcharts
Programming languages
Pseudocode
Pseudocode describes an algorithm using structured, human-readable statements without requiring the syntax of a specific programming language.
Example:
START
Read A, B
IF A > B
Print A
ELSE
Print B
END IF
STOP
Complexity Analysis
Algorithm efficiency is commonly measured using:
Time Complexity
Space Complexity
Time Complexity
Time complexity describes how the running time or number of basic operations grows with input size.
Space Complexity
Space complexity describes how the memory requirement grows with input size.
Big-O Notation
Big-O notation is commonly used to describe an asymptotic upper bound on an algorithm's growth.
Common complexities:
| Complexity | Example |
|---|---|
| O(1) | Array access |
| O(log n) | Binary Search |
| O(n) | Linear Search |
| O(n log n) | Merge Sort |
| O(n²) | Bubble Sort |
| O(2ⁿ) | Some recursive problems |
| O(n!) | Some brute-force permutation algorithms |
Best, Average and Worst Case
An algorithm can be analyzed under different input conditions.
Best Case
Minimum time/resources required for an input of a given size.
Average Case
Expected performance over a specified distribution of inputs.
Worst Case
Maximum time/resources required for an input of a given size.
For example, in linear search:
Best case: O(1)
Worst case: O(n)
Searching Algorithms
Searching algorithms are used to find a particular element.
Linear Search
Linear search checks elements sequentially.
Time Complexity
Best case: O(1)
Worst case: O(n)
Advantage
Works even when the data is unsorted.
Binary Search
Binary search repeatedly divides a sorted search space into two halves.
Steps
Find the middle element.
Compare it with the target.
If equal, return the position.
If target is smaller, search the left half.
If target is larger, search the right half.
Repeat until found or the search interval becomes empty.
Time Complexity
Best case: O(1)
Worst case: O(log n)
Important: Binary search requires the data to be sorted according to the comparison being used.
Sorting Algorithms
Sorting arranges data in a specified order.
Important sorting algorithms:
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
Quick Sort
Heap Sort
Bubble Sort
Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order.
Complexity
Typical worst-case:
O(n²)
Bubble Sort is simple but generally inefficient for large datasets.
Selection Sort
Selection Sort repeatedly selects the smallest or largest remaining element and places it in its correct position.
Complexity
Typical:
O(n²)
Insertion Sort
Insertion Sort builds a sorted portion one element at a time.
Complexity
Best case: O(n)
Worst case: O(n²)
It can work well for small or nearly sorted datasets.
Merge Sort
Merge Sort uses the divide-and-conquer technique.
Steps
Divide the array into smaller parts.
Recursively sort the parts.
Merge the sorted parts.
Complexity
Best: O(n log n)
Average: O(n log n)
Worst: O(n log n)
Merge Sort generally requires additional memory for merging.
Quick Sort
Quick Sort selects a pivot and partitions the data around it.
Complexity
Average: O(n log n)
Worst: O(n²)
The worst case can occur with unfavorable pivot choices.
Heap Sort
Heap Sort uses a heap data structure.
Complexity
Best: O(n log n)
Average: O(n log n)
Worst: O(n log n)
Recursion
Recursion occurs when a function calls itself to solve a smaller instance of the same problem.
A recursive algorithm normally requires:
Base case
Recursive case
Examples:
Factorial
Fibonacci
Tree traversal
DFS
Merge Sort
Quick Sort
Recursion uses the call stack to maintain active function calls.
Divide and Conquer
Divide and conquer solves a problem by:
Dividing it into smaller subproblems.
Solving the subproblems.
Combining their results.
Examples:
Merge Sort
Quick Sort
Binary Search
Greedy Algorithm
A greedy algorithm makes the locally best choice at each step with the goal of obtaining an overall optimal solution.
Examples:
Kruskal's Algorithm
Prim's Algorithm
Dijkstra's Algorithm for non-negative edge weights
Huffman Coding
A greedy strategy does not automatically guarantee an optimal solution for every problem.
Dynamic Programming
Dynamic Programming (DP) solves problems by breaking them into overlapping subproblems and storing previously computed results.
Two important characteristics are:
Overlapping subproblems
Optimal substructure
Common examples:
0/1 Knapsack
Longest Common Subsequence
Matrix Chain Multiplication
Fibonacci using memoization/tabulation
Backtracking
Backtracking builds a solution incrementally and abandons a partial solution when it cannot lead to a valid complete solution.
Examples:
N-Queens
Sudoku
Graph coloring
Maze solving
Graph Algorithms
Graphs consist of vertices and edges.
Important graph algorithms include:
BFS
DFS
Dijkstra's Algorithm
Prim's Algorithm
Kruskal's Algorithm
Floyd-Warshall Algorithm
Breadth-First Search (BFS)
BFS explores vertices level by level.
It generally uses a queue.
Applications:
Shortest path in an unweighted graph
Level-order traversal
Network exploration
Depth-First Search (DFS)
DFS explores as deeply as possible before backtracking.
It can be implemented using:
Stack
Recursion
Applications:
Graph traversal
Cycle detection
Topological sorting
Connected components
Dijkstra's Algorithm
Dijkstra's algorithm finds shortest paths from a source vertex to other vertices in a weighted graph with non-negative edge weights.
It is a greedy algorithm.
Prim's Algorithm
Prim's algorithm finds a Minimum Spanning Tree (MST) of a connected weighted undirected graph.
It grows the MST by repeatedly selecting a minimum-weight edge that connects the current tree to a new vertex.
Kruskal's Algorithm
Kruskal's algorithm also finds a Minimum Spanning Tree.
It:
Sorts edges by weight.
Selects the smallest edge that does not create a cycle.
Continues until the MST is complete.
Kruskal's algorithm commonly uses a Disjoint Set Union (Union-Find) data structure for cycle detection.
Floyd-Warshall Algorithm
Floyd-Warshall is a dynamic-programming algorithm used to find shortest paths between all pairs of vertices.
Its standard time complexity is:
O(V³)
Minimum Spanning Tree
A Minimum Spanning Tree (MST) is a spanning tree of a connected weighted undirected graph having minimum total edge weight.
Important algorithms:
Prim's Algorithm
Kruskal's Algorithm
For a graph with V vertices, an MST contains exactly:
V − 1 edges
Algorithm Stability
A sorting algorithm is stable if equal-key elements retain their relative order after sorting.
Examples of commonly stable sorting algorithms:
Bubble Sort
Insertion Sort
Merge Sort
Standard in-place Quick Sort is generally not stable.
In-Place Algorithm
An in-place algorithm uses only a small amount of additional memory beyond the input storage, subject to the implementation.
Examples include typical implementations of:
Selection Sort
Insertion Sort
Heap Sort
Important Algorithm MCQs for Bihar STET 2026
1. What is an algorithm?
A. A computer hardware component
B. A finite sequence of well-defined steps to solve a problem
C. A database
D. An operating system
Answer: B. A finite sequence of well-defined steps to solve a problem
2. Which is an essential characteristic of an algorithm?
A. Infinite execution
B. Ambiguity
C. Finiteness
D. Randomness
Answer: C. Finiteness
3. Which notation is commonly used for asymptotic upper bound?
A. Big-O
B. Big-A
C. Big-P
D. Big-X
Answer: A. Big-O
4. What is the worst-case complexity of linear search?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Answer: C. O(n)
5. Binary search requires:
A. Random data
B. Sorted data
C. A graph
D. A stack
Answer: B. Sorted data
6. What is the worst-case time complexity of binary search?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Answer: B. O(log n)
7. Which sorting algorithm uses divide and conquer?
A. Bubble Sort
B. Merge Sort
C. Selection Sort
D. Insertion Sort
Answer: B. Merge Sort
8. What is the worst-case complexity of Merge Sort?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n²)
Answer: C. O(n log n)
9. What is the average-case complexity of Quick Sort?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n²)
Answer: C. O(n log n)
10. What is the worst-case complexity of Quick Sort?
A. O(1)
B. O(log n)
C. O(n log n)
D. O(n²)
Answer: D. O(n²)
11. Which sorting algorithm repeatedly compares adjacent elements?
A. Merge Sort
B. Bubble Sort
C. Quick Sort
D. Heap Sort
Answer: B. Bubble Sort
12. Which sorting algorithm is generally efficient for nearly sorted data?
A. Insertion Sort
B. Selection Sort
C. Bubble Sort only
D. Heap Sort
Answer: A. Insertion Sort
13. Which technique divides a problem into smaller subproblems and combines their solutions?
A. Greedy
B. Divide and Conquer
C. Hashing
D. Encryption
Answer: B. Divide and Conquer
14. Which algorithm generally uses a queue?
A. DFS
B. BFS
C. Binary Search
D. Quick Sort
Answer: B. BFS
15. DFS can be implemented using:
A. Stack
B. Queue only
C. Heap only
D. Hash table only
Answer: A. Stack
16. Which algorithm finds shortest paths from a source in a graph with non-negative edge weights?
A. Kruskal
B. Dijkstra
C. Prim
D. Merge Sort
Answer: B. Dijkstra
17. Which algorithm is used to find a Minimum Spanning Tree?
A. Binary Search
B. Prim's Algorithm
C. Linear Search
D. Dijkstra only
Answer: B. Prim's Algorithm
18. Which algorithm also finds a Minimum Spanning Tree?
A. Kruskal's Algorithm
B. Binary Search
C. BFS
D. Floyd-Warshall
Answer: A. Kruskal's Algorithm
19. Kruskal's algorithm primarily processes:
A. Vertices in arbitrary order
B. Edges in increasing order of weight
C. Edges in decreasing order only
D. Nodes by depth
Answer: B. Edges in increasing order of weight
20. Dijkstra's algorithm does not correctly handle:
A. Non-negative weights
B. Positive weights
C. Negative edge weights in general
D. Connected graphs
Answer: C. Negative edge weights in general
21. Which algorithm finds shortest paths between all pairs of vertices?
A. DFS
B. Floyd-Warshall
C. Prim
D. Binary Search
Answer: B. Floyd-Warshall
22. The standard time complexity of Floyd-Warshall is:
A. O(V)
B. O(V²)
C. O(V³)
D. O(log V)
Answer: C. O(V³)
23. Dynamic Programming is particularly useful when a problem has:
A. Only independent subproblems
B. Overlapping subproblems and optimal substructure
C. No subproblems
D. Only sorting operations
Answer: B. Overlapping subproblems and optimal substructure
24. Which is an example of a dynamic programming problem?
A. Matrix Chain Multiplication
B. Linear Search
C. Bubble Sort only
D. Binary Search only
Answer: A. Matrix Chain Multiplication
25. Which technique abandons a partial solution when it cannot lead to a valid solution?
A. Greedy
B. Backtracking
C. Hashing
D. Sorting
Answer: B. Backtracking
26. N-Queens is commonly solved using:
A. Backtracking
B. Binary Search
C. BFS only
D. Selection Sort
Answer: A. Backtracking
27. Which algorithm makes a locally optimal choice at each step?
A. Dynamic Programming
B. Greedy Algorithm
C. Backtracking
D. Divide and Conquer
Answer: B. Greedy Algorithm
28. An MST of a connected graph with V vertices contains:
A. V edges
B. V + 1 edges
C. V − 1 edges
D. 2V edges
Answer: C. V − 1 edges
29. Which data structure is commonly used by Kruskal's algorithm to detect cycles efficiently?
A. Stack
B. Queue
C. Disjoint Set Union
D. Binary Search Tree only
Answer: C. Disjoint Set Union
30. Which complexity represents constant time?
A. O(n)
B. O(log n)
C. O(1)
D. O(n²)
Answer: C. O(1)
Quick Revision – Algorithms One-Liners
Algorithm → Finite sequence of well-defined steps.
Input → Data supplied to an algorithm.
Output → Result produced by an algorithm.
Finiteness → Algorithm terminates after finite steps.
Big-O → Common notation for asymptotic upper bound.
Linear Search → O(n) worst case.
Binary Search → O(log n) worst case.
Binary Search → Requires sorted data.
Bubble Sort → Adjacent comparison and swapping.
Insertion Sort → Builds sorted portion incrementally.
Merge Sort → Divide-and-conquer; O(n log n).
Quick Sort → Average O(n log n), worst O(n²).
Heap Sort → O(n log n) worst case.
Recursion → Function solves smaller instances of itself.
BFS → Uses queue.
DFS → Uses stack or recursion.
Dijkstra → Single-source shortest paths with non-negative edge weights.
Prim → Minimum Spanning Tree.
Kruskal → Minimum Spanning Tree.
Floyd-Warshall → All-pairs shortest paths.
Greedy → Makes locally optimal choices.
Dynamic Programming → Uses overlapping subproblems and optimal substructure.
Backtracking → Explores and abandons invalid partial solutions.
MST → Contains V−1 edges for V vertices.
DSU → Useful for cycle detection in Kruskal's algorithm.
Bihar STET Algorithms Preparation Tips
For Bihar STET Computer Science, candidates should focus on algorithm characteristics, complexity analysis, searching, sorting, recursion, divide-and-conquer, greedy algorithms, dynamic programming, backtracking and graph algorithms.
Pay special attention to the differences between:
Linear Search vs Binary Search
Bubble Sort vs Insertion Sort
Merge Sort vs Quick Sort
BFS vs DFS
Prim vs Kruskal
Greedy vs Dynamic Programming
Dijkstra vs Floyd-Warshall
Most Important Topics
Algorithm Characteristics
Pseudocode and Flowcharts
Time Complexity
Space Complexity
Big-O Notation
Best/Average/Worst Case
Linear Search
Binary Search
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
Quick Sort
Heap Sort
Recursion
Divide and Conquer
Greedy Algorithms
Dynamic Programming
Backtracking
BFS and DFS
Dijkstra's Algorithm
Prim's Algorithm
Kruskal's Algorithm
Floyd-Warshall Algorithm
Minimum Spanning Tree