Vous êtes sur la page 1sur 9

3

.
.java java - .
, java - ,
zip.
, , ,
, .
.
" .1234567_7654213.ZIP :
.Submission System -
. ,
, () , ,
.

.
.
,
, .
( , ') , :
.bennyl@bgu.ac.il , (
).
zip -
Submission System , .
.Java -
( ,
, ).

.
. .
. 3 4 , .
:
http://www.cs.bgu.ac.il/~ipis141/Syllabus#grading_policy

( 05[ )Trie].
Trie , . Trie
.
Trie.http://en.wikipedia.org/wiki/Trie :
Trie ( .)nodes ( )
. .
( )root , -.
. .
, .t
.
, .try
. , . tre
tre
.
Trie - .i, in, ink, tree, try : -
.root

root
i
`
n
f
k
f

t
r
y
e

e
e

: (.)a-z

:
. TrieNode .
:
;TrieNode[] children
;String data
children 62 ( " )
. .TrieNode
.
' 'a 'b' ,5 1 .
.null
, ' 'a children
5 .null
-null .
data . .
, data ,
data
.null
, tr , data
tr ,null data try
,try .
. data .null

: .
) insert(String w, int index .TrieNode
Trie w . index w
.
pseudo-code :
insert (w, index):
if w.length() = index : //we already insert all letters in w
data w
else
w[index] //the letter inside w at the position of index.
let be the position of in the English alphabet
if children[ ] is null create it.
children[ ].insert(w, index+1) // a recursive call on the child

:
TrieNode root = new TrieNode();
root.insert("tree", 0);
root.insert("try", 0);
root.insert("i", 0);
root.insert("in", 0);

1.
2.
3.
4.
5.
6.

root.insert("ink", 0);
. "
:1
root
data = null
children= index:

25

value:

null

null

null

:6
data = null
children =

index:

value:

null

null

25

null

root
data = null
children =

t
r
e

index:

value:

null

null

11

data = "tree"
children=
index:

25

value:

null

null

null

:3
root
t
r
e
e

y
e

25

null

:4
root
t

i
`

r
y
e

e
e

:0
root
t

i
`

n
f

y
e

e
e

2 Trie:
root
i
`
n
f
k
f

t
r
y
e

e
e

insert . insert
TrieNode pseudo-code
( ).

.
.Trie
size():
;result 1
for each c : existing children of this node
)(result result + c.size
;return result

.
.TrieNode

: .Trie
( TrieNode
).

)( : String[] allWords ,Trie .


o : "i", "in", [ :
"]"ink", "tree", "try
)( :boolean isLeaf "" (
).
o : i" -
false
ink - .true
)( : int maxWordLength .Trie
o : ,4
" "tree .4
insert
( UnsupportedCharacterException )
( ).

TestTask1
. TestTask1

, .


6
. 60.
. ,
, .
,
.

[ 60].
'_' . " "hel_o "."w_r_d
Trie
'_' " .
) String[] solveRiddle(String riddle, int index TrieNode
( .)riddle index .riddle -
UnsupportedCharacterException
( ).
, :
;)(TrieNode root = new TrieNode
;)root.insert("hello", 0
;)root.insert("nice", 0
;)root.insert("nine", 0
;)root.insert("nicer", 0
;)String[] solution = root.solveRiddle("n__e", 0
printArray(solution); //we saw this function in the practical sessions.

:
nice
nine
TestTask2 ,
TestTask2 .

, .

60[ .]
, :

k -.

" "k

: solve, salve " "1 " solve, solar "6


) String[] findSimilarWords(String w, int index, int k
.TrieNode
" "k . w index
.
:

UnsupportedCharacterException
.
ArgumentOutOfRangeException k .

TestTask3 ,
TestTask3 .

, .

60[ .]
.
( ).
, thisisaneasytask "( "this is an easy task
" .)Trie
) String[] split(String letters, int index, TrieNode root
.TrieNode
letters : .
Trie .
.Trie
UnsupportedCharacterException
.
TestTask4 ,
TestTask4 .

, .

Vous aimerez peut-être aussi