CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.

Slides:



Advertisements
Similar presentations
Stack & Queues COP 3502.
Advertisements

ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
COMP 110 Introduction to Programming Mr. Joshua Stough.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Summary of lectures (1 to 11)
Tree Traversals & Maps Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Algorithms and Data Structures Representing Sequences by Arrays and Linked Lists.
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Information and Computer Sciences University of Hawaii, Manoa
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CS102 – Data Structures Lists, Stacks, Queues, Trees & HashTables. David Davenport.
Data Structures Systems Programming. Systems Programming: Data Structures 2 2 Systems Programming: 2 Data Structures  Queues –Queuing System Models –Queue.
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.
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.
CSE205 Review Session SAMUEL & JESSA. Recursion WHAT IS RECURSION?  Recursion is a tool a programmer can use to invoke a function call on itself. 
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.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
Data-structure-palooza Checkout DataStructures from SVN.
April 27, 2017 COSC Data Structures I Review & Final Exam
Reading data into sorted list Want to suck text file in and produce sorted list of the contents: Option 1 : read directly into array based list, sort afterwards.
CPS Review of Data Structures l We’ve studied concrete data structures/type (CDT)  Vectors Homogeneous aggregates supporting random access  Linked.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
COSC 2P03 Week 21 Stacks – review A Last-In First-Out (LIFO) structure Basic Operations: –push : insert data item onto top of stack –pop : remove data.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
Week 15 – Monday.  What did we talk about last time?  Tries.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Chapter 12 Abstract Data Type.
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
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.
Chapter 12 – Data Structures
12 C Data Structures.
Chapter 15 Lists Objectives
Heaps And Priority Queues
Week 15 – Monday CS221.
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.
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
structures and their relationships." - Linus Torvalds
Lesson Objectives Aims
Lesson 6. Types Equality and Identity. Collections.
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
CS6045: Advanced Algorithms
structures and their relationships." - Linus Torvalds
DATA STRUCTURES IN PYTHON
Lists, Stacks, Queues, Trees & HashTables. David Davenport
Presentation transcript:

CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002

Abstract Data Structures Data Structures - collections of data Already seen two (~ fixed/static) arrays - elements of same type objects - elements of differing types Dynamic Data Structures space allocated as needed later released & available for reuse Abstract Data Structures common conceptual (list, stack, queues, trees...) multiple implementations (static & dynamic)

Lists (linked-lists) Familiar eg. shopping list, phone no’s, … set of items, each (except first & last) with a unique successor & predecessor Operations insert, delete, search, iterate, … dogcatmousehorse head

List - implementation Using Java Vector class Using arrays (simple approach) Implicit succ/pred Linked lists (singly & doubly) Using objects & references using arrays and/or files! Java Collections Framework… ArrayList & LinkedList

Linked Lists – misc. Implementation Node class – data & next {Node} List class – head Methods print print in reverse! add (at head) append search insert (& in order) delete

Linked Lists – misc. Alternative array implementation How can new be implemented? & dispose? Need to keep track of free space… how? ABDGCABDGC data next head 0 Can also do this with Random Access Files (simply replace X[i] with seek(i) & read)

Linked Lists – misc. Free space as list! What sort of data structure is this? ADGCADGC data next head 0 free 1 New: Remove & return first element of free space list Dispose: add to beginning of free space list If data items occupied varying numbers of consecutive array elements how would this affect allocation/deallocation of free space? How would it be initialized?

Stacks Abstract - LIFO (Last In, First Out) Methods push, pop & isEmpty isFull & constructor Uses in method calling, in interrupt handling, calculator (postfix expressions!) Implementation Java Stack class arrays & linked-lists apple orange banana pushpop top

Queues Abstract – FIFO (First In, First out) Methods enqueue, dequeue & isEmpty isFull & constructor Uses simulations in event handling Implementation Arrays & linked lists BCD E A enqueue (rear) dequeue (front)

Binary Trees Nodes with 0, 1 or 2 children Recursive – children are trees too! Traversals - inOrder, preOrder, postOrder + 5 / root leftright Each traversal produces corresponding expression; inFix, preFix, postFix

Binary Trees Efficient insert/delete & search! (binary search tree) David Ayse Gunes Derya Mehmet TankutKadriye root leftright < root> root O(log 2 N) if balanced! insert/delete O(1)

Hash What’s the fastest way to find something? Remember where you put it & look there! Hashing - computes location from data david gunes derya “derya” hash Hash function values david -- 0 gunes -- 2 derya -- 3 Collisions? ayse -- 2 Solutions: linear probing linked lists