# Lecture 6: Binary Search Trees CSCI Algorithms I

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Lecture 6: Binary Search Trees CSCI Algorithms I Andrew Rosenberg September 24, 2009

2 Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort

3 Today Some C++ review Binary Search Trees

4 Homework Stats Mean: (w/o late penalties) Standard Deviation: 15 Median: 87.5

6 C++ Review Header files. Return values: vector<int> vs. vector<int>*

7 C++ Review Header files. Return values: vector<int> vs. vector<int>* Global variables.

8 C++ Review Header files. Return values: vector<int> vs. vector<int>* Global variables. &(*ptr) == ptr

9 C++ Review Header files. Return values: vector<int> vs. vector<int>* Global variables. &(*ptr) == ptr i++ vs. ++i

10 Data Structures Data structure is a set of elements and the relationship between them. The appropriate data structure for a task is determined by the functions it needs to support.

11 Data Structures Data structure is a set of elements and the relationship between them. The appropriate data structure for a task is determined by the functions it needs to support. A dictionary supports (minimally) Insert, Search and Delete. Other data structures might need Minimum, Maximum, etc.

12 Data Structures Data structure is a set of elements and the relationship between them. The appropriate data structure for a task is determined by the functions it needs to support. A dictionary supports (minimally) Insert, Search and Delete. Other data structures might need Minimum, Maximum, etc. For a restricted domain, D = {1,...,k}, we can use an array, A[1..k]. This allows Insert, Search and Delete to be O(1).

13 Data Structures Data structure is a set of elements and the relationship between them. The appropriate data structure for a task is determined by the functions it needs to support. A dictionary supports (minimally) Insert, Search and Delete. Other data structures might need Minimum, Maximum, etc. For a restricted domain, D = {1,...,k}, we can use an array, A[1..k]. This allows Insert, Search and Delete to be O(1). Aside: Hashing attempts to map an unrestricted domain to a restricted one.

14 Binary Search Tree Binary Search Trees (BSTs) are a simple and efficient implementation of a dictionary. A BST is a rooted binary tree. The keys are at the nodes. For every node, v, the keys of the left subtree key(v) For every node, v, the keys of the right subtree > key(v)

15 Binary Search Tree Binary Search Trees (BSTs) are a simple and efficient implementation of a dictionary. A BST is a rooted binary tree. The keys are at the nodes. For every node, v, the keys of the left subtree key(v) For every node, v, the keys of the right subtree > key(v) Binary Search Trees are not, by definition, balanced.

16 Binary Search Tree Data Structure parent key left right

17 Binary Search Tree Example null root

18 Binary Search Tree Example null root

19 Not a Binary Search Tree Example null root

20 Not a Binary Search Tree Example null root

21 Height of a BST The height of a BST is at most n 1. The height of a BST is at least log n.

22 Sorting with a BST Binary Search Trees are sorted. Constructing a sorted array is Θ(n) Traverse(T) if T.root then Traverse(T.left) Print T.key Traverse(T.right) end if

23 Sorting with a BST Binary Search Trees are sorted. Constructing a sorted array is Θ(n) Traverse(T) if T.root then Traverse(T.left) Print T.key Traverse(T.right) end if Can we prove that this is correct and Θ(n)?

24 Searching a BST Search(T, x) if T then if T.key = x then return T else if T.key < x then return Search(T.left, x) else return Search(T.right, x) end if end if else return null end if

25 Searching a BST Search(T,x) is O(height) If balanced, height = log n, so O(log n). Worst case scenario, a sequential search, O(n).

26 Finding specific elements in a BST Minimum(T) = O(height). Traverse to the left. Maximum(T) = O(height). Traverse to the right. Successor(T) - Find the node with smallest key greater than T.key.

27 Successor(T) Successor(T) If T has a right child, then return Minimum(T.right) If T has no right child, and is a left child, then return T.parent If T has no right child and is a right child, then traverse up until a left child is found - then this node s parent. Else T has no successor. Successor(T) = O(height)

28 Inserting an Element into a BST Insert(T,x) if T then if T.key x then Insert(T.left, x) else Insert(T.right, x) end if else T NewNode(x). end if Insert is a lot like Search. Insert(T,x) = O(height)

29 Building a BST To build a BST, Insert n random elements in order to an empty BST. It takes O(n log n) to build a BST from such a set of random elements. Run Insert n times. n i=1 log i = n log n Expected height = O(log n)

30 Building a BST To build a BST, Insert n random elements in order to an empty BST. It takes O(n log n) to build a BST from such a set of random elements. Run Insert n times. n i=1 log i = n log n Expected height = O(log n) Can a BST be constructed in less than O(n log n)?

