Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 354129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:53:42+00:00 2026-05-12T11:53:42+00:00

I am trying to write an application that performs operations on a grid of

  • 0

I am trying to write an application that performs operations on a grid of numbers, where each time a function runs the value of each cell is changed, and the value of each cell is dependent on its neighbours. The value of each cell would be a simple integer.

What would be the best way of storing my data here? I’ve considered both a flat list/array structure, but that seems ineffective as I have to repeatedly do calculations to work out which cell is ‘above’ the current cell (when there is an arbitrary grid size) and nested lists, which doesn’t seem to be a very good way of representing the data.

I can’t help but feel there must be a better way of representing this data in memory for this sort of purpose. Any ideas?

(note, I don’t think this is really a subjective question – but stack overflow seems to think it is.. I’m kinda hoping there’s an accepted way this sort of data is stored)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:53:43+00:00Added an answer on May 12, 2026 at 11:53 am

    Here are a few approaches. I’ll (try to) illustrate these examples with a representation of a 3×3 grid.

    The flat array

    +---+---+---+---+---+---+---+---+---+
    | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
    +---+---+---+---+---+---+---+---+---+
    
    a[row*width + column]
    

    To access elements on the left or right, subtract or add 1 (take care at the row boundaries). To access elements above or below, subtract or add the row size (in this case 3).

    The two dimensional array (for languages such as C or FORTRAN that support this)

    +-----+-----+-----+
    | 0,0 | 0,1 | 0,2 |
    +-----+-----+-----+
    | 1,0 | 1,1 | 1,2 |
    +-----+-----+-----+
    | 2,0 | 2,1 | 2,2 |
    +-----+-----+-----+
    
    a[row,column]
    a[row][column]
    

    Accessing adjacent elements is just incrementing or decrementing either the row or column number. The compiler is still doing exactly the same arithmetic as in the flat array.

    The array of arrays (eg. Java)

    +---+   +---+---+---+
    | 0 |-->| 0 | 1 | 2 |
    +---+   +---+---+---+
    | 1 |-->| 0 | 1 | 2 |
    +---+   +---+---+---+
    | 2 |-->| 0 | 1 | 2 |
    +---+   +---+---+---+
    
    a[row][column]
    

    In this method, a list of “row pointers” (represented on the left) each is a new, independent array. Like the 2-d array, adjacent elements are accessed by adjusting the appropriate index.

    Fully linked cells (2-d doubly linked list)

    +---+   +---+   +---+
    | 0 |-->| 1 |-->| 2 |
    |   |<--|   |<--|   |
    +---+   +---+   +---+
     ^ |     ^ |     ^ |
     | v     | v     | v
    +---+   +---+   +---+
    | 3 |-->| 4 |-->| 5 |
    |   |<--|   |<--|   |
    +---+   +---+   +---+
     ^ |     ^ |     ^ |
     | v     | v     | v
    +---+   +---+   +---+
    | 6 |-->| 7 |-->| 8 |
    |   |<--|   |<--|   |
    +---+   +---+   +---+
    

    This method has each cell containing up to four pointers to its adjacent elements. Access to adjacent elements is through the appropriate pointer. You will need to still keep a structure of pointers to elements (probably using one of the above methods) to avoid having to step through each linked list sequentially. This method is a bit unwieldy, however it does have an important application in Knuth’s Dancing Links algorithm, where the links are modified during execution of the algorithm to skip over “blank” space in the grid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 195k
  • Answers 195k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't access the serial port from AIR, but this… May 12, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer Yes, you need to specifc (18,2) for decimal/numeric The same… May 12, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer A quick definition of the "permanent generation": "The permanent generation… May 12, 2026 at 6:56 pm

Related Questions

I am trying to open a SQLConnection and this exception occurs: Description: The application
I am working on a web application (ASP.NET) game that would consist of a
I am fairly new to c# and am trying to write a n-tiered web
I wrote a small software synth for the iPhone. To further tune performance I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.