Assignment 1
Assignment 1
1
comp2123 Assignment 1 s1 2025
∑ | q i − q i +1 | .
0≤i <n−1 s.t. i is even
Examples:
a) Design a data structure that supports the required operations in the re-
quired time and space.
b) Briefly argue the correctness of your data structure and operations.
c) Analyse the running time of your operations and space of your data structure.
2
comp2123 Assignment 1 s1 2025
Specifically, for every building x ∈ [0, n − 1], compute the two closest indices i
and j to x such that:
i < x, j > x, A[i ] > A[ x ] and A[ j] > A[ x ].
Note:
• A[∗] denotes the element at index ∗ in the array.
• Indices start at 0.
Examples:
Input: A=[7,3,9,12,2,6,5,15]
Output:
L=[None, 0, None, None, 3, 3, 5, None]
R=[2, 2, 3, 7, 5, 7, 7, None]
Input: A=[6,2,4,1,10,7,8,11]
Output:
L=[None, 0, 0, 2, None, 4, 4, None]
R=[4, 2, 4, 4, 7, 6, 7, None]
Input: A=[10,3,2]
Output:
L=[None, 0, 1]
R=[None, None, None]
3
comp2123 Assignment 1 s1 2025