Jump to content

Better structure


Zilee

Recommended Posts

I have an array with 10,000+ elements and it is time to port it into a better structure. Should I code a binary tree or maybe a linked list?The array contains objects and there isn't really much need to display it, so I mostly need a structure with quick data access and quick deletion.

Link to comment
Share on other sites

Depending on what your data is, you could use a linked list, a tree (binary, red/black, b-tree, etc), directed graph, hash tables, etc. It depends how your nodes are related to each other and what you're goals are. Look up descriptions of the various data structures to see what their strengths and weaknesses are. A random-access data structure like an associative array is about as quick as you can get for lookups and deletions, but if that doesn't suit your needs for whatever reason, like if you're searching for a specific node but can't use a random-access structure, then you'll need to traverse a tree or list to find what you're looking for.

Link to comment
Share on other sites

How is your "array" currently stored/generated? Can you use a server-side language?
Yes I use server-side javascript to keep my structure in memory and available to everyone.
Depending on what your data is, you could use a linked list, a tree (binary, red/black, b-tree, etc), directed graph, hash tables, etc. It depends how your nodes are related to each other and what you're goals are. Look up descriptions of the various data structures to see what their strengths and weaknesses are. A random-access data structure like an associative array is about as quick as you can get for lookups and deletions, but if that doesn't suit your needs for whatever reason, like if you're searching for a specific node but can't use a random-access structure, then you'll need to traverse a tree or list to find what you're looking for.
Yes, it seems that a key-value collection will be ideal. I will have to display portions of the array to the user... I think a hash of hashes will be the best.I remember coding in a language that did had severely hindered performance when using multi-dimension arrays, is it the same case with JS?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...