Recurrence and if-else statement

I am new to programming. I am trying to use recursion and if-else statement only to print the 99 beers lyrics. Here is my code. How can I make it better to print the lyrics well. The method countdown prints the lyrics while countdownB should print th

Convert a for loop to a java recursive method

I'm trying to convert this loop to a recursive method. This iterative version works: (recursive attempt comes after that) public static int subCompareTwoCol(JobS j1, int index1, int index2, int indexTab1){ //Almost same method as above but with modif

Recursive implementation of the binary python search tree

I'm trying to implement Binary Search tree in python using recursion. I got trapped in some infinite recursions happening in my program.I'm making recursive calls to the function RecursBST by passing address and the data until the top traverse down t

How to calculate the number of recursive calls in Java?

I was using the below given method to calculate height of a binary tree, int height(Node root) { if (root == null) return 0; else { int lheight = height(root.left); int rheight = height(root.right); if (lheight > rheight) return(lheight+1); else retu

Check the ascending order of a list in Racket

I'm new to racket and trying to write a function that checks if a list is in strictly ascending order. '( 1 2 3) would return true '(1 1 2) would return false (repeats) '(3 2 4) would return false My code so far is: Image of code (define (ascending?

Need help finding the second largest number in a list. Racket

I've been struggling with this question for a lot now. Could someone please explain the logic behind the program by using the simplest way possible possibly recursion? Thank you.Have 2 variables (say x and y) Move through the list of numbers Keep lar

Recursive tail function for sum of fractions

I am trying to convert this recursive function into a tail recursive function def sumOfFractions(n: Int): Double = { require(n > 0, "Parameter n has to be greater than 0"); if (n==1) 1.0 else 1.0 / n + sumOfFractions(n - 1) } I thought that t

Complicated recursive function

I need to write a function nested_sum(L) that will sum all the ints inside a list no matter if they are inside another list. This with calling recrusively to another function mult2(n). Example: >>> nestedSum(mult2( [1,['a',3,'b',2],[4,['h',8,[10]

Recursive function of program C

I have a small problem I want to build a function that returns with recursive function the nn expression with one parameter in the calling function. Can someone help me? My thought so far : int powerThroughRecursion(int n) { if (n == 0) { return 1; }

PHP PCRE allows nested patterns (recursion) in a string

I got a string like 1(8()3(6()7())9()3())2(4())3()1(0()3()) which is representing a tree. A bracket appears, if we go one level deeper. Numbers on the same level are neighbours. Now want to add nodes, for example I want to add a 5 to every path where

Recursive search for a substring in an array with strings

For the next array, the keys of each sub-array indicates the node-id (0) and category name (1) . What i am trying to do is to find the parent node-id for each sub-category. For example, the parent id for '3968976031' is '10176091' and the parent id f

T-SQL recursive query to display the nested tree structure

I have the following 2 tables: CREATE TABLE [Names] ( [Id] INT PRIMARY KEY, [Name] VARCHAR(100) ) CREATE TABLE [Relationships] ( [Parent] [int] REFERENCES [Names]([Id]), [Child] [int] REFERENCES [Names]([Id]) ) Sample Data: INSERT [NAMES] VALUES (1,'

using the recursive method for the trinary search

I am writing a recursive method that, instead of carrying out a binary search algorithm, splits an array into three and uses a trinary search algorithm. I am fairly positive that my recursive case is correct, yet there seems to be a problem with my b

Recursive C ++ fibonacci function

Below is my code. I tried to print the Fibonacci recursive function [at the very end] but it gave me segment fault. What is wrong with my code? I spent like 3 hours on this and couldn't figure it out. Can someone please be kind enough to give me some

Find a seg defect in the recursive code for successor inorder

Hey guys I'm just practicing recursive code on a binary search tree. I'm getting a seg fault but I'm not sure where the problem is (probably something stupid staring me right in the face). I have other functions that are working fine like counting th

Refactoring the recursive modifications of the tree

How can I refactor the following code: class ModifyTree{ public void doActionsOnTree(Tree tree) { rAction1(tree.getRoot()); rAction2(tree.getRoot()); } private void action1(Node node) { // do something with node; } private void action2 (Node node) {

Python: How to select all other elements in a for loop

Let's say I have: def recursive(data): for i in data: if condition: recursive(HERE IS THE ISSUE) How do I pass in the data from the current i to the final element in the list?Check out enumerate this will also return the current loop index which you

Update the manager table tree by recurrence

I have a table (see image) Employees (manager is manager of another and so on) with id, parentid, salary, totalsalary. The last one needs to be updated so that every employee had Sum of its Descendants salary. I have already written script, which get

Recursive explanation

Today in the class of Java the professor came up with this example but I really couldn't understand very well the process how to go through this method in order to get the result = 4. Could any body please put some lines as clear as possible how is t

Function with a variable number of For loops (python)

My problem is difficult to explain. I want to create a function that contains nested for loops, the amount of which is proportional to an argument passed to the function. Here's a hypothetical example: Function(2) ...would involve... for x in range (

C ++ recursion aid

I am having trouble with recursion. Can anyone show me how to get this into code form? given vector <int> with values 1,2,3,4,5,.. i want to write a function that compares all of the value with each other. i dont care about 1 != 2 being equivalent t

Find a binary tree and print valuable children

So I have spent many sleepless nights the last two weeks trying to work on what I thought would be a simple program: I am trying to create a Binary Tree from a list of integers in a specific file. The numbers are inserted into a binary tree. I then p