World's most popular travel blog for travel bloggers.

[Solved]: A "triangular" data structure for commutative relationships

, , No Comments
Problem Detail: 

A multiplication table is symmetric over a diagonal, so only about $n^2/2$ of the elements in an $n \times n$ multiplication table contain unique information. Same goes for addition tables. In fact, the same is true for any table that represents a commutative relationship. Is there a data structure that can take advantage of commutativity to avoid storing redundant values?

Asked By : Qaz

Answered By : David Richerby

Some languages, such as C, support ragged arrays: two-dimensional arrays where the rows have different lengths. That lets you avoid the redundancy of representing a symmetric function in a square array.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/28221

0 comments:

Post a Comment

Let us know your responses and feedback