VROOM_VARUN's blog

By VROOM_VARUN, history, 7 weeks ago, In English

Hey there, :)

Normally whenever I am working on a task requiring a segment tree or some similar data structure problem, and my code does not work, I find myself at a loss for what to do because it seems kind of hard to tell whether or not the segment tree is working properly or not...

I wrote this quick function to print a somewhat simple segment tree, but it feels rather ugly, and I don't think it would be feasible for more complex data structures.

Print_seg function

Do you have any functions/scripts that you use to debug data structure problems, and if so, I would appreciate it if you would share it in the comments :p

 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

You can print as u recurse in the SegTree query?

»
7 weeks ago, # |
  Vote: I like it +6 Vote: I do not like it

There is definitely no way that fits all. I’d say, try to actively think what you are looking for while debugging and output that. I know that one thing I do often is print the aggregates over the whole tree (the “implicit array”) at each step. This usually makes it easier to assert the correctness, due to the flat representation. However, it works for some applications and not for others.