Lecture 3 – Data collection List ADT

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Lists CS 3358.
Lists Chapter 6 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Chapter 6 Queues and Deques.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
1 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Searching: Binary Trees and Hash Tables CHAPTER 12 6/4/15 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education,
Week 3 – Wednesday.  What did we talk about last time?  ADTs  List implementation with a dynamic array.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
ICOM 4035 – Data Structures Lecture 3 – Bag ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
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.
Unit 1 - Introducing Abstract Data Type (ADT) Part 1.
Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 24 to end.
Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 1 to 11.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Introduction toData structures and Algorithms
CSCE 210 Data Structures and Algorithms
Data Abstraction: The Walls
Linked List ADT used to store information in a list
Lecture 6 of Computer Science II
Unit – I Lists.
Cpt S 122 – Data Structures Abstract Data Types
Chapter 4 Linked Structures.
Fundamentals of Programming II Overview of Collections
Linked Lists Chapter 6 Section 6.4 – 6.6
Object-Oriented Analysis and Design
CE 221 Data Structures and Algorithms
CS Data Structures Chapter 8 Lists Mehmet H Gunes
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Object-Orientated Programming
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.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
CMSC 341 Lecture 5 Stacks, Queues
Array Lists Chapter 6 Section 6.1 to 6.3
Chapter 4 Link Based Implementations
Chapter 15 Lists Objectives
Arrays and Linked Lists
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Graphs Chapter 11 Objectives Upon completion you will be able to:
Object-Oriented Programming Using C++ Second Edition
Linked Lists.
Dynamic Data Structures and Generics
Chapter 11 Data Structures 1.
Chapter 4 Unordered List.
Dynamic Data Structures and Generics
Introduction to Data Structure
Data Structures & Algorithms
Software Design Lecture : 39.
Lecture 2 – Abstract Data Type (ADT)
CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations.
CMPT 225 Lecture 5 – linked list.
Lecture 4 – Data collection List ADT
CMPT 225 Lecture 7 – Stack.
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

Lecture 3 – Data collection List ADT CMPT 225 A grocery list Lecture 3 – Data collection List ADT

Last Lecture Abstract Data Type (ADT) Example: Temperature class Definition + “Wall” metaphor How to design an ADT How to implement an ADT in C++ How to test an ADT Example: Temperature class Implemented as an ADT Implemented as a non-ADT Compare both implementations -> Homework

Learning Outcomes At the end of this lecture, a student will be able to: define data collection ADT (designed and implemented as an abstract data type - ADT) and data structure (concrete data type - CDT) and differentiate between the two define one of the concrete data types, namely array, and demonstrate, simulate, and trace its operations convert specifications into high-level design, apply software engineering and design concepts, and express OO design in UML class diagrams write C++ code encapsulate methods and variables for an ADT into a C++ class

Today’s menu Overview of data collections Introduce our first data collection: List Design List as an ADT Design the visible section of our List ADT class Its public interface –> its public section (the gaps in the wall) 2. Design the invisible section of our List ADT class Its private section (what is hidden behind the wall) Look at arrays (one of the concrete data structures)

Terminology Data Collection versus Data Structure (abstract data type - ADT) (concrete data type - CDT) ADT that models a collection of data This collection of data is what is hidden behind the wall Example: List Data structures are constructs available as part of a programming language Examples: array linked list (nodes and pointers)

Categories of data organizations Linear Data organization in which each element has a unique predecessor (except for the first element, which has none) and a unique successor (except for the last element, which has none) Non-Linear Data organization in which there is no first element, no last element and for each element, there is no concept of a predecessor and a successor

Categories of data organizations – cont’d Hierarchical Data organization in which each element has only one predecessor -> its parent (except for the first element, which has none) and up to many successors (except for the last element(s), which has none) Graph Data organization in which each element can have many predecessors and many successors

Our first data collection: List Let’s introduce our first data collection: List while solving a problem! Problem Statement - FriendsBook Application Design and implement an application that maintains the data for a simple social network. Each person in the network must have a profile that contains the person’s name, optional image, current status and a list of friends. Your application must allow a user to join the network by creating a profile, leave the network, modify the profile, search for other profiles, and add friends. Source: Walls and Mirrors Textbook 6th Edition - Programming Problem 11 - Chapter 9 - Page 287

Step 2 – Design solution

Step 2 - Design List as an ADT Public interface (Specifications) List ADT class Insert Data collection Application or test driver (client code) i.e., other classes Private data members -> concrete data structure Search The wall of a data collection ADT isolates its data structure from the client code that uses it. 10

Note about Data Collections Most of the time, in a software development project, we do not design and implement data collections ADT classes, instead we make use of what is already available Examples: STL vectors But in CMPT 225, we will design our own data collection ADT classes -> Why? This means that in our assignments, we cannot make use of library data collections ADT classes (like STL vectors)

Two kinds of List Position-oriented Value-oriented Operations done based on position of data Value-oriented Operations done based on value of data

Activity: Step 2 – Design List’s public interface

Step 2 – Design List’s underlying concrete data structure List ADT class 2 possible underlying concrete data structures: ________________________ Insert Data collection Private data members -> concrete data structure Search

Array Data structure (or CDT) Contiguous memory locations are used when an array is allocated Indexed data structure Direct access (as opposed to random access) What can we do with an array Insert element into it – how? Remove element from it – how? no need to “erase” an element from an array cell, simply overwrite it Traverse (iterate through) Search for a particular element – may not visit every element Expand (resize) an array (see Expandable Array under Readings for more information)

Direct Access versus Sequential Access (array) (linked list)

Advantages of Array Indexing For example: thePatients[3] time efficient Because array cells are assigned contiguous memory locations, traversing an array is very simple

Disadvantages of Array All elements stored in an array must have the same data type In C++, an array does not know its size (capacity), i.e., the number of cells it has We must keep track of its size using a variable Size is required when creating an array If we overestimate the size of our array -> we waste memory If we underestimate the size of our array -> we risk running out of space Solution: expand array -> How expensive is this operation? In C++, there are no bound check on array indices, so we must ensure that our index is 0 <= index < array size

√ Learning Check We can now … Explain the difference between a data collection (designed and implemented as an abstract data type - ADT) and data structure (concrete data type - CDT) and differentiate between the two List different categories of data organization Describe a List ADT Design a List as an ADT Design its public interface (public section) Design its invisible/hidden section (private section) Using concrete data structure Look at arrays (one of the concrete data structures)

Next Lectures Implement the array-based List ADT and test it Introduce test cases Introduce dynamically allocated memory Introduce linked lists (another concrete data structure) Implement the link-based List ADT and test it