Operations with matrices – Matrix Class in c ++

In particular, all the exercises are not difficult to solve, but I got stuck in fashion and it was the problem that made me think for a while.

I solved it, but honestly I do not feel good with the solution. I did not like it because it has a complexity of O (n2) and with a very large matrix it can take a long time due to the number of routes and comparisons.

The solution consisted of:

Create another auxiliary matrix with the same number of rows columas and fill it with zeros.
Go through the original matrix and compare the first element with all the other elements of the matrix and count their repetitions and so on with the other elements.
If I find a repetition, I increase the value in that position of the auxiliary matrix by one.
Then find the largest element of the auxiliary matrix.
And finally go through the auxiliary matrix, when some element of this matrix is ​​equal to the largest element, that is, that was the element that was repeated in the original matrix. Therefore fashion is in that position

You may also like...

1 Response

  1. 2017

    […] Previous story Operations with matrices – Matrix Class in c ++ […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!