find values on parallel array recursively

parallel arrays java
parallel arrays javascript
parallel arrays quizlet
how to sort parallel arrays in python
parallel arrays vs 2d array
which of the following is an advantage of using parallel arrays?
parallel arrays java stack overflow
parallel arrays visual basic

I need to write a recursive method that takes two parallel arrays and the word to find, look for the word specified and sum the values of each time the index matches on the other array. For example:

array1 = "Toyota", "Honda", "Honda", "Toyota", "Toyota", ......n

array2 = 22500, 18000, 29000, 22500, 32000, ....... n

If I say that I need to look for the word "Toyota", it should sum the values on the second array anytime it finds the index. In this case, it should sum, 22500+22500+32000.

How can I make my recursion method so it takes the appropriate parameters and makes the calculations recursively. I will be using hard coded values.

This is what I have so far. I'm pretty sure my recursive method needs more parameters, but i'll see if somebody can help me

static int printRecursively(int A[], int N) {
        if(N <= 0) {

            return 0;


        return (printRecursively(A, N - 1) + A[N -1]);


Start with a "cursor" at position 0. Then return the sum of the number at that position and whatever sum is returned from the same method call with cursor value as cursor+1. If there is nothing at cursor+1, that means you have reached the end of the array, in which case just return the number at that position.

public static void main(String[] args) {
    String arr1[] = new String[]{"Toyota", "Honda", "Honda", "Toyota", "Toyota"};
    int arr2[] = new int[]{22500, 18000, 29000, 22500, 32000};

    System.out.println(getSum(arr1, arr2, "Toyota", 0));

private static int getSum(String arr1[], int arr2[], String word, int cursor) {
    if (cursor == arr1.length - 1) return arr1[arr1.length - 1].equals(word) ? arr2[arr2.length - 1] : 0;
    return arr1[cursor].equals(word)
            ? arr2[cursor] + getSum(arr1, arr2, word, cursor + 1)
            : getSum(arr1, arr2, word, cursor + 1);



find values on parallel array recursively, which of the following is an advantage of using parallel arrays? parallel arrays java stack overflow parallel arrays python w3schools. I need to write a recursive  its not okay! your code will not find the maximum element in the array, it will only return the element that has a higher value than the elements next to it, to solve this problem,the maximum value element in the range can be passed as argument for the recursive method.

I don't think your current data structures are optimal for this problem. Instead, I recommend using a hashmap of cars to values:

Map<String, List<Integer>> map = new HashMap<>();
List<Integer> values = Arrays.asList(22500, 22500, 32000);
map.put("Toyota", values);
values = Arrays.asList(18000, 29000);
map.put("Honda", values);

Then, to get the sum of values for a given car, we can easily use a stream:

int sum = map.get("Toyota").stream().reduce(0, (a, b) -> a + b);

Generally speaking, a good way to approach this is to represent the data where the car is a key, and the values are to what that key is pointing.

Parallel Array, Search for the value of the required attribute in the respective array (e.g. search for values greater than 200 in the above example) using either of the linear search/  Recursively find the minimum according to the following: Recursively traverse the array from the end. Base case: If the remaining array is of length 1, return the only present element i.e. arr [0] if (n == 1) return arr [0]; Recursive call: If the base case is not met, then call the function by passing the array of one size less from the end, i.e. from arr [0] to arr [n-1].

Something alike the following may suit your needs

public static int recursiveSum(String search, String[] names, int[] values, int start) {
    // Check that the two arrays are of the same length
    // And that start does not exceed the bounds of either
    if((names.length != values.length) || start > names.length)
        return 0;

    // If the value at the 'start' of the array is the one we're looking for
    if(names[start].equals(search)) {
        return values[start] + recursiveSum(search, names, values, start + 1);
    } else {
        // Otherwise just skip onto the next value of the arrays
        return recursiveSum(search, names, values, start + 1);

recursiveSum("Toyota", names, values, 0)

Recursive program to linearly search an element in a given array , Program to find the minimum (or maximum) element of an array · Recursive program to print formula for GCD of n integers · Recursive program to print triangular  Find Sum of Array Elements using Recursion – Java Code. Now, we know how to calculate sum using iterative approach. Let’s try to calculate the sum using recursive approach. To solve this problem recursively, I have created one method calculateSum(). It takes two argument one is array and the second is the length of an array.

Proceedings of the Fifth ACM SIGPLAN International Conference on , E (value recursion) Products (-, -)ag) : o – 3 + ox 3 fstag) :: or x 3 -> or sndo.8) :: a (a +3) → Y Parallel Arrays repo) :: ox Int—[a]] – replication lena) :: |a| – Int to find an efficient flattened representation for recursive data structures, and thus,  Here, we develop C and Java code to find the maximum element in an array using recursion. We develop a method revursiveMax that takes an array arr storing n integers, where n >= 1 and returns the maximum element in arr. Following are the Java and C codes respectively to find the maximum element of an array using recursion.

Can recursion be done in parallel? Would that make sense , In general, you want to parallelize only "embarrassingly parallel" tasks. NET are designed to automatically figure out how much parallelism is efficient; you choice, because the input values complety depend on previously calculated results. It sorts an array by doing the following: If the array is small then sort it using  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Recursive sum of an array in C [duplicate]

Recursion, For factorial(), the value of n decreases by 1 for each call, so the Now we describe a recursive formulation that enables us to find the Solution: GrayCode​.java uses Java's string data type; uses a boolean array. Note: some visual artifacts are noticeable parallel to the x and y axes. @AnimeaAnimea if you are going to print the array after putting values in it then you are going to print the values in it. you've put the values "2" and "3" in the array so if you want to print them, print them. if not, delete them. you can't save the values in the array and expect they won't be there – No Idea For Name Sep 2 '13 at 13:32