Abstract Data Types data object set or collection of instances

Slides:



Advertisements
Similar presentations
Linear Lists – Array Representation
Advertisements

Linear ADT Done By : Kishan Gopaul.
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
F28PL1 Programming Languages Lecture 14: Standard ML 4.
Chapter Three: Lists, Operators, Arithmetic CS 461.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Abstract Data Types data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
CHAPTER 3 COLLECTIONS SET Collection. 2 Abstract Data Types A data type consists of a set of values or elements, called its domain, and a set of operators.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Data Structures data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
Linear Lists – Linked List Representation CSE, POSTECH.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Iterators & Chain Variants. Iterators  An iterator permits you to examine the elements of a data structure one at a time.  C++ iterators Forward iterator.
1 Chapter 3 Data Representation Part 1. 2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based,
Containers Overview and Class Vector
Data Collections: Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 11/4/2009.
Lecture DS & Algorithms:09 Abstract Data Types. Lecture DS & Algorithms:09 2 Abstract Data Types Data Type: A data type is a collection of values and.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Lists. Container Classes Many applications in Computer Science require the storage of information for collections of entities e.g. a student registration.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
SNU IDB Lab. Ch5. Linear Lists – Array Representation © copyright 2006 SNU IDB Lab.
1 Section 1.6 Sets. 2 Set Fundamental discrete structure on which all other discrete structures are built Can be loosely defined as a collection of elements.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Linear List Array representation Data structures A data structure is a particular way of storing and manipulating data in a computer so that it can be.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Data Structures & Algorithms
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
1 Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 at end of class today –Continue working on HW3 Questions?
Data Structure Specification  Language independent  Abstract Data Type  C++  Abstract Class.
TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:
Linear (or Ordered) Lists instances are of the form (e 0, e 1, e 2, …, e n-1 ) where e i denotes a list element n >= 0 is finite list size is n.
The Class arrayList General purpose implementation of linear lists. Unknown number of lists.
Linked Data Structures
Reminder: Course Policy
-TAs and office hours announced
The Class ArrayLinearList
Lists CS 3358.
Data Abstraction: The Walls
A lightening tour in 45 minutes
List Representation - Array
The Class chain.
Object Oriented Programming COP3330 / CGS5409
Queues.
The Class arrayList General purpose implementation of linear lists.
-TAs and office hours announced
CMSC 341 Binary Search Trees.
Data Abstraction: The Walls
Mathematical Background 1
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Lists - I The List ADT.
Lists - I The List ADT.
OPERATIONS WITH INTEGERS: ADD, SUBTRACT, MULTIPLY & DIVIDE.
CSE 3302 Programming Languages
QUIZ.
CMSC 341 Binary Search Trees.
The Class chain.
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
The Class chain.
Lists - I The List ADT.
Programming II (CS300) Chapter 07: Linked Lists
Lists - I The List ADT.
Data Abstraction: The Walls
Trees Trees are a very useful data structure. Many different kinds of trees are used in Computer Science. We shall study just a few of these.
Arrays and ArrayLists.
The List Container and Iterators
Data Structures & Programming
Presentation transcript:

Abstract Data Types data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa} Any set or collection is a data object. Order in which you list the instances doesn’t matter. {1,2,3} and {3,2,1} are the same data object.

Data Object instances may or may not be related myDataObject = {apple, chair, 2, 5.2, red, green, Jack} The instances of integer and daysOfWeek are related. In the former, all instances are whole numbers, whereas in the latter all instances name days of the week. The instances of myDataObject don’t seem to be related.

Data Structure Data object + Among instances of integer 369 < 370 relationships that exist among instances and elements that comprise an instance Among instances of integer 369 < 370 280 + 4 = 284 You can have ordering relationships –2 before –1 before 0 before 1 etc (relational operators such as <, >, =, etc). Elements could be related by operations such as add, subtract, etc.

Data Structure Among elements that comprise an instance 369 3 is more significant than 6 3 is immediately to the left of 6 9 is immediately to the right of 6

add, subtract, predecessor, multiply Data Structure The relationships are usually specified by specifying operations on one or more instances. add, subtract, predecessor, multiply

Linear (or Ordered) Lists instances are of the form (e0, e1, e2, …, en-1) where ei denotes a list element n >= 0 is finite list size is n

Linear Lists L = (e0, e1, e2, e3, …, en-1) relationships e0 is the zero’th (or front) element en-1 is the last element ei immediately precedes ei+1 A data object is a set of instances; an instance of a linear list is an ordered set of elements.

Linear List Examples/Instances Students in MyClass = (Jack, Jill, Abe, Henry, Mary, …, Judy) Exams in MyClass = (exam1, exam2, exam3) Days of Week = (S, M, T, W, Th, F, Sa) Months = (Jan, Feb, Mar, Apr, …, Nov, Dec) Size of Students in our class is 240, Exams is 3, DOW is 7, and Months is 12. Notice that Days of Week is used as an example of both a data object and of a linear list. As a data object, {S, M, T, …} and {M, W, S, …} describe the same data object with 7 allowable instances S, M, T, … As a linear list (S, M, T, …) and (M, W, S, …) are two different instances of a linear list. Linear List itself may be viewed as data object, which is simply the set of all possible linear list instances.

Linear List Operations—Length() determine number of elements in list L = (a,b,c,d,e) length = 5

Linear List Operations—Retrieve(theIndex) retrieve element with given index L = (a,b,c,d,e) Retrieve(0) = a Retrieve(2) = c Retrieve(4) = e Retrieve(-1) = error Retrieve(9) = error

Linear List Operations—IndexOf(theElement) determine the index of an element L = (a,b,d,b,a) IndexOf(d) = 2 IndexOf(a) = 0 IndexOf(z) = -1 The index of a nonexistent element is defined to be –1. When theElement is in the list an index between 0 and Size()-1 is the result. So –1 would be an invalid index and is used to represent the case when theElement is not in the list

Linear List Operations—Delete(theIndex) delete and return element with given index L = (a,b,c,d,e,f,g) Delete(2) returns c and L becomes (a,b,d,e,f,g) index of d,e,f, and g decrease by 1

Linear List Operations—Delete(theIndex) delete and return element with given index L = (a,b,c,d,e,f,g) Delete(-1) => error Delete(20) => error

Linear List Operations—Insert(theIndex, theElement) insert an element so that the new element has a specified index L = (a,b,c,d,e,f,g) Insert(0,h) => L = (h,a,b,c,d,e,f,g) index of a,b,c,d,e,f, and g increase by 1

Linear List Operations—Insert(theIndex, theElement) L = (a,b,c,d,e,f,g) Insert(2,h) => L = (a,b,h,c,d,e,f,g) index of c,d,e,f, and g increase by 1 Insert(10,h) => error Insert(-6,h) => error

Data Structure Specification Language independent Abstract Data Type C++ Class

Linear List Abstract Data Type AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations IsEmpty(): return true iff the list is empty, false otherwise Length(): return the list size (i.e., number of elements in the list) Retrieve(index): return the indexth element of the list IndexO f(x): return the index of the first occurrence of x in the list, return -1 if x is not in the list Delete(index): remove and return the indexth element, elements with higher index have their index reduced by 1 Insert(theIndex, x): insert x as the indexth element, elements with theIndex >= index have their index increased by 1 }

Linear List As A C++ Class To specify a general linear list as a C++ class, we need to use a template class. We shall study C++ templates later. So, for now we restrict ourselves to linear lists whose elements are integers.

Linear List As A C++ Class class LinearListOfIntegers { bool IsEmpty() const; int length() const; int Retrieve(int index) const; int IndexOf(int theElement) const; int Delete(int index); void Insert(int index, int theElement); }

Data Structures In Text Generally specified as a C++ (template) class.