Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 14 - Wednesday.  What did we talk about last time?  Heapsort  Timsort  Counting sort  Radix sort.

Similar presentations


Presentation on theme: "Week 14 - Wednesday.  What did we talk about last time?  Heapsort  Timsort  Counting sort  Radix sort."— Presentation transcript:

1 Week 14 - Wednesday

2  What did we talk about last time?  Heapsort  Timsort  Counting sort  Radix sort

3

4

5

6 Student Lecture

7

8  We can use a (non-binary) tree to record strings implicitly where each link corresponds to the next letter in the string  Let’s store:  ba  bar  bat  barry  can  candle  as

9 a s b a r r y t c a n d l e

10  Now you add:  he  she  her  help  sat  rat

11 public class Trie { private static class TrieNode { public char letter; public boolean terminal; public TrieNode[] children; } private TrieNode root; public Trie() { root = new TrieNode(); root.letter = ' '; root.terminal = false; root.children = null; }

12 Signature for recursive method: private static boolean contains(TrieNode node, String word, int index) Called by public proxy method: public boolean contains(String word) { return contains(root, word, 0); }

13 Signature for recursive method: private static void insert(TrieNode node, String word, int index) Called by public proxy method: public void insert(String word) { insert(root, word, 0); }

14 private static void inorder(TrieNode node, String prefix) if( node.terminal ) System.out.println(prefix); if( node.children != null ) for( TrieNode child : node.children ) inorder(child, prefix + child.letter); } Called by public proxy method: public void inorder(String word) { inorder(root, ""); }

15  Let m be the length of a particular string  Find Costs:  O(m)  Insert Costs:  O(m)

16

17

18  Review up to Exam 1!  IDEA forms

19  Work on Project 4  Work on Assignment 7  Due when you return from Thanksgiving


Download ppt "Week 14 - Wednesday.  What did we talk about last time?  Heapsort  Timsort  Counting sort  Radix sort."

Similar presentations


Ads by Google