31 Building a BST To build a BST, Insert n random elements in order to an empty BST. It takes O(n log n) to build a BST from such a set of random elements. Run Insert n times. n i=1 log i = n log n Expected height = O(log n) Can a BST be constructed in less than O(n log n)? No. It s equivalent to a comparison sort. Since Comparison sorting is Ω(n log n), constructing a BST is Ω(n log n).

32 Delete(T,v) Delete(T,v) If v is a leaf, delete v. If v has 1 child, delete v, replace v with its child. If v has 2 children, swap v with Successor(v), then Delete(v). How long does each case take?

33 Delete(T,v) Delete(T,v) If v is a leaf, delete v. If v has 1 child, delete v, replace v with its child. If v has 2 children, swap v with Successor(v), then Delete(v). How long does each case take? How can we be sure Delete(v) terminates?

34 Delete(T,v) Delete(T,v) If v is a leaf, delete v. If v has 1 child, delete v, replace v with its child. If v has 2 children, swap v with Successor(v), then Delete(v). How long does each case take? How can we be sure Delete(v) terminates? Show that this holds the BST properties.

35 Recap Binary Search Trees are an efficient, simple dictionary data structure. Construction O(n log n) Insertion O(log n) Search O(log n) Deletion O(log n) Binary Search Trees are sorted representations of data.

36 Bye Next time (8/1) Heaps. For Next Class Homework 3 Due. Read Sections 8.1, 8.2, 8.3, 8.4

### 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. 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

### Heap. Binary Search Tree. Heaps VS BSTs. < el el. Difference between a heap and a BST:

Heaps VS BSTs Difference between a heap and a BST: Heap el Binary Search Tree el el el < el el Perfectly balanced at all times Immediate access to maximal element Easy to code Does not provide efficient

### 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

### 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

### 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

### Balanced Binary Search Tree

AVL Trees / Slide 1 Balanced Binary Search Tree Worst case height of binary search tree: N-1 Insertion, deletion can be O(N) in the worst case We want a tree with small height Height of a binary tree with

### 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

### 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:

### 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:

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### Binary Search Trees > = Binary Search Trees 1. 2004 Goodrich, Tamassia

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:

### 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 CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

### 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

### 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

### 1 2-3 Trees: The Basics

CS10: Data Structures and Object-Oriented Design (Fall 2013) November 1, 2013: 2-3 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 2-3 Trees in

### Tree Properties (size vs height) Balanced Binary Trees

Tree Properties (size vs height) Balanced Binary Trees Due now: WA 7 (This is the end of the grace period). Note that a grace period takes the place of a late day. Now is the last time you can turn this

### 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

### 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

### 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

### 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:

### 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)

### 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

### 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

### 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

### 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

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### 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

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### 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

### Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets We ve been talking a lot about efficiency in computing and run time. But thus far mostly ignoring data

### Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

### schema binary search tree schema binary search trees data structures and algorithms 2015 09 21 lecture 7 AVL-trees material

scema binary searc trees data structures and algoritms 05 0 lecture 7 VL-trees material scema binary searc tree binary tree: linked data structure wit nodes containing binary searc trees VL-trees material

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### CS 253: Algorithms. Chapter 12. Binary Search Trees. * Deletion and Problems. Credit: Dr. George Bebis

CS 2: Algorithms Chapter Binary Search Trees * Deletion and Problems Credit: Dr. George Bebis Binary Search Trees Tree representation: A linked data structure in which each node is an object Node representation:

### 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

### A Comparison of Dictionary Implementations

A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function

### 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

### 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

### 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

### 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

### Physical Data Organization

Physical Data Organization Database design using logical model of the database - appropriate level for users to focus on - user independence from implementation details Performance - other major factor

### 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)

### 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

### 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

### 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

### CSE 326: Data Structures B-Trees and B+ Trees

