Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002."— Presentation transcript:

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

2 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)

3 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

4 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

5 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

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

7 Linked Lists – misc. Free space as list! What sort of data structure is this? 0123456701234567 4 5 3 2 6 7 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?

8 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

9 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)

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

11 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)

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

13


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

Similar presentations


Ads by Google