Chapter 8: Data Abstractions

Similar documents
Chapter 8: Data Abstractions

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

CS301 - Data Structures Glossary By

Boolean Representations and Combinatorial Equivalence

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Data Structure. IBPS SO (IT- Officer) Exam 2017

Fundamentals of Data Structure

Motivation. CS389L: Automated Logical Reasoning. Lecture 5: Binary Decision Diagrams. Historical Context. Binary Decision Trees

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

CS521 \ Notes for the Final Exam

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Stacks, Queues and Hierarchical Collections

Behavior models and verification Lecture 6

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Binary Trees

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Course Review for Finals. Cpt S 223 Fall 2008

Programming II (CS300)

Binary Decision Diagrams

Data Structures Question Bank Multiple Choice

DATA STRUCTURES AND ALGORITHMS

TREES Lecture 10 CS2110 Spring2014

Chapter 6: Programming Languages

Data Structures and Algorithms

Model Checking I Binary Decision Diagrams

Trees. (Trees) Data Structures and Programming Spring / 28

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Properties of red-black trees

Chapter 20: Binary Trees

Data Structure - Binary Tree 1 -

[ DATA STRUCTURES] to Data Structures

Symbolic Model Checking

3. Fundamental Data Structures

CSE 530A. B+ Trees. Washington University Fall 2013

Algorithms and Data Structures

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Unit 4: Formal Verification

EE 368. Weeks 5 (Notes)

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Fundamental Algorithms

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

CS 8391 DATA STRUCTURES

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

DATA STRUCTURE AND ALGORITHM USING PYTHON

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

[ DATA STRUCTURES ] Fig. (1) : A Tree

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

The questions will be short answer, similar to the problems you have done on the homework

On Proof Systems Behind Efficient SAT Solvers. DoRon B. Motter and Igor L. Markov University of Michigan, Ann Arbor

B-Trees and External Memory

Indexing Methods. Lecture 9. Storage Requirements of Databases

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

Question Bank Subject: Advanced Data Structures Class: SE Computer

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

B-Trees and External Memory

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Graph. Vertex. edge. Directed Graph. Undirected Graph

Basic Data Structures (Version 7) Name:

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

Trees Chapter 19, 20. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

15.082J/6.855J/ESD.78J September 14, Data Structures

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Graph and Digraph Glossary

Programming II (CS300)

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

( ) n 3. n 2 ( ) D. Ο

Trees. Eric McCreath

CS24 Week 8 Lecture 1

A set of nodes (or vertices) with a single starting point

12 Abstract Data Types

Formal Verification. Lecture 7: Introduction to Binary Decision Diagrams (BDDs)

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

and 6.855J February 6, Data Structures

Data Structures and Algorithms (DSA) Course 9 Lists / Graphs / Trees. Iulian Năstac

CS-301 Data Structure. Tariq Hanif

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Building Java Programs

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Types II. Hwansoo Han

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

Trees. CSE 373 Data Structures

Department of Computer Science and Technology

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Binary Decision Diagrams and Symbolic Model Checking

Lecture Notes on Binary Decision Diagrams

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Data and File Structures Laboratory

Why Do We Need Trees?

Transcription:

Chapter 8: Data Abstractions Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Presentation files modified by Farn Wang Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 8: Data Abstractions 8. Data Structure Fundamentals 8.2 Implementing Data Structures 8.3 A Short Case Study 8.4 Customized Data Types 8.5 Classes and Objects 8.6 Pointers in Machine Language Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-2

Basic Data Structures Homogeneous array Heterogeneous array List Stack Queue Tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-3

Lists, stacks, and queues Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-4

Terminology for Lists List: A collection of data whose entries are arranged sequentially Head: The beginning of the list Tail: The end of the list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-5

Terminology for Stacks Stack A list in which entries are removed and inserted only at the head LIFO: Last-in-first-out Top: The head of list (stack) Bottom or base: The tail of list (stack) Pop: To remove the entry at the top Push: To insert an entry at the top Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-6

Terminology for Queues Queue: A list in which entries are removed at the head and are inserted at the tail FIFO: First-in-first-out Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-7

Tree - An example of an organization chart Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-8

