Great Deal! Get Instant \$10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

# A5.dvi School of Computer Science University of Guelph CIS*3490 The Analysis and Design of Algorithms Winter 2023 Instructor: Fangju Wang Assignment 5 (100%) For this assignment, you are...

1 answer below Â»
A5.dvi
School of Computer Science
University of Guelph
CIS*3490 The Analysis and Design of Algorithms
Winter 2023
Instructor: Fangju Wang
Assignment 5 (100%)
For this assignment, you are required to write programs in C. No pseudocode.
Question 1: Subset-Sum Problem (50%)
The subset-sum problem is to find a subset of a given set A = {a1, a2, ..., an} of n positive
integers, such that the subsetâ€™s sum is equal to a given positive integer d. For example, fo
A = {1, 2, 5, 6, 8} and d = 9, there are two subsets {1, 2, 6} and {1, 8} whose sums are equal to
9 .
Write the following programs for finding the number of the subsets whose sums are equal to
a given positive integer d. In the above example, the number is 2.
1.1 A program to implement a
ute force (exhaustive search) algorithm (15%)
1.2 A possibly more efficient program based on the backtracking technique (35%)
Requirements:
When a program is executed, it prompts for a file name and a positive integer d, reads in the
file containing the set A, and computes and reports the number of the subsets whose sums are
equal to d.
The program for 1.1 is also required to report the number of all the subsets evaluated. The
program for 1.2 is also required to report the number of the dead ends. The programs are not
equired to list the subsets.
A program is required to report the running time for finding the subsets. The running time
should not include the time for reading the file.
You can use file data A5 Q1 1.txt to develop/test your programs. This file contains 25 integers.
A different data file will be used to grade your programs. The numbers of integers and data
formats of the two data files will be the same.
Question 2: Person-Job Assignment Problem (50%)
In an assignment problem, there are n people who need to be assigned to execute n jobs, one
person per job. Each person is assigned to exactly one job and each job is assigned to exactly
one person. A person creates a value in doing a job. In this assignment problem, V [i.j] in
the n Ã— n matrix V stores the value created by person i in doing job j (i, j = 1, 2, ...n). The
problem is to find a person-job assignment that maximizes the total value.
1
Write the following programs to solve the assignment problem with a given V .
2.1 A program to implement a
ute force (exhaustive search) algorithm (15%)
2.2 A possibly more efficient program based on the
anch-and-bound technique (35%)
Requirements:
When a program is executed, it prompts for a file name, reads in the file containing matrix V ,
and computes and reports the assignment and the total value created. Please see the guide fo
the format for reporting and assignment.
The program for 2.1 is also required to report the number of all the assignments evaluated.
The program for 2.2 is also required to report the maximum upper bound in each step.
A program is required to report the running time for finding the assignment. The running
time should not include the time for reading the file.
You can use file data A5 Q2 1.txt to develop/test your programs. This file contains a 12 Ã— 12
matrix, for 12 persons and 12 jobs. A different data file will be used to grade your programs.
The numbers of integers and data formats of the two data files will be the same.
Note: Write your own code for this assignment. NO code from any source is allowed.
Due time: 08:00am, Monday April 10, 2023. Submit your work as a tar or zip file to Moodle.
2

A5_guide.dvi
School of Computer Science
University of Guelph
CIS*3490 The Analysis and Design of Algorithms
Winter 2023
Instructor: Fangju Wang
Assignment 5 Guide
Hints and suggestions for individual questions:
â€¢ Q1: For the subset sum problem, please read pages 427 and 428 for more information.
â€“ For Q1.1, you can create the 2n subsets, calculate the sum for each of them, and
find the subset that maximizes the sum. Your program input and output can be
something like:
Brute force program for subset sum problem
Enter the file name and subset sum: data_A5_Q1_1.txt 1200
Number of all the subsets: XXXXXXXXXX
Number of the subsets whose sums are 1200: 8909
Execution time = 4764 ms
â€“ For Q1.2, you can follow the algorithm illustrated in Figure 12.4 (p428). You
program input and output can be something like:
Backtracking program for subset sum problem
Enter the file name and subset sum: data_A5_Q1_1.txt 1200
Number of dead ends: XXXXXXXXXX
Number of the subsets whose sums are 1200: 8909
Execution time = 2093 ms
The numbers of dead ends may differ slightly.
â€¢ Q2: For the person-job assignment problem, please read page 119 for more information.
â€“ For Q2.1, you can generate all the permutations (representing all the possible person-
job assignments), evaluate all of them and find the one that has the maximum value.
Your program input and output can be something like:
Brute force program for assignment problem
Enter the file name: data_A5_Q2_1.txt
The number of all the possible assignments: XXXXXXXXXX
The person-job assignment selected:
XXXXXXXXXX5 10 9
The total value: 993
Execution time = 31899 ms
1
In the person-job assignment expression, the jth integer is the person assigned to
job j. For example, person 8 is assigned to job 1, person 4 is assigned to job 2, and
so on.
â€“ For Q2.2, please read pages XXXXXXXXXXYou can follow the algorithm illustrated in
Figures 12.5, 12.6 and 12.7. Please note the example in the figures is to find the
minimum, whereas this question is to find the maximum. Your program input and
output can be something like:
Branch and bound program for assignment problem
Enter the file name: data_A5_Q2_1.txt
Maximum upper bound: 1044
Maximum upper bound: 1030
Maximum upper bound: 1025
Maximum upper bound: 1025
Maximum upper bound: 1025
Maximum upper bound: 1025
Maximum upper bound: 1004
Maximum upper bound: 992
Maximum upper bound: 976
Maximum upper bound: 976
Maximum upper bound: 976
Maximum upper bound: 976
The person-job assignment selected:
XXXXXXXXXX5 10 2
Max total value 976
Execution time = 2 ms
The person-job assignment is expressed in the same way as in Q2.1.
The upper bounds may differ slightly. A
anch and bound algorithm may or may
not get the optimal solution.
Note:
You can develop your programs using any C system, as long as your programs can be
co
ectly compiled and executed on the Linux system in SoCS.
You are allowed to use standard li
ary functions. Your programs should be submitted as
a tar file or zip file containing your program files and readme and makefile. The readme file
should contain a
ief description of how to compile and run each program.
Any compilation e
or or warning will result in a mark deduction. There will be some marks
allocated for documentation.
Each file should have a comment at the beginning containing your name, id, date, and the
assignment name. Each function should have a
ief comment describing its purpose. Also,
any section of code where it is not easily apparent what the code does should have a short
comment.
2

XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX10

XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX
Answered 4 days After Mar 29, 2023

## Solution

Sumit Kumar answered on Apr 03 2023
SOLUTION.PDF