Data Structures Binary Search Trees • Dictionary ADT / Search ADT • Quick Tree Review • Binary Search Trees

Total Page:16

File Type:pdf, Size:1020Kb

Data Structures Binary Search Trees • Dictionary ADT / Search ADT • Quick Tree Review • Binary Search Trees Today’s Outline CSE 326: Data Structures Binary Search Trees • Dictionary ADT / Search ADT • Quick Tree Review • Binary Search Trees 5/30/2008 1 5/30/2008 2 The Dictionary ADT ADTs Seen So Far •jfogarty • Priority Queue • Data: James •Stack Fogarty –Push –Insert – a set of insert(jfogarty, ….) CSE 666 –Pop – DeleteMin (key, value) • phenry pairs Peter • Queue Henry CSE 002 – Enqueue find(boqin) – Dequeue • Operations: • boqin Then there is decreaseKey… • boqin – Insert (key, Bo, Qin, … Bo Qin value) CSE 002 – Find (key) Need pointer! Why? The Dictionary ADT is also Because find not efficient. – Remove (key)called the “Map ADT” 5/30/2008 3 5/30/2008 4 A Modest Few Uses Implementations insert find delete Θ(1) Θ(n) Θ(n) •Sets • Unsorted Linked-list • Dictionaries • Networks : Router tables Θ(1) Θ(n) Θ(n) • Unsorted array • Operating systems : Page tables • Compilers : Symbol tables log n + n Θ(log n) log n + n Probably the most widely used ADT! • Sorted array SO CLOSE! What limits the performance? 5/30/2008 5 5/30/2008 Time to move elements, can we mimic BinSearch with BST?6 Tree Calculations Tree Calculations Example Recall: height is max t How high is this tree? A number of edges from root to a leaf B C D E F G Find the height of the tree... H I height(t) = 1 + max {height(t.left), height(t.right)} height(B) = 1 runtime: height(C) = 4 J K L L Θ(N) (constant time for each node; so height(A) = 5 each node visited twice) M N 5/30/2008 7 5/30/2008 8 More Recursive Tree Calculations: Inorder Traversal Tree Traversals void traverse(BNode t){ A traversal is an order for visiting all the nodes of a tree + if (t != NULL) traverse (t.left); * 5 Three types: process t.element; • Pre-order: Root, left subtree, right subtree 2 4 traverse (t.right); • In-order: Left subtree, root, right subtree } (an expression tree) } • Post-order: Left subtree, right subtree, root 5/30/2008 9 5/30/2008 10 Binary Trees Binary Tree: Representation • Binary tree is A – a root left right A pointerpointer A – left subtree (maybe empty) B C B C B C – right subtree (maybe left right left right empty) pointerpointer pointerpointer D E F D E F Data • Representation:left right G H D E F pointer pointer left right left right left right pointerpointer pointerpointer pointerpointer I J 5/30/2008 11 5/30/2008 12 Binary Tree: Special Cases Binary Tree: Some Numbers! For binary tree of height h: – max # of leaves: 2h, for perfect tree A A A – max # of nodes: 2h+1 – 1, for perfect tree B C B C B C – min # of leaves: 1, for “list” tree D E F D E F G D E F G – min # of nodes: h+1, for “list” tree Complete Tree Perfect Tree H I Full Tree Average Depth for N nodes? 5/30/2008 13 5/30/2008 14 Binary Search Tree Data Structure Example and Counter-Example • Structural property – each node has ≤ 2children – result: • storage is small 8 5 8 • operations are simple • average depth is small 5 11 4 8 5 11 • Order property – all keys in left subtree smaller than root’s key 2 6 10 12 1 7 11 2 7 6 10 18 – all keys in right subtree larger than root’s key – result: easy to find any given key 4 7 9 14 3 4 All children must 15 20 obey order • What must I know about what I store? 13 BINARY SEARCH TREES? 21 Comparison, equality testing 5/30/2008 15 5/30/2008 16 Find in BST, Recursive Find in BST, Iterative Node Find(Object key, Node Find(Object key, 10 Node root) { Node root) { if (root == NULL) 10 return NULL; 5 15 while (root != NULL && if (key < root.key) root.key != key) { if (key < root.key) 5 15 2 9 20 return Find(key, root.left); root = root.left; else if (key > root.key) else 2 9 20 7 17 30 return Find(key, root = root.right; root.right); } else 7 17 30 return root; return root; Runtime: } } Runtime: 5/30/2008 17 5/30/2008 18 Insert in BST BuildTree for BST 10 • Suppose keys 1, 2, 3, 4, 5, 6, 7, 8, 9 are Insert(13) inserted into an initially empty BST. 5 15 Insert(8) Insert(31) Runtime depends on the order! – in given order 2 9 20 Θ(n2) 7 17 30 – in reverse order Insertions happen only Θ(n2) at the leaves – easy! Runtime: – median first, then left median, right median, etc. 5, 3, 7, 2, 1, 6, 8, 9 better: n log n 5/30/2008 19 5/30/2008 20 Bonus: FindMin/FindMax Deletion in BST 10 • Find minimum 10 5 15 5 15 2 9 20 • Find maximum 2 9 20 7 17 30 7 17 30 Why might deletion be harder than insertion? 5/30/2008 21 5/30/2008 22 Non-lazy Deletion Lazy Deletion • Removing an item disrupts the tree Instead of physically deleting nodes, just mark them as structure. deleted • Basic idea: find the node that is to be + simpler 10 removed. Then “fix” the tree so that it is + physical deletions done in batches still a binary search tree. + some adds just flip deleted 5 15 flag • Three cases: 2 9 20 – node has no children (leaf node) – extra memory for “deleted” flag – many lazy deletions = slow – node has one child finds 7 17 30 – some operations may have to – node has two children be modified (e.g., min and max) 5/30/2008 23 5/30/2008 24 Non-lazy Deletion – The Leaf Case Deletion – The One Child Case Delete(17) 10 Delete(15) 10 5 15 5 15 2 9 20 2 9 20 7 17 30 7 30 5/30/2008 25 5/30/2008 26 Deletion – The Two Child Case Deletion – The Two Child Case 10 Idea: Replace the deleted node with a value Delete(5) guaranteed to be between the two child subtrees 5 20 Options: 2 9 30 • succ from right subtree: findMin(t.right) • pred from left subtree : findMax(t.left) 7 A value guaranteed to be between the two subtrees! - succ from right subtree Now delete the original node containing succ or pred What can we replace 5 with? -predfrom left subtree • Leaf or one child case – easy! 5/30/2008 27 5/30/2008 28 Finally… Balanced BST Observation 10 • BST: the shallower the better! • For a BST with n nodes 7 replaces 5 7 20 – Average height is O(log n) – Worst case height is O(n) • Simple cases such as insert(1, 2, 3, ..., n) 2 9 30 lead to the worst case scenario Original node containing Solution: Require a Balance Condition that 7 gets deleted 1. ensures depth is O(log n) – strong enough! 2. is easy to maintain – not too strong! 5/30/2008 29 5/30/2008 30 Potential Balance Conditions Potential Balance Conditions 1. Left and right subtrees of the root 3. Left and right subtrees of every node have equal number of nodes have equal number of nodes Too weak! Too strong! Do height mismatch example Only perfect trees 2. Left and right subtrees of the root 4. Left and right subtrees of every node have equal height have equal height Too strong! Too weak! Only perfect trees Do example where there’s a left chain and a right chain, no other nodes 5/30/2008 31 5/30/2008 32 Balanced BST Observation CSE 326: Data Structures • BST: the shallower the better! • For a BST with n nodes AVL Trees – Average height is O(log n) – Worst case height is O(n) • Simple cases such as insert(1, 2, 3, ..., n) lead to the worst case scenario Solution: Require a Balance Condition that 1. ensures depth is O(log n) – strong enough! 2. is easy to maintain – not too strong! 33 34 Potential Balance Conditions The AVL BalanceAdelson-Velskii Condition and Landis 1. Left and right subtrees of the root AVL balance property: have equal number of nodes 2. Left and right subtrees of the root Left and right subtrees of every node have equal height have heights differing by at most 1 3. Left and right subtrees of every node have equal number of nodes • Ensures small depth 4. Left and right subtrees of every node – Will prove this by showing that an AVL tree of height h must have a lot of (i.e. O(2h)) nodes have equal height • Easy to maintain – Using single and double rotations 35 36 AVL trees or not? The AVL Tree Data Structure 6 4 8 Structural properties This is an 1. Binary tree property AVL tree 1 7 11 (0,1, or 2 children) 8 10 12 2. Heights of left and right subtrees of every node 5 11 6 differ by at most 1 4 8 Result: 2 6 10 12 Worst case depth of any 1 5 7 11 node is: O(log n) 4 7 9 13 14 3 Ordering property 15 2 – Same as for BST 37 38 Proving Shallowness Bound Testing the Balance Property Let S(h) be the min # of nodes in an AVL tree of height h=4 AVL tree of height h with the min # of nodes (12) 10 We need to be able to: Trees of height h = 1, 2, 3 …. 8 1. Track Balance 5 15 Claim: S(h) = S(h-1) + S(h-2) + 1 2.
Recommended publications
  • Application of TRIE Data Structure and Corresponding Associative Algorithms for Process Optimization in GRID Environment
    Application of TRIE data structure and corresponding associative algorithms for process optimization in GRID environment V. V. Kashanskya, I. L. Kaftannikovb South Ural State University (National Research University), 76, Lenin prospekt, Chelyabinsk, 454080, Russia E-mail: a [email protected], b [email protected] Growing interest around different BOINC powered projects made volunteer GRID model widely used last years, arranging lots of computational resources in different environments. There are many revealed problems of Big Data and horizontally scalable multiuser systems. This paper provides an analysis of TRIE data structure and possibilities of its application in contemporary volunteer GRID networks, including routing (L3 OSI) and spe- cialized key-value storage engine (L7 OSI). The main goal is to show how TRIE mechanisms can influence de- livery process of the corresponding GRID environment resources and services at different layers of networking abstraction. The relevance of the optimization topic is ensured by the fact that with increasing data flow intensi- ty, the latency of the various linear algorithm based subsystems as well increases. This leads to the general ef- fects, such as unacceptably high transmission time and processing instability. Logically paper can be divided into three parts with summary. The first part provides definition of TRIE and asymptotic estimates of corresponding algorithms (searching, deletion, insertion). The second part is devoted to the problem of routing time reduction by applying TRIE data structure. In particular, we analyze Cisco IOS switching services based on Bitwise TRIE and 256 way TRIE data structures. The third part contains general BOINC architecture review and recommenda- tions for highly-loaded projects.
    [Show full text]
  • Trees • Binary Trees • Newer Types of Tree Structures • M-Ary Trees
    Data Organization and Processing Hierarchical Indexing (NDBI007) David Hoksza http://siret.ms.mff.cuni.cz/hoksza 1 Outline • Background • prefix tree • graphs • … • search trees • binary trees • Newer types of tree structures • m-ary trees • Typical tree type structures • B-tree • B+-tree • B*-tree 2 Motivation • Similarly as in hashing, the motivation is to find record(s) given a query key using only a few operations • unlike hashing, trees allow to retrieve set of records with keys from given range • Tree structures use “clustering” to efficiently filter out non relevant records from the data set • Tree-based indexes practically implement the index file data organization • for each search key, an indexing structure can be maintained 3 Drawbacks of Index(-Sequential) Organization • Static nature • when inserting a record at the beginning of the file, the whole index needs to be rebuilt • an overflow handling policy can be applied → the performance degrades as the file grows • reorganization can take a lot of time, especially for large tables • not possible for online transactional processing (OLTP) scenarios (as opposed to OLAP – online analytical processing) where many insertions/deletions occur 4 Tree Indexes • Most common dynamic indexing structure for external memory • When inserting/deleting into/from the primary file, the indexing structure(s) residing in the secondary file is modified to accommodate the new key • The modification of a tree is implemented by splitting/merging nodes • Used not only in databases • NTFS directory structure
    [Show full text]
  • CS 106X, Lecture 21 Tries; Graphs
    CS 106X, Lecture 21 Tries; Graphs reading: Programming Abstractions in C++, Chapter 18 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution 2.5 License. All rights reserved. Based on slides created by Keith Schwarz, Julie Zelenski, Jerry Cain, Eric Roberts, Mehran Sahami, Stuart Reges, Cynthia Lee, Marty Stepp, Ashley Taylor and others. Plan For Today • Tries • Announcements • Graphs • Implementing a Graph • Representing Data with Graphs 2 Plan For Today • Tries • Announcements • Graphs • Implementing a Graph • Representing Data with Graphs 3 The Lexicon • Lexicons are good for storing words – contains – containsPrefix – add 4 The Lexicon root the art we all arts you artsy 5 The Lexicon root the contains? art we containsPrefix? add? all arts you artsy 6 The Lexicon S T A R T L I N G S T A R T 7 The Lexicon • We want to model a set of words as a tree of some kind • The tree should be sorted in some way for efficient lookup • The tree should take advantage of words containing each other to save space and time 8 Tries trie ("try"): A tree structure optimized for "prefix" searches struct TrieNode { bool isWord; TrieNode* children[26]; // depends on the alphabet }; 9 Tries isWord: false a b c d e … “” isWord: true a b c d e … “a” isWord: false a b c d e … “ac” isWord: true a b c d e … “ace” 10 Reading Words Yellow = word in the trie A E H S / A E H S A E H S A E H S / / / / / / / / A E H S A E H S A E H S A E H S / / / / / / / / / / / / A E H S A E H S A E H S / / / / / / /
    [Show full text]
  • Amortized Analysis Worst-Case Analysis
    Beyond Worst Case Analysis Amortized Analysis Worst-case analysis. ■ Analyze running time as function of worst input of a given size. Average case analysis. ■ Analyze average running time over some distribution of inputs. ■ Ex: quicksort. Amortized analysis. ■ Worst-case bound on sequence of operations. ■ Ex: splay trees, union-find. Competitive analysis. ■ Make quantitative statements about online algorithms. ■ Ex: paging, load balancing. Princeton University • COS 423 • Theory of Algorithms • Spring 2001 • Kevin Wayne 2 Amortized Analysis Dynamic Table Amortized analysis. Dynamic tables. ■ Worst-case bound on sequence of operations. ■ Store items in a table (e.g., for open-address hash table, heap). – no probability involved ■ Items are inserted and deleted. ■ Ex: union-find. – too many items inserted ⇒ copy all items to larger table – sequence of m union and find operations starting with n – too many items deleted ⇒ copy all items to smaller table singleton sets takes O((m+n) α(n)) time. – single union or find operation might be expensive, but only α(n) Amortized analysis. on average ■ Any sequence of n insert / delete operations take O(n) time. ■ Space used is proportional to space required. ■ Note: actual cost of a single insert / delete can be proportional to n if it triggers a table expansion or contraction. Bottleneck operation. ■ We count insertions (or re-insertions) and deletions. ■ Overhead of memory management is dominated by (or proportional to) cost of transferring items. 3 4 Dynamic Table: Insert Dynamic Table: Insert Dynamic Table Insert Accounting method. Initialize table size m = 1. ■ Charge each insert operation $3 (amortized cost). – use $1 to perform immediate insert INSERT(x) – store $2 in with new item IF (number of elements in table = m) ■ When table doubles: Generate new table of size 2m.
    [Show full text]
  • Lecture 26 Fall 2019 Instructors: B&S Administrative Details
    CSCI 136 Data Structures & Advanced Programming Lecture 26 Fall 2019 Instructors: B&S Administrative Details • Lab 9: Super Lexicon is online • Partners are permitted this week! • Please fill out the form by tonight at midnight • Lab 6 back 2 2 Today • Lab 9 • Efficient Binary search trees (Ch 14) • AVL Trees • Height is O(log n), so all operations are O(log n) • Red-Black Trees • Different height-balancing idea: height is O(log n) • All operations are O(log n) 3 2 Implementing the Lexicon as a trie There are several different data structures you could use to implement a lexicon— a sorted array, a linked list, a binary search tree, a hashtable, and many others. Each of these offers tradeoffs between the speed of word and prefix lookup, amount of memory required to store the data structure, the ease of writing and debugging the code, performance of add/remove, and so on. The implementation we will use is a special kind of tree called a trie (pronounced "try"), designed for just this purpose. A trie is a letter-tree that efficiently stores strings. A node in a trie represents a letter. A path through the trie traces out a sequence ofLab letters that9 represent : Lexicon a prefix or word in the lexicon. Instead of just two children as in a binary tree, each trie node has potentially 26 child pointers (one for each letter of the alphabet). Whereas searching a binary search tree eliminates half the words with a left or right turn, a search in a trie follows the child pointer for the next letter, which narrows the search• Goal: to just words Build starting a datawith that structure letter.
    [Show full text]
  • Balanced Trees Part One
    Balanced Trees Part One Balanced Trees ● Balanced search trees are among the most useful and versatile data structures. ● Many programming languages ship with a balanced tree library. ● C++: std::map / std::set ● Java: TreeMap / TreeSet ● Many advanced data structures are layered on top of balanced trees. ● We’ll see several later in the quarter! Where We're Going ● B-Trees (Today) ● A simple type of balanced tree developed for block storage. ● Red/Black Trees (Today/Thursday) ● The canonical balanced binary search tree. ● Augmented Search Trees (Thursday) ● Adding extra information to balanced trees to supercharge the data structure. Outline for Today ● BST Review ● Refresher on basic BST concepts and runtimes. ● Overview of Red/Black Trees ● What we're building toward. ● B-Trees and 2-3-4 Trees ● Simple balanced trees, in depth. ● Intuiting Red/Black Trees ● A much better feel for red/black trees. A Quick BST Review Binary Search Trees ● A binary search tree is a binary tree with 9 the following properties: 5 13 ● Each node in the BST stores a key, and 1 6 10 14 optionally, some auxiliary information. 3 7 11 15 ● The key of every node in a BST is strictly greater than all keys 2 4 8 12 to its left and strictly smaller than all keys to its right. Binary Search Trees ● The height of a binary search tree is the 9 length of the longest path from the root to a 5 13 leaf, measured in the number of edges. 1 6 10 14 ● A tree with one node has height 0.
    [Show full text]
  • Lecture 04 Linear Structures Sort
    Algorithmics (6EAP) MTAT.03.238 Linear structures, sorting, searching, etc Jaak Vilo 2018 Fall Jaak Vilo 1 Big-Oh notation classes Class Informal Intuition Analogy f(n) ∈ ο ( g(n) ) f is dominated by g Strictly below < f(n) ∈ O( g(n) ) Bounded from above Upper bound ≤ f(n) ∈ Θ( g(n) ) Bounded from “equal to” = above and below f(n) ∈ Ω( g(n) ) Bounded from below Lower bound ≥ f(n) ∈ ω( g(n) ) f dominates g Strictly above > Conclusions • Algorithm complexity deals with the behavior in the long-term – worst case -- typical – average case -- quite hard – best case -- bogus, cheating • In practice, long-term sometimes not necessary – E.g. for sorting 20 elements, you dont need fancy algorithms… Linear, sequential, ordered, list … Memory, disk, tape etc – is an ordered sequentially addressed media. Physical ordered list ~ array • Memory /address/ – Garbage collection • Files (character/byte list/lines in text file,…) • Disk – Disk fragmentation Linear data structures: Arrays • Array • Hashed array tree • Bidirectional map • Heightmap • Bit array • Lookup table • Bit field • Matrix • Bitboard • Parallel array • Bitmap • Sorted array • Circular buffer • Sparse array • Control table • Sparse matrix • Image • Iliffe vector • Dynamic array • Variable-length array • Gap buffer Linear data structures: Lists • Doubly linked list • Array list • Xor linked list • Linked list • Zipper • Self-organizing list • Doubly connected edge • Skip list list • Unrolled linked list • Difference list • VList Lists: Array 0 1 size MAX_SIZE-1 3 6 7 5 2 L = int[MAX_SIZE]
    [Show full text]
  • Introduction to Linked List: Review
    Introduction to Linked List: Review Source: http://www.geeksforgeeks.org/data-structures/linked-list/ Linked List • Fundamental data structures in C • Like arrays, linked list is a linear data structure • Unlike arrays, linked list elements are not stored at contiguous location, the elements are linked using pointers Array vs Linked List Why Linked List-1 • Advantages over arrays • Dynamic size • Ease of insertion or deletion • Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to be shifted For example, in a system if we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040] If we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 • Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved Why Linked List-2 • Drawbacks of Linked List • Random access is not allowed. • Need to access elements sequentially starting from the first node. So we cannot do binary search with linked lists • Extra memory space for a pointer is required with each element of the list Representation in C • A linked list is represented by a pointer to the first node of the linked list • The first node is called head • If the linked list is empty, then the value of head is null • Each node in a list consists of at least two parts 1.
    [Show full text]
  • Assignment 3: Kdtree ______Due June 4, 11:59 PM
    CS106L Handout #04 Spring 2014 May 15, 2014 Assignment 3: KDTree _________________________________________________________________________________________________________ Due June 4, 11:59 PM Over the past seven weeks, we've explored a wide array of STL container classes. You've seen the linear vector and deque, along with the associative map and set. One property common to all these containers is that they are exact. An element is either in a set or it isn't. A value either ap- pears at a particular position in a vector or it does not. For most applications, this is exactly what we want. However, in some cases we may be interested not in the question “is X in this container,” but rather “what value in the container is X most similar to?” Queries of this sort often arise in data mining, machine learning, and computational geometry. In this assignment, you will implement a special data structure called a kd-tree (short for “k-dimensional tree”) that efficiently supports this operation. At a high level, a kd-tree is a generalization of a binary search tree that stores points in k-dimen- sional space. That is, you could use a kd-tree to store a collection of points in the Cartesian plane, in three-dimensional space, etc. You could also use a kd-tree to store biometric data, for example, by representing the data as an ordered tuple, perhaps (height, weight, blood pressure, cholesterol). However, a kd-tree cannot be used to store collections of other data types, such as strings. Also note that while it's possible to build a kd-tree to hold data of any dimension, all of the data stored in a kd-tree must have the same dimension.
    [Show full text]
  • Advanced Data Structures
    Advanced Data Structures PETER BRASS City College of New York CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.cambridge.org Information on this title: www.cambridge.org/9780521880374 © Peter Brass 2008 This publication is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2008 ISBN-13 978-0-511-43685-7 eBook (EBL) ISBN-13 978-0-521-88037-4 hardback Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. Contents Preface page xi 1 Elementary Structures 1 1.1 Stack 1 1.2 Queue 8 1.3 Double-Ended Queue 16 1.4 Dynamical Allocation of Nodes 16 1.5 Shadow Copies of Array-Based Structures 18 2 Search Trees 23 2.1 Two Models of Search Trees 23 2.2 General Properties and Transformations 26 2.3 Height of a Search Tree 29 2.4 Basic Find, Insert, and Delete 31 2.5ReturningfromLeaftoRoot35 2.6 Dealing with Nonunique Keys 37 2.7 Queries for the Keys in an Interval 38 2.8 Building Optimal Search Trees 40 2.9 Converting Trees into Lists 47 2.10
    [Show full text]
  • Search Trees
    Lecture III Page 1 “Trees are the earth’s endless effort to speak to the listening heaven.” – Rabindranath Tagore, Fireflies, 1928 Alice was walking beside the White Knight in Looking Glass Land. ”You are sad.” the Knight said in an anxious tone: ”let me sing you a song to comfort you.” ”Is it very long?” Alice asked, for she had heard a good deal of poetry that day. ”It’s long.” said the Knight, ”but it’s very, very beautiful. Everybody that hears me sing it - either it brings tears to their eyes, or else -” ”Or else what?” said Alice, for the Knight had made a sudden pause. ”Or else it doesn’t, you know. The name of the song is called ’Haddocks’ Eyes.’” ”Oh, that’s the name of the song, is it?” Alice said, trying to feel interested. ”No, you don’t understand,” the Knight said, looking a little vexed. ”That’s what the name is called. The name really is ’The Aged, Aged Man.’” ”Then I ought to have said ’That’s what the song is called’?” Alice corrected herself. ”No you oughtn’t: that’s another thing. The song is called ’Ways and Means’ but that’s only what it’s called, you know!” ”Well, what is the song then?” said Alice, who was by this time completely bewildered. ”I was coming to that,” the Knight said. ”The song really is ’A-sitting On a Gate’: and the tune’s my own invention.” So saying, he stopped his horse and let the reins fall on its neck: then slowly beating time with one hand, and with a faint smile lighting up his gentle, foolish face, he began..
    [Show full text]
  • Splay Trees Last Changed: January 28, 2017
    15-451/651: Design & Analysis of Algorithms January 26, 2017 Lecture #4: Splay Trees last changed: January 28, 2017 In today's lecture, we will discuss: • binary search trees in general • definition of splay trees • analysis of splay trees The analysis of splay trees uses the potential function approach we discussed in the previous lecture. It seems to be required. 1 Binary Search Trees These lecture notes assume that you have seen binary search trees (BSTs) before. They do not contain much expository or backtround material on the basics of BSTs. Binary search trees is a class of data structures where: 1. Each node stores a piece of data 2. Each node has two pointers to two other binary search trees 3. The overall structure of the pointers is a tree (there's a root, it's acyclic, and every node is reachable from the root.) Binary search trees are a way to store and update a set of items, where there is an ordering on the items. I know this is rather vague. But there is not a precise way to define the gamut of applications of search trees. In general, there are two classes of applications. Those where each item has a key value from a totally ordered universe, and those where the tree is used as an efficient way to represent an ordered list of items. Some applications of binary search trees: • Storing a set of names, and being able to lookup based on a prefix of the name. (Used in internet routers.) • Storing a path in a graph, and being able to reverse any subsection of the path in O(log n) time.
    [Show full text]