Announcements (4//08) CSE 26: Data Structures B-Trees and B+ Trees Brian Curless Spring 2008 Midterm on Friday Special office hour: 4:-5: Thursday in Jaech Gallery (6 th floor of CSE building) This is

### Algorithms Chapter 12 Binary Search Trees

Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University

### 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

### 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

### 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

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

### Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

### 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

### 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

### In our lecture about Binary Search Trees (BST) we have seen that the operations of searching for and inserting an element in a BST can be of the

In our lecture about Binary Search Trees (BST) we have seen that the operations of searching for and inserting an element in a BST can be of the order O(log n) (in the best case) and of the order O(n)

### 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

### - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

### , each of which contains a unique key value, say k i , R 2. such that k i equals K (or to determine that no such record exists in the collection).

The Search Problem 1 Suppose we have a collection of records, say R 1, R 2,, R N, each of which contains a unique key value, say k i. Given a particular key value, K, the search problem is to locate the

### Binary Search Trees. Ric Glassey glassey@kth.se

Binary Search Trees Ric Glassey glassey@kth.se Outline Binary Search Trees Aim: Demonstrate how a BST can maintain order and fast performance relative to its height Properties Operations Min/Max Search

### 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:

### B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

B+ Tree and Hashing B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree Properties Balanced Tree Same height for paths

### 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

### Merge Sort. 2004 Goodrich, Tamassia. Merge Sort 1

Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm design paradigm: Divide: divide the input data S in two disjoint subsets

### Rotation Operation for Binary Search Trees Idea:

Rotation Operation for Binary Search Trees Idea: Change a few pointers at a particular place in the tree so that one subtree becomes less deep in exchange for another one becoming deeper. A sequence of

### Sidebar: Data Structures

Sidebar: Data Structures A data structure is a collection of algorithms for storing and retrieving information. The operations that store information are called updates, and the operations that retrieve

### 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

### 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)

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### 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

### 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

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### 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

### 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

### 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,

### Binary Search Tree. 6.006 Intro to Algorithms Recitation 03 February 9, 2011

Binary Search Tree A binary search tree is a data structure that allows for key lookup, insertion, and deletion. It is a binary tree, meaning every node of the tree has at most two child nodes, a left

### 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:

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) and the general binary

### Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

### Outline. Introduction Linear Search. Transpose sequential search Interpolation search Binary search Fibonacci search Other search techniques

Searching (Unit 6) Outline Introduction Linear Search Ordered linear search Unordered linear search Transpose sequential search Interpolation search Binary search Fibonacci search Other search techniques

### Analysis of Binary Search algorithm and Selection Sort algorithm

Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to

### Zabin Visram Room CS115 CS126 Searching. Binary Search

Zabin Visram Room CS115 CS126 Searching Binary Search Binary Search Sequential search is not efficient for large lists as it searches half the list, on average Another search algorithm Binary search Very

### Persistent Binary Search Trees

Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents

### Data storage Tree indexes

Data storage Tree indexes Rasmus Pagh February 7 lecture 1 Access paths For many database queries and updates, only a small fraction of the data needs to be accessed. Extreme examples are looking or updating

### Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

### 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

### Intro. to the Divide-and-Conquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4

Intro. to the Divide-and-Conquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4 I. Algorithm Design and Divide-and-Conquer There are various strategies we

### Data Structures, Practice Homework 3, with Solutions (not to be handed in)

Data Structures, Practice Homework 3, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 9, Exercise 1: What is the order of each of the following tasks in the worst case? (a) Computing

### Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park

Sorting Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Overview Comparison sort Bubble sort Selection sort Tree sort Heap sort Quick sort Merge

### Binary Search Trees. basic implementations randomized BSTs deletion in BSTs

Binary Search Trees basic implementations randomized BSTs deletion in BSTs eferences: Algorithms in Java, Chapter 12 Intro to Programming, Section 4.4 http://www.cs.princeton.edu/introalgsds/43bst 1 Elementary

### CompSci-61B, Data Structures Final Exam

Your Name: CompSci-61B, Data Structures Final Exam Your 8-digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings.

### Quiz 1 Solutions. (a) T F The height of any binary search tree with n nodes is O(log n). Explain:

Introduction to Algorithms March 9, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Quiz 1 Solutions Problem 1. Quiz 1 Solutions True

### Binary Search Trees. Each child can be identied as either a left or right. parent. right. A binary tree can be implemented where each node

Binary Search Trees \I think that I shall never see a poem as lovely as a tree Poem's are wrote by fools like me but only G-d can make atree \ {Joyce Kilmer Binary search trees provide a data structure

### Review of Hashing: Integer Keys

CSE 326 Lecture 13: Much ado about Hashing Today s munchies to munch on: Review of Hashing Collision Resolution by: Separate Chaining Open Addressing \$ Linear/Quadratic Probing \$ Double Hashing Rehashing

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### 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

### CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] edge. parent

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] Trees Important terminology: edge root node parent Some uses of trees: child leaf model arithmetic expressions and other expressions

### Unit 4.3 - Storage Structures 1. Storage Structures. Unit 4.3

Storage Structures Unit 4.3 Unit 4.3 - Storage Structures 1 The Physical Store Storage Capacity Medium Transfer Rate Seek Time Main Memory 800 MB/s 500 MB Instant Hard Drive 10 MB/s 120 GB 10 ms CD-ROM

### APP INVENTOR. Test Review

APP INVENTOR Test Review Main Concepts App Inventor Lists Creating Random Numbers Variables Searching and Sorting Data Linear Search Binary Search Selection Sort Quick Sort Abstraction Modulus Division