Binary Trees (1) Outline and Required Reading: Binary Trees ( 6.3) Data Structures for Representing Trees ( 6.4)
|
|
|
- Magdalen Clark
- 10 years ago
- Views:
Transcription
1 1 Binary Trees (1) Outline and Required Reading: Binary Trees ( 6.3) Data Structures for Representing Trees ( 6.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
2 Binary Tree 2 Binary Tree tree with the following properties Proper and Ordered! each internal node has two children children of internal nodes form ordered pairs: left node 1 st, right node 2 nd A 1 st child of A B C 2 nd child of A D E F G I J Application representation of arithmetic expression, decision process,
3 Binary Tree (cont.) 3 Example 1 [ binary tree for decision process ] Are you a mammal? Yes No Are you bigger than cat? Do you live under water? Yes No Yes No Kangaroo Mouse Trout Can you fly? Yes No Robin Snake
4 Properties of Binary Trees 4 Binary Tree Notation A n number of nodes e number of external nodes B C i number of internal nodes h height of the tree D E F G level set of nodes with the same depth I J Property 1.1 Level d has at most 2 d nodes. Proof Let us annotate max number of nodes at level d with mn(d). Clearly, mn(0) = 1, and mn(d) = 2*mn(d-1) for d 0. Hence, mn(d) = 2*mn(d-1) = 2*2*mn(d-2) = 2*[2*[..2*mn(0)]] = 2 d
5 Properties of Binary Trees (cont.) 5 Property 1.2 A full binary tree of height h has (2 h+1 1) nodes. Full binary tree. Proof n = mn(0) + mn(1) mn(d) = = h = = + 1 h + 1 h = 2 1
6 Properties of Binary Trees (cont.) 6 Induction as a Proof Technique Assume we want to verify the correctness of a statement (P(n)). (1) First, prove that P(n) holds for n=1 (2, 3); (2) Assume it holds for an arbitrary n and try to prove it holds for (n+1) Property 2 In a binary tree, the number of external nodes is 1 more than the number of internal nodes, i.e. e = i + 1. Proof Clearly true for one node. Clearly true for tree nodes. Assume true for trees with up to n nodes.
7 Properties of Binary Trees (cont.) 7 Let T be a tree with n+1 nodes (top diagram). 1. Choose a leaf and its parent (which, of course, is internal). For example, the leaf a and parent p. 2. Remove the leaf and its parent (middle diagram). 3. Splice the tree back without the two nodes (bottom diagram). 4. Since S has n-1 nodes, S satisfies initial assumption. 5. T is just S + one leaf + one internal so it also satisfies the assumption. a p
8 Properties of Binary Trees (cont.) 8 Approach (2): Assume true for a tree with n nodes (e = i + 1). Now, we want to add new external nodes: 1. Cannot add only one external that would violate the property of proper binary tree. Hence, it cannot be: e = i Add two externals. In this case, one old external becomes internal, so we have: e new = (e-1)+2 = e+1 = i+1+1 = i+2 i new = i+1 Hence, e new = i new + 1
9 Properties of Binary Trees (cont.) 9 Property 3 The number of external nodes (e) satisfies: (h+1) e 2 h. Proof At every level (except last) there is only one internal node. Full binary tree. Property 4 The number of internal nodes (i) satisfies: h i 2 h -1. Proof Based on Property 3: Based on Property 2: h+1 e 2 h h+1 i+1 2 h h i 2 h -1
10 Properties of Binary Trees (cont.) 10 Property 5 The total number of nodes (n) satisfies: 2h+1 n 2 h+1-1. Proof Based on Property 3: (h+1) e 2 h Based on Property 2 and n=i+e: (h+1) (n+1)/2 2 h 2h+1 n 2 h+1-1 Property 6 The height (h) satisfies: log 2 (n+1)-1 h (n-1)/2. Proof Based on Property 5, the following two inequalities hold: 2h+1 n h (n-1)2 n 2 h+1-1 n+1 2 h+1 log 2 (n+1) h + 1 log 2 (n+1) - 1 h
11 Properties of Binary Trees (cont.) 11 Property 7 The height (h) satisfies: log 2 (e) h e-1. Proof Based on Property 6: Based on Property 2: log 2 (n+1)-1 h (n-1)/2 log 2 (2e-1+1)-1 h (2e-1-1)/2 log 2 (2e)-1 h e-1 log 2 (2)+log 2 (e)-1 h e-1 log 2 (e) h e-1
12 Properties of Binary Trees (cont.) 12 Summary of Properties Number of external, internal, and overall nodes as a function of tree s height n = e + i e = i + 1 (h+1) e 2 h h i 2 h -1 2h+1 n 2 h+1-1 All other expressions can be obtained from these three. Tree s height as a function of number of external, internal, of overall nodes log 2 (n+1)-1 h (n-1)/2 log 2 (e) h e-1 log 2 (i+1) h i
13 Binary Tree ADT: Interface 13 Binary Tree ADT Additional Methods extends Tree ADT, i.e. inherits all its methods public Position leftchild(position v); /* return the left child of a node */ /* error occurs if v is an external node */ public Position rightchild(position v); /* return the right child of a node */ /* error occurs if v is an external node */ public Position sibling(position v); /* return the sibling of a node */ /* error occurs if v is the root */
14 Binary Tree: Array-Based Implementation 14 Indexing Scheme for every node v of T, let its index/rank p(v) be defined as follows if v is the root: p(v) = 1 if v is the left child of node u: p(v) = 2p(u) if v is the right child of node u: p(v) = 2p(u) A B 2 3 C D E F G No element at A B C D E F G rank 0! Advantages simple implementation, easy access
15 Binary Tree: Array-Based Implementation (cont.) 15 Space Complexity let use the following notation n number of nodes in T p M maximum value of p(v) N array size (N=p M +1), i.e. space usage 1) Best Case: full, balanced tree all array slots occupied N = p M +1 = n+1 = O(n) 2) Worst Case: highly unbalanced tree many slots empty height: h = (n-1)/2 max p(v): p M = 2 h+1 1 = 2 (n+1)/2 1 required: N = p M +1 = 2 (n+1)/2 = O(2 n ) array size max p M - as if this was full binary tree
16 Array-Based Binary Tree: Performance 16 Run Times Good Good! all methods, except positions and elements run in constant O(1) time Method position, elements swapelements, replaceelement root, parent, children leftchild, rightchild, sibling isinternal, isexternal, isroot expandexternal, removeaboveexternal Time O(n) O(1) O(1) O(1) O(1) O(1) Space Usage Poor! (in general) best case (full balanced tree): O(n) worst case (highly unbalanced tree): O(2 n )
17 Link Structure - Based Implementation of Binary Tree 17 Node in Linked Structure object containing for Binary Trees 1) element 2) reference to parent 3) reference to the right child 4) reference to the left child if node is the root: reference to parent = null if node is external: references to children = null parent left child element right child
18 18 Link Structure - Based Implement. of Binary Tree (cont.) Example 4 [ binary tree and its linked list implementation ] A B C A B C D E D E
19 BTNode ADT: Implementation 19 BTNode Class generalization of Position ADT, i.e. implements Position interface public class BTNode implements Position { private Object element; private BTNode left, right, parent; public BTNode(Object o, BTNode u, BTNode v, BTNode w) { setelement(o); setparent(u); setleft(v); setright(w); } public Object element() { return element; } public void setelement(object o) { element = o; }
20 BTNode ADT: Implementation (cont.) 20 public BTNode getleft() { return left; } public void setleft(btnode v) { left = v; } public BTNode getright() { return right; } public void setright(btnode v) { right = v; } } public BTNode getparent() { return parent; } public void setparent(btnode v) { parent = v; } Root Node: BTNode root = BTNode(o,null,v, w) External Node: BTNode root = BTNode(o, u, null, null)
21 BTNode ADT: Implementation (cont.) 21 Null_Node contains no elements, no children, has only reference to the parent implements Position interface! Extended BT every external node reference becomes reference to Null_Node with this approach, there is never a need to check whether a reference to a child is null implementation presented here, and in the textbook, does not employ Null_Node A null null null null null null (A.getLeft()).element(); A (A.getLeft()).element();
22 LinkedBinaryTree ADT: Implementation 22 LinkedBinaryTree Class implements BinaryTree interface, and also provides 2 additional methods 1) expandexternal 2) removeaboveexternal public class LinkedBinaryTree implements BinaryTree { } private Position root; /* reference to the root */ private int size; /* number of nodes */ public LinkedBinaryTree() { root = new BTNode(null, null, null, null); size = 1; } public void expandexternal (Position v) { } public void removeaboveexternal (Position v) { } For other methods, and their implementation details, see pp of the textbook.
23 LinkedBinaryTree ADT: Implementation (cont.) 23 expandexternal() Method transforms v from external into internal node, by creating 2 new external nodes and making them the children of v error occurs if v is internal A expandexternal(a) A public void expandexternal (Position v) { if (isexternal(v)) { ((BTNode) v ).setleft(new BTNode(null, (BTNode) v, null null); ((BTNode) v ).setrigth(new BTNode(null, (BTNode) v, null null); size += 2; } } Application of expandexternal() used for building a tree see pp. 27
24 LinkedBinaryTree ADT: Implementation (cont.) 24 removeaboveexternal() Method removes external node w together with its parent v, replacing v with the sibling of w error occurs if w is internal w v z removeaboveexternal(w) z Application of removeaboveexternal() used to dismantle a tree
25 LinkedBinaryTree ADT: Implementation (cont.) 25 public void removeaboveexternal (Position v) { if (isexternal(v)) { BTNode p = (BTNode) parent(v); BTNode s = (BTNode) sibling(v); v p s if (isroot(p)) { s.setparent(null); root = s; } else { }; BTNode g = (BTNode) parent(p); if (p == lefchild(g)) g.setleft(s); else g.setright(s); s.setparent(g); g v p s } } size-=2;
26 LinkedBinaryTree ADT: Implementation (cont.) 26 Run Times Good Good! all methods, except positions and elements run in constant O(1) time Space Complexity Good! only O(n), since there is one BTNode object per every node of the tree no empty slots as in array-based implementation Method position, elements swapelements, replaceelement root, parent, children leftchild, rightchild, sibling isinternal, isexternal, isroot expandexternal, removeaboveexternal Time O(n) O(1) O(1) O(1) O(1) O(1) Only immediate children!
27 LinkedBinaryTree ADT: Implementation (cont.) 27 Example 5 [ creating a tree ] LinkedBinaryTree t = new LinkedBinaryTree(); t.root().setelement( Albert ); t.expandexternal(tree.root()); t.root().leftchild().setelement( Betty ); t.root().rightchild().setelement( Chris ); t.expandexternal(tree.root().leftchild()); t.root().leftchild().leftchild().setelement( David ); t.root().leftchild().rightchild().setelement( Elvis ); Albert Betty Chris David Elvis
Full and Complete Binary Trees
Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full
Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *
Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest
Binary Heap Algorithms
CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected] 2005 2009 Glenn G. Chappell
6 March 2007 1. Array Implementation of Binary Trees
Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of
Binary Trees and Huffman Encoding Binary Search Trees
Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary
Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child
Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 11-6 Arbitrary binary tree FIGURE 11-7 Binary search tree Data Structures Using
Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R
Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent
Algorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property
CmSc 250 Intro to Algorithms Chapter 6. Transform and Conquer Binary Heaps 1. Definition A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called
From Last Time: Remove (Delete) Operation
CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From
Chapter 14 The Binary Search Tree
Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a
Binary Heaps. CSE 373 Data Structures
Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely
How To Create A Tree From A Tree In Runtime (For A Tree)
Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:
Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees
Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture
Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles
B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:
The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).
CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical
Analysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!
Data Structures Fibonacci Heaps, Amortized Analysis
Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:
Cpt S 223. School of EECS, WSU
Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)
Binary Search Trees (BST)
Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search
Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1
Stacks (and Queues) 1 Stacks Stack: what is it? ADT Applications Implementation(s) 2 CSCU9A3 1 Stacks and ueues A stack is a very important data structure in computing science. A stack is a seuence of
B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees
B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:
Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;
50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)
Algorithms and Data Structures
Algorithms and Data Structures CMPSC 465 LECTURES 20-21 Priority Queues and Binary Heaps Adam Smith S. Raskhodnikova and A. Smith. Based on slides by C. Leiserson and E. Demaine. 1 Trees Rooted Tree: collection
Why Use Binary Trees?
Binary Search Trees Why Use Binary Trees? Searches are an important application. What other searches have we considered? brute force search (with array or linked list) O(N) binarysearch with a pre-sorted
Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg
Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a
Binary Search Trees 3/20/14
Binary Search Trees 3/0/4 Presentation for use ith the textbook Data Structures and Algorithms in Java, th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldasser, Wiley, 04 Binary Search Trees 4
Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)
Hash Tables Tables so far set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation
Mathematical Induction. Lecture 10-11
Mathematical Induction Lecture 10-11 Menu Mathematical Induction Strong Induction Recursive Definitions Structural Induction Climbing an Infinite Ladder Suppose we have an infinite ladder: 1. We can reach
Analysis of Algorithms I: Binary Search Trees
Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary
7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
GRAPH THEORY LECTURE 4: TREES
GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection
The ADT Binary Search Tree
The ADT Binary Search Tree The Binary Search Tree is a particular type of binary tree that enables easy searching for specific items. Definition The ADT Binary Search Tree is a binary tree which has an
Recursive Implementation of Recursive Data Structures
Recursive Implementation of Recursive Data Structures Jonathan Yackel Computer Science Department University of Wisconsin Oshkosh Oshkosh, WI 54901 [email protected] Abstract The elegant recursive definitions
TREE BASIC TERMINOLOGIES
TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and
Questions 1 through 25 are worth 2 points each. Choose one best answer for each.
Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in
Converting a Number from Decimal to Binary
Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive
A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:
Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree
API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.
Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing
Ordered Lists and Binary Trees
Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:
Artificial Intelligence
Artificial Intelligence ICS461 Fall 2010 1 Lecture #12B More Representations Outline Logics Rules Frames Nancy E. Reed [email protected] 2 Representation Agents deal with knowledge (data) Facts (believe
ER E P M A S S I CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A-1998-5
S I N S UN I ER E P S I T VER M A TA S CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A-1998-5 UNIVERSITY OF TAMPERE DEPARTMENT OF
Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb
Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations
DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT
DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT By GROUP Avadhut Gurjar Mohsin Patel Shraddha Pandhe Page 1 Contents 1. Introduction... 3 2. DNS Recursive Query Mechanism:...5 2.1. Client
Data Structures and Algorithms
Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list
Union-Find Problem. Using Arrays And Chains
Union-Find Problem Given a set {,,, n} of n elements. Initially each element is in a different set. ƒ {}, {},, {n} An intermixed sequence of union and find operations is performed. A union operation combines
Analysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications
Optimal Binary Search Trees Meet Object Oriented Programming
Optimal Binary Search Trees Meet Object Oriented Programming Stuart Hansen and Lester I. McCann Computer Science Department University of Wisconsin Parkside Kenosha, WI 53141 {hansen,mccann}@cs.uwp.edu
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
ADTs,, Arrays, Linked Lists
1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract
Data Structure with C
Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which
Load Balancing. Load Balancing 1 / 24
Load Balancing Backtracking, branch & bound and alpha-beta pruning: how to assign work to idle processes without much communication? Additionally for alpha-beta pruning: implementing the young-brothers-wait
Keys and records. Binary Search Trees. Data structures for storing data. Example. Motivation. Binary Search Trees
Binary Search Trees Last lecture: Tree terminology Kinds of binary trees Size and depth of trees This time: binary search tree ADT Java implementation Keys and records So far most examples assumed that
Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson
Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications Array-Based Linked List-Based 4 Additional Information Mike Jacobson (University
PES Institute of Technology-BSC QUESTION BANK
PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions
Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay
Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay Lecture - 17 Shannon-Fano-Elias Coding and Introduction to Arithmetic Coding
This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues 1. 2004 Goodrich, Tamassia
This lecture Abstract data types Stacks Queues ADTs, Stacks, Queues 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
Symbol Tables. Introduction
Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The
Binary Multiplication
Binary Multiplication Q: How do we multiply two numbers? eg. 12, 345 6, 789 111105 987600 8641500 + 74070000 83, 810, 205 10111 10101 10111 00000 1011100 0000000 + 101110000 111100011 Pad, multiply and
DATABASE DESIGN - 1DL400
DATABASE DESIGN - 1DL400 Spring 2015 A course on modern database systems!! http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn! Uppsala Database Laboratory! Department of Information
Heaps & Priority Queues in the C++ STL 2-3 Trees
Heaps & Priority Queues in the C++ STL 2-3 Trees CS 3 Data Structures and Algorithms Lecture Slides Friday, April 7, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
CS711008Z Algorithm Design and Analysis
CS711008Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap 1 Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 The slides were
Analysis of Algorithms I: Optimal Binary Search Trees
Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search
EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27
EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27 The Problem Given a set of N objects, do any two intersect? Objects could be lines, rectangles, circles, polygons, or other geometric objects Simple to
Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).
Binary search tree Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Data strutcure fields usually include for a given node x, the following
THIS CHAPTER studies several important methods for sorting lists, both contiguous
Sorting 8 THIS CHAPTER studies several important methods for sorting lists, both contiguous lists and linked lists. At the same time, we shall develop further tools that help with the analysis of algorithms
Lecture 7: NP-Complete Problems
IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Basic Course on Computational Complexity Lecture 7: NP-Complete Problems David Mix Barrington and Alexis Maciel July 25, 2000 1. Circuit
Hash Tables. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited
Hash Tables Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited We ve considered several data structures that allow us to store and search for data
Why? A central concept in Computer Science. Algorithms are ubiquitous.
Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online
root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain
inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each
Sample Questions with Explanations for LSAT India
Five Sample Analytical Reasoning Questions and Explanations Directions: Each group of questions in this section is based on a set of conditions. In answering some of the questions, it may be useful to
Find-The-Number. 1 Find-The-Number With Comps
Find-The-Number 1 Find-The-Number With Comps Consider the following two-person game, which we call Find-The-Number with Comps. Player A (for answerer) has a number x between 1 and 1000. Player Q (for questioner)
Fundamental Algorithms
Fundamental Algorithms Chapter 6: AVL Trees Michael Bader Winter 2011/12 Chapter 6: AVL Trees, Winter 2011/12 1 Part I AVL Trees Chapter 6: AVL Trees, Winter 2011/12 2 Binary Search Trees Summary Complexity
Chapter 13: Query Processing. Basic Steps in Query Processing
Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing
Approximation Algorithms
Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms
Big Data and Scripting. Part 4: Memory Hierarchies
1, Big Data and Scripting Part 4: Memory Hierarchies 2, Model and Definitions memory size: M machine words total storage (on disk) of N elements (N is very large) disk size unlimited (for our considerations)
Lecture Notes on Binary Search Trees
Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 17 March 17, 2010 1 Introduction In the previous two lectures we have seen how to exploit the structure
CS473 - Algorithms I
CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine
Section #6: Addressing
Section #6: Addressing Problem 1: Routing entries Consider the following routing table for router A, given in CIDR ( slash-n ) notation: 56.162.0.0/15: Port 0 56.164.0.0/15: Port 1 56.166.0.0/16: Port
Binary search tree with SIMD bandwidth optimization using SSE
Binary search tree with SIMD bandwidth optimization using SSE Bowen Zhang, Xinwei Li 1.ABSTRACT In-memory tree structured index search is a fundamental database operation. Modern processors provide tremendous
Classification On The Clouds Using MapReduce
Classification On The Clouds Using MapReduce Simão Martins Instituto Superior Técnico Lisbon, Portugal [email protected] Cláudia Antunes Instituto Superior Técnico Lisbon, Portugal [email protected]
Parallelization: Binary Tree Traversal
By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First
Arithmetic Coding: Introduction
Data Compression Arithmetic coding Arithmetic Coding: Introduction Allows using fractional parts of bits!! Used in PPM, JPEG/MPEG (as option), Bzip More time costly than Huffman, but integer implementation
A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
Algorithms Chapter 12 Binary Search Trees
Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 [email protected] Department of Computer Science and Engineering National Taiwan Ocean University
Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)
Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse
Binary Search Trees CMPSC 122
Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than
Section IV.1: Recursive Algorithms and Recursion Trees
Section IV.1: Recursive Algorithms and Recursion Trees Definition IV.1.1: A recursive algorithm is an algorithm that solves a problem by (1) reducing it to an instance of the same problem with smaller
Class Notes CS 3137. 1 Creating and Using a Huffman Code. Ref: Weiss, page 433
Class Notes CS 3137 1 Creating and Using a Huffman Code. Ref: Weiss, page 433 1. FIXED LENGTH CODES: Codes are used to transmit characters over data links. You are probably aware of the ASCII code, a fixed-length
Lecture Notes on Binary Search Trees
Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative
! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.
Approximation Algorithms Chapter Approximation Algorithms Q Suppose I need to solve an NP-hard problem What should I do? A Theory says you're unlikely to find a poly-time algorithm Must sacrifice one of
OPTIMAL BINARY SEARCH TREES
OPTIMAL BINARY SEARCH TREES 1. PREPARATION BEFORE LAB DATA STRUCTURES An optimal binary search tree is a binary search tree for which the nodes are arranged on levels such that the tree cost is minimum.
Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model
Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Outline Using High-Level Conceptual Data Models for
Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C
Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate
Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s
Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number
Homework until Test #2
MATH31: Number Theory Homework until Test # Philipp BRAUN Section 3.1 page 43, 1. It has been conjectured that there are infinitely many primes of the form n. Exhibit five such primes. Solution. Five such
Chapter 13. Disk Storage, Basic File Structures, and Hashing
Chapter 13 Disk Storage, Basic File Structures, and Hashing Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and Extendible Hashing
