You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Radix-Tree/README.markdown
+23-2
Original file line number
Diff line number
Diff line change
@@ -11,14 +11,35 @@ The RadixTree class itself has one member variable, root, of type Root. The Root
11
11
12
12
Typical operations on a radix tree include lookup, insertion, deletion, find predecessor, find successor, and find all strings with common prefix. The running time of lookup, insertion, and deletion is O(k) where k is the length of the key. This is different from most trees because these operations usually run in O(logn) time where n is the number of nodes in the tree.
13
13
14
-
### Find(_ str: String) -> Bool
14
+
### RadixTree.find(_ str: String) -> Bool
15
15
16
16
The find function returns true if the String you are searching for is in the tree and false if it is not. Every RadixTree contains at the very least one String ("") so find("") will always return true. A String is considered "in the tree" if the String you are searching for is a concatenation of Edge labels while traversing downwards or a prefix of that concatenation. For example, if you look at the example tree above, find("roma") will return true because it is a prefix of the traversal "r"->"om"->"an". On the other hand, find("romans") will return false.
17
17
18
-
### Insert(_ str: String) -> Bool
18
+
### RadixTree.insert(_ str: String) -> Bool
19
19
20
20
The insert function returns true if the String you are trying to insert was successfully inserted into the RadixTree and false if the String is already in the tree. Similarly to find(""), insert("") will always return false because an empty RadixTree contains "" by default.
21
21
22
+
### RadixTree.remove(_ str: String) -> Bool
23
+
24
+
THIS IS NOT IMPLEMENTED YET
25
+
26
+
### Root.level() -> Int
27
+
28
+
The level function returns how far down in the tree the Root or Edge in question is. A Root object will always return 0. A child of the Root will return 1, a child of a child of the root will return 2, etc.
29
+
30
+
### RadixTree.height() -> Int
31
+
32
+
The height function returns an Int equal to the highest level in the Tree. An empty tree will return 0.
33
+
34
+
### RadixTree.printTree()
35
+
36
+
The printTree function was used to visualize the tree itself. This function is a little buggy and not perfect yet but gets the job done thus far.
The sharedPrefix function is a non-member function in the RadixTree.swift file. It takes in two String objects and returns the shared prefix between them. For example,
41
+
sharedPrefix("apples", "oranges") will return "" and sharedPrefix("court", "coral") will return "co". This function is used in the implementation of the find, insert, and remove functions.
42
+
22
43
## See Also
23
44
24
45
[Radix Tree - Wikipedia](https://en.wikipedia.org/wiki/Radix_tree)
0 commit comments