Terminology for a Tree Tree: A collection of data whose entries have a hierarchical organization Node: An entry in a tree Root node: The node at the top Terminal or leaf node: A node at the bottom Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-9

Terminology for a Tree (continued) Parent: The node immediately above a specified node Child: A node immediately below a specified node Ancestor: Parent, parent of parent, etc. Descendent: Child, child of child, etc. Siblings: Nodes sharing a common parent Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-

Terminology for a Tree (continued) Binary tree: A tree in which every node has at most two children Depth: The number of nodes in longest path from root to leaf Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-

Tree terminology Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-2

Additional Concepts Static Data Structures: Size and shape of data structure does not change Dynamic Data Structures: Size and shape of data structure can change Pointers: Used to locate data Used for constructing dynamic structures Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-3

Dynamic linked lists - example Novel records arranged by title but linked according to authorship Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-4

Storing Arrays Homogeneous arrays Row-major order versus column major order Address polynomial Heterogeneous arrays Components can be stored one after the other in a contiguous block Components can be stored in separate locations identified by pointers Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-5

The array of temperature readings stored in memory starting at address x Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-6

A two-dimensional array with four rows and five columns stored in row major order Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-7

Storing the heterogeneous array Employee Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-8

Storing Lists Contiguous list: List stored in a homogeneous array Linked list: List in which each entries are linked by pointers Head pointer: Pointer to first entry in list NIL pointer: A non-pointer value used to indicate end of list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-9

Names stored in memory as a contiguous list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-2

The structure of a linked list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-2

Deleting an entry from a linked list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-22

Inserting an entry into a linked list Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-23

Storing Stacks and Queues Stacks usually stored as contiguous lists Queues usually stored as Circular Queues Stored in a contiguous block in which the first entry is considered to follow the last entry Prevents a queue from crawling out of its allotted storage space Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-24

A stack in memory Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-25

A queue implementation with head and tail pointers Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-26

A circular queue containing the letters P through V Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-27

Storing Binary Trees Linked structure Each node = data cells + two child pointers Accessed via a pointer to root node Contiguous array structure A[] = root node A[2],A[3] = children of A[] A[4],A[5],A[6],A[7] = children of A[2] and A[3] Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-28

The structure of a node in a binary tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-29

The conceptual and actual organization of a binary tree using a linked storage system Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-3

A tree stored without pointers Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-3

A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-32

Manipulating Data Structures Ideally, a data structure should be manipulated solely by pre-defined procedures. Example: A stack typically needs at least push and pop procedures. The data structure along with these procedures constitutes a complete abstract tool. Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-33

A procedure for printing a linked list procedure print_list(list) { c = list; while (c is not NIL) do { print the name pointed to by c; let c by the next element to c in the list; } } Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-34

Case Study Problem: Construct an abstract tool consisting of a list of names in alphabetical order along with the operations search, print, and insert. Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-35

The letters A through M arranged in an ordered tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-36

The binary search as it would appear if the list were implemented as a linked binary tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-37

The successively smaller trees considered by the procedure in Figure 8.8 when searching for the letter J Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-38

Printing a search tree in alphabetical order Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-39

A procedure for printing the data in a binary tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-4

Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-4

A procedure for inserting a new entry in a list stored as a binary tree Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-42

User-defined Data Type A template for a heterogeneous structure Example: define type EmployeeType to be {char Name[25]; int Age; real SkillRating; } Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-43

Abstract Data Type A user-defined data type with procedures for access and manipulation Example: define type StackType to be {int StackEntries[2]; int top = ; procedure push(value){ StackEntries[top] value; top = top + ; } procedure pop... } Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-44

Class An abstract data type with extra features Characteristics can be inherited Contents can be encapsulated Constructor methods to initialize new objects Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-45

A stack of integers implemented in Java and C# Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-46

Pointers in Machine Language Immediate addressing: Instruction contains the data to be accessed Direct addressing: Instruction contains the address of the data to be accessed Indirect addressing: Instruction contains the location of the address of the data to be accessed Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-47

Our first attempt at expanding the machine language in Appendix C to take advantage of pointers Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-48

Loading a register from a memory cell that is located by means of a pointer stored in a register Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-49

Indirect vs. direct addressing Direct addressing PC 9C PC AB2 BR AB2 BR AB2 35AD AB2 35AD Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-5

Indirect vs. direct addressing PC Indirect addressing 9C PC 35AD.. 35AD BR *AB2 BR AB2 35AD AB2 35AD Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-5

Beyond the basics Tree applications heirarchical network topology of network cluster computing circuit signal propagations Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-52

Beyond the basics Trees depth log(# of nodes in the tree) efficient membership checking Questions? Can we maintain the log depths with dynamic node insertion and deletion? Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-53

Beyond the basics Trees Maintaining the log depths with dynamic node insertion and deletion? trees implemented with pointers: solutions 2-3 trees red-black trees splay trees Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-54

Beyond the basics Graphs undirected directed Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-55

Beyond the basics Graph problems Find a path (with a cost?) between two nodes. Find a cycle in a graph. Find the biconnected components Check if a graph is planar. Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-56

Beyond the basics DAG (directed acyclic graphs) Directed graphs without cycles Can be used for Boolean formula presentation. Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-57

Truth Table, DNF, and CNF x x 2 x 3 F Disjunctive normal form (DNF) F = ( x x 2 x 3 ) (x x 2 x 3 ) (x x 2 x 3 ) Conjunctive normal form (CNF) F = (x x 2 x 3 ) (x x 2 x 3 ) (x x 2 x 3 ) ( x x 2 x 3 ) ( x x 2 x 3 ) Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 58

Binary Decision Tree (BDT) - predecessor of BDD with redundancies Same size as truth tables Lots of redundancy: Out of 8 subtrees rooted at b 2 only 3 are distinct!!! Merge isomorphic subtrees BDD Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 59

Truth Table and Decision Tree x x 2 x 3 F x x 2 x 2 x 3 x 3 x 3 x 3 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6

Structure sharing in BDT ( a b a2 b2) ( a b a2 b2) (a b a2 b2) (a b a2 b2) function values determined at b Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6

Binary Decision Diagram (BDD) BDD: A minimal canonical form representation for Boolean formulas. minimum size representation (for a given var ordering) Motivation: Too much space redundancy in traditional representations BDD is more compact than truth tables, conjunctive normal form, disjunctive normal form, binary decision trees, etc. BDD has a canonical form BDD operations are efficient Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley unique BDD for a function 62

BDD (Binary Decision Diagram) minimal canonical form of Boolean functions minimal efficiency (space & computation) for a specific variable ordering Canonical form: unique BDD for a function y (x y) z x z Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 63

BDD function evluation Using path traversal to evaluate function x y z y x (x y) z y z x z x y z Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 64

BDD Reduction (I) - from bottom up x at leaf level x x 2 x 2 x 2 x 2 x 3 x 3 x 3 x 3 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 65

BDD Reduction (II) - from bottom up x at level x 3 x x 2 x 2 x 2 x 2 x 3 x 3 x 3 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 66

BDD Reduction (III) - from bottom up x 2 x at level x 2 x 2 x 2 x x 3 x 3 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 67

Relations for Logic Blocks: Example x x 2 x 3 y y 2 x x 2 x 3 y y 2 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 68

Example (continued) x x 2 x 3 y y 2 F other x x 2 x 3 y y 2 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 69

Relations for FSMs: Example Ins CS CSC NS NSC A B, A A B B B A C B C A A, C B Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7

Example (continued) Relation = i a a 2 b b 2 + a a 2 b b 2 + ia a 2 b b 2 + ia a 2 b b 2 + ia a 2 b b 2 + ia a 2 b b 2 i a b a 2 b 2 Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7

Efficient Operations on BDDs Apply NOT, AND, OR, EXOR, etc. Quantification (existential, universal) Replace Compose Specialized operators Generalized cofactor (constrain, restrict) Compatible projection, etc. Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 72

Components of BDDs and Their Use Nodes (represent functions; complexity) Terminal nodes (constant functions) Edges (relationship between functions) Paths (true and false var. assignments) Cuts (variable partitions and subsets) Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 73

Properties of BDDs Canonicity Compactness (with some exceptions) Representing a variety of discrete objects Boolean functions Compositional sets Encodings and labelings Facilitating symbolic methods Two-level minimization State traversal of FSMs Copyright 28 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 74