Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA & Linked List Implementation Group VI Presented by Regulapati Venkata Ramana Rao.

Similar presentations


Presentation on theme: "JAVA & Linked List Implementation Group VI Presented by Regulapati Venkata Ramana Rao."— Presentation transcript:

1 JAVA & Linked List Implementation Group VI Presented by Regulapati Venkata Ramana Rao

2 Objective Purpose Types of linked list Organization Different operations Bio-Oh of each operation Case study

3 Introduction Is the linear data structure represented by nodes Is an alternative to the contiguous array implementation It Consists of collection of connected, dynamically allocated Nodes Each node will have at least two elements Element itself The link to the next node in the list 1112 Link to next node Element

4 Introduction Linked List Node Representation Class ListNode { Object element; ListNodenextNode; }

5 Why Linked List ? Inserting or deleting of an item into/from list is easy, where as it requires extensive data movement if we use arrays Insertion Into Sorted Array Insert 4 into above array Increase the array size Locate the position of 4. Big-oh is O(N) Move the elements by one position. Big-oh is O(N) So Big-Oh is O(N2) Introduction

6 Array After Inserting Linked List Implementation Inserting Element 4 Create new node with element 4 ListNode tmp = new ListNode(); tmp.element = 4; Search the position of elementBig-Oh(N) tmp header

7 Introduction Insertion… Point the new node link to the node after the new node temp.next = current.next; Point the previous node link to new node current.next = tmp; Big-Oh is O(N) Note: So Linked list is efficient in this case tmp current

8 Linked Lists are 3 types Single Linked List Consists of data element and reference to the next Node in the Linked list First node is accessed by reference (Header Node) Last node is set to NULL Types Head

9 Types Double Linked List Consists of nodes with two link members one points to the previous and other to the next node Maximizes the needs of list traversals Compared to the Singled list inserting and deleting nodes is a bit slower as both the links has to be updated It requires the extra storage space for the second link 11 Head

10 Types Circular Linked list Similar to the doubly linked list, but the last node link points to the first node instead of null Useful in algorithms where there is no particular first or last item Advantage is we can make head to point any node without destroying the list Operations are similar to single linked list except identifying the last node in the list. To find the last node compare the last node to head node (i.e you have found the last node if its link points to the same node that the head points)

11 Types Circularly Linked List Representation first

12 Header & Trailer Nodes Header Node: A placeholder node at the beginning of list, used to simplify list processing.It doesnt hold any data but satisfies that the every node has a previous node. Trailer Node: A placeholder node at the end of list, used to simplify list processing

13 Single LinkedList Operations Insertion of node Consider 3 cases of insertion Node is first node in the linked list Node is an inner node Node is last node Deleting specific node Printing/Traversing Liked List Find specific node Find Length of Linked List

14 Implementation All the above mentioned operations are implemented on a sorted singly linked list in the following example The implementation has these classes List.java… This is the interface LinkedList.java … Implementation for the methods declared in interface Node.java… This is actual Node in Linked list and also has Accessor / Mutator methods TestLinkedList.java… Test client program

15 List.java Interface

16 Node.java

17

18 LinkedList.java //This class Implements the List interface

19 LinkedList.java

20

21

22

23

24

25 InvalidElementException.java

26 ClientLinkedList.java

27

28


Download ppt "JAVA & Linked List Implementation Group VI Presented by Regulapati Venkata Ramana Rao."

Similar presentations


Ads by Google