In my college, I learned how to define data structures like binary trees and graphs. We were made to write c++ programs that used to run and added nodes to the tree( that we told the compiler to add) . And once we were done adding nodes to the tree, we used to do lookups of different values to make sure our program was working... The code looked similar to the standard code for a binary search tree you could find on geeksforgeeks. But now I'm trying to build a website that helps students in finding details about the teachers of our college... The key here will be the numeric employee id of the teacher and I want to implement a binary search tree on the backend... And I can't figure out how to implement it.
One option that appears in front of me is to run a js script that defines a new tree from the linear array of teachers that I have right at the time when a request comes to the backend asking for a particular teacher's data. I will run the search function defined in my code after the tree is done being constructed and give the returned value as response to user...
But won't this be inefficient? Having to define a tree from array again and again just to return the result of one persons query? Isn't there a way to permanently store the tree and keep it ready to go for quickly answering every person's query?
Is there a way to store a tree in a quick access file or some way to keep the server ready to search entries?
How do I make a tree persist so that it stays ready for lookups when different users request data from it instead of having to run the tree construction code again and again?
How are these efficient data structures actually implement in applications like websites, software, etc. ?