TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.

Slides:



Advertisements
Similar presentations
Lecture 10 Disjoint Set ADT.
Advertisements

The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
They’re not just binary anymore!
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Grammars and Parsing  Recursive Definitions of Properties.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
What is a heap? Always keep the thing we are most interested in close to the top (and fast to access). Like a binary search tree, but less structured.
+ 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,
1 The Disjoint Set ADT CS146 Chapter 8 Yan Qing Lei.
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.
CPSC 252 Binary Heaps Page 1 Binary Heaps A complete binary tree is a binary tree that satisfies the following properties: - every level, except possibly.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
ADT Binary Search Tree Ellen Walker CPSC 201 Data Structures Hiram College.
Binary Search Trees (BST)
Recursion and Induction  For advanced algorithm development, recursion is an essential design technique Recursive Procedures What is a Proof? Induction.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R3. Priority Queues.
CSI 312 Dr. Yousef Qawqzeh Heaps and Priority Queue.
Computer Engineering Rabie A. Ramadan Lecture 6.
Course: Programming II - Abstract Data Types HeapsSlide Number 1 The ADT Heap So far we have seen the following sorting types : 1) Linked List sort by.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Merge Sort 1/12/2018 5:48 AM Merge Sort 7 2   7  2  2 7
Chapter 12 – Data Structures
CSCE 210 Data Structures and Algorithms
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Top 50 Data Structures Interview Questions
Data Structure Interview Question and Answers
Chapter 15 Lists Objectives
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Cinda Heeren / Geoffrey Tien
Specifications What? Not how!.
Part-D1 Priority Queues
Bohyung Han CSE, POSTECH
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
structures and their relationships." - Linus Torvalds
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
What is a heap? Always keep the thing we are most interested in close to the top (and fast to access). Like a binary search tree, but less structured.
ITEC 2620M Introduction to Data Structures
Ch. 8 Priority Queues And Heaps
CS6045: Advanced Algorithms
Chapter 10 1 – Binary Trees Tree Structures (3 slides)
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Introduction to Data Structure
DATA STRUCTURE.
CSC 143 Binary Search Trees.
Fundamental Structures of Computer Science II
structures and their relationships." - Linus Torvalds
EE 312 Software Design and Implementation I
Abstract Data Types (ADTs)
Presentation transcript:

TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type  Specification  Design  Architecture [Structure, Function] Abstract Data Types  Lists, Trees  Stacks, Queues  Priority Queue, Union-Find  Dictionary

Abstract Data type  i is an instance of type T, i  T  e is an element of set S, e  S  o is an object of class C, o  C Abstract Data Type  Structures: data structure declarations  Functions: operation definitions An ADT is identified as a Class  in languages such as C++ and Java Designing algorithms and proving correctness of algorithms  based on ADT operations and specifications

ADT Specification The specification of an ADT describe how the operations (functions, procedures, or methods) behave  in terms of Inputs and Outputs A specification of an operation consists of:  Calling prototype  Preconditions  Postconditions The calling prototype includes  name of the operation  parameters and their types  return value and its types The preconditions are statements  assumed to be true when the operation is called. The postconditions are statements  assumed to be true when the operation returns.

Operations for ADT Constructors  create a new object and return a reference to it Access functions  return information about an object, but do not modify it Manipulation procedures  modify an object, but do not return information State of an object  current values of its data Describing constructors and manipulation procedures  in terms of Access functions Recursive ADT  if any of its access functions returns the same class as the ADT

ADT Design e.g. Lists  Every computable function can be computed using Lists as the only data structure! IntList cons(int newElement, IntList oldList)  Precondition: None.  Postconditions: If x = cons(newElement, oldList) then 1. x refers to a newly created object; 2. x != nil; 3. first(x) = newElement; 4. rest(x) = oldList int first(IntList aList) // access function  Precondition: aList != nil IntList rest(IntList aList) // access function  Precondition: aList != nil IntList nil //constant denoting the empty list.

Binary Tree A binary tree T is a set of elements, called nodes, that is empty or satisfies:  1. There is a distinguished node r called the root  2. The remaining nodes are divided into two disjoint subsets, L and R, each of which is a binary tree. L is called the left subtree of T and R is called the right subtree of T. There are at most 2 d nodes at depth d of a binary tree. A binary tree with n nodes has height at least Ceiling[lg(n+1)] – 1. A binary tree with height h has at most 2 h+1 –1 nodes

Stacks A stack is a linear structure in which insertions and deletions are always make at one end, called the top. This updating policy is call last in, first out (LIFO)

Queue A queue is a linear structure in which  all insertions are done at one end, called the rear or back, and  all deletions are done at the other end, called the front. This updating policy is called first in, first out (FIFO)

Priority Queue A priority queue is a structure with some aspects of FIFO queue but  in which element order is related to each element’s priority,  rather than its chronological arrival time. As each element is inserted into a priority queue, conceptually it is inserted in order of its priority The one element that can be inspected and removed is the most important element currently in the priority queue.  a cost viewpoint: the smallest priority  a profit viewpoint: the largest priority

Union-Find ADT for Disjoint Sets Through a Union operation, two (disjoint) sets can be combined.  (to insure the disjoint property of all existing sets, the original two sets are removed and the new set is added)  Let the set id of the original two set be, s and t, s != t  Then, new set has one unique set id that is either s or t. Through a Find operation, the current set id of an element can be retrieved. Often elements are integers and  the set id is some particular element in the set, called the leader, as in the next e.g.

Union-Find ADT e.g. UnionFind create(int n)  // create a set (called sets) of n singleton disjoint sets {{1},{2},{3},…,{n}} int find(UnionFind sets, e)  // return the set id for e void makeSet(unionFind sets, int e)  //union one singleton set {e} (e not already in the sets) into the exiting sets void union(UnionFind sets, int s, int t)  // s and t are set ids, s != t  // a new set is created by union of set [s] and set [t]  // the new set id is either s or t, in some case min(s, t)

Dictionary ADT A dictionary is a general associative storage structure. Items in a dictionary  have an identifier, and  associated information that needs to be stored and retrieved.  no order implied for identifiers in a dictionary ADT