Lists, Stacks, and Queues-Data Structures-Lecture Slides, Slides of Data Structures and Algorithms

Prof. Gangesh Charu delivered this lecture at Alagappa University for Data Structures course. Its main points are: Linked, Lists, Stacks, Queues, Abstract, Data, Types, ADT, Operations, Implementation, Operations, Simple, Array

Typology: Slides

2011/2012
On special offer
50 Points
Discount

Limited-time offer


Uploaded on 07/15/2012

sahill
sahill 🇮🇳

4.8

(4)

46 documents

1 / 93

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
7/7/2012 Lists, Stacks, and Queues 3-1
Chapter 3
Lists, Stacks, and Queues
EE 232 Data Structures
Session-05 , Spring-07
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
Discount

On special offer

Partial preview of the text

Download Lists, Stacks, and Queues-Data Structures-Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

7/7/2012 Lists, Stacks, and Queues 3-

Chapter 3

Lists, Stacks, and Queues

EE 232 Data Structures Session-05 , Spring-

7/7/2012 Lists, Stacks, and Queues 3-

Chapter 3: Lists, Stacks, and Queues

3.1 Abstract Data Types (ADT)

3.2 The List ADT

3.3 The Stack ADT

3.4 The Queue ADT

7/7/2012 Lists, Stacks, and Queues 3-

Chapter 3: Lists, Stacks, and Queues

3.1 Abstract Data Types (ADT)

3.2 The List ADT

3.3 The Stack ADT

3.4 The Queue ADT

7/7/2012 Lists, Stacks, and Queues 3-

Abstract Data Types (ADT)

Data type  a set of objects + a set of operations

Example  integer

  • set of whole numbers {…, -2, -1, 0, 1, 2, 3,…}
  • operations: +, -, x, /

7/7/2012 Lists, Stacks, and Queues 3-

Abstract Data Types (ADT)…

Why do we call it abstract?

 In an ADT’s definition, it is not mentioned how to implement the set of operations

 ADTs are not directly usable

 They have to be implemented

 A given ADT may have more than one implementation

7/7/2012 Lists, Stacks, and Queues 3-

Chapter 3: Lists, Stacks, and Queues

3.1 Abstract Data Types (ADT)

3.2 The List ADT

3.3 The Stack ADT

3.4 The Queue ADT

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Operations

PrintList : prints the list  MakeEmpty : create an empty list  Find : returns the position of an object in a list

  • list: 34,12, 52, 16, 12
  • Find (52)  3  Insert : insert an object to the list
  • Insert (X,3)  34, 12, 52, X, 16, 12  Delete : delete an element from the list
  • Delete (52)  34, 12, X, 16, 12  FindKth : retrieve the element at a certain position

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

 The List ADT can be implemented using an array or a linked list

Simple array implementation  Elements are stored in contiguously

 an estimate of the maximum size of the list is required and this usually requires a high overestimate, which wastes considerable space

4 -3 5 -2 -1 2 6 -2 1 - A 1 A N

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Linked Lists  consists of a series of structures, which are not necessarily adjacent in memory  Each structure or node contains the element and a pointer (called Next ) to a structure containing its successor

A 1 A N

4 -3 (^) …….. -1 NULL

A node in the list

Pointer is a variable that contains the address where some other data are stored

Conceptual view

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Running time of the operations

PrintList (L)  Find (L, key)  FindKth (L,i) takes O ( i )

A 1 800 A 2 712 A 3 992 A 4 692 A 5 0 1000 800 712 992 692 Actual view

O ( N )

O ( N )

O ( N )

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Deletion from a Linked List  Requires one pointer change

 Running time O (1)

NULL A 1 A 4

4 -3 5 -

A 3 delete

A 2

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Array versus Linked Lists

 Linked lists are more complex to code and manage than arrays, but they have some distinct advantages  Dynamic

  • a linked list unlike an array easily grows and shrinks in size when necessary  Easy and fast insertions and deletions

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

#ifndef _List_H #define _List_H struct Node; typedef struct Node* PtrToNode; typedef PtrToNode List; typedef PtrToNode Position; List MakeEmpty( List L ); int IsEmpty( List L ); int IsLast( Position P, List L ); Position Find( ElementType X, List L ); void Delete( ElementType X, List L ); Position FindPrevious( ElementType X, List L ); void Insert( ElementType X, List L, Position P ); void DeleteList( List L ); Position Header( List L ); Position First( List L ); Position Advance( Position P ); ElementType Retrieve( Position P );

#endif /* _List_H */

struct Node { ElementType Element; Position Next; };

Programming Details…

7/7/2012 Lists, Stacks, and Queues 3-

The List ADT…

Programming Details…

/* Return true if L is empty */

int IsEmpty( List L ) { return L->Next == NULL; }

Running time?