Computer Science 112 Fundamentals of Programming II Overview of Collections.

Slides:



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

Fundamentals of Python: From First Programs Through Data Structures
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.
CS 171: Introduction to Computer Science II Hashing and Priority Queues.
Priority Queues. 2 Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The “smallest” element.
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.
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.
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
©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.
8 – Objects as building blocks Visual Basic: An Object Oriented Approach.
Priority Queues. Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out –The “smallest” element.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Fundamentals of Python: From First Programs Through Data Structures
The Design and Analysis of Algorithms
Important Problem Types and Fundamental Data Structures
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.
Computer Science Department Data Structures and Algorithms Lecture 1.
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.
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
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.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Heaps & Priority Queues
Heaps Chapter 17 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
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.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
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.
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.
Fundamentals of Programming II Overview of Collections
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.
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
Chapter 15 Lists Objectives
structures and their relationships." - Linus Torvalds
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: From First Programs Through Data Structures
structures and their relationships." - Linus Torvalds
Heaps Chapter 6 Section 6.9.
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Computer Science 112 Fundamentals of Programming II Overview of Collections

The Need for 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 D1D2D 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 D1D2D Lists allow accesses, replacements, insertions, and removals at any position

Linear Collections List Stack Queue Priority Queue D1D2D Stacks allow accesses, insertions and removals at one end only

Linear Collections List Stack Queue Priority Queue D1D2D Queues allow insertions at one end and removals and accesses at the other end

Linear Collections List Stack Queue Priority Queue D1D2D 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 D1 D2 D3 Each element except the root has a unique predecessor Each can have zero or more successors

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

Unordered Collections Bag Set Dictionary D4 D3 D5 D1D2

Sorted Collections Sorted Set Sorted Dictionary D4 D3 D5 D1D2 The elements are not ordered by position, but they are ordered by content

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)

For Monday Searching, Sorting, and Complexity Analysis Chapter 3