0 votes 0 votes My question is : in the row [8][-8] to [8][5] will be 5-(-8)+1 = 14 elements , right ? so , it should be 1060 then considering 4 Byte is one element. I know , this is pretty basic question. But , still got me wrong :) DS data-structures + – worst_engineer asked Dec 29, 2015 edited Nov 13, 2016 by mcjoshi worst_engineer 3.7k views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments mcjoshi commented Nov 13, 2016 reply Follow Share A[5,.....,15][-8,....,8] = A[11][17]. So, to reach A[8][5], we need to cross $3$ rows (8-5) each having $17$ elements. and then we need to cross $13$ columns. Thus Address $= 800 + (3*17 + 13)*4 = 1056$ 1 votes 1 votes `JEET commented Dec 19, 2019 reply Follow Share @mcjoshi Can you please elaborate what you did there? 0 votes 0 votes `JEET commented Dec 19, 2019 reply Follow Share @Satbir Can you please help me with this? I mean how number of rows which are crossed are calculated?? 0 votes 0 votes Please log in or register to add a comment.
6 votes 6 votes Row major order = base address + [ (Row - smalest index) $\times$ Total column + (column - smallest index of column) ] $\times$ size = 800 + [ (8 - 5) $\times$ 17 + ( 5 - (-8)) ] $\times$ 4 = 800 + [51 + 13 ] $\times$ 4 = 800 + 256 = 1056 Prashant. answered Nov 13, 2016 Prashant. comment Share Follow See 1 comment See all 1 1 comment reply `JEET commented Dec 19, 2019 reply Follow Share How you got $\mathbf{3}$ rows. I mean why you subtracted $\mathbf{8-5}$. 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes Just transform the array hunk0123 answered Nov 4, 2018 hunk0123 comment Share Follow See all 3 Comments See all 3 3 Comments reply `JEET commented Dec 19, 2019 reply Follow Share This is a really good solution. Thanks brother. 0 votes 0 votes `JEET commented Dec 19, 2019 reply Follow Share Will this technique work in every problem? 0 votes 0 votes `JEET commented Dec 19, 2019 reply Follow Share I mean here it turned out that both the subtraction produced favorable answer. 0 votes 0 votes Please log in or register to add a comment.