Category "recursion"

question regarding max value in an array with recursion in JavaScript

Currently, I was able to get the following function to retreive the max value from an array through recursion const max = ([a,...rest]) => !rest.length || a

How to use recursion to sum up a list of numbers up until a certain index

I have to write a code that makes use of recursion to sum numbers in a list up until the index is equal to a pre-determined integer value. i.e. list = [1,4,8,

How can i make for loop a recursive method

How can I make this code a recursive method? for (int i = 3; i < arr.length; i++) { writer.write(arr[i] + "\n"); strout += arr[i] + "\n"; }

Parsing recursive json, from markdown AST

Recursive functions are not my forté, and im pretty sure thats what is needed here. I have a nested json object, which represents a nested checklist It i

Can someone explain to me what is the details of line 5 return numberList[index] + sum(numberList, index - 1);

Can someone explain the syntax process? How line 5 will be implemented and what is the sequence for these three elements and what is the value each time in the

How to get the difference of two objects by subtracting properties, regardless of depth level?

I want to subtract the values of two objects of the exact same structure. Although one answer exists here, it's limited to objects of no-depth. In my case, I'm

finding the longest sequence of identical digits in an integer (Java)

I need to write a recursive method that takes an int as input and returns the longest sequence of identical numbers in it as an int (NOT as a string). counting

How do I understand this Recursion Base Code Problem

I'm learning the recursion concept in js, I got a very basic question of the base code returning problem. function factorial(n) { if (n === 1) { ret

How do I correctly memoize this recurrence relation?

I am solving a problem: Given a list of integers nums, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. Fo

Time/Space Complexity of Generating Parentheses [Java]

I am preparing a tutorial to solve the generating parentheses problem. (LeetCode #22) LeetCode mentions three different solutions but the third one looks confus

scala bubbleSort endless recursion

I am trying to get this implementation to work, tho it ends in an infinite loop. What am I missing? def bubbleSort(l: List[Int]): List[Int] = if(isSorted(l)) l

How to filter array of nested objects with unknown depth based on given search term

There are similar answers here but all of the ones I've seen and tested don't go pass two levels deep, so I don't think this is a duplicate problem...I am tryin

O(log n) algorithm in theory runs much slower in practice

The algorithm is for calculating 2^n recursively. I have used the Master theorem to determine that the time complexity is indeed O(log n) which seems to correct

Difference between += and = 1+ in Java

Me and my friend have been working on a problem for school. We are traversing a graph with DFS and are counting the number of nodes in each given component. We

How do I change this recursive approach to iterative approach?

This is a game function from pygame. If user press left (pygame.KEYDOWN.K_LEFT), angle -= 1. Else if user press right (pygame.KEYDOWN.K_RIGHT), angle += 1. 'Eve

Fill treeview from custom array of objects. Recursion call

I'm using treeview to display my hierarchical data. I have following array of objects: const data = [ { id: 1, hierarchyid: "/", level: 0, name: "Mhz" },

How I use return inside a recursive functions in php

I have a php recursive function as shown in the below: function displayDropdown(&$catList, $parent, $current=[], $level=0) { if ($parent==0) { foreac

Binary search with recursion c#

I got stuck with my binary search method and I don't really know what I'm doing. At this moment I got 1 Error (CS0161) not all code paths return a value int l

Confusion about recursion in a BST python

I am trying to understand the recursive call within the binary function is_bst. The goal of the function is to check if a tree is a binary search tree or not. N

How to check if all elements in an array are equal using recursion in Python?

I am practising recursion and am not sure why my code is failing. def isEqual(arr, n): if(n==1): return arr[n] return arr[n-1]==isEqual(arr, n-1