Skip to content

Commit a49bce2

Browse files
De La Briandais Trie
First commit for this project.
1 parent e47e805 commit a49bce2

File tree

13 files changed

+127137
-0
lines changed

13 files changed

+127137
-0
lines changed
67 KB
Binary file not shown.

De La Briandais Trie/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# De La Briandais Trie
2+
3+
The purpose of this project was to gain a better understanding of search algorithms and symbol tables by implementing an autocompletion engine. For more information on how to use the program as well as the actual files to run, check out the `doc/` and `src/` folders, respectively.
4+
5+
**Contact Information**
6+
7+
![interests](https://avatars1.githubusercontent.com/u/38919947?s=400&u=49ab1365a14fac78a91e425efd583f7a2bcb3e25&v=4)
8+
9+
Yogindra Raghav (YogiOnBioinformatics)
10+
11+
yraghav97@gmail.com
12+

De La Briandais Trie/bin/DLB.class

2.2 KB
Binary file not shown.

De La Briandais Trie/bin/Node.class

802 Bytes
Binary file not shown.
6.2 KB
Binary file not shown.

De La Briandais Trie/doc/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Classes
2+
3+
This project consists of multiple different classes including:
4+
5+
`Node.java`
6+
7+
A class that creates a Node of proper structure for a DLB trie (DLB.java uses this class)
8+
9+
`DLB.java`
10+
11+
The actual trie which maintains the dictionary and user history and is used by ac_test.java
12+
13+
`ac_test.java`
14+
15+
Main class that has user interface for users to enter words in and maintain their history of used words in a txt file
16+
17+
18+
**Contact Information**
19+
20+
![interests](https://avatars1.githubusercontent.com/u/38919947?s=400&u=49ab1365a14fac78a91e425efd583f7a2bcb3e25&v=4)
21+
22+
Yogindra Raghav (YogiOnBioinformatics)
23+
24+
yraghav97@gmail.com

De La Briandais Trie/doc/approach.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Approach
2+
3+
My approach to implementing the Symbol Table involved using Java.util.HashMap.
4+
I decided to use this because of how quick this data structure is.
5+
In terms of asymptotic run-time statistics, the methods get() and put() which I used frequently ran in O(1).
6+
Due to the speed of inputting and outputting data from this structure, I felt it to be the best for my project.

De La Briandais Trie/info_sheet.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
========================================
2+
CS/COE 1501 Assignment Information Sheet
3+
----------------------------------------
4+
5+
You must submit an information sheet with every assignment. Also be sure
6+
to submit all materials following the procedures described on the
7+
submission procedures page.
8+
9+
Name: Yogindra Raghav
10+
11+
Lecture section: D (W/27712)
12+
13+
Recitation day and time: Friday 12:00PM
14+
15+
Assignment #: 1
16+
17+
Program due date: 02/08/2018
18+
19+
Handed in date: 02/08/2018
20+
21+
Source code file name(s):
22+
ac_test.java
23+
24+
25+
26+
27+
28+
29+
Other file name(s) (if relevant):
30+
31+
Node.java
32+
DLB.java
33+
34+
35+
36+
37+
38+
Does your program run without error?: No errors
39+
40+
If not, what is/are the error(s) and which parts of your program run
41+
correctly?:
42+
43+
44+
45+
46+
Additional comments to the grader:
47+
48+
49+
50+
51+
52+
53+
54+

De La Briandais Trie/src/DLB.java

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import java.lang.*;
2+
import java.util.ArrayList;
3+
4+
5+
6+
public class DLB{ //DOES THIS NEED TO BE STATIC?????
7+
8+
ArrayList<String> returnStrings = new ArrayList<String>();
9+
10+
public Node root;
11+
12+
public DLB() {
13+
root = new Node();
14+
15+
}
16+
17+
public boolean add(String word){
18+
19+
char[] wordArr = word.toCharArray();
20+
Node thisNode = root;
21+
Node newNode;
22+
23+
for(int i =0; i<wordArr.length; i++){
24+
if(thisNode.bottomNode ==null){
25+
if(i == wordArr.length-1){
26+
newNode = new Node(wordArr[i], word, null, null);
27+
28+
}
29+
else{
30+
newNode = new Node(wordArr[i]);
31+
32+
}
33+
34+
thisNode.bottomNode = newNode;
35+
thisNode = thisNode.bottomNode;
36+
}
37+
else {
38+
thisNode = thisNode.bottomNode;
39+
if(thisNode.character!=wordArr[i]){
40+
if (thisNode.rightNode == null){
41+
if(i == wordArr.length-1){
42+
newNode = new Node(wordArr[i], word, null, null);
43+
44+
}
45+
else{
46+
newNode = new Node(wordArr[i]);
47+
48+
}
49+
thisNode.rightNode = newNode;
50+
thisNode = thisNode.rightNode;
51+
}
52+
else{
53+
while(thisNode.rightNode!=null){ //CHECK IF I NEED TO USE BREAKLOOP DURING TESTING
54+
thisNode= thisNode.rightNode;
55+
if(thisNode.character==wordArr[i]){
56+
break;
57+
}
58+
if(thisNode.rightNode==null){
59+
if(i==wordArr.length-1){
60+
newNode = new Node(wordArr[i], word, null, null);
61+
62+
}
63+
else{
64+
newNode = new Node(wordArr[i]);
65+
66+
}
67+
thisNode.rightNode = newNode;
68+
thisNode = thisNode.rightNode;
69+
}
70+
}
71+
}
72+
}
73+
else if(i == wordArr.length-1){ //CHECK THIS CODE RIGHT HERE!!!!!!!!!!!!!!!
74+
thisNode.value = word;
75+
}
76+
}
77+
}
78+
return true;
79+
}
80+
81+
public Node findNode(String prefix){
82+
char[] wordArr = prefix.toCharArray();
83+
Node thisNode = root;
84+
//thisNode = thisNode.bottomNode;
85+
86+
for(int i =0; i<wordArr.length; i++){
87+
thisNode= thisNode.bottomNode;
88+
if(thisNode.character!=wordArr[i]){
89+
while(thisNode.rightNode!=null){
90+
thisNode = thisNode.rightNode;
91+
if(thisNode.character==wordArr[i]){
92+
93+
break;
94+
95+
}
96+
if(thisNode.rightNode==null){
97+
return null;
98+
99+
}
100+
}
101+
}
102+
if((thisNode.character==wordArr[i]) && (i == wordArr.length-1)){
103+
return thisNode;
104+
}
105+
106+
}
107+
108+
return null; //CHECK THIS CODE RIGHT HERE!!!!!!!1
109+
}
110+
111+
public ArrayList<String> findWordsWithPrefix(String prefix){
112+
Node foundNode = findNode(prefix);
113+
Node thisNode= foundNode;
114+
115+
Node nodeForRightLoop = foundNode;
116+
//nodeForRightLoop = nodeForRightLoop.bottomNode;
117+
118+
StringBuilder builder = new StringBuilder(prefix);
119+
120+
if(foundNode==null){
121+
return null;
122+
}
123+
124+
if(thisNode.value!=null){
125+
returnStrings.add(thisNode.value);
126+
}
127+
128+
while(thisNode.bottomNode!=null){
129+
130+
thisNode = thisNode.bottomNode;
131+
if(thisNode.value!=null){
132+
returnStrings.add(thisNode.value);
133+
}
134+
else{
135+
136+
}
137+
}
138+
139+
while(nodeForRightLoop.rightNode!=null){
140+
nodeForRightLoop = nodeForRightLoop.rightNode;
141+
142+
if(nodeForRightLoop.value!=null){
143+
returnStrings.add(nodeForRightLoop.value);
144+
getBottomNodeValues(nodeForRightLoop);
145+
146+
}
147+
else{
148+
getBottomNodeValues(nodeForRightLoop);
149+
150+
}
151+
152+
153+
}
154+
155+
156+
return returnStrings;
157+
}
158+
159+
/* public ArrayList<String> findWordsWithPrefix(Node daNode){
160+
Node foundNode = daNode;
161+
Node thisNode= foundNode;
162+
163+
Node nodeForRightLoop = foundNode;
164+
nodeForRightLoop = nodeForRightLoop.bottomNode;
165+
166+
StringBuilder builder = new StringBuilder(prefix);
167+
168+
if(foundNode==null){
169+
return null;
170+
}
171+
172+
if(thisNode.value!=null){
173+
returnStrings.add(thisNode.value);
174+
}
175+
176+
while(thisNode.bottomNode!=null){
177+
178+
thisNode = thisNode.bottomNode;
179+
if(thisNode.value!=null){
180+
returnStrings.add(thisNode.value);
181+
}
182+
else{
183+
184+
}
185+
}
186+
187+
while(nodeForRightLoop.rightNode!=null){
188+
nodeForRightLoop = nodeForRightLoop.rightNode;
189+
190+
if(nodeForRightLoop.value!=null){
191+
returnStrings.add(nodeForRightLoop.value);
192+
getBottomNodeValues(nodeForRightLoop);
193+
}
194+
else{
195+
getBottomNodeValues(nodeForRightLoop);
196+
}
197+
198+
199+
}
200+
201+
202+
return returnStrings;
203+
} */
204+
205+
public void getBottomNodeValues(Node getMoreNodes){
206+
Node myNode = getMoreNodes;
207+
while(myNode.bottomNode!=null){
208+
209+
myNode= myNode.bottomNode;
210+
if(myNode.value!=null){
211+
returnStrings.add(myNode.value);
212+
}
213+
else{
214+
215+
}
216+
}
217+
}
218+
219+
220+
}

De La Briandais Trie/src/Node.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.lang.*;
2+
3+
public class Node{
4+
public char character;
5+
public String value;
6+
public Node rightNode;
7+
public Node bottomNode;
8+
9+
public Node(){
10+
this('\u0000', null, null, null);
11+
}
12+
public Node(char a){
13+
this(a, null, null, null);
14+
15+
}
16+
public Node (char a, String val){
17+
this(a, val, null, null);
18+
}
19+
public Node(char a, String val, Node rNode, Node bNode){
20+
character = a;
21+
value = val;
22+
rightNode = rNode;
23+
bottomNode = bNode;
24+
}
25+
26+
public Node getRightNode(){
27+
if(rightNode==null){
28+
return null;
29+
}
30+
else{
31+
return rightNode;
32+
}
33+
}
34+
public Node getBottomNode(){
35+
if(bottomNode==null){
36+
return null;
37+
}
38+
else{
39+
return bottomNode;
40+
}
41+
}
42+
43+
}

De La Briandais Trie/src/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# EXAMPLE USAGE
2+
3+
NOTE: To understand more about the project, the classes, etc. check out the `doc/` folder and the `P1 instructions.pdf` for more information.
4+
5+
Compilation:
6+
7+
javac ac_test.java
8+
9+
Execution:
10+
11+
java ac_test
12+
13+
14+
**Contact Information**
15+
16+
![interests](https://avatars1.githubusercontent.com/u/38919947?s=400&u=49ab1365a14fac78a91e425efd583f7a2bcb3e25&v=4)
17+
18+
Yogindra Raghav (YogiOnBioinformatics)
19+
20+
yraghav97@gmail.com
21+
22+
23+
24+

0 commit comments

Comments
 (0)