BRAC UNIVERSITY
Department of Computer Science and Engineering
Examination: Midterm Semester ‘Summer 2022
Duration: 70 Minutes Full Marks: 30
CSE 220: Data Structures
‘Answer the following questions.
Figures in the right margin indicate marks.
Name: ASIVIOR, AFSL SHAGAD ID; 20241033 Section: | A-
1, Implement the following addArrays function which takes as input two linear arrays of
10
COI, the same length/capacity and constructs a new linear array of the same length/capacity
COS as output. The first element of this new array should be the sum of the first element of
the first array and the last element of the second array; the second element should be the
sum of the second element of the first array and the second last element of the second
array and so on. If there is any “None” value in any of the arrays, you ean assume that it
isa zero.
You are not allowed to use any built-in python functions except len() and range().
Using negative indices in python (such as ar|-1]) is not allowed.
Python:
defaddArrays(arrl, arr2):
# Write your code here
Java:
public int{] addArrays(int{} arr}, int) arr2) {
1 Write your code here
J
Sample Input Sample Output Explanation
arl =[1, 4, 5, 8, None, Nane, None} (1,4, 10, 17, 8,4, 7] 1#None = 1
ar2 = [7, 4, 8, 9, 5, None, None] 4#None = 4
ar3 = addArrays(arl, a2) 545=10
print(ar3) 849=17
And soon.2. Complete the following hasCyele fi
COS input and as output to determine
it as a cyclic linked list. Ifthe linked list has a cycle,
Importantly, no nodes should be constructed in the impleme
Tints You can take the help of multiple data structures to solve
‘he list will have n maximum of 1000 nodes.
Pythor
def hasCycle(head):
# Write your code here
10
sntation of the method,
his problem and assume
Java:
public boolean hasCycle(Node head) {
1/ Write your code here
}
Sample Input Sample | Explanation
Output
head True _| There is a cycle in the linked list
v where the node at index 1 can be
15 ~> 41> 33 - ; reached again and again.
False | There is no cycle in the linked list
head where a particular node can be
v reached again and again. 2
15 > 41 --> 33 -> -43-> None
notation to postfix using stack following the given
3. ‘a. Convert the following infix
con, precedence ofthe operators. You must show the workings. Yau donot need to
writegode. ,/ 4, /
B-a¥ hme WEiked ta ldeede
‘Precedence (decreases down the order) ‘ NN
L*/
2.%
3.4+,-
4.
5. &&
6
b. Evaluate the following postfix expression using stack, You must show the workings.
You do not need to write code.
Kideh /
ry
L hkl
5671 9*3(7% SH AOS