Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I need to use square matrix of size between 100x100 and 1000x1000.
I only need to read the matrix, modify some values and copy the matrix (many many times!)
It's more efficent to use the rectangular form, like int[][], or the multidimensional form, like int[,] ?
Or there is a better way or a better class to use?
There are two factors involving when deciding between arrays, Memory and performance. The Multi dimensional array has a good memory management than the jagged array, which is array of arrays. In case of performance, the jagged array is the fastest may be due to poor implementation of CLR. so clearly when you have a matrix form which requires multiple traversals, its better to use jagged arrays though it has some memory hit.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
So I am making an inventory system and I have a choice to make inventory through lists and arrays. Which approach is better and why in C#? This inventory system is for a 2d Platformer in unity.
In .Net, a list is a wrap of an array. It has similar performance, but List has built-in methods to resize the array, which contains all entries of the list. If your arrays are never resized, not need to use List.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Many times I avoid to use arrays, because of must be careful to work its size, and I must certainly know data type of elements.
I notice, I usually use List, I am not sure this is necessary many times.
I would like to know how to design code when I work with collections.
Can someone help me to approach to collections? Thanks.
* Arrays
* List and List<T>
* Dictionary, Hashtable, Queue, Stack ...etc.
* Sets
Your question is more fundamental. First of all read about basic differences between that data structures. Then you would understand when is is better to use which of them.
Complete guide you could find here -
https://msdn.microsoft.com/en-us/library/ms379570%28v=vs.80%29.aspx?f=255&MSPPError=-2147217396
You would become data strutures guru after reading this.
For example:
If you need to call element by index - Array is your choice as it allows you to do it easily, but if you know that you would be continuously adding elements to data structure - then List is much better.
Good practice for you would be trying to implement yourself all data structures you point out using simple Array.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How hashset memory overhead depends on objects size? And what if objects have different size?
The size of the HashSet is going to be related to the size of a variable of the type of objects that the HashSet holds. So for all reference types, that's the size of a reference, regardless of which type it is.
And what if objects have different size?
A HashSet can only store objects of one type, so they can't have a different size. They must all be the same size.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a 2D array of size [3000,3] and I have to find Euclidean Distances between the 3000 values in first dimension 3 times (second dimension).
What I am doing now is makin a nested for loop, I looked for ways of making it faster, but the only think I found was setting up a structure as here.
Perhaps doing 3 for loops is faster than doing a nested loop. Does anyone know how the processing time goes in this case?
It won't matter at all whether you run a loop three times via nested-loop or via separate loops, as long as the amount of iterations are the same.
If you can improve your algorithm, so that you need fewer iterations (fewer than 3000 x 3), that might get you somewhere.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is a List in C# equal to that of an ArrayList in terms of time complexity?
As it is my understanding that they're both similar in how they function, being dynamic arrays?
Both ArrayList and List<T> have the same basic implementation, using an array to store the items, reallocating as necessary when items are added. Indeed, much of List<T> is simply copy/paste from ArrayList, with appropriate changes to support the generics.
While there may be small differences in actual performance, the "big-O" complexity of operations in each would be the same.