Questions tagged [array]
An array is a systematic arrangement of similar objects, usually in rows and columns.
214
questions
1
vote
1
answer
36
views
Determing uniformity of (name, value) array [closed]
I have an array of objects that represent some type and its value.
I'm looking for an algorithm to determine how random or uniform the array is.
For example Item("name": "A", "...
0
votes
0
answers
37
views
JavaScript: My logic traversing multi-dimensional arrays
Consider the following:
Let's say below is the multi-dimensional, and you are given the starting point of [2, 2].
const WORLD = [
['P', 'P', 'P', 'C', 'P'],
['P', 'M', 'P', 'C', 'P'],
...
0
votes
0
answers
66
views
Best choice for a holding large number of objects in java
I have a set of array, containing a large number of objects (products), which has lately grown so large, searching in it takes about a minute, which is considered too long, since one search is ...
2
votes
2
answers
534
views
JS - two array filters vs. one forEach?
I've had a question for a while. I know that the Array prototype method filter is generally preferred over forEach, and I believe it is typically faster at the job as well.
But what about if I have ...
2
votes
1
answer
360
views
Do C++ compilers optimize/pack small data types (e.g. boolean values)?
This occurred to me when looking at stencil computations in numpy. This python library compiles compute-intensive components, so I believe that it's a valid example. Here making selections on an array ...
-2
votes
2
answers
188
views
Comparing and replacing values in an array [closed]
I am currently working on a program that replaces the value in an array if the value next to it is the same as the current value. So If the array is [0,0,0,1,0,1,0], when the program runs it'll turn ...
4
votes
2
answers
236
views
Arrays vs Maps for listing items that have a unique id
I've been finding that for a lot of code I've been writing recently, it naively might look like this:
Array approach:
const options = [
{
id: 'red',
label: 'Red',
data: '#f00'
...
7
votes
7
answers
2k
views
What is the difference between an index and an offset?
I am looking to understand the difference between the words index and offset.
I have never seen "offset" in reference to lists/arrays/etc in programming. I have only seen index.
To me, these ...
0
votes
1
answer
117
views
how to store the data for function f(time,length)
I have a function which has discrete time step ,discrete length from origin . These two give height of the function. For example at time 1.2sec , and length 5.5cm from origin height is 10cm. The step ...
-4
votes
1
answer
187
views
A good metaphor for "lists" (arrays)? [closed]
When teaching students Python lists (which are more like arrays, not linked-lists) I'd like to use metaphor of list being a collection of boxes put in row.
But this doesn't work well:
indexes are ...
8
votes
2
answers
3k
views
Is there a sensible way to sort coordinates?
Sorting is generally used to solve problems where distance between elements matters. A sorted list/array has the convenient property that the smaller the difference between the indices of any two ...
0
votes
3
answers
455
views
How to guarantee an ID is unique in a non-UUID set of values?
I would like to have IDs of different sizes from the alphabet 0-9. So I have 5-length IDs as in 10000 or 13531, etc.. I have 10, 15, 20, up to 39 digit strings (the size of a UUID). I would like to ...
-2
votes
1
answer
87
views
Are jagged arrays lvalue or not?
When I was study lvalue i see that
C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array.
(from
https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-...
3
votes
1
answer
178
views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
2
votes
2
answers
322
views
sizeof(a)/sizeof(a[0]) vs sizeof(a)/sizeof(t) where t is type in C from K.N.King
I'm trying to understand why sizeof(a)/sizeof(t) is inferior for getting the length of an array to sizeof(a)/sizeof(a[0]) if just as it's possible to have different types, my elements could also be of ...
-2
votes
1
answer
804
views
Generate large Excel files and response from API
I need to generate a large Excel file (something around 50 megs) and send response to another API which will provide it to the front end for a download option.
My question is if it will be better to ...
1
vote
1
answer
108
views
How should I approach the comparison of two BMP images?
I am currently writing a Python program that retrieves the pixels from two BMP files and finds the percent difference between them (without using the Pillow library for the purpose of learning). I can ...
-3
votes
1
answer
637
views
C# is fantastic, if only List 'd respect Remove&Return [closed]
In the domain of system-modeling (e, systemVerilog, matlab, phyton), lists are obsoleting arrays, stacks and queues(*) altogether. Other domains that use python, perl and ruby have that same mindset, ...
1
vote
3
answers
300
views
Are 'array elements' and 'array values' the same?
Array := {"title": "Book Title", "author": "John Doe"}
Some people use the following terminology:
title and author are keys.
Book Title and John Doe are values.
"title": "Book Title" and "author": ...
-1
votes
1
answer
93
views
Algorithm that maps consecutive whole numbers to sets of numbers
Where would I begin if I wanted to develop an algorithm that maps consecutive whole numbers to a long list of unique sets of whole numbers. For example:
0 = {0, 0, 0}
1 = {0, 0, 1}
2 = {0, 0, 2} ...
1
vote
1
answer
42
views
Determine array of objects collective identity and be able to inspect it
I have an array of objects and I'm trying to see, through each request, whether or not a new member appeared in my collection.
The way I currently do it is, I require each member of the collection to ...
1
vote
3
answers
1k
views
Does the gcc optimize out local arrays the same way it would optimize out a local variable?
If I write this code in a function:
void func(void)
{
int x = 0;
int y = 3724832+x;
}
It would (probably) optimize the variable y out because it isn't being used. Even if I'm wrong about ...
0
votes
1
answer
242
views
PHP: simple class for storing read-only data structure, array alternative
I need to share some associative data between different parts of my application with two requirements:
immutability (so read-only)
safety against mispelling or unavailable index inside the data
...
2
votes
1
answer
57
views
At what size array in Swift would you consider switching to CoreData?
I've developed a reading tracking app in Swift and for simplicity's sake I used arrays for my model. It stores some data about the books a user reads and a small image of the cover. I save them to ...
1
vote
0
answers
40
views
is it better to have tracking fields that are maintained separately for arrays? [duplicate]
I wasn't sure exactly how to word this question, but basically, I have a struct stNeuralLayers (for a neural network I'm playing around with) with fields that are matrices (such as a double[,] ...
0
votes
2
answers
285
views
Should execution continue if array is empty?
Just a general programming best practices question.
If I have a function like that takes in an array of items and the function then calls a series of other functions which filter and act on the items ...
2
votes
1
answer
638
views
How should I define hardcoded strings with some variable parts? Reuse more characters? Or keep the whole sentence?
for example, sometimes I need to define a hardcoded string with some variable parts, I often have trouble to choose the style:
style 1 : reuse every characters when possible
showMessage(num){
let ...
2
votes
2
answers
358
views
Should I use Array or Set if both can be used to finish my task?
for example, Suppose I have a 2d array:
let filterArr=[
[1,1,0,1,1],
[0,1,1,1,0],
[1,1,0,1,0]
];
I want to find and store the index of column that all are 1, i.e.:position 1 and 3, and the ...
0
votes
1
answer
160
views
For arrays, should I use the first position to store the selected element, instead of variable like "selectedIndex", if possible?
For example, I have a toggle button, which would show the current selected element, and would show next element when it is clicked, and it can loop back to first element. I have 2 ways to store the ...
2
votes
2
answers
159
views
Should special case be inside or outside the for loop here?
For example, suppose I have 2 arrays:
let arr1=[5,2,1];
let arr2=["abcde","ab","a"];
my work is simple : to check if length of strings in arr2 are larger than corresponding element with same index ...
3
votes
2
answers
124
views
Should I move tasks which is just for a specific element only out of for loop?
For example, I have a for loop, which element 0 has additional function to run compared with other elements, my question is, should the additional function be:
1.place inside for loop
for(int i=0;i&...
2
votes
3
answers
2k
views
How do I put objects of different types derived from a common base in the same array? [closed]
I have two classes called Player and Enemy both inheriting from a class called GameObject, how do I store them both in an array of type GameObject while still keeping their own unique information?
I ...
3
votes
1
answer
123
views
Array rotation algorithm
I'm developing an application which sends quotes to clients via email.
Since quotes are obtained from various resources (per each client) they end up in a single array which is then used as a source ...
-1
votes
2
answers
1k
views
How does a dynamic array access work?
In C if i declare
int x[4]
Which tells me its an integer array with each array element size fixed of size 4.
So after initialization when I access x[3] : address of array +element size which is 2 *...
1
vote
2
answers
105
views
Linked-list iteration patterns
If you have a linked-list, where the items are not necessarily close to each other in memory, wondering if it is (in general) better/worse/no difference to do the following.
Say you want to iterate ...
3
votes
1
answer
292
views
What is best practice for handling mapping arbitrary depth in arrays?
I have a set of data:
id | name | parentid
------------------------
1 | parent | 0
2 | child | 1
3 | child | 1
4 | parent | 0
5 | child | 4
6 | subchild | 5
7 | child | 4
...
2
votes
2
answers
5k
views
How exactly indexing works in arrays?
I only know that index is faster but don't know why is it faster.
Suppose I have an array int[] a = {2,3,6,7}. Then I will try to find the element at a[3] and the speed of this will be O(1). Why? How ...
11
votes
2
answers
2k
views
How did the custom of using square brackets for array elements develop?
Many programming language use the syntax a[i] to refer to the i'th element of an array, sequence, or vector a - specifically, C and Pascal (from the late 1960s and early 1970s) do this. On the other ...
1
vote
2
answers
409
views
Are there any use cases for List when Deques and Arrays are available?
I've been thinking about this over the past few weeks, and I've come up with no good arguments. My perspective is from Java, but if anyone has any language-specific cases outside of this language, I'...
3
votes
4
answers
102
views
Store csv data as rows or columns in view of the needed processing?
Assume I have some data a csv-Files like
ObjectName, PropertyA, PropertyB, PropertyC
"Name1", 3, 1, 4
"Name2", 1, 5, 9
"Name3", 2, 6, 5
...
and a typical question I want to answer would be
For ...
5
votes
3
answers
3k
views
Is "Array[1]" the first element or second element in the array?
Following the reading of the question Why are zero-based arrays the norm?, I wonder about the terms to use for referring to specific array elements, in the perspective of linguistic reading of ...
0
votes
1
answer
97
views
What is the name or description of my technique for filtering items in array? [closed]
I've tried posting this question on StackOverflow but they told me to try it here since it's not so specific. I'd like to know the name of the algorithm or technique of following implementation. I ...
1
vote
0
answers
67
views
How should I store a frequently accessed array with an unknown number of elements in mongodb?
I have a simple "Index" object defined as follows:
{
"position": 4,
"value": 345
}
And I'm trying to figure out the best way to store this object in a mongo database, assuming that:
The "...
-1
votes
1
answer
2k
views
Why is it possible to access an array out of bounds with negative indexes much further than with positive indexes?
I have written two small programs in which I declare a very small array.
Then I try to access values out of bounds.
The interesting thing I noticed that when I try to decrement the index I can ...
1
vote
2
answers
169
views
Is it unnecessary to have a method that merely loops through an array and calls another method with each item?
For example, if there's multiple lines to be drawn, I could do
function drawLines(lines) {
lines.forEach(function (line) {
drawLine(line);
});
}
function drawLine(line) {
//...
}
...
2
votes
3
answers
2k
views
Return array pointers vs. populating an array inserted as a parameter?
Which is better? I noticed the latter is used in a lot of C code. People will typically malloc an array, and then pass that as a parameter to a function, which will then populate it. Whereas in Java, ...
-4
votes
2
answers
3k
views
How to create a method that takes array list as argument?
To create a method that takes an array as an argument, you would do this:
public static void printAges(int[] age) { // prints ages to screen
for (int x = 0; x < age.length; x++) {
...
2
votes
1
answer
163
views
Handling out of bounds requests in embedded C library
We're currently building a library in C that configures itself from tables in EEPROM.
This leaves the possibility however that some caller requests a field that is out of bounds, and the question ...
1
vote
1
answer
850
views
Merging algorithm for overlapping intervals
I have been searching for an efficient algorithm to merge overlapping intervals on a dynamic array of intervals. For example, (start time, end time) wise,
[(1, 2), (4, 8), (3, 10)]
becomes
[(1, 2)...
0
votes
1
answer
1k
views
Lower bound for finding a value in sorted array
Suppose we have a sorted array of unique elements, A[n]. I am trying to find the lower bound for finding a specific element x in the array. I suspect the lower bound to be log_2(n+1).
I tried to use ...