Advanced Data Structures

Slides:



Advertisements
Similar presentations
DATA STRUCTURE RECAP Yiqun Zhang University of Houston.
Advertisements

©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
Trees, Binary Trees, and Binary Search Trees COMP171.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
1 Advanced Data Structures. 2 Topics Data structures (old) stack, list, array, BST (new) Trees, heaps, union-find, hash tables, spatial, string Algorithm.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
BST Data Structure A BST node contains: A BST contains
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Lec 15 April 9 Topics: l binary Trees l expression trees Binary Search Trees (Chapter 5 of text)
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Fundamentals of Python: From First Programs Through Data Structures
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Important Problem Types and Fundamental Data Structures
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
More Trees COL 106 Amit Kumar and Shweta Agrawal Most slides courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Chapter 12. Binary Search Trees. Search Trees Data structures that support many dynamic-set operations. Can be used both as a dictionary and as a priority.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Trees, Binary Trees, and Binary Search Trees COMP171.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Chapter 4: Trees Part I: General Tree Concepts Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Binary Search Trees (BST)
Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
Graphs Upon completion you will be able to:
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
Binary Tree.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Foundation of Computing Systems Lecture 4 Trees: Part I.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
Chapter 7 Trees_ Part2 TREES. Depth and Height 2  Let v be a node of a tree T. The depth of v is the number of ancestors of v, excluding v itself. 
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Chapter 12 Abstract Data Type.
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008
Chapter 15 Lists Objectives
Binary Search Tree (BST)
Lecture 22 Binary Search Trees Chapter 10 of textbook
Trees.
i206: Lecture 13: Recursion, continued Trees
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
Lecture 12 CS203 1.
CMSC 202 Trees.
Binary Trees, Binary Search Trees
Trees.
Important Problem Types and Fundamental Data Structures
Trees.
Binary Trees, Binary Search Trees
Heaps Chapter 6 Section 6.9.
Presentation transcript:

Advanced Data Structures Cpt S 223 Advanced Data Structures Washington State University

Topics Data structures Algorithm design & analysis Queue Tree Graph Cpt S 223 Topics Data structures Algorithm design & analysis Queue Tree Graph Washington State University

What is a “data structure”?

Why study data structures? Cpt S 223 Why study data structures? Example problem Given: a set of N numbers Goal: search for number k Solution Store numbers in an array of size N Linearly scan array until k is found or array is exhausted Number of checks Best case: 1 Worst case: N Average case: N/2 3 7 6 1 10 8 43 Washington State University

Why study data structures? Cpt S 223 Why study data structures? Solution #2 Store numbers in a binary search tree Search tree until find k Number of checks Best case: 1 Worst case: log2N Average case: (log2N)/2 7 3 10 1 6 8 43 Washington State University

Analysis Does it matter? N vs. log2N Cpt S 223 Washington State University

Analysis Does it matter? Assume 1 cycle per transaction O(N) algorithm Cpt S 223 Analysis Does it matter? Assume N = 1,000,000,000 1 billion (Walmart transactions in 100 days) 1 GHz processor = 109 cycles per second 1 cycle per transaction O(N) algorithm 1 billion transactions = > 1 billion clock cycles O(lg N) algorithm 1 billion transactions => 30 clock cycles Washington State University

Example 2 Scheduling job in a printer Cpt S 223 Example 2 Scheduling job in a printer Write a code to manage the printer queue Functions to support Insert, delete Special accommodations needed for: Priority Dynamic update Scheduling challenges Washington State University

Example 3 Exploring the Facebook connection network Cpt S 223 Example 3 Exploring the Facebook connection network Write a code to tell who is connected to who (directly or indirectly) through your Facebook profile 6-degrees of separation Washington State University

Example 4 Pattern matching Cpt S 223 Example 4 Pattern matching Write a code to do Google search on your web database Washington State University

Summary Keep the data organized Choice of data structures matters Cpt S 223 Summary Keep the data organized Choice of data structures matters Appropriate data structures ease design & improve performance Challenge Design appropriate data structure & associated algorithms for a problem Analyze to show improved performance Washington State University

Queue ADT Like a stack, a queue is also a list. However, with a queue, insertion is done at one end, while deletion is performed at the other end. Accessing the elements of queues follows a First In, First Out (FIFO) order. Like customers standing in a check-out line in a store, the first customer in is the first customer served.

: Basic operations enqueue: insert an element at the rear of the list dequeue: delete the element at the front of the list

Implementation of Queue Just as stacks can be implemented as arrays or linked lists, so with queues. Dynamic queues have the same advantages over static queues as dynamic stacks have over static stacks

Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete) is O(log N)? Trees Basic concepts Tree traversal Binary tree Binary search tree and its operations

Trees A tree T is a collection of nodes T can be empty (recursive definition) If not empty, a tree T consists of a (distinguished) node r (the root), and zero or more nonempty subtrees T1, T2, ...., Tk

Continue..

Tree Traversal Used to print out the data in a tree in a certain order Pre-order traversal (Root, left, right) Print the data at the root Recursively print out all data in the leftmost sub tree Recursively print out all data in the rightmost sub tree

Continue…

Continue…. Inorder traversal (left, root, right) Recursively print out all data in the leftmost sub tree Print the data at the root Recursively print out all data in the rightmost sub tree

Continue…

Continue.. Post-order traversal (left, right, root) Recursively print out all data in the leftmost sub tree Recursively print out all data in the rightmost sub tree Print the data at the root

Continue..

Binary Trees A tree in which no node can have more than two children

Continue.. The depth of an “average” binary tree is considerably smaller than N, even though in the worst case, the depth can be as large as N – 1.

Binary Search Trees (BST) A data structure for efficient searching, inser-tion and deletion Binary search tree property For every node X All the keys in its left subtree are smaller than the key value in X All the keys in its right subtree are larger than the key value in X

Continue..

Graph A Simple graph G = (V, E) consists of a nonempty set V of vertices and a possibly empty set E of edges, each edge being a set of two vertices from V. The number of vertices and edges are denoted by |V| and |E|, respectively.

Graph Representation There are variety of ways to represent a graph. Adjacency lists. An adjacency matrix of graph G = (V, E) is a binary |V| x |V| matrix such that each entry of this matrix An incident matrix of graph G = (V, E) is a binary |V| x |E| matrix such that each entry of this matrix

Continue..

Continue.. Adjacency matrix Incident matrix

Graph Traversal As in trees, traversing a graph consists of visiting each vertex only one time. The simple traversal algorithm used for trees can not be applied here because graph may include cycles (result in to infinite loop) or, isolated vertices (left some nodes). The most popular algorithms for traversing in graphs are: Depth First Search Breadth First search

Thank you