# JAVA & Linked List Implementation

## Presentation on theme: "JAVA & Linked List Implementation"— Presentation transcript:

Group VI Presented by Regulapati Venkata Ramana Rao

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

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 Link to next node Element 11 12

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

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) 1 2 3 5 6 7

Introduction 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 element Big-Oh(N) 1 2 3 4 5 6 7 header 1 2 5 6 tmp 4

Introduction Insertion… Note: So Linked list is efficient in this case
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 current 1 2 5 6 tmp 4

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 Head 11 12 13

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 Head 11 11 11

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)

Types Circularly Linked List Representation first 11 12 13

Header & Trailer Nodes Header Node: A placeholder node at the beginning of list, used to simplify list processing.It doesn’t 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

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

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

List.java Interface

Node.java

Node.java

LinkedList.java //This class Implements the List interface

InvalidElementException.java