Fundamentals of Programming II Overview of Collections

Slides:



Advertisements
Similar presentations
Computer Science 112 Fundamentals of Programming II Queues and Priority Queues.
Advertisements

Computer Science 112 Fundamentals of Programming II Overview of Collections.
Data Structures Simple data type –int, char, long Reference data type –Integer, String, Composite data type == Data Structure –Collection of elements.
Working With Collections in the AP ™ Java Subset 2003 ACTE Convention © 2003 by Kenneth A. Lambert.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Review. What to know You are responsible for all material covered in lecture, the readings, or the programming assignments There will also be some questions.
CHAPTER 3 COLLECTIONS Abstract Data Types. 2 A data type consists of a set of values or elements, called its domain, and a set of operators acting on.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Fundamentals of Python: From First Programs Through Data Structures
The Design and Analysis of Algorithms
1 Chapter 25 Trees Iterators Heaps Priority Queues.
Foundation of Computing Systems Lecture 6 Trees: Part III.
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
© 2006 Pearson Education Chapter 10: Non-linear Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Fundamentals of Python: From First Programs Through Data Structures Chapter 13 Collections, Arrays, and Linked Structures.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
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.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
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.
Heaps & Priority Queues
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
Partially Ordered Data ,Heap,Binary Heap
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.
Data Structures and Design in Java © Rick Mercer
Trees Chapter 15.
Fundamentals of Programming II Introduction to Trees
The Design and Analysis of Algorithms
Abstraction A tool (concept) to manage complexity
Data Structures Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective.
Heapsort.
Data Structures and Database Applications Abstract Data Types
Introduction to Data Structure
Chapter 10: Non-linear Data Structures
ECET 370 HELPS Lessons in Excellence- -ecet370helps.com.
ECET 370 HELPS Education for Service- - ecet370helps.com.
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
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Chapter 15 Lists Objectives
structures and their relationships." - Linus Torvalds
A Data Structure Bestiary
Fundamentals of Python: From First Programs Through Data Structures
Locators 3 a 1 g 4 e 12/1/2018 4:40 AM Locators Locators
Locators 3 a 1 g 4 e 12/29/2018 7:56 AM Locators Locators
Fundamentals of Python: From First Programs Through Data Structures
Heapsort.
Important Problem Types and Fundamental Data Structures
Data Structures for Shaping and Scheduling
structures and their relationships." - Linus Torvalds
Heaps Chapter 6 Section 6.9.
Lecture 3 – Data collection List ADT
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Fundamentals of Programming II Overview of Collections Computer Science 112 Fundamentals of Programming II Overview of Collections

Why Collections? Some programs need a container to manage several data objects You’ve used lists, tuples, and dictionaries in Python There are other types of collections as well

What Is a Collection? A collection is a container for zero or more data objects A collection tracks its own size and resizing is automatic A collection comes with built-in operations for access, insertions, removals, etc. Details of the underlying data structures and operations are hidden in the implementation, so we ignore them

Built-in Python Collections String Tuple List Set Dictionary

Basic Categories of Collections Linear Hierarchical Graph Unordered

Linear Collections List Stack Queue Priority Queue 0 1 2 D1 D2 D3 0 1 2 D1 D2 D3 Elements are ordered by position Each element except the first has a unique predecessor Each element except the last has a unique successor

Linear Collections List Stack Queue Priority Queue 0 1 2 D1 D2 D3 0 1 2 D1 D2 D3 Lists allow accesses, replacements, insertions, and removals at any position

Linear Collections List Stack Queue Priority Queue 0 1 2 D1 D2 D3 0 1 2 D1 D2 D3 Stacks allow accesses, insertions and removals at one end only

Linear Collections List Stack Queue Priority Queue 0 1 2 D1 D2 D3 0 1 2 D1 D2 D3 Queues allow insertions at one end and removals and accesses at the other end

Linear Collections List Stack Queue Priority Queue 0 1 2 D1 D2 D3 0 1 2 D1 D2 D3 Priority queues sort elements by priority, but elements with equal priority are added and removed in queue-like order

Hierarchical Collections Binary tree General tree Binary search tree Heap D2 D1 D3 Each element except the root has a unique predecessor Each can have zero or more successors

Graph Collections Undirected graph Directed graph D1 D2 D3 D4 D5 Each element can have zero or more predecessors Each can have zero or more successors

Unordered Collections Bag Set Dictionary D1 D2 D3 D4 D5 No notion of position from the user’s perspective We can visit all the objects with a for loop

Sorted Collections Sorted Set Sorted Dictionary D1 D2 D3 D4 D5 The elements are not ordered by position, but they are ordered by content (ascending order)

Aspects of a Collection Formal properties (what it is and what you can do with it – as expressed in its interface) Implementations – array-based, link-based, etc. Performance characteristics – space/time tradeoffs of different implementations

Basic Types of Operations Create a collection: list(), list(aCollection) Obtain the string representation: str(aCollection) Obtain the number of items currently in the collection: len(aCollection)

Basic Types of Operations Test an item for membership: item in aCollection Iterate through the items: for item in aCollection: . . . Concatenate two collections (of the same type): aCollection1 + aCollection2 Test for equality: aCollection == anObject

Basic Types of Operations Make the collection empty: aCollection.clear() Add an item: aCollection.add(item) Remove an item: aCollection.remove(item)

Searching, Sorting, and Complexity Analysis Chapter 3 For Monday Searching, Sorting, and Complexity Analysis Chapter 3