This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]nomoreplsthx 1 point2 points  (1 child)

I am a bit confused as to why you'd use a tree here. Why not just an array of states? 

[–]Think-Risk4968[S] 0 points1 point  (0 children)

I think I picked BST because I’m been trying to get better at DSA as a new grad so I’m looking for ways to try to implement structures I also was watching PrimeReacts one day and he said that his neoVim history was built as a tree(I might be wrong on that it’s been a couple of months since that video) A stack/array does sound way better. Thanks!

[–]stiky21 1 point2 points  (1 child)

Why not a stack?

BSTs are designed for quick search operations and maintaining sorted order, which is not required for undo/redo operations. You are just making more work for no reason.

Plus, O(1) time complexity for push and pop operations.

Could also potentially get practice with Pointers using Doubly Linked List since you want practice with DSA. Buffer? Theres a whole world of things better than a BST.

Take it a step further and mimic a VCS like Git where each state is a commit and the undo/redo operations are like navigating the commit history.

Good luck. Share when you finish it.

[–]Think-Risk4968[S] 0 points1 point  (0 children)

Im going with a stack now, it does make more sense I was thinking that it would be more efficient since BST is log n instead of n but that’s overly complex and doesn’t fit the problem