Sei sulla pagina 1di 18

AV 482 Data Structures and

DBMS
Instructor: B. S. Manoj
Lecture-5
These slides are the works of many people who own the copyright for their work.
You may use it for your class room purpose at IIST for AV 482 (Data Structures
And DBMS) in July-November 2016 semester. Any other form of commercial or
Non-commercial public distribution may require prior permissions in writing from the
Copyright owners.
8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

General Updates
Course Website Registration verification
If you have dual account registrations, keep only one.
Your friends, who left the course, also may unenroll.
Cleaning the course registration is required for grading.

Home Work-I
Questions can be found at the end of todays slides.
Answers shall be posted online at course website.

Programming Assignment-I
Submit the code the time complexity result comparison
document online
8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

Suggested G2 slot

DBMS Semi-slot

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

Cursor Based List ADT Implementation


Realizes linked list
implementations
in programming systems
without pointers

Key features of cursor


based implementations
Data storage is in a
collection of structures
Memory allocation is
needed for New structures
Simulates pointers using
array indices
8/12/2016

typedef int
PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node
{
ElementType Element;
Position next;
};

Struct Node CursorSpace[SpaceSize];

IIST AV 482: Data Structures and DBMS


July-November 2016

Functions for Cursor based List


Slot

P=1

static Position Cursor Alloc(Void)


{
Position P;

P = CursorSpace[0].Next;
CursorSpace[0].Next =
CursorSpace[P].Next;
Slot

return P;
}
P

Elem
ent

Next

3
8/12/2016

Slot

10

IIST AV 482: Data Structures and DBMS


0July-November 2016

Elem
ent

0
P1

..

..

10

Elem
ent

Next

..

..

10

Next

Functions for Cursor based List


static void CursorFree(Position P)
{
CursorSpace[P].Next =
CursorSpace[0].Next;
CursorSpace[0].Next = P;
}
Slot
Elem
Slot

Elem
ent

Next
P=1

10

IIST AV 482: Data Structures and DBMS


July-November 2016

Elem
ent

Next

10

Slot

ent

10

P=2

Next

8/12/2016

Slot

Elem
ent

Next

10

A CursorArray with two lists

8/12/2016

Slot

Element Next

Slot

Element Next

Header

Header

Header

10

Header

10

10

10

IIST AV 482: Data Structures and DBMS


8
July-November 2016

Find(.)

Slot

Elemen Next
t

Position Find(ElementType X, List L)


{
L=3 (i.e., Header)
Position P;
P = CursorSpace[L].Next;
P=7

Header

While(P &&
CursorSpace[P].Element != X)
{
P = CursorSpace[P].Next;
P=8
}

10

10

Return P;
}

8/12/2016

P=8

IIST AV 482: Data Structures and


DBMS
8/12/2016
July-November 2016

Insert in cursor lists


Void Insert(ElementType X, List L, Position P)
{
Position TmpCell;
TmpCell = CursorAlloc();

TmpCell
0

If(TmpCell == 0)
Error(Out of space);

CursorSpace[TmpCell].Element = X;
CursorSpace[TmpCell].Next = CursorSpace[P].Next;
CursorSpace[P].Next = TmpCell;
}
8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

Slot

Elem
ent

Next

Head

84
58

7
8
9
10
10

Delete(.)
Void Delete(ElementType X, List L)
{
Position P, TmpCell;
P = FindPrevious(X, L);
if(!IsLast(P, L))
{
TmpCell = CursorSpace[P].Next;
CursorSpace[P].Next =
CursorSpace[TmpCell].Next;
CursorFree(TmpCell);
}
TmpCell
}

Slot

Elemen Next
t

Header

10

82

10

P=7

8
8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

11

int IsLast( position p, LIST L) /* using a header node */


{
return(CursorSpace[p].next == 0)
}

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

12

List ADT implementations


List ADT
Pointer implementation
Double pointer implementation
Array with pointers
Cursor Implementation

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

13

Cursor Based List ADT Implementation


Realizes linked list implementations
in programming systems without pointers

Key features of cursor based


implementations
Data storage is in a collection of structures
Memory allocation is needed for New structures
Simulates pointers using array indices

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

14

Programming assignment-1
Create a large doubly linked list of N items (preferably
greater than 1000)
Insert or Delete a randomly chosen element and measure
the time required for a number of operations (>50)
Compare the time taken with the theoretical estimate of
the time complexity for the insert or delete operations
For the insert or delete operations, position is given as the
number of elements from the list head (Traversal may also
be part of the time complexity measurement)
Create a simple comparison graph in a document (word or
pdf) and submit it along with the code (in a single .c file).
Submissions method: online
Deadline: will be IIST
updated
AV 482: Data Structures and DBMS

8/12/2016

July-November 2016

15

Home Work-1

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

16

Home Work-1 (contd..)

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

17

Home Work-1 (contd..)

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

18

We covered
List ADT
Implementations
Pointer based
Array with Pointer based
Cursor based

8/12/2016

IIST AV 482: Data Structures and DBMS


July-November 2016

19

Potrebbero piacerti anche