9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.

Slides:



Advertisements
Similar presentations
Abstract Data Types and Algorithms
Advertisements

Abstract Data Types and Subprograms
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Abstract Data Types and Subprograms
Chapter 8 Abstract Data Types and Subprograms. 2 Chapter Goals Distinguish between an array-based visualization and a linked visualization Distinguish.
Connecting with Computer Science, 2e
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
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.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Marc Smith and Jim Ten Eyck
Important Problem Types and Fundamental Data Structures
Slides modified by Erin Chambers Problem Solving and Algorithm Design, part 2.
Trees & Graphs Nell Dale & John Lewis (adaptation by Michael Goldwasser and Erin Chambers)
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha.
Chapter 9 Abstract Data Types and Algorithms. 2 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified.
Chapter 9 Abstract Data Types and Algorithms. 2 Chapter Goals Define an abstract data type and discuss its role in algorithm development Distinguish between.
Chapter 16: Searching, Sorting, and the vector Type.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Chapters 7, 8, & 9 Quiz 3 Review 1. 2 Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of.
Chapter 8: Data Abstractions Senem Kumova Metin. 8-2 Chapter 8: Data Abstractions 8.1 Basic Data Structures – Arrays – Lists, Stacks, Queues – Trees 8.2.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
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 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.
Chapter 8 Abstract Data Types and Subprograms. 2 Chapter Goals Distinguish between an array-based visualization and a linked visualization Distinguish.
Graphs Upon completion you will be able to:
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 16: Searching, Sorting, and the vector Type.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
CPS120: Introduction to Computer Science Sorting.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Chapter 12 Abstract Data Type.
Data Structure By Amee Trivedi.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 12 – Data Structures
Data Structure Interview Question and Answers
Chapter 15 Lists Objectives
Abstract Data Types and Subprograms
Introduction to Data Structure
Chapter 17 Object-Oriented Data Structures
Heap Chapter 9 Objectives Upon completion you will be able to:
structures and their relationships." - Linus Torvalds
ITEC 2620M Introduction to Data Structures
CMSC 202 Trees.
Binary Search Trees Chapter 7 Objectives
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Important Problem Types and Fundamental Data Structures
structures and their relationships." - Linus Torvalds
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation The goal in design is to reduce complexity through abstraction

9-2 Abstract Data Types Data structures The implementation of a composite data fields in an abstract data type Containers Objects whole role is to hold and manipulate other objects

9-3 Stacks A stack is an abstract data type in which accesses are made at only one end –LIFO, which stands for Last In First Out –The insert is called Push and the delete is called Pop

9-4 Queues A Queue is an abstract data type in which items are entered at one end and removed from the other end –FIFO, for First In First Out –Like a waiting line in a bank or supermarket –No standard queue terminology Enqueue, Enque, Enq, Enter, and Insert are used for the insertion operation Dequeue, Deque, Deq, Delete, and Remove are used for the deletion operation.

9-5 Array-Based Implementations Recall that –an array is a named collection of homogeneous items –An item’s place within the collection is called an index If there is no ordering on the items in the container, we call the container unsorted If there is an ordering, we call the container sorted

9-6 Array-Based Implementations Figure 9.2 list of integers

9-7 Linked Implementation Linked implementation An implementation based on the concept of a node A node is made up of two pieces of information –the item that the user wants in the list, and –a pointer to the next node in the list

9-8 Linked Implementation Figure 9.4 Anatomy of a linked list

9-9 Lists List operations –Create itself –Insert an item –Delete an item –Print itself –Know the number of items it contains Generic data type (or class) A data type or class in which the operations are specified but the type or class of the objects being manipulated is not

9-10 Selection Sort List of names –Put them in alphabetical order Find the name that comes first in the alphabet, and write it on a second sheet of paper Cross out the name on the original list Continue this cycle until all the names on the original list have been crossed out and written onto the second list, at which point the second list is sorted

9-11 Selection Sort Figure 9.9 Example of a selection sort (sorted elements are shaded)

9-12 Quicksort Based on the idea that it is faster and easier to sort two small lists than one larger one –Given a large stack of final exams to sort by name –Pick a splitting value, say L, and divide the stack of tests into two piles, A–L and M–Z –note that the two piles do not necessarily contain the same number of tests –Then take the first pile and subdivide it into two piles, A–F and G–L –This division process goes on until the piles are small enough to be easily sorted by hand

9-13 Quicksort Figure 9.12 Ordering a list using the Quicksort algorithm

9-14 Binary Search A sequential search of a list begins at the beginning of the list and continues until the item is found or the entire list has been searched A binary search looks for an item in a list using a divide-and-conquer strategy

9-15 Binary Search Binary Search Algorithm –Binary search algorithm assumes that the items in the list being searched are sorted –The algorithm begins at the middle of the list in a binary search –If the item for which we are searching is less than the item in the middle, we know that the item won’t be in the second half of the list –Once again we examine the “middle” element (which is really the item 25% of the way into the list) –The process continues with each comparison cutting in half the portion of the list where the item might be

9-16 Binary Search Figure 9.14 Trace of the binary search

9-17 Trees ADTs such as lists, stacks, and queues are linear in nature More complex relationships require more complex structures

Trees (cont’d) Hierarchical structures are called trees Binary trees –Each node has no more than two children –The beginning of the tree is a unique starting node called the root –The node to the left of a node, if it exists, is called its left child –The node to the right of a node, if it exists, is its right child –If a node in the tree has no children, it is called a leaf node Figure 9.16 A binary tree 9-39

9-19 Binary Search Trees A binary search tree has the shape property of a binary tree In addition, a binary search tree has a semantic property: The value in any node is greater than the value in any node in its left subtree and less than the value in any node in its right subtree

9-20 Binary Search Tree Figure 9.18 A binary search tree

9-21 Graphs Graph A data structure that consists of a set of nodes and a set of edges that relate the nodes to each other Undirected graph A graph in which the edges have no direction Directed graph (Digraph) A graph in which each edge is directed from one vertex to another (or the same) vertex

9-22 Graphs Figure 9.21 Examples of graphs

9-23 Chapter Goals Define an abstract data type and discuss its role in algorithm development Distinguish between a data type and a data structure Distinguish between an array-based implementation and a linked implementation Distinguish between an array and a list

9-24 Chapter Goals Distinguish between an unsorted list and a sorted list Describe the Quicksort algorithm Apply the selection sort, the bubble sort, and the Quicksort to a list of items by hand Apply the binary search algorithm

9-25 Chapter Goals Distinguish between the behavior of a stack and a queue Draw the binary search tree that is built from inserting a series of items Demonstrate your understanding of the algorithms in this chapter by hand simulating them with a sequence of items