• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Binary Search Tree and Database

 
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
I'm currently working on a personal project that addresses programmers who want to share their skills, I decided to implement Binary Search Tree on the project in order to offer the end-user search operation whether using programming language or framework, more specifically, how I intermingled BST and data stored on database to offer the the end-user search operation
could anyone gives me some hints or guide me to achieve this operation
 
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You first need to tell us what you've already tried and what you're stuck on.
 
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and remember, we don't use the word “urgent”
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:...and remember, we don't use the word “urgent”



Sorry, I didn't know that

Thanks
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:

Stephan van Hulst wrote:You first need to tell us what you've already tried and what you're stuck on.



I want to implement the binary search tree in my current project, I want to use BST as the engine of the project's search page that offers to end-user to perform search operation whether based on a programming language or framework, more specifically, the end-user enter a keyword such as Java, Python, or  JavaScript then the page will show up all programmers that have been already subscribed and choose Java programming language as a primary language and vice versa (similarly to framework keyword)



 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't use the quote button all the time; that simply duplicates old information which we have to delete.
Your requirements are confused; you are mixing what you want to do and how you want to implement it. Please have a look at this FAQ.
 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You first need to tell us [...] what you're stuck on.

 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently building a personal project, more specifically, a website that offers an ability to programmers around the world to register and share their skills such as the programming language that codes with or framework, furthermore, tech companies are able to access the website (I named programmer) and looking for the programmer based on a programming language or frameworks keywords, in other words, the end-user (tech companies) enter a keyword in the search page like "Java" and therefore it exhibits the result that end-user looking for

I stack on implementing binary search tree as the engine of the search page to allow the end-user to do search operations like searching for a programmer who knows coding using Java Language, or other languages

NB: I can achieve this search operation using MySQL

 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:I stack on implementing binary search tree as the engine of the search page to allow the end-user to do search operations like searching for a programmer who knows coding using Java Language, or other languages


You must have a reason to think that a BST is going to be a good data structure for your search engine. Why? How is it supposed to work according to you? What are the nodes of the tree and how will you perform the search.

If you're sure that this is the correct data structure, then what problem are you having with implementing it? And why do you want to write a custom implementation instead of relying on, for instance, TreeMap?

NB: I can achieve this search operation using MySQL


I'm confused. Do you now want to perform the search in your database or do you want to implement it server-side?
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan,
The main reason behind implementing a BST, however, it offers many advantages in terms of performance

I don't know how can I store retrieved data in BST in order to offer the end-user fast searching

I've been tried some approaches. The following lines demonstrate how I did it in my current project,


the domain package has a bean class named User




the Controller package has a class named SignUPServlet

I - the first approaches that I've tried



the DSA package has classes that define the functionalities of the BST data structure, such as inserting, find, delete

the issue that I encounter, I want the end-user to perform search operation based on String, for example, let us assume that the end-user wants a programmer that programming with Java language, the end-user type "Java Language" on the search box therefore the result page will exhibit all programmer that programming with Java Language, in the above illustration, the definition of the BST that I've written below, the end-user should type a number that should exists in BST to return the result



I think writing these lines will offer a fast insertion to my  database, in addition, the data stored in my database as well as BST to perform search operations on the search page as I've been explained above


What do you mean by implementing it on the server-side?
I'm wondering what is the purpose of algorithm and data structure? Shall we use Algorithm and Data Structure on Java Web Application?
How do I implement BST for example in my current project?
is it true that Algorithms and Data Structure are used for programming a database management system?

 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:. . . a BST . . . offers many advantages in terms of performance

And, in this case, many disadvantages in terms of functionality.

I don't know how can I store retrieved data in BST in order to offer the end-user fast searching . . .

Doesn't that show that a BST is the wrong data structure?
Did you read the FAQ I showed you? You aren't describing the functionality you want. You start off with functionality, and within a sentence or two, you have changed to implementation details. You have chosen the wrong data structure and now you are trying to mould your app to fit that data structure.

Don't try storing passwords as text; that is a sure‑fire recipe for being hacked.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've read the link that you've sent above

