Answer the question
In order to leave comments, you need to log in
How to find the maximum among all local minima of a given matrix?
What are some ideas for solving this problem.
I know that you need to first find the minimums, and among them to find the maximum.
The minimum (as well as the maximum) can be found by comparing an element with its left, right, top, and bottom elements.
There are 3 options for the location of the matrix element:
1) Corner (has two neighbors)
2) Frame (has three neighbors, these are elements from the edges of the matrix)
3) Internal (have 4 neighbors)
How can this problem be solved using the C language?
Answer the question
In order to leave comments, you need to log in
The idea is this: make a solution algorithm on a piece of paper, then program it.
Do a manual search on different matrices, as you find a pattern, you can write an algorithm.
The algorithm is trivial - iterate over all the cells of the matrix in two nested loops. Check that the current cell is a local minimum (compare with all neighbors). If so, then you need to compare it with the current candidate to the maximum.
In fact, there are 2 nested tasks here: 1) Check if the value is a local minimum 2) Find the maximum in the matrix (possibly ignoring some cells).
I advise you to solve problems separately using functions.
For the first task, write a function.
bool IsLocalMinumum(int a[][m], int n, int m, int i, int j);
if (!IsLocalMinimum(a, n, m, i, j)) continue;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question