What can be best suited data structure that supports the following operations in O(log n) time:
search(x) finds the element with key x
insert(x) insert an element with a key x
delete(x) delete an element with a key x
deleteLast() removes the most recently inserted element
I know that a binary search tree can handle first three operations pretty good. But how to handle fourth query. If BST is not a good solution than also tell what can be best suited data structure for handling all four queries.
Simply you can maintain a separate temporary pointer to the parent element of the most recently inserted node.This pointer can be used to delete the most recently inserted element.
I hope this may help!