I think that I've explained what I'm going to do above and give this concrete example to clarify the idea

the example above is a tiny example to illustrate or demonstrate the idea that I want to implement in the project
 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:What do you mean by implementing it on the server-side?


I meant that you're using the BST to store the users in the server that hosts your web application, as opposed to the database.

I'm wondering what is the purpose of algorithm and data structure? Shall we use Algorithm and Data Structure on Java Web Application?


Not sure what you're asking here. All applications are written using algorithm and data structures. Are you referring to anything specific?

How do I implement BST for example in my current project?


You are asking the wrong question. You're asking "How can I use a hammer to chop down a tree?". Instead you should be asking: "I want to chop down a tree, what tool do I use?".

is it true that Algorithms and Data Structure are used for programming a database management system?


I'm not sure why you're writing "Data Structure" and "Algorithms" in capital letters, as if it means anything special. When you write a type that contains some fields, that's a data structure. When you write some statements that perform some operation, that's an algorithm. As I said before, ALL applications are written using algorithms and data structures.

Now, let's take a step back. You have a big problem: You're designing your application from the bottom up. Instead, you should be taking a top-down approach: Start with an high-level design and stop worrying about the details.

I can tell you now that storing users in both a database and in-memory is a bad idea. It doesn't make sense, and even if it did, it's going to give you a lot of headache in keeping the two synchronized. You need to make a choice: Do you want to store your users in a database, or do you want to store them in-memory?

Normally with a web application you store everything in a database and do searching and sorting there, but seeing as you want to practice/demonstrate low-level algorithms, maybe this time you can store your users in an in-memory database of your own design.

That's the thing though, start with a design. Stop coding. Stop thinking about binary search trees. Start explaining what a service that stores users for your application would look like from a high abstraction level and what operations you would want such a service to perform. After you've done that you can write a service contract. Test your service contract by making a simple implementation that uses the standard API without writing everything from scratch. When you're convinced that your design works, only then start thinking about how you can replace the implementation with low-level code of your own.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm wondering what is the purpose of algorithm and data structure? Shall we use Algorithm and Data Structure on Java Web Application?


Not sure what you're asking here. All applications are written using algorithm and data structures. Are you referring to anything specific?

I mean at what is the practical use of binary search trees? I want to give me a concrete example or list the cases that should necessary to implement these data structures that aren't built-in in the Java language


Is it possible to use a binary search tree in a java web application? how shall I achieve that?

As all know that circular linked list is used in music play applications to give an ability whether to iterate backward or forward through the list of music that the application offers, my question is how do I implement a certain data structure and its function to my application?

Now, let's take a step back. You have a big problem: You're designing your application from the bottom up. Instead, you should be taking a top-down approach: Start with an high-level design and stop worrying about the details.



I've completed all tasks of the project that I'm working on, the last step is that we talk about it now

do you want to store them in-memory?


No, I won't

Normally with a web application you store everything in a database and do searching and sorting there, but seeing as you want to practice/demonstrate low-level algorithms, maybe this time you can store your users in an in-memory database of your own design.


I asked a person about the purpose or the goal of the algorithm and data structure and where do we implement them, "algorithm and data structure are used to program a database management system" said


Shall you give me a concrete example of the usage of algorithm and data structure that we've been talked about it till now? if you know some projects that integrate Graph, Tree on GitHub?


Thanks Stephan for your reply, I appreciate it
 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following lines will explain what I want to achieve,

Actually, I'm building a web project that refers programmer community who can register and share their skills, the only task that remains on the project, it's the search page that will be used by the end-user to perform search operations whether using programmer language or frameworks keywords, the issue that I've been faced while I'm trying to fix this issue, I want to use binary search tree as the engine of search operations on the search page, that's mean, how do I build a bridge between stored data in MySQL and Binary Search Tree?, more specifically, I want the binary search tree performs search operations on the stored data in MySQL, all these has one meaning, the stored data in MySQL should be the same in BST, the following lines demonstrate that:

bst.insert(bst.nItems(), new User(firstName, lastName, email, password));

I've tried some approaches, the first one, I've tried to store simultaneously on binary search tree (using insert() method) and MySQL, Moreover, I stored data in the first test (tab), and its successfully registered on MySQL and printed on the eclipse's console, however, when I tried to store a different data on the same data I spot that the first data vanished, in addition, the BST's print() method prints only the last data that has been registered

The question rolls up on my mind, it's how I build a bridge or a stream that assumes the flow's data that floods out in the MySQL it will be the same data in BST?

NB: I decided to use a binary search tree as the holder for the data because it either offers fast searching and insertion
 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:. . . the stored data in MySQL should be the same in BST, the following lines demonstrate that:

bst.insert(bst.nItems(), new User(firstName, lastName, email, password)); . . .

No, your previous discussion demonstrated that is incorrect.

I think this post is best merged to your old thread.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Houssam El wrote:. . . the stored data in MySQL should be the same in BST, the following lines demonstrate that:

No, your previous discussion demonstrated that is incorrect.

I think this post is best merged to your old thread.



What do you mean by "incorrect"?
is it whether impossible or possible to achieve it?
 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have already been told you will have synchronisation problems between the database and the tree. You should also not make fast performance your principal goal. Remember you have delays with networks and people typing into their browsers; the 0.1μs you might save with a faster data structure will be completely overwhelmed by the second or so it takes to get from the user's hand to your data structure.
 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:The question rolls up on my mind, it's how I build a bridge or a stream that assumes the flow's data that floods out in the MySQL it will be the same data in BST?


You don't.

You should have one authoritative source of data. Either your MySQL database, or something you built yourself in-memory using your own tree data structure. I'm sorry if that's not what you want to hear, but it's the fact of the matter.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:. . . one authoritative source of data. . . .



Then, I will use MySQL

can you guide me on how I can use in-memory in order to use my own tree data structure?
 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please start by writing a description of what the tree is supposed to contain, and how its contents are to be ordered.
 
Houssam El
Ranch Hand
Posts: 177
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please start by writing a description of what the tree is supposed to contain, and how its contents are to be ordered.



I'm so sorry Campbell, I've made such mistakes that push you to correct my posts while I was writing these posts

the following lines will explain what I want to achieve,

Actually, I'm building a web project that refers programmer community who can register and share their skills, the only task that remains on the project, it's the search page that will be used by the end-user to perform search operations whether using programmer language or frameworks keywords, the issue that I've been faced while I'm trying to fix this issue, I want to use binary search tree as the engine of search operations on the search page, that's mean, how do I build a bridge between stored data in MySQL and Binary Search Tree?, more specifically, I want the binary search tree performs search operations on the stored data in MySQL, all these has one meaning, the stored data in MySQL should be the same in BST, the following lines demonstrate that:

bst.insert(bst.nItems(), new User(firstName, lastName, email, password)); // I know it's incorrect

therefore it fails

I've tried some approaches, the first one, I've tried to store simultaneously on binary search tree (using insert() method) and MySQL, Moreover, I stored data in the first test (tab), and its successfully registered on MySQL and printed on the eclipse's console, however, when I tried to store a different data on the same data I spot that the first data vanished, in addition, the BST's print() method prints only the last data that has been registered

The question rolls up on my mind, it's how I build a bridge or a stream that assumes the flow's data that floods out in the MySQL it will be the same data in BST?

NB: I decided to use a binary search tree as the holder for the data because it either offers fast searching and insertion
 
Campbell Ritchie
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, but that doesn't tell us anything new. you have told us everthing already once.
Why do you need a second data structure apart from the database? As far as I can see, that will achieve two things:-
  • 1: Make your program more complicated than it need be, and thereby more error‑prone.
  • 2: Introduce the risk of having new data in one place and stale (old) data in another place.
  • Databases are designed specficially for that sort of query; once a query has been run one it will probably be indexed, and similar subsequent queries will run very quickly.
     
    Houssam El
    Ranch Hand
    Posts: 177
    2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi
    I give up   I will delegate this task to the database
     
    Campbell Ritchie
    Marshal
    Posts: 74048
    332
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank goodness!
     
    I'm sure glad that he's gone. Now I can read this tiny ad in peace!
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic