Assignment 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

NUST School of Electrical

Engineering and Computer Science


Theory of Computation Section A
Fall 2022
Assignment 3

Max marks: 10

In this assignment, you will implement a brute force algorithm to decision problem of Subset Sum. We
recall that in this problem we are given a set S and a target T. The decision problem will print Yes if a
subset S’ adds to T and No otherwise

You need to do the following

1) Generate sets of size n= 2, 4. 8, 16,32,64,128, 256,512, 1024, 2048, 4096, 8192, and 16, 384
a. The numbers will be generated randomly from 1 till 100,000 using a pseudo random
generator and stored in an Array/list of size n
b. Since a set needs to contain unique numbers, so you will need to check that the new
number is not a repetition and discard that number if it is.
2) Now you have a set S so you will randomly generate a target T between 1 till 20,000
3) Now you will need to generate all subsets of S and check they add to T or not. Give an
appropriate message
a. You can generate all subsets of a set by generating all binary numbers one by one calling
it b. Here b will have a length of |S|. Include a number if the corresponding digit in b is 1
Hint
 You store the digits independently in an array
The array can be filled by running a loop from n= 0 ⋯ 2|S|−1 in decimal. Convert that
each n to decimal using the division method as explained here. While performing the
division method fill the array or list in an appropriate manner.
Example:
Assume your set is S={a,b,c}
You need to generate the numbers 000,001, 010, 011, 100, 101, 110, 111 for
filtering elements of S for each subset of the powerset of S. Note that 111 is 7 in
decimal
b. Record the time taken to make the decision for each value of n and draw a plot with the
x axis is n and y axis is time in (secs)
Deliverables

1) Your source code in C/C++ or python. Source file not copy pasted on word.
2) The image of the plot

You might also like