• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing submatrix with a main matrix

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have a matrix of the following form.
Ex:

1 0 0 0 1 0 1 1 0 1 1
0 0 0 1 0 1 0 1 1 1 0
1 1 1 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 1
1 0 0 1 1 0 0 0 0 0 1
1 1 1 0 0 0 1 0 0 0 0

I have to search in this matrix a submatrix(A) of the form
0 1 1
0 0 1
0 0 0. and the program should give the output:i) Total no.of submatrix present in the main matrix and ii)row and column elements forming the submatrix in the main matrix.

For Ex: in the above example we can find the submatrix for R4,R5,R6&C9,C10,C11

THe search must take into consideration the combinations all the rows and colums.i.e.,the rows and colums are not only consecutive but also the program should compare submatrix(A) with the submatrix from the main matrix using the combination like row1,2,5& column 1,2,4 and so on.......

I havenot done any programming like this before where I can compare a submatrix with a main matrix. I have written the program using if and for loops and that worked out pretty well, but for my file it took almost 1day to run since there were many loops.

So please suggest me for generating the code and how to proceed with the programming.

THanx in advance.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the submatrix size is fixed, you only need 2 for loops. Even if the submatrix can be of a variable size and shape, you would still only need 4 for loops, and the program would still only take 1 second to run.

If you want some assistance, sina, you need to do more than just describe the exercise and ask someone to do it for you. You need to show the code you have written (using [code] tags, so that it is readable), and explain what you have done to work out what the problem is. Then we can give you some hints.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic