Java Collections Framework: Understanding Linked Lists and Their Operations, Lecture notes of Data Structures and Algorithms

An overview of linked lists, their types, and various operations that can be performed on them in the context of the java collections framework. Topics include insertion, deletion, display, search, and comparison using interfaces such as comparable and comparator. The document also covers the use of arraylist and linkedlist, as well as static utility methods in the collections class for sorting, searching, and finding extremes in collections.

Typology: Lecture notes

2018/2019

Uploaded on 08/23/2019

jeffomanga
jeffomanga 🇰🇪

3

(1)

4 documents

1 / 48

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Mr. James Ombogo
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30

Partial preview of the text

Download Java Collections Framework: Understanding Linked Lists and Their Operations and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Mr. James Ombogo

 To explore different types of linklists and operations that can be performed on them.  To explore the relationship between interfaces and classes in the Java Collections Framework hierarchy.  To use the common methods defined in the Collection interface for operating collections.  To use the Iterator interface to traverse the elements in a collection  To use a for-each loop to traverse the elements in a collection  To explore how and when to use ArrayList or LinkedList to store a list of elements.  To compare elements using the Comparable interface and the Comparator interface.  To use the static utility methods in the Collections class for sorting, searching, shuffling lists, and finding the largest and smallest element in collections (§22.6).

 Linked list can be visualized as a chain of nodes, where every node points to the next node.  As per above shown illustration, following are the important points to be considered. LinkedList contains an link element called first.

 Each Link carries a data fields and a Link Field called next. Each Link is linked with its next link using its next link. Last Link carries a Link as null to mark the end of the list.

 Following are the various types of linked list.

 Simple Linked List − Item Navigation is forward only.

 Doubly Linked List − Items can be navigated forward and backward way.

 Circular Linked List − Last item contains link of the first element as next and and first element has link to last element as prev.

 Adding a new node in linked list is a more than one step activity. We Shall learn this with diagrams

 here. First, create a node using the same structure and find the location where it has to be inserted

 Imagine that we are inserting a node B

NewNode, between A LeftNode and C

RightNode. Then point B.next to C

 NewNode.next −> RightNode;

 Similar steps should be taken if the node being inserted at the beginning of the list. While putting it at the end, then the second last node of list should point to new node and the new node will point to NULL.

 Deletion is also a more than one step process. We shall learn with pictorial representation. First,

 locate the target node to be removed, by using searching algorithms.

 This operation is a thorough one. We need to make the last node be pointed by the head node and reverse the whole linked list.

 Doubly Linked List is a variation of Linked list in which navigation is possible in both ways either forward and backward easily as compared to Single Linked List. Following are important terms to understand the concepts of doubly Linked List  Link − Each Link of a linked list can store a data called an element.  Next − Each Link of a linked list contain a link to next link called Next.  Prev − Each Link of a linked list contain a link to previous link called Prev.  LinkedList − A LinkedList contains the connection link to the first Link called First and to the last link called Last.

 Following are the basic operations supported by an list.  Insertion − add an element at the beginning of the list.  Deletion − delete an element at the beginning of the list.  Insert Last − add an element in the end of the list.  Delete Last − delete an element from the end of the list.  Insert After − add an element after an item of the list.  Delete − delete an element from the list using key.  Display forward − displaying complete list in forward manner.  Display backward − displaying complete list in backward manner.

 Circular Linked List is a variation of Linked list in which first element points to last element and last element points to first element. Both Singly Linked List and Doubly Linked List can be made into as circular linked list.