Questions tagged [recursion]

The tag has no usage guidance.

11 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
210 views

Pset3 Tideman: lock_pairs skips middle pair if it creates a cycle

I'm having issues figuring out how to solve this problem without using recursion (I'm not sure how to solve things recursively). Its a program that determines the winner of a Tideman election and I'm ...
1
vote
0answers
735 views

Tideman lock_pairs recursion problem

I'm currently working on Pset3 Tideman and am stuck on the recursion part of lock_pairs function. I tried implementing an additional function to check for a cycle, and obviously, it's not working. ...
1
vote
0answers
2k views

Valgrind says “Invalid read of size 4” while freeing memory recursively in a trie

My PSET "mispelling" works fine and contains no memory leak but when I run the program with Valgrind it says Invalid read of size 4. My unload function calls a deleteTrie function which looks like ...
0
votes
1answer
13 views

How h increases while executing for loop. In lecture3 recursion example

#include <cs50.h> #include <stdio.h> void draw(int h); int main(void) { // Get height of pyramid int height = get_int("Height: "); // Draw pyramid draw(height);...
0
votes
0answers
49 views

lock_pairs skips final pair if it creates cycle

I have been working on the tideman problem from Problem Set 3. After multiple attempts, I have been able to pass all the required checks except one: "lock_pairs skips final pair if it creates ...
0
votes
3answers
2k views

I don't understand how the collatz(n) recursive function works

If you watch the short on recursion in week2 2018, Doug explains how calculate the steps for the collatz conjecture. I don't understand how the solution he proposes can work: int collatz(int n) { ...
0
votes
1answer
110 views

pset5 unload base case

I haven't written any code yet, although I've written pseudocode for this problem, and I keep coming back to the issue of base case. I built a trie and now want to recursively unload it. I think I've ...
0
votes
0answers
112 views

How can I write a recursive function if that function's parameter is void? - pset5 - unload

Per the specification, we are not allowed to alter the declarations of load, check, size, or unload in dictionary.c or dictionary.h. Yet in Zamyla's walkthrough for unload, if one implements with a ...
0
votes
1answer
197 views

Pset5 Unload - Recursion with Tries - Fails Valgrind with apostrophes

I'm getting a strange problem in my unload() code, or more specifically the freeNode() recursive function that unload() calls. I think I have the recursive part of the function nailed; once free(...
0
votes
0answers
52 views

Touching Color Issues, Recursion and Pseudo-randoms in Scratch

http://scratch.mit.edu/projects/42012966 Hello All, So I was trying to build this little recursive scribbler that makes random little networks of lines, basically like an ant colony but have run into ...
-1
votes
1answer
151 views

Because of calling recursive function don't do printf?

Because of calling recursive function don't do printf (bubble sort)? (actually only first time) #include <stdio.h> int* bubblesort(int n1, int arr[]) { for (int i = 0; i < n1 - ...