Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
65 views

so im trying to make a mergesort for list with tuples, but no matter what i look at i dont see anything wrong with the implementation im doing. But still @tailrec is not being detected by Scala for ...
JokerFever's user avatar
0 votes
3 answers
122 views

I'm looking to implement a tail-recursive function to calculate the binomial coefficient of two numbers n and k. If k > n then 0 should be returned. Similarly if n == k or k == 0 it should return 1....
Jonas Jacob Biermann's user avatar
1 vote
1 answer
67 views

I'm currently taking an undergraduate course in functional programming, and we just learned about environments in Scheme. From what I understand, an environment is the context in which a function is ...
Martician's user avatar
2 votes
1 answer
119 views

I'm compiling a simple C program, implementing an inorder tree traversal function: void inorderTraversal(struct TreeNode* root) { if (root == NULL) { return; } inorderTraversal(...
Fish Toucher's user avatar
1 vote
0 answers
76 views

I have this active pattern: [<return: Struct>] let (|Integer|_|) self = let rec loop acc (isNegative: bool) self = match self with | C(digit, tail) when (...
Gabriel's user avatar
  • 11
-1 votes
1 answer
96 views

I am learning about different recursive approaches for reversing a linked list in C++. I have implemented both head and tail recursion methods, but I'm unsure about their differences and which one is ...
Aman maurya's user avatar
0 votes
0 answers
34 views

I am working on a practice problem and I have found a recursive solution. However, I can't figure out how to express the solution as tail recursion. I think that the issue that I am having can be ...
David Moneysmith's user avatar
3 votes
1 answer
107 views

I solving the problem of "Best-time-to-buy-and-sell-stock" at leetcode https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/ with 2 approaches: With first, I ...
Jelly's user avatar
  • 1,434
2 votes
1 answer
129 views

In the paper Stack Safety for Free, Phil Freeman defines the MonadRec type class as follows. class (Monad m) <= MonadRec m where tailRecM :: forall a b. (a -> m (Either a b)) -> a -> m b ...
Aadit M Shah's user avatar
  • 74.5k
0 votes
1 answer
229 views

UPDATE 2024.03.16: Provided code that produces the correct output, but is still not tail-recursive. How can I create a tail recursive merge method in Scala on a self-referential tree structure (or is ...
chaotic3quilibrium's user avatar
0 votes
0 answers
85 views

Here is my function: <func:function name="entry-check"> <xsl:param name="bunch"/> <xsl:param name="history"/> <xsl:param name="index&...
Ivanhou's user avatar
  • 11
2 votes
3 answers
122 views

In the following code, all calls to retry get the warning "Recursive call is not a tail call": private tailrec suspend fun <T> retry(numberOfRetries: Int, block: suspend () -> T): ...
david.mihola's user avatar
  • 13.1k
0 votes
1 answer
55 views

I need a tail recursive function that appends a list1 infront of list2. I tried it this way let rec append lst1 lst2 acc = match lst1 with | [] -> acc @ lst2 | hd::tl -> append lst1 tl (...
J.B's user avatar
  • 25
0 votes
1 answer
99 views

I'm using an example of adding two linked lists together from leetcode. The lists are in reverse order and the resulting list must be reversed as well. My code is recursive and it's only faster than ...
ATL_DEV's user avatar
  • 9,658
3 votes
0 answers
196 views

I have an algorithm using deep recursion (20 seconds). Perl complains and I shut it up with "no warnings 'recursion'". I change it to tail recursion (32 seconds) in the hope that it will be ...
Chan Tai Man's user avatar
1 vote
1 answer
61 views

This actually comes from me initially misreading the text of Exercise 1.12. The request is indeed to Write a procedure that computes elements of Pascal's triangle by means of a recursive process. I ...
Enlico's user avatar
  • 30.2k
-1 votes
2 answers
82 views

public int removeMin(Integer[] arr, int count) { Integer[] tempArr = new Integer[arr.length -1]; int index = 0; for (int i = 1; i<arr.length; i++) { tempArr[index] = arr[i] ...
ansh87's user avatar
  • 3
0 votes
2 answers
98 views

The advantage of tail recursion is that we call the function (recursion) again in the last action of the code, so the stack variables doesn't need to be saved. So here do this will act the same? and I ...
Daniel Zaken's user avatar
1 vote
3 answers
76 views

I have an array of classes: const transferClasses = [ { id: "c5d91430-aaab-ed11-8daf-85953743f5cc", name: "Class1", isTransfer: false, children: [], }, { ...
ko1p's user avatar
  • 37
0 votes
1 answer
143 views

Searching tail recursion on the internet I stumbled on How does compiler know whether the recursion is a tail recursion or not and how does it optimize tail recursion. If I understand correctly then ...
duong_dajgja's user avatar
  • 4,276
1 vote
1 answer
113 views

I'm new to Python and recursion is a foreign thing to me. For my assignment I have functions that involve tail recursion, a while loop, or a generator as specified by _t, _w, or _g if the function ...
mamelody's user avatar
1 vote
0 answers
75 views

I have this program: #include <iostream> #include <vector> int foo(std::vector<int> bar) { if (bar[0] == 0) return bar[0]; else { bar[0] -= 1; ...
justANewb stands with Ukraine's user avatar
0 votes
1 answer
270 views

The goal is to remove the last node of a linked list. (Python) The code that I have written only added to the list instead of taking the tail away. I'm not sure if the error is coming from this part ...
BRN's user avatar
  • 1
1 vote
2 answers
509 views

I wrote this simple function to append an element to the end of a list recursively: --takes arguments x and lst and appends x to the end of list append1::a->[a]->[a] append1 x [] = x:[] append1 ...
floxam's user avatar
  • 25
4 votes
2 answers
318 views

I'm currently writing an auto-grader for a Haskell course. For the section on "tail-recursion", I need a way to automatically and safely detect whether a given Haskell function is tail-...
Mobin's user avatar
  • 49

1
2 3 4 5
28