Skip to main content

Command Palette

Search for a command to run...

Introduction to Backtracking

Updated
1 min readView as Markdown

Backtracking is “Recursion + Pass by Reference + Undoing the change after function call”

Pseudo Code:

void backtrackingFunction(...params){
    if(invalid) return;
    if(valid){
        ans.push(value);
        return;
    }

    --- Do the operations --- 
    Must pass the params by reference which are being updated

    backtrackingFunction(...updatedParams);

    --- Undo the operations ---
}