Doubly linklist

4
Algorithm Analysis Heap Sort Submitted By:Sunawar Khan MS(CS) 813-MSCS-F14 Submitted To: Dr. A. Awan INTERNATIONAL ISLAMIC UNIVERSITY ISLAMABAD

Transcript of Doubly linklist

Page 1: Doubly linklist

Algorithm Analysis

Heap Sort

Submitted By:Sunawar KhanMS(CS)

813-MSCS-F14Submitted To: Dr. A. Awan

INTERNATIONAL ISLAMIC UNIVERSITYISLAMABAD

Page 2: Doubly linklist

Doubly-Linked List

• A doubly-linked list takes all the functionality of a singly-linkedlist and extends it for bi-directional movement in a list. We cantraverse, in other words, a linked list from the first node in thelist to the last node in the list; and we can traverse from thelast node in the list to the first node in the list. In this sec-tion, we will maintain our focus primarily on the differences be-tween a doubly-linked list and a singly-linked list. Operationsof a Doubly-Linked List Our list will include two constructors:Node and DoublyList. Let us outline their operations.

Node

• Data stores a value.

• Next points to the next node in the list.

• Previous points to the previous node in the list..

DoublyList

• Length retrieves the number of nodes in a list.

• Head assigns a node as the head of a list.

• Tail assigns a node as the tail of a list.

• Add(value) adds a node to a list.

• SearchNodeAt(position) searches for a node at n-position in ourlist.

• Remove(position) removes a node from a list

Page 3: Doubly linklist

Characteristics

• MeritThe advantage of a doubly linked list is that we dont needto keep track of the previous node for traversal or no need oftraversing the whole list for finding the previous node.

• DemeritThe disadvantage is that more pointers needs to be handledand more links need to updated.

Time Complexity of Link List

• Average Case

– Access O(n)

– Search O(n)

– Insertion O(1)

– Deletion O(1)

• Worst Case Case

– Access O(n)

– Search O(n)

– Insertion O(1)

– Deletion O(1)

Page 4: Doubly linklist

Application of Linked ListCreating dynamic lists, like the queue of McDonald’s, insertion isdone at one end and deletion at other. And these operations happenfrequently. As a way of storing when random access is not required.In situations like that mentioned in point one, order jumps are notdone, so no random access is required and hence linked list areperfect for it. If random element deletion/insertion is required inconstant time. In case of fixed DS like array, need to re-shift po-sition of all remaining element. If a node of array is heavy, theninserting/deleting costs will be high. In case of Linked list, it willbe comparatively very cheap. Linked lists are used in variety ofapplications in computer Science. Majority, they are used in placeswhere we have to use dynamic memory or size of input is not knownin advance . The main Applications of Linked Lists are

• For representing Polynomials

• In Dynamic Memory Management

• In Symbol Tables

• Representing Sparse Matrix

• Tree

• Graph

• Stack

• Queue

• LRU/MRU

• Symbol table management in compiler design

• Hash table