write solutions to these tasks: Task 1 Let there be a set of key-priority pairs (x1,…
- User
write solutions to these tasks: Task 1 Let there be a set of key-priority pairs (x1, y1),(x2, y2), . . . ,(xn, yn). Additionally, it is known that x1 < x2 < · · · < xn. It is known that all priorities are distinct. Propose a linear algorithm for building a Cartesian tree over this set of pairs. Task 2 An n×n table is given. It is required to come up with a structure with construction time O(n 2 log2 n) and the answer to the query for the minimum in the rectangle in O(1). Task 3 The strings p and s are given. s consists only of small letters of the English alphabet, while p can also contain ’⋆’ characters. It is required to determine in time O(|p| + |s|) whether it is possible to substitute some strings (possibly different ones) instead of ’⋆’ characters, so that string p becomes a substring of s. 1 Task 4 Given a binary search tree, initially the right_brother field in it is not filled. Write pseudocode of the function: ’void fill_right_brother(const TreeNode *root)’ which fills it. This field must contains a pointer to the “right brother”, i.e. to the vertex that is located in the tree at the same depth and has the smallest value of the larger ones. Let n denote the number of vertices in the tree, and let h denote the height of the tree. The running time must be O(n), and we can use: (a) O(h) extra memory; (b) O(1) extra memory. We can assume that TreeNode stores pointers to Left son, Right son, Parent. Task 5 There is an array containing n numbers from 1 to n. The array is read-only. Using O(1) of extra memory, find any two numbers that are the same, or determine that all the numbers are different. The running time should be: (a) O(n log2 n); (b) O(n log n). 2 Task 6 A sequence of numbers a1, a2, . . . , an is given. Find the shortest non-empty zero-sum segment in time O(n). Task 7 Given a matrix A of size a×b and a matrix B of size c×d consisting of letters of some alphabet Σ. It is necessary to find all occurrences of matrix B in matrix A as submatrix. In this case c ≥ a, d ≥ b. The time and memory complexity is O(a · b). It is not allowed to use hashes and suffix structures (suffix array, suffix tree, suffix automaton). like a student doing homework. explain the solution without writing code
- Assistant