Practice-Exam-Final

pdf

School

University of Massachusetts, Amherst *

*We aren’t endorsed by this school

Course

241

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

10

Uploaded by DoctorPorpoiseMaster992

Report
1 ECE 241 Fall 2023 Practice Exam (Final) Solution Prof. M. Zink Name: ____________________________________________________ ID Number: ____________________________________________________ This exam is closed book, closed notes. No electronic devices (including calculators) are allowed. Be concise, but show your work. Write legibly. When writing code, please indent appropriately and give your variables meaningful names. Time: 120 minutes. Maximum Achieved Question 1 Question 2 Question 3 Question 4 Question 5 Total 100
2 Question 1 State Machines This problem focuses on state machines and their implementation a) For the state machine shown in Figure 1, which of the following expression will result in a match? Figure 1 Expression True False aacd ad abbbbd dabbbd a(b+|c)d bbacd b) List 4 valid expressions for the state machine shown in Figure 1! E.g., abbbbbd is a valid expression. c) Create a state machine (similar to the one shown in Figure 1) that matches the regular expression ba*b. d) Write a version for the class Edge that represents an edge in a finite state machine. (4 points) 1 2 5 6 3 a b d b c d d
3 e) Complete the missing lines in the code for the class Vertex that represents a vertex in a finite state machine. (6 points) class Vertex: def __init__ ( self , n): self . number = n self . edgeList = [] self .isAcceptingState = def setAcceptingState ( self ): def addEdge ( self , e): def followEdge ( self , c): return Question 2: Fast Fourier Transform (FFT) We have learned that the FFT is an essential algorithm for Shazam (an App that identifies a song by playing a recording to a smartphone). a) The Fast Fourier Transform makes use of a divide and conquer algorithm to simplify the number of operations, breaking a big FFT into smaller FFTs, which are easier to solve).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
4 List the four steps the divide and conquer approach of the Fast Fourier Transform. What is the complexity O(…) of the algorithm? b) Complete the code below to implement a recursive FFT function. # Recursive FFT function import numpy as np def FFT (x): N = len ( x ) N = 1024 x = np.random.random(N) t = Timer( lambda : FFT(x)) print ( 'Elapsed time: {} s' .format( str (t.timeit( number = 1 )))) Question 3: Linear Programming a) Consider a company that manufactures only two types of lemonade A and B. Both lemonades require carbonated water and either lemons. To manufacture each unit of A and B, following quantities are required: Each unit of A requires 1 unit of carbonated water and 3 units of lemons
5 Each unit of B requires 1 unit of carbonated water and 5 units of lemons The company has a total of 12 units of carbonated water and 16 units of lemons. On each sale, the company makes a profit of $4 per unit A sold and $6 per unit B sold. Let the total number of units produced of A = x, and the total number of units produced of B = y Now, the company wishes to maximize its profit. How many units of A and B should it produce respectively? Solve this optimization problem by formulating it as a linear program. Start by translating it in tabular form (use the table below for that task). Water Lemons Profit per Unit A B Total b) Figure 2 shows the graphs for the linear program shown below. Briefly explain how you can determine the optimal result for x 1 and x 2 based on the graph shown in Figure 3. Identify all vertexes that define the area of all valid solutions and explain why only one of them represents the optimal solution! Maximize 𝑥 1 + 𝑥 2 Subject to 3𝑥 1 − 𝑥 2 ≤ 10 2𝑥 1 + 𝑥 2 ≤ 10 5𝑥 1 − 2𝑥 2 ≥ −2 𝑥 1 , 𝑥 2 ≥ 0
6 Figure 3 c) Given the linear program below, determine the maximum values for x 3 , for which the constraints for x 1 , x 4 , x 5 are still valid . z = 27 + 𝑥 2 4 + 𝑥 3 2 3𝑥 6 4 𝑥 1 = 9 − 𝑥 2 4 𝑥 3 2 𝑥 6 4 𝑥 4 = 21 − 3𝑥 2 4 5𝑥 3 2 + 𝑥 6 4 𝑥 5 = 6 − 3𝑥 2 4 − 4𝑥 3 + 𝑥 6 2 d) One major component of the simplex algorithm is pivoting. In this problem you are tasked to perform pivoting for the linear program shown below and x 1 = 9. Start by solving the 3 rd constraint for x 1 and substitute it in the remaining equations z = 3𝑥 1 + 𝑥 2 + 2𝑥 3 𝑥 4 = 30 − 𝑥 1 − 𝑥 2 − 3𝑥 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
7 𝑥 3 = 24−2𝑥 1 − 2𝑥 2 − 5𝑥 3 𝑥 6 = 36 − 4𝑥 1 − 𝑥 2 − 2𝑥 3
8 Question 4: Machine Learning We have seen that Linear Regression is one of the many approaches to build a model in Machine Learning, which can be used to predict labels based on a certain set of features. a) A Linear Regression example is shown in Figure 4. First specify the general equation that defines the Mean Square Error. Based on that equation calculate the Mean Square Error. To allow us to give you partial credit, calculate the error value for each data point and use these values for your Mean Square Error Calculation. Figure 4 b) The example in Figure 5 shows on potential model for the data points (shown as red dots). Can this model be improved? If so, draw a new line that represents the improved model in the figure and explain why it is a better model. 0 2 4 6 8 10 12 0 2 4 6 8 10 12 Corelation 1
9 Figure 5 c) Assume you are given a dataset that contains the information shown below. Your goal is to develop a Machine Learning approach that predicts class of an Iris flower. Based on the given information in the table below, which columns identify potential features, which identify labels? Sepal length Sepal width Petal length Petal width Class 0 2 4 6 8 10 12 14 0 2 4 6 8 10 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10 Question 5 : FFT in Action We have learned that the FFT is an essential algorithm for Shazam (an App that identifies a song by playing a recording to a smartphone). a) (10 Points) Briefly explain how the Shazam App uses FTT to identify a song that is recorded on a smartphone by identifying steps 1. through 5. shown in Figure 6. What other algorithm is used in the fingerprinting process? Figure 7 Speaker Ambient Noise MIC 1. 2. 3. Shazam DB 5.