Trie and Search Trees Dr. Andrew Wallace PhD BEng(hons) EurIng

Slides:



Advertisements
Similar presentations
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Advertisements

Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
David Luebke 1 5/4/2015 Binary Search Trees. David Luebke 2 5/4/2015 Dynamic Sets ● Want a data structure for dynamic sets ■ Elements have a key and satellite.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Data Compressor---Huffman Encoding and Decoding. Huffman Encoding Compression Typically, in files and messages, Each character requires 1 byte or 8 bits.
Lecture 6 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan
CS 171: Introduction to Computer Science II
Trees Chapter 8.
Lempel-Ziv Compression Techniques Classification of Lossless Compression techniques Introduction to Lempel-Ziv Encoding: LZ77 & LZ78 LZ78 Encoding Algorithm.
Higher Order Tries Key = Social Security Number.   9 decimal digits. 10-way trie (order 10 trie) Height
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Indexed Search Tree (Trie) Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
6/26/2015 7:13 PMTries1. 6/26/2015 7:13 PMTries2 Outline and Reading Standard tries (§9.2.1) Compressed tries (§9.2.2) Suffix tries (§9.2.3) Huffman encoding.
Lempel-Ziv Compression Techniques
Dr. Andrew Wallace PhD BEng(hons) EurIng
A Binary Search Tree Implementation Chapter 25 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Data Compression Gabriel Laden CS146 – Dr. Sin-Min Lee Spring 2004.
Lecture 06: Tree Structures Topics: Trees in general Binary Search Trees Application: Huffman Coding Other types of Trees.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Lecture Objectives  To learn how to use a Huffman tree to encode characters using fewer bytes than ASCII or Unicode, resulting in smaller files and reduced.
© 2004 Goodrich, Tamassia Tries1. © 2004 Goodrich, Tamassia Tries2 Preprocessing Strings Preprocessing the pattern speeds up pattern matching queries.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Data Structures and Algorithms Lecture (BinaryTrees) Instructor: Quratulain.
data ordered along paths from root to leaf
Trees Dr. Andrew Wallace PhD BEng(hons) EurIng
Trees (Ch. 9.2) Longin Jan Latecki Temple University based on slides by Simon Langley and Shang-Hua Teng.
Data Structures Haim Kaplan and Uri Zwick November 2012 Lecture 3 Dynamic Sets / Dictionaries Binary Search Trees.
CSE 250 September 29 – October 3, A NNOUNCEMENTS Homework 4 due 10/5 Project 1 posted for 10/6 Exam 2 10/8 No classes meet 10/9 Project 1 due 10/26.
Sets of Digital Data CSCI 2720 Fall 2005 Kraemer.
Huffman Codes Juan A. Rodriguez CS 326 5/13/2003.
Chapter 7 Trees_Part3 1 SEARCH TREE. Search Trees 2  Two standard search trees:  Binary Search Trees (non-balanced) All items in left sub-tree are less.
Binary Search Trees (BST)
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
Lecture 7 Source Coding and Compression Dr.-Ing. Khaled Shawky Hassan
Trees (Ch. 9.2) Longin Jan Latecki Temple University based on slides by Simon Langley and Shang-Hua Teng.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
1 Lexicographic Search:Tries All of the searching methods we have seen so far compare entire keys during the search Idea: Why not consider a key to be.
1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7.
Tables, hashtables, relations and dictionaries Dr. Andrew Wallace PhD BEng(hons) EurIng
Prof. Paolo Ferragina, Algoritmi per "Information Retrieval" Basics
Compression and Huffman Coding. Compression Reducing the memory required to store some information. Lossless compression vs lossy compression Lossless.
Search Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
HUFFMAN CODES.
Tries 07/28/16 11:04 Text Compression
Tries 5/27/2018 3:08 AM Tries Tries.
Binary Search Tree (BST)
Lempel-Ziv Compression Techniques
Lecture 22 Binary Search Trees Chapter 10 of textbook
Tries 9/14/ :13 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
Data Compression If you’ve ever sent a large file to a friend, you may have compressed it into a zip archive like the one on this slide before doing so.
Chapter 8 – Binary Search Tree
Find in a linked list? first last 7  4  3  8 NULL
Search Sorted Array: Binary Search Linked List: Linear Search
Lempel-Ziv Compression Techniques
Chapter 11 Data Compression
Binary Trees: Motivation
Data Structure and Algorithms
Tries 2/23/2019 8:29 AM Tries 2/23/2019 8:29 AM Tries.
Heaps By JJ Shepherd.
Search Sorted Array: Binary Search Linked List: Linear Search
Presentation transcript:

Trie and Search Trees Dr. Andrew Wallace PhD BEng(hons) EurIng

Overview Trie Binary search trees

Trie Special type of tree retrieval Dynamic sets Key is a string Root node is an empty string

Trie Anna : data Andrew : data Alexandra : data Alwen : data Bertil : data Bridget : data Beryl : data A B L NER W EN A Data

Trie Implementation As a table 2 x 2 array One columns per letter in the alphabet, n One row per node, m log 2 m to represent the data

Trie Implementation As a linked list Each node contains A letter Link to child de la Brandais tree

Trie operations Insert child Delete child Child Look up

Trie implementation Auto correct File structures DNA sequencing Data compression LZ78 Huffman encoding

Trie implementation LZ78 Lossless data compression Dictionary based Random access

Trie implementation She sells sea shells SH E _L S _ E A Step PhraseOutput 1 S0, S 2 H0, H 3 E0, E 4 _0, _ 5 SE1, E 6 L0, L 7 LL6, L 8 S_1, _ 9 A 0, A 10 _SHELLS4, SHELLS LS E L L H

Trie Encode(n) Dictionary  empty Prefix  empty DictionaryIndex  1 while(n is not empty) Char  next character in n if(Prefix + Char exists in the Dictionary) Prefix  Prefix + Char else if(Prefix is empty) CodeWordForPrefix  0 else CodeWordForPrefix  DictionaryIndex for Prefix Output: (CodeWordForPrefix, Char) insertInDictionary( ( DictionaryIndex, Prefix + Char) ) DictionaryIndex++ Prefix  empty

Huffman coding Frequency encoding FrequencyValue :2 5:1 13:*

Huffman coding FrequencyValue * 13:* 10:3 23:*

Huffman coding FrequencyValue :* 15:3 35:* 23 *

Huffman coding FrequencyValue 23 * 23:5 35:4 48:* 35 *

Huffman coding FrequencyValue 48 * 35:* 23:* 48:*

Huffman coding To encode: Right = 1 and left = 0 Example 1 = = = 10 4 = 00 5 = 01 8:2 5:1 13:*10:3 23:* 20:5 15:4 35:* 48:*

Huffman coding Applications Zip file compression Jpeg PNG

Binary Search trees Each node has max two child nodes Relationship between child nodes Nodes key is larger than all the nodes in the left sub tree Nodes key is smaller than all the nodes in the right sub tree

Binary Search trees Binary search tree and a binary tree In a binary search tree all nodes much have a label Delete and Insert needs a label as does create tree for the root Delete can break the tree Fix it downwards Insert must insert in sorted order

Binary Search trees Operations Search Insert Delete

Binary Search trees Search Fast if tree is ordered Does node have value x? Where is 12? Search left if node value is greater than x Search right if node value is less than x How long will it take? Tree is complete O(log n)

Binary Search trees Searching a tree TreeSearch(x, k) if x = NULL or k = key[x] then return x if k key[x] then return TreeSearch(left[x], k) else return TreeSearch(right[x], k)

Binary Search trees Insert Keep the tree complete Check left sub tree. If it is full, insert the value in the higher tree and move old down the tree

Binary Search trees

Delete a node Case 1 No sub trees Case 2 One sub tree Case 3 Two sub trees

Binary Search trees Case 2 Move sub tree to the delete node’s position Delete 18 Move 12 upwards

Binary Search trees Case 3 Delete the node Promote the lowest value in the right sub tree Delete 10 Promote

Binary Search trees

Applications Construction of a dictionary In order travers gives a sorted sequence Router tables in networking

Binary Search trees Balancing a binary search tree Rotations Self-balancing Performed at key times

Binary Search trees Binary tree extensions Quad tree As a binary tree but based on 4 instead of 2 Breaks up a 2D region into 4 parts Handy for collision detection

Questions?