Presentation is loading. Please wait.

Presentation is loading. Please wait.

CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,

Similar presentations


Presentation on theme: "CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,"— Presentation transcript:

1 CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM JORY DENNY AND MUKULIKA GHOSH 1

2 ITERATORS AND POSITION (CH 6.2.1) 2

3 LISTS  List ADT (Ch. 6.2.2)  Doubly linked list (Ch. 6.2.3) 3

4 LIST ADT (CH 6.2.2) 4

5 INSERT(P,E) 5 ABXC ABC p ABC p X q p q

6 ERASE(P) 6 ABCD p ABC D p ABC

7 EXERCISE: LIST PERFORMANCE AND SPACE (BEST, WORST, AVERAGE) Singly-linked ListDoubly-linked List Worst case Average case Best case 7 Singly-linked ListDoubly-linked List Space usage for list of n elements

8 LIST PERFORMANCE AND SPACE SUMMARY Singly-linked ListDoubly-linked List Worst case Average case Best case 8 Singly-linked ListDoubly-linked List Space usage for list of n elementsO(n)

9 VECTORS (CH 6.1)  The Vector ADT (Ch. 6.1.1)  Array-based implementation (Ch. 6.1.2) 9

10 VECTOR ADT (CH 6.1.1)  The Vector ADT extends the notion of array by storing a sequence of arbitrary objects  An element can be accessed, inserted or removed by specifying its rank (number of elements preceding it)  An exception is thrown if an incorrect rank is specified (e.g., a negative rank) 10

11 APPLICATIONS OF VECTOR  Direct applications  Sorted collection of objects (elementary database)  Indirect applications  Auxiliary data structure for algorithms  Component of other data structures 11

12 EXERCISE 12

13 ARRAY-BASED VECTOR (CH 6.1.2) STORAGE 012n i 0 13

14 ARRAY-BASED VECTOR (CH 6.1.2) INSERTION 14 V 012n i V 012n i V 012n e i

15 ARRAY-BASED VECTOR (CH 6.1.2) DELETION 15 V 012n r V 012n e i V 012n i

16 EXERCISE: ARRAY-BASED VECTOR PERFORMANCE (BEST, WORST, AVG) 16 Array based Vector (Fixed) Array-based Vector (Growable) Space used by Vector at(i) Set(i,e) insert(i,e) erase(i) size() empty()

17 EXERCISE: ARRAY-BASED VECTOR PERFORMANCE 17 Array based Vector (Fixed) Array-based Vector (Growable) Doulbly-linked List Vector Space used by Vector ? at(i), set(i,e) ? insert(i,e) ? erase(i) ? size(), empty() ?

18 SEQUENCES  Sequence ADT (Ch. 6.3.1)  Implementations of the sequence ADT (Ch. 6.3.2-3) 18

19 SEQUENCE ADT (CH 6.3.1) 19

20 APPLICATION OF SEQUENCES  The Sequence ADT is a basic, general-purpose, data structure for storing an ordered collection of elements  Direct applications:  Generic replacement for stack, queue, vector, or list  Small database (e.g., address book)  Indirect applications:  Building block of more complex data structures 20

21 ARRAY BASED IMPLEMENTATION OF SEQUENCE (CH 6.3.3) 21 0123 positions elements S lf

22 EXERCISE: SEQUENCE PERFORMANCE (BEST,WORST, AVG) Circular Array based SequenceDoubly-linked List based Sequence 22 Circular Array based SequenceDoubly-linked List based Sequence Space usage

23 SEQUENCE SUMMARY Circular Array based SequenceDoubly-linked List based Sequence 23 Circular Array based SequenceDoubly-linked List based Sequence Space usage O(N)O(n)


Download ppt "CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,"

Similar presentations


Ads by Google