Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data structure to use?

I need a data structure with the following properties:

  • Access to elements must be very fast
  • Elements, that are not added, shouldn't take memory (as ideal, size of empty structure near to zero)
  • Each element has two integer coordinates (x,y) (access to elements only by them)
  • Max count of elements known at creation time (over 10^3)
  • Element contains few float values

It would be good if you also directed to an implementation of this structure in C or C++.

like image 861
Pavel Avatar asked Oct 25 '10 14:10

Pavel


People also ask

How do you know which data structure to use in a question?

How to identify which data structure or algorithm we should first attempt to solve a particular problem. Like if we have a sorted input array, we should start from the Binary Search. Similarly, if we can have a well detailed document that can help, I would highly appreciate it.

What type of data structure is used?

How are data structures used? In general, data structures are used to implement the physical forms of abstract data types. Data structures are a crucial part of designing efficient software. They also play a critical role in algorithm design and how those algorithms are used within computer programs.


2 Answers

Are you looking for a sparse matrix ?

like image 102
Victor Nicollet Avatar answered Sep 19 '22 17:09

Victor Nicollet


Check this out - you could alter the element type to float if this does everything you want.

Concise Sparse Matrix Package in C

For C++ you could use Boost.uBLAS - sparse_matrix details here.

like image 35
Steve Townsend Avatar answered Sep 20 '22 17:09

Steve Townsend