0% found this document useful (0 votes)
13 views8 pages

lec-20,21 tries data structure - Copy

Uploaded by

akyadav123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

lec-20,21 tries data structure - Copy

Uploaded by

akyadav123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Tries: Example

T S

H I I

E I N N

$ N N S $ $ G

$ $ $ $
Tries: Example
 Tries are appropriate when many words begin
with the same sequence of letters.
 i.e; when the number of distinct prefixes
among all words in the set is much less than
the total length of all the words.
 Each path from the root to the leaf
corresponds to one word in the represented
set.
 Nodes of the trie correspond to the prefixes of
words in the set.
Tries: Example
 The symbol $ is added at the end of each word
so that no prefix of a word can be a word itself.
 The Trie corresponds to the set {THE,THEN
THIN, TIN, SIN, SING}
 Each node has at most 27 children, one for
each letter and $
 Most nodes will have many fewer than 27
children.
 A leaf reached by an edge labeled $ cannot
have any children.
Tries nodes as ADT
 A node in a trie can be viewed as:
 Mapping whose domain is {A,B,…Z, $}
 And whose value set is the type “Pointer
to trie node”.
 A trie can be identified with its root.
 => ADT’s TRIE and TRIENODE have the
same data type.
 However, there operations are different.
Operations on Tries nodes
 ASSIGN(node,c,p): Assign value p (a
pointer to a node) to character c in node
node.
 VALUEOF(node, c): Produce the value
associated with character c in node.
 GETNEW(node, c): Make the value of
node for character c be a pointer to a
new node.
 MAKENULL(node): Makes node to be
null mapping.
Sets
 A Set is a collection of members (or
elements).

 Each member of a set is either itself a set


or is a primitive element called an atom.

 All elements of a set are different.


Sets
 Set can be integers, characters or strings.
 All elements can be of the same type.
 Atoms in a set can be linearly ordered.
 A linear order (denoted by <) on a set S
(“less than” or precedes”) satisfies two
properties:
 For any a and b in S, exactly one of a < b, a = b,
or b < a is true.
 For all a, b and c in S, if a < b and b < c, then a <
c (transitivity).
Set Notation
 A set of atoms is generally exhibited by
putting curly brackets around its members.
 Example: {1,4}, denotes the set whose
members are 1 and 4.

 Set is not a list, since order of elements in


a set is not important.
 {4,1} is the same set as {1,4}

You might also like