Questions tagged [parallel-arrays]

Use for questions about using in separate array per field (I.e. `name[10], subject[10], grade[10]`.) to store structured records instead of array of objects with fields/properties.

This tag is for questions that concern usage of multiple (parallel) arrays to store records in array-per-field manner (vs. using classes to store fields of an entity together and than have a single array of such entities). See Wikipedia for more information.

Example of parallel arrays (JavaScript-like language):

   var names = ["Bob", "Alice"];
   var subject = ["Crypto", "Compression"];
   var grades = [9002, 9001];

Same data as objects:

   var students = [
     {name:"Bob", subject: "Crypto", grade: 9002},
     {name:"Alice", subject: "Compression", grade: 9001}
   ];

Cases when you would use parallel arrays:

  • arrays is the only data structure you know or "should" know depending on how far you in the programming course. If that is the case make sure to clearly spell out in the question, especially if assignment in question calls for using arrays.
  • your specific case shows significant benefits of using parallel array to store the data. Add reasoning and, ideally, performance measurements to the question. Expect alternative suggestions to represent the data as valid answers.
71 questions
6
votes
4 answers

Why use parallel arrays in Java?

Is there any real use case for parallel arrays in Java? It seems too cumbersome to maintain N arrays which are interrelated. Example: int ages[] = {0, 17, 2, 52, 25}; String names[] = {"None", "Mike", …
zengr
  • 38,346
  • 37
  • 130
  • 192
5
votes
5 answers

Looping over parallel arrays that are different lengths

I am a begginer and this is my first question. I've scoured the net for answers and I am coming up short. Any help any of you can provide will put a smile on my face!! I am writing a program that loops over two arrays simultaneously. These are char…
dmitrivada
  • 51
  • 1
  • 3
3
votes
2 answers

Searching a Parallel Array in Python

This is a homework question, I got the basics down, but I can't seem to find the correct method of searching two parallel arrays. Original Question: Design a program that has two parallel arrays: a String array named people that is initialized with…
paradd0x
  • 675
  • 8
  • 15
3
votes
1 answer

Bubble Sort Parallel Array

I need to read and load a data file into 2 arrays (1 parallel). The data consists of a list of 100 integers (ID#) that correspond with a double(Price) that look like this: [ID] - [Price] 837 - 14.88 253 - 65.12 931 - 11.96 196 - 20.47 I need to use…
2
votes
1 answer

creating a list of books in Javascript

I'm having a problem trying to sort the booklist I'm creating for an assignment. The titles of the books are supposed to move with the dates and be sorted from oldest to newest after clicking the button. However, I don't know why Don Quixote and…
user16505746
2
votes
1 answer

Preferred way of processing this data with parallel arrays

Imagine a sequence of java.io.File objects. The sequence is not in any particular order, it gets populated after a directory traversal. The names of the files can be like…
Geo
  • 93,257
  • 117
  • 344
  • 520
2
votes
2 answers

What are the differences between parallel and multidimensional arrays

//Ask the user to start the program (the outer loop) output “To begin, enter Y or y. To end the program, enter the letter N:” input getUserDecision // If the user enters Y or y, the outer loop begins while (getUserDecision = “Y”) OR…
Will McKenzie
  • 21
  • 1
  • 8
2
votes
4 answers

How do you remove an elements from three parallel arrays of the same index in java?

I need to have user input the name they would like to have removed then find the index of in the array that, that name is held. Then I need to remove the name along with the price and rating. I may only use parallel arrays. I'm not sure if they…
DarthKiro
  • 31
  • 3
1
vote
2 answers

Instantiate an ArrayList of Circles

so the question basically says to Use a for loop to add 10 Circles to the ArrayList each with a random radius in the range of 2-5 and Print a table of all of the Circles in the ArrayList. You can use System.out.println(String.format("%.3f",…
1
vote
3 answers

Using Parallel array Show highest sales value, and the month in which it occurred

I'm trying to display in the Message dialog on the JOptionPane the highest number of sales from my array of sales. And I also want to show in which month they happened, but I am failing to find a way to display the month. public static void…
1
vote
1 answer

Is MPI_Gather compulsory after MPI_Scatter?

Is MPI_Gather compulsory after MPI_Scatter or can we just scatter and leave data on the nodes. I scattered a 2D array and counted the evens and odds. the program is working fine without gather. I think since gather only returns the scattered items,…
1
vote
1 answer

Implementing an insert function onto array implementation of Binary Search Tree

I am attempting to use the functionality of Binary Search Trees without actually create Node objects and giving them left/right children and instead using the basic idea of a Binary Search Tree within three parallel arrays: left, data, and right. At…
WeekendJedi
  • 67
  • 10
1
vote
1 answer

Simple array operation in parallel using julia

I am working on a project which include some simple array operations in a huge array. i.e. A example here function singleoperation!(A::Array,B::Array,C::Array) @simd for k in eachindex(A) @inbounds C[k] = A[k] * B[k] / (A[k] +B[k]); end I try…
1
vote
0 answers

Displaying desired range of a parallel array

I'm relatively new to coding and need a little bit of help with a homework problem. I have gotten pretty far in the problem, but I am struggling to display only the desired range in my output. My code runs well, but it just isn't giving me the…
luhook04
  • 21
  • 2
1
vote
1 answer

How would I approach Parallel Arrays to store different types of information in java

I have the following task which is that: There may be up to ten teams. Parallel Arrays are used to store the team Names, as well as to keep track of the number of Wins, Overtime Losses, and Points. After the result for the last team is entered,…
user13477443
1
2 3 4 5