Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE) PDF Download

A linked list is a sequence of data structures, which are connected together via links.
Linked List is a sequence of links which contains items. Each link contains a connection to another link. Linked list is the second most-used data structure after array. Following are the important terms to understand the concept of Linked List.

  • Link: Each link of a linked list can store a data called an element.
  • Next: Each link of a linked list contains a link to the next link called Next.
  • LinkedList: A Linked List contains the connection link to the first link called First.

Linked List Representation

Linked list can be visualized as a chain of nodes, where every node points to the next node.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

As per the above illustration, following are the important points to be considered.

  • Linked List contains a link element called first.
  • Each link carries a data field(s) 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.

Types of Linked 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.
  • Circular Linked List: Last item contains link of the first element as next and the first element has a link to the last element as previous.

Basic Operations

Following are the basic operations supported by a list.

  • Insertion: Adds an element at the beginning of the list.
  • Deletion: Deletes an element at the beginning of the list.
  • Display: Displays the complete list.
  • Search: Searches an element using the given key.
  • Delete: Deletes an element using the given key.
1. Insertion Operation

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.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)Imagine that we are inserting a node B (NewNode), between A (LeftNode) and C (RightNode). Then point B.next to C −
NewNode.next −> RightNode;
It should look like this:
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)Now, the next node at the left should point to the new node.
LeftNode.next −> NewNode;
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)This will put the new node in the middle of the two. The new list should look like this:
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)Similar steps should be taken if the node is being inserted at the beginning of the list. While inserting it at the end, the second last node of the list should point to the new node and the new node will point to NULL.

2. Deletion Operation

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.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

The left (previous) node of the target node now should point to the next node of the target node −
LeftNode.next −> TargetNode.next;
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)This will remove the link that was pointing to the target node. Now, using the following code, we will remove what the target node is pointing at.

TargetNode.next −> NULL;
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)We need to use the deleted node. We can keep that in memory otherwise we can simply deallocate memory and wipe off the target node completely.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

3. Reverse Operation

This operation is a thorough one. We need to make the last node to be pointed by the head node and reverse the whole linked list.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

First, we traverse to the end of the list. It should be pointing to NULL. Now, we shall make it point to its previous node −



Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

We have to make sure that the last node is not the last node. So we'll have some temp node, which looks like the head node pointing to the last node. Now, we shall make all left side nodes point to their previous nodes one by one.

Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

Except the node (first node) pointed by the head node, all nodes should point to their predecessor, making them their new successor. The first node will point to NULL.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

We'll make the head node point to the new first node by using the temp node.
Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

The document Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
119 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Representation & Basic Operations - Programming and Data Structures - Computer Science Engineering (CSE)

1. What is a linked list representation?
Ans. A linked list representation is a way to store and organize data in a linear manner. It consists of nodes, where each node contains a data element and a reference (or link) to the next node in the list. This allows for dynamic memory allocation and efficient insertion and deletion operations.
2. What are the basic operations associated with linked list representation?
Ans. The basic operations associated with linked list representation are: - Insertion: Adding a new node at the beginning, end, or any specific position of the linked list. - Deletion: Removing a node from the linked list, either from the beginning, end, or any specific position. - Traversal: Visiting each node in the linked list to perform a specific operation or access its data. - Searching: Finding a specific element or node within the linked list. - Updating: Modifying the data of a particular node in the linked list.
3. How are linked lists represented in memory?
Ans. Linked lists are represented in memory using nodes. Each node contains a data element and a reference (or link) to the next node in the list. The first node in the linked list is called the head node, and the last node is called the tail node. The tail node's reference points to NULL, indicating the end of the list. The memory for each node is dynamically allocated, allowing for flexible memory usage.
4. What are the advantages of using linked list representation?
Ans. Some advantages of using linked list representation include: - Dynamic memory allocation: Linked lists allow for efficient memory usage as nodes can be allocated and deallocated dynamically. - Flexibility in insertion and deletion: Insertion and deletion operations can be performed easily by adjusting the links between nodes, without the need to shift or rearrange existing elements. - Efficient use of memory: Linked lists do not require a fixed amount of memory, allowing for efficient use of memory space. - Easy implementation of data structures: Linked lists provide a foundation for implementing other data structures, such as stacks and queues.
5. What are the limitations of using linked list representation?
Ans. Some limitations of using linked list representation include: - Sequential access: Unlike arrays, linked lists do not support direct access to elements based on their index. To access a specific element, traversal through the linked list is required. - Extra memory overhead: Linked lists require additional memory for storing the links between nodes, which can increase memory overhead compared to arrays. - Slower search operations: Searching for a specific element in a linked list may require traversing the entire list, resulting in slower search operations compared to arrays. - Lack of random access: Linked lists do not support random access to elements, making operations like binary search or quicksort less efficient.
119 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Free

,

Objective type Questions

,

MCQs

,

practice quizzes

,

Semester Notes

,

video lectures

,

pdf

,

ppt

,

Sample Paper

,

Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

,

Important questions

,

Summary

,

study material

,

Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

,

Viva Questions

,

Previous Year Questions with Solutions

,

shortcuts and tricks

,

past year papers

,

Extra Questions

,

Representation & Basic Operations | Programming and Data Structures - Computer Science Engineering (CSE)

,

mock tests for examination

,

Exam

;