Debugging Recursive pathfinding

How do you guys debug recursive pathfinding routines? I can't keep track of what depth and branch or path I'm in. I'm a beginner in recursive functions in general, do any of you know of a helpful trick?

Attached: 1629482464307.jpg (1080x1038, 217.79K)

put a print statement at the start of the function that shows the current state of the variables. you might be able to find out what's wrong from that. if not, just add more print statements

Pen and paper.

std::swap(a, b);

>dequan
boy, did his mother pull a boner on him

wtf is that magic trick there
i thought you could only do it the a = b + (b = a) - a way

alright that image was pretty damn funny. But yeah to answer your question just use a debugger on and step through a small graph. You're pathfinding using recursion so i guess its DFS? DFSing an arbitrary graph is like 5-10 loc. Shouldn't be that hard to debug a small graph.

Is this b8?

both retarded you should be using XOR XOR instead so you don't overflow

Make unittests for your algorithm and and reduce the input size to a few nodes that test various scenarios e.g

- Handling a cycle
- zero nodes
- 2 Branches
- 2 Branches but they're linked at depth 2

etc

If you're trying to debug it on the large input its going to be a bitch. Also consider using an iterative implementation with a stack so that you don't have to jump through all the call stack frames / for performance in general.

printing as a method to visualize the tree is also a good / quick approach.

if the interviewer doesn't care what language just say
a,b = b,a
it's correct in many and won't get you hired or fired

faster ways of doing
a ^= b
b ^= a
a ^= b
?

bruh

(a, b) = (b, a)

guess the language

Python?

Waterloo

>Daquan
>Fired

user, you've been called to HR for creating a hostile work environment to underrepresented minorities

>Oh no, using a THIRD variable, which requires more MEMORY!!!
>Use nigger retarded XOR stuff because MUH PERFORMANCE
>More memory impacts muh CPU cache PERFOMRANCE by 0.1 ns.
>Must only use TWO VARIABLES to SWAP Jhrheakfuueigvboizsduzious! Gd code, gud programmiiiing! Only use two ONLY, SIRS!!!

God, I love OCD programmers.

Attached: pepesmirky.jpg (474x385, 24.73K)

this creates two extra variables

>recursive
that's the problem. recursivity when the cpu design goes against it is a mental illness.
you must only use two registers, eax = a, ecx = b.

how often are you swapping variables in practice? Can't think if when I've ever need to do this

it does not require more memory

>reusing variables
I shiggy diggy

just print the depth you fucking retard