Algorithms question:
Assumptions:
Integers in each row are sorted in ascending from left toright.
Integers in each column are sorted in ascending from top tobottom.
Special Assumptions:
The matrix may have missing elements. If that is the case: thecell value will be replaced with a special value called INF. Thinkof INF as a value that is bigger than any number (similar toinfinity in mathematics).
If a row contains this INF value, it will be the last value onthe row.
If a column contains this INF value, it will be the last valueon the column.
Example: if our matrix contains one INF value (and the rest arenumbers), the INF value will be located at the bottom row of therightmost column.
If our matrix has NO numbers, all cells will have INF values
Question:
Create an efficient algorithm valueInsert(B, n, value)where B is a non-full 2D matrix (thus a matrix satisfying the aboveassumptions and containing at least one INF value), value is anumber to be inserted. The algorithm must be in-place thusadditional matrix/array can NOT be used.
147 11 15 5 8 12 19 6 9 16 22 2 3 10 13 14 17 14 17 24 18 21 23 26 30
Algorithms question: Assumptions: Integers in each row are sorted in ascending from left to right. Integers in each colu
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am