- Inam Ullah Shaikh (22I-0857 H)
- Abdul Munhim Hussain (22I-1021 H)
This project is submitted as part of the Design and Analysis of Algorithms (CS-2009) course. It focuses on solving algorithmic problems using dynamic programming, recursion, and other algorithmic strategies. The project includes pseudocode implementations and time complexity analysis for multiple problems.
- Problem 1: Structure Calculation
- Problem 2: Optimal Strategy Computation
- Problem 3: Algorithmic Problem
- Problem 4: Computational Optimization
This problem involves using dynamic programming to calculate structures efficiently.
FUNCTION calculateStructures(n):
for i = 0 to n:
for j = 0 to n:
if i = 0:
dp[i][j] = 1
else:
dp[i][j] = 0
for i = 1 to n:
for j = 1 to n:
if j <= i:
dp[i][j] = dp[i][j - 1] + dp[i - j][j - 1]
else:
dp[i][j] = dp[i][j - 1]
return dp[n][n - 1]
- Initialization: O(n²)
- DP Computation: O(n²)
- Overall Complexity: O(n²)
This problem focuses on optimizing attack strategies using a dynamic programming approach.
FUNCTION BestStrategy(DP, start, end, noofattacks):
if end - start <= noofattacks:
return 0
if noofattacks == 0:
return DP[start][end]
if memo[start][noofattacks] != -1:
return memo[start][noofattacks]
result = INT_MAX
for split = 0 to end - 1:
right = BestStrategy(DP, split + 1, end, noofattacks - 1)
left = DP[start][split]
result = min(result, left + right)
memo[start][noofattacks] = result
return result
- Time Complexity: O(n³)
- Space Complexity: O(n²)
This section presents another problem with a dynamic programming-based solution.
FUNCTION computeValues(arr, size):
dp = allocate 2D array of size [size][size]
for i = 0 to size - 1:
for j = i to size - 1:
dp[i][j] = dp[i][j-1] + arr[j] * factor
return dp[0][size-1]
- Time Complexity: O(n²)
This section includes an optimization-based computational problem.
FUNCTION optimizePath(graph, nodes):
dp = initialize 2D array of size [nodes][nodes]
for k = 0 to nodes - 1:
for i = 0 to nodes - 1:
for j = 0 to nodes - 1:
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
return dp
- Time Complexity: O(n³)
This project implements and analyzes multiple algorithmic problems using dynamic programming and recursion. The solutions are evaluated based on their time complexity and efficiency in different scenarios. The findings provide a deeper understanding of the design and analysis of algorithms.
- Clone this repository:
git clone https://github.com/munhim/Algorithms-Project.git
- Compile and run the programs in a suitable compiler.
- Modify input values to test different cases.
This project is for educational purposes only.
For any queries, contact: