Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Report on Algorithm Implementations in Java

Introduction

The objective of this assignment was to implement various algorithms


using Java, specifically focusing on Divide and Conquer and Greedy
algorithms. The algorithms chosen are fundamental in computer
science for solving complex problems efficiently. This report documents
the implementation, testing, and performance comparison of these
algorithms.

Implemented Algorithms

1. Quick Sort
• Purpose: To sort an array of elements.
• Implementation: Quicksort is a divide and conquer algorithm.
It picks an element as a pivot and partitions the given array
around the picked pivot.

2. Merge Sort
• Purpose: To sort an array of elements.
• Implementation: MergeSort is also a divide and conquer
algorithm. It divides the array into two halves, recursively sorts
them, and then merges the sorted halves

3. Closest-Pair Problem:
• Purpose: To find the smallest distance between a pair of points
in a plane.
• Implementation: The algorithm sorts points based on their
coordinates and recursively finds the closest pair of points.

4. Strassen’s Matrix Multiplication:


• Purpose: To multiply two matrices more efficiently than the
conventional method.
• Implementation: Strassen’s algorithm reduces the number of
multiplications involved in matrix multiplication using a divide
and conquer approach.

5. Quick hull:

• Purpose: To find the convex hull of a set of points.


• Implementation: Quickhull is a divide and conquer algorithm
similar to Quicksort. It recursively finds the hull on either side
of a line segment.

6.Prim’s Minimum Spanning Tree (MST):

• Purpose: To find the minimum spanning tree of a weighted


graph.
• Implementation: Prim's algorithm builds the MST by starting
from a single vertex and adding the smallest edge from the tree
to another vertex.

7. Traveling Salesman Problem (Approximate Solution):

• Purpose: To find the shortest possible route that visits each city
and returns to the origin city.
• Implementation: The approximate solution uses a greedy
algorithm to build the tour incrementally.

8. Kruskal’s MST:

• Purpose: To find the minimum spanning tree of a weighted


graph.
• Implementation: Kruskal’s algorithm sorts all the edges in the
graph by weight and adds them one by one to the MST,
avoiding cycles.

9. Dijkstra’s Shortest Path:

• Purpose: To find the shortest path from a source node to all


other nodes in a graph.
• Implementation: Dijkstra’s algorithm uses a priority queue to
explore the shortest paths from the source node.

10. Huffman Codes:

• Purpose: To compress data by encoding characters based on


their frequencies.
• Implementation: Huffman coding builds a binary tree where
the path from the root to a character represents its binary
code.
Performance Comparison

To compare the performance of these algorithms, each was tested with


different input sizes and data characteristics. The running time of each
algorithm was recorded and compared. Here are some key
observations:

1. QuickSort and MergeSort: Both algorithms showed optimal


performance for large datasets. QuickSort's performance can
degrade in the worst-case scenario (O(n^2)), but it generally
outperformed MergeSort due to lower constant factors.

2. Closest-Pair Problem: The divide and conquer approach


significantly reduced the running time compared to the brute-
force method, especially for large sets of points.

3. Prim’s and Kruskal’s MST: Both algorithms performed well,


with Kruskal’s algorithm being more efficient for sparse graphs
and Prim’s algorithm for dense graphs.

4. Strassen’s Matrix Multiplication: This algorithm was faster


than the conventional matrix multiplication for larger matrices
due to fewer multiplications.

5. Dijkstra’s Shortest Path: The performance was optimal for


graphs with non-negative weights. The priority queue
implementation ensured efficient pathfinding.
6. Huffman Codes: The encoding and decoding processes were
efficient, and the compression ratio improved with higher
frequency variations in the data.

GROUP MEMBERS
ACHEAMPONG OSEI ALEXANDER 11135938
ANINKORAH PETER ABOAGYE 11353051
PRINCE ASARE TANOH 11211360
ASARE ELISHA KWADWO 11305471
SHANI ABDUL RAHAMAN KACHU 11142071
DONKOR BENEDICT CYRIL 11357259
GODFRED FIAVE 11199207
ABDUL RAZAK MUSAH 11223634

You might also like