You are on page 1of 10

Department of Computer Science and Engineering (CSE)

DOUBLY LINK LISTS

• A Doubly Linked List (DLL) contains an extra pointer, typically


called previous pointer, together with next pointer and data
which are there in singly linked list.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

REPRESENTATIONS

[1]

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

APPLICATIONS OF DOUBLY LINK LIST


• Doubly linked list can be used in navigation systems
where both front and back navigation is required.
• It is used by browsers to implement backward and
forward navigation of visited web pages i.e. back
and forward button.
• It is also used by various application to
implement Undo and Redo functionality.
• It can also be used to represent deck of cards in games.
• It is also used to represent various states of a game.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

ADVANTAGES

• A DLL can be traversed in both forward and backward


direction.

• The delete operation in DLL is more efficient if pointer to


the node to be deleted is given.

• In singly linked list, to delete a node, pointer to the previous


node is needed. To get this previous node, sometimes the
list is traversed. In DLL, we can get the previous node using
previous pointer.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

DISADVANTAGES
• Every node of DLL Require extra space for an previous
pointer. It is possible to implement DLL with single
pointer .
• All operations require an extra pointer previous to be
maintained. For example, in insertion, we need to modify
previous pointers together with next pointers.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

HOW TO DO INSERTION IN A DOUBLY LINK LIST


Algorithm: Suppose we want to insert node between LOCA & LOCB.
1. [OVERFLOW?] If AVAIL=NULL, then: Write: OVERFLOW & Exit
2. [Remove node from AVAIL list and copy new data into node]
• Set NEW=AVAIL,
• AVAIL=FORW[AVAIL]
• INFO[NEW]=ITEM
• BACK[AVAIL]=NULL
3. [Insert node into the list]
• Set FORW[LOCA]=NEW
• FORW[NEW]=LOCB
• BACK[LOCB]=NEW
• BACK[NEW]=LOCA
4. Exit

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

DELETION IN DOUBLY LINK LIST


• Algorithm:
1. [Delete node]
• Set FORW[BACK[LOC]]=FORW[LOC] &
BACK[FORW[LOC]]=BACK[LOC],
• 2. [Return node to the AVAIL list]
• Set FORW[LOC]=AVAIL & AVAIL=LOC
• 3. Exit

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Some important Questions


Q1 How many pointers a doubly link list have?
Q2 “Doubly link list is better than singly link list .” Comment.
Q3 Name any 2 applications of doubly link list

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Books Recommended
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series,
Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures
using C and C++”, Prentice Hall of India.
• Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data
Structures and Algorithms”, Addison Wesley.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

THANKS

University Institute of Engineering (UIE)

You might also like