Comparison of Common Algorithms
Comparison of Common Algorithms
Main Body
A. Sorting Algorithms:
1. Linear Search:
Time Complexity: O(n)
Computational Cost: Low
Stability: Stable
2. Binary Search:
Time Complexity: O(log n)
Computational Cost: Low
Stability: Stable
B. Sorting Algorithms:
1. Bubble Sort:
Time Complexity: O(n^2)
Computational Cost: Moderate
Stability: Stable
2. Selection Sort:
Time Complexity: O(n^2)
Computational Cost: Moderate
Stability: Unstable
3. Quick Sort:
Time Complexity: O(n^2) - O(n log n)
Computational Cost: High
Stability: Unstable
4. Merge Sort:
Time Complexity: O(n log n)
Computational Cost: High
Stability: Stable
5. Insertion Sort:
Time Complexity: O(n^2)
Computational Cost: Moderate
Stability: Stable
Advance Algorithm Analysis Assignment 02| ZAIN ABBAS
C. Graph Algorithms:
1. Breadth-First Search (BFS):
Time Complexity: O(V + E)
Computational Cost: High
Stability:
it is a graph traversal algorithm used to explore and search for
nodes in a graph. The concept of stability does not apply to BFS
because BFS does not perform any sorting or rearrangement of
elements
2. Depth-First Search (DFS):
Time Complexity: O(V + E)
Computational Cost: High
Stability: DFS doesn't make comparisons between elements; it
simply explores the graph by following edges. It doesn't involve
ordering or comparing elements based on their values.
3. Dijkstra's Algorithm:
Time Complexity: O(V^2) or O(E log V)
Computational Cost: High
Stability: Dijkstra's Algorithm has a specific goal of finding the
shortest path in a weighted graph, which involves finding the
minimum distance from a source node to all other nodes.
D. Other Algorithms:
1. Fibonacci Sequence:
Time Complexity: O(2^n)
Computational Cost: High
Stability: Fibonacci Sequence is a mathematical sequence defined
by a recursive mathematical formula where each term is the sum of
the two preceding ones (e.g., 0, 1, 1, 2, 3, 5, 8, 13, ...). It is not an
algorithm in the sense that it doesn't involve a step-by-step
procedure for solving a computational problem or manipulating
data.
2. Knapsack Problem:
Time Complexity: O(nW)
Computational Cost: High
Stability: Knapsack Problem falls into the category of optimization
problems, where the goal is to find the best solution among a set of
possible solutions.
3. Huffman Coding:
Time Complexity: O(n log n)
Computational Cost: High
Stability: Stable
Advance Algorithm Analysis Assignment 02| ZAIN ABBAS
Comparison Table
Table 1.1
Conclusion: In conclusion, the choice of algorithm can significantly impact the efficiency
and stability of various computational tasks. It is essential to consider factors like time
complexity, computational cost, and stability when selecting the most appropriate
algorithm for a specific problem. While some algorithms excel in sorting data efficiently,
others are designed for graph traversal or optimization problems. Understanding these
characteristics is essential for making informed decisions in algorithm design and
selection.