katrin-ibrahim / Analysis-and-Design-of-algorithms

Solutions to assignments for Analysis and Design of algorithms course

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Analysis and Design of algorithms

This repository contains the answers to the programming assignments for the Analysis and design of algorithms

SquidGame.java

Problem Description

  • Split the given array into K sub-arrays such that maximum sum of all sub arrays is minimum

  • You are required to implement two methods, a naive brute force method for the problem and the most efficient method you can think of for the problem.

  • Both methods return a string encoding of the solution represented as follows: maxSum; P1Sum; P2Sum; . . . ; PkSum

Sample Input/Output

k=2, l=[100,100,100,100]
Output: 200;100,100;100,100
k=2, l=[10,20,30,40]
Output: 60;10,20,30;40

FinalGame.java

Problem Statement

  • Given an m × n grid-shaped maze. A cell in the maze can either contain only one of the player or an obstacle. The player is allowed to move in the four directions up, down, left and right given that the cell he will be moving to does not contain an obstacle. Your task is to use bfs and dfs to output a valid path for the player from his starting position to a given destination position.

  • Both bfs and dfs methods take a String representing the grid formatted as follows: m, n; rowStart, colStart; o1r, o2c, . . . , okr, okc; rowEnd, colEnd

  • where: • m, n represent the dimensions of the grid. m is the total number of rows and n is the total number of columns.

• rowStart, colEnd is the row number and column number respectively of the starting position of the player.

• oir and oic represent the row and column number of the position of obstacle i for all 1 ≤ i ≤ k. • rowEnd, colEnd is the row number and column number respectively of the end position of the player. Both methods return a string encoding solution, if one exists, formatted as follows: step1, . . . , stepl ; stepsNum

  • where:

• step1, . . . , steps are the steps the player should follow to reach the end position from the start position without running into any obstacles.

• stepsNum is the number of returned steps.

Sample Input/Output

grid = "3,3;0,0;0,1,1,1;0,2"
Output by BFS:down,down,right,right,up,up;6
Output by DFS: down,down,right,right,up,up;6
grid = "3,3;0,0;0,1,1,1,2,1;0,2"
Output by BFS: No Solution
Output by DFS: No Solution
grid = "10,10;1,6;2,4,5,8,0,8,0,9,9,1,7,2,2,5,2,6,5,9,6,4;4,9"
Output by BFS: right,down,down,down,right,right;6
Output by DFS: right,right,right,down,left,left,down,right,right,down;10

ElectricNetwork.java

Problem Statement

  • The string "T1,T2,5;T1,T3,5;T1,T4,7;T2,T3,6;T2,T4,5;T3,T4,5;" represents a graph. Every edge is represented by the two edges it connects and its weight all separated by commas. Semicolons separate between the different edges.
  • Your method should return the minimum connections and a string encoding of the picked edges.
  • The output is another string formatted as the picked edges represented just like the

Sample Input/Output

graph = "T1,T2,5;T1,T3,5;T1,T4,7;T2,T3,6;T2,T4,5;T3,T4,5;"
Output: T1,T3,5;T1,T2,5;T2,T4,5;15

Acknowledgements

License

MIT

About

Solutions to assignments for Analysis and Design of algorithms course

License:MIT License


Languages

Language:Java 100.0%