24CLC10 Final
24CLC10 Final
Final test
75 minutes
Example 1
• Output: [5,4,3,2,1]
Example 2
• Output: [2,1]
Example 3
• Input: head = []
• Output: []
Constraints:
Hint: A linked list can be reversed iteratively or recursively. Could you implement both? You can
choose one way to implement in this exam.
• id
• firstname
• lastname
• email2
• profession
Then, you use I/O libraries like <fstream> to open the file, and then process its content line by
line. Function prototype is defined as:
9 int main () {
10 const std :: string filename = " data . csv " ;
11 std :: vector < Record > records = readCSV ( filename ) ;
12
22 return 0;
23 }
Now let’s see how it work in the case of kernel size equals to 1. Assume that the value in our kernel
(also known as “weights”) is “2”, we will multiply each element in the input vector by 2, one after
another until the end of the input vector, and get our output vector. The size of the output vector
is the same as the size of the input.
First, we multiply 1 by the weight, 2, and get “2” for the first element. Then we shift the kernel
by 1 step, multiply 2 by the weight, 2 to get “4”. We repeat this until the last element, 6, and
multiply 6 by the weight, and we get “12”. This process produces the output vector.
The different sized kernel will detect differently sized features in the input and, in turn, will result
in different sized feature maps. Let’s look at another example, where the kernel size is 1x2, with
the weights “2”. Like before, we slide the kernel across the input vector over each element. We
perform convolution by multiply each element to the kernel and add up the products to get the
final output value. We repeat this multiplication and addition, one after another until the end of
the input vector, and produce the output vector.
First, we multiply 1 by 2 and get “2”, and multiply 2 by 2 and get “2”. Then we add the two
numbers, 2 and 4, and we get “6”–that is the first element in the output vector. We repeat the
same process until the end of the input vector and produce the output vector.
With given function prototype, your task is completing the function conv1D with kernel size 2.
1 int * conv1D ( const int * input , int inputSize , const int * kernel , int kernelSize ,
int & outputSize ) {
2 // Calculate the size of the output
3 outputSize = inputSize - kernelSize + 1;
4 // YOUR CODE HERE
5 }
6
7 int main () {
8 int input [] = {1 , 2 , 3 , 4 , 5};
9 int kernel [] = {2 , 2};
10 int inputSize = sizeof ( input ) / sizeof ( input [0]) ;
11 int kernelSize = sizeof ( kernel ) / sizeof ( kernel [0]) ;
12
13 int outputSize = 0;
14
15 try {
16 int * result = conv1D ( input , inputSize , kernel , kernelSize , outputSize ) ;
17
24 delete [] result ;
25 } catch ( const std :: exception & e ) {
26 std :: cerr << e . what () << std :: endl ;
27 }
28
29 return 0;
30 }
Example
The Levenshtein distance between “kitten” and “sitting” is 3, since the following three edits
change one into the other, and there isn’t a way to do it with fewer than three edits:
Given the pseudocode of Levenshtein distance as below, your task is implement this function in
C++.
5 for i from 0 to m
6 d [i , 0] := i
7 for j from 0 to n
8 d [0 , j ] := j
9
10 for i from 1 to m
11 for j from 1 to n
12 {
13 if s [ i ] = t [ j ] then cost := 0
14 else cost := 1
15 d [i , j ] := minimum (
16 d [i -1 , j ] + 1 , // deletion
17 d [i , j -1] + 1 , // insertion
18 d [i -1 , j -1] + cost // substitution
19 )
20 }
21
22 return d [m , n ]
Regulations
Please follow these regulations:
• Please arrive at the room 15 minutes early to settle in and carefully check your computer
(keyboard, mouse, network, IDEs). You are allowed to use any IDE.
• After completing the test, check your submission before and after uploading to Moodle.
• Before leaving, delete your code, turn off the computer, and arrange the chairs properly.
Your source code must be contributed in the form of a compressed file and named your submission
according to the format StudentID.zip. Here is a detail of the directory organization:
StudentID
Exercise 1.cpp
Exercise 2.cpp
Exercise 3.cpp
Exercise 4.cpp
The end.