-
January 13th, 2017, 08:55 PM
#1
How properly implement search functionality?
Good Day to all Java Gurus!
Consider a tree data structure implemented by the following Java class:
public class Tree {
private List<Tree> leaves = new LinkedList<Tree>();
private Tree parent = null;
private String data;
public Tree(String data, Tree parent) {
this.data = data;
this.parent = parent;
}
}
I am trying to figure out how to implement search functionality using a method with the footprint: Tree firstMatch(Tree, Regex). This method takes a tree, searches that tree for leaves/branches in which the data matches the given regex expression and returns the first branch/leaf (another Tree object) that matches. I need to implement two different search algorithms: a Depth-First Search (DFS), and another search algorithm (anything better then DFS?).
Thank you for help
-
January 14th, 2017, 07:22 AM
#2
Re: How properly implement search functionality?
Norm
-
January 14th, 2017, 10:00 AM
#3
Re: How properly implement search functionality?
Hi Norm, thank you for response,
I know JS, PHP, but total Noob to Java
-
January 14th, 2017, 10:41 AM
#4
Re: How properly implement search functionality?
Ok, Time to start learning.
Do you have the steps for algorithms you want to implement in java?
Can you list the steps needed to build the tree to be searched? Start with that. You'll need the tree for the searches.
Be sure to wrap all posted code in code tags.
Norm
-
January 15th, 2017, 07:14 AM
#5
Re: How properly implement search functionality?
a Depth-First Search (DFS), and another search algorithm (anything better then DFS?
Another common search algorithm is Breadth-First-Search. See https://en.wikipedia.org/wiki/Breadth-first_search
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|