CS102 – Data Structures Lists, Stacks, Queues, Trees & HashTables. David Davenport.

Slides:



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

Stacks, Queues, and Linked Lists
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Stack & Queues COP 3502.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
CS 171: Introduction to Computer Science II
Trees Chapter 8.
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.
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.
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.
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.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
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.
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
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.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Stacks and Queues Introduction to Computing Science and Programming I.
Trees.ppt1 Introduction Many data structures are linear –unique first component –unique last component –other components have unique predecessor and successor.
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.
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.
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.
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
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’
Binary Trees Definition A binary tree is: (i) empty, or (ii) a node whose left and right children are binary trees typedef struct Node Node; struct Node.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 6 Data Structures.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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. 
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.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
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
Chapter 15 Lists Objectives
Heaps And Priority Queues
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Cinda Heeren / Geoffrey Tien
Week 15 – Monday CS221.
Visit for more Learning Resources
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
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.
Stacks and Queues 1.
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 & HashTables. David Davenport

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 headtail

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

Lists: using arrays… (simple) Implicit Succ/Pred relationship dogcatmousehorse animals { String[] } valid { int }

{ List } Lists: using object/ref… head { Node } cat { Node } dog { Node } mouse { Node } private class Node { Stringdata; Nodenext; public Node( String data, Node next) { this.data = data; this.next = next; } public class List { Nodehead; public List() { head = null; } // inner class Node } horse { Node }

Linked List operations… { List } head { Node } cat { Node } dog { Node } mouse { Node } horse { Node } bird { Node }

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 StackOverflow & StackUnderflow

Expression Evaluation… / ~ambiguous! a)8 / 2 = 4 b) – 2 = 3.75 c)5 + 3 / 2 = 6.5 d)8 / 4 – 2 = 2 Notations Infix5 + 3 Prefix+ 5 3 Postfix5 3 + HP 35 Polish notation: Jan Łukasiewicz

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)

Trees have a Root Nodes Branches {children} Leaves root Examples:  Family trees  Files/folders  GUI containers & ui components

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

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

Hash Tables 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