Topic 2. Collections

Similar documents
Queues. Lesson 4. CS 32: Data Structures Dept. of Computer Science

Topic 14. The BinaryTree ADT

tree nonlinear Examples

An Introduction to Collections, Generics, and the Timing Class

CS 206 Introduction to Computer Science II

1 P age DS & OOPS / UNIT II

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

Sequence Abstract Data Type

COMP 250 Winter stacks Feb. 2, 2016

+ Abstract Data Types

Linked Structures. See Section 3.2 of the text.

LIFO : Last In First Out

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Queue rear tail front head FIFO

Week 6. Data structures

Abstract Data Types Data Structure Grand Tour Java Collections.

Largest Online Community of VU Students

Abstract Data Types Data Structure Grand Tour Java Collections.

Abstract Data Types Data Structure Grand Tour Java Collections.

Queue. COMP 250 Fall queues Sept. 23, 2016

Separate Compilation and Namespaces Week Fall. Computer Programming for Engineers

Stacks and Queues

Slides for Faculty Oxford University Press All rights reserved.

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

ECE 122. Engineering Problem Solving Using Java

Lists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50

CS302 - Data Structures using C++

csci 210: Data Structures Stacks and Queues

Algorithms and Data Structures

Some major graph problems

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview

Algorithms and Data Structures

Final Exam Data Structure course. No. of Branches (5)

CS 206 Introduction to Computer Science II

CS2102, B11 Exam 1. Name:

Problem 1: Building and testing your own linked indexed list

Binary Trees. Height 1

CS302 - Data Structures using C++

Data Structure (CS301)

Maximum Contiguous Subsequence Sum. Check out from SVN: MCSSRaces

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

CS301 - Data Structures Glossary By

Programming, Data Structures and Algorithms Prof. Hema A Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

INTERFACES IN JAVA. Prof. Chris Jermaine

DATA STRUCTURES CHAPTER 1

Data Structure. Recitation VII

Programming II (CS300)

CS Introduction to Data Structures Week 3, 2017

Assignment 8 CSCE 156/156H/RAIK 184H Spring 2017

Laboratory Module Trees

Lists. ordered lists unordered lists indexed lists 9-3

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

INSTITUTE OF AERONAUTICAL ENGINEERING

STUDENT LESSON A9 Recursion

LECTURE OBJECTIVES 6-2

Binary Trees Due Sunday March 16, 2014

(Refer Slide Time: 02.06)

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

Understanding an ADT implementation: Abstraction functions

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Lecture 14: More Inheritance & Genericity

ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CS171 Midterm Exam. October 29, Name:

CSE 143. Lecture 4: Stacks and Queues

Data structure and algorithm in Python

CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O

CMSC351 - Fall 2014, Homework #2

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

ADTs, Arrays, Linked Lists

12 Abstract Data Types

TREES. Trees - Introduction

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

CS1150 Principles of Computer Science Methods

Type Checking and Type Equality

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

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

2008 Winton. Modeling Resources

STACKS AND QUEUES. Problem Solving with Computers-II

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Week 6: Data. Let's focus first on application domain data.

Trees. Carlos Moreno uwaterloo.ca EIT

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

Exam question (5p) 08/02/2017 DFR - Data Structures & Algorithms 1

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

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

CSE 373 Final Exam 3/14/06 Sample Solution

Advanced Java Concepts Unit 3: Stacks and Queues

MLR Institute of Technology

Computer Science 9608 (Notes) Chapter: 4.1 Computational thinking and problem-solving

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

data structures and algorithms lecture 6

Building Java Programs

Principles of Computer Science

Pop Quiz 2: Answers. Data structures Recursion Big-O

Data Abstraction and Specification of ADTs

CS 302 ALGORITHMS AND DATA STRUCTURES

Data Structures -- Introduction

Introduction to Data Structures and Algorithms

Transcription:

Topic 2 Collections

Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections 2-2

Collections Collection: a group of items that we wish to treat as a conceptual unit Example: a stamp collection In computer science, we have collections of items also Examples: stack, queue, list, tree, graph The proper choice of a collection for a given problem can affect the efficiency of a solution! 2-3

Examples of Collections What do collections look like? Queue: first item in is first item out e.g. a lineup at a checkout counter Stack: last item in is first item out e.g. a stack of plates in the cafeteria List: we can have ordered lists or unordered lists e.g. a shopping list; a list of names and phone numbers; a to-do list 2-4

Example: stack of plates New plate is added at the top of the stack, and will be the first one removed 2-5

Example: queue at checkout First person served will be the one at the front of queue New person is added to the rear of the queue 2-6

Example: ordered list of numbers New number must be added so that the ordering of the list is maintained 16 23 29 40 51 67 88 58 2-7

Examples of Collections The previous examples are linear collections: items are organized in a straight line Each item except the first has a unique predecessor, and each item except the last has a unique successor within the collection 2-8

Examples of Collections We also have nonlinear collections Hierarchical collections: trees items are ordered in an upside down tree Each item except the one at the top has a unique predecessor but may have many successors Examples: taxonomies, computer file systems 2-9

Example of a tree: computer file system Root directory of C drive Documents and Settings Program Files My Music Desktop Favorites Start Menu Adobe Microsoft Office 2-10

Examples of Collections Another nonlinear collection is a graph: items can have many predecessors and many successors Example: maps of airline routes between cities 2-11

Example of a graph: airline routes between cities London 2-12

Abstraction In solving problems in computer science, an important design principle is the notion of abstraction Abstraction separates the purpose of an entity from its implementation Example in real life: a car (we do not have to know how an engine works in order to drive a car) Examples in computer systems: a computer, a file Example in Java: class, object 2-13

Abstraction Abstraction provides a way of dealing with the complexity of a large system We will deal with each collection in a general way, as a data abstraction We will think of what we want to do with the collection, independently of how it is done For example, we may want to add something to a queue, or to remove it from the queue 2-14

Collection as an Abstraction Example: think of a queue of customers Suppose what we want to do is to deal with the first customer in the queue, i.e. dequeue a customer How is this dequeue done? We may not need to know, if someone else looked after the details Or, if we are involved in the how We may choose to program in Java or some other language There may be several ways of implementing a queue that differ in efficiency 2-15

Collection as an Abstraction In other words, we want to separate The interface of the collection: what we need in order to interact with it, i.e. the operations on the collection This is from the perspective of a user of the collection The implementation of the collection: the underlying details of how it is coded This is from the perspective of a writer of the collection code 2-16

Issues with Collections For each collection that we examine, we will consider: How does the collection operate conceptually? How do we formally define its interface? What kinds of problems does it help us solve? In what ways might we implement it? What are the benefits and costs of each implementation? 2-17

Abstract Data Types (ADTs) Data type: a set of values and the operations defined on those values Example: integer data type (int) Values? operations? Abstract data type : a collection of data together with the set of operations on that data Why abstract? It s a data type whose values and operations are not inherently defined in a programming language Examples: stack, queue, list, tree 2-18

Data Structures Data structure: a construct within a programming language, used to implement a collection Example: array So, what is the difference between the terms abstract data type and data structure? (Note that sometimes the terms are used interchangeably, in generalizations about data structures ) 2-19