0% found this document useful (0 votes)
27 views

Linked List: Dept. of Computer Science Faculty of Science and Technology

This document provides an overview of linked lists including: 1. The definition of a linked list as a data structure consisting of nodes where each node contains data and a link to the next node. 2. A comparison of linked lists to arrays, noting that in linked lists data is not stored consecutively in memory. 3. An example of linked list representation in memory using nodes.

Uploaded by

Rehaan Razib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Linked List: Dept. of Computer Science Faculty of Science and Technology

This document provides an overview of linked lists including: 1. The definition of a linked list as a data structure consisting of nodes where each node contains data and a link to the next node. 2. A comparison of linked lists to arrays, noting that in linked lists data is not stored consecutively in memory. 3. An example of linked list representation in memory using nodes.

Uploaded by

Rehaan Razib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Linked List

Course Code: CSC 2106 Course Title: Data Structure (Theory)

Dept. of Computer Science


Faculty of Science and Technology

Lecturer No: 8.1 Week No: 8 Semester: Fall 20_21


Lecturer: Kaniz Fatema, [email protected]
Lecture Outline

1. Linked List
2. Array vs. Linked List
3. Representation of Linked List in memory
4. Traversing a Linked List
Linked List
Definition and example

Definition: Linked list is a data structure consisting of a group of memory space


which together represent a list i.e. a sequence of data.

Each data is stored in a separate memory space/block (called cell/node)

Each memory block contains the data along with link/location/address to the
memory location for the next data in the list.
0 1 2 3 4

int

Data Link Data Link Data Link Data Link Data Link
Linked List
Array vs. Linked List

A sequence of data can also be represented as an array. But in an array, data are
stored consecutively in the memory.

For example, an array to contain 5 integer values of type int called mimo could


be represented like this:

A linked list is a sequence of data. But in a linked list the data are not stored
consecutively in the memory
Info[node] = = 20
Link[node] = = NULL

head

1001

Node 1
Node 0

10 2005 20 3010

1001 2005

Node 2

20 NULL

3010
Linked List
Array vs. Linked List (Representation in memory)

Address Memory
Address Memory FF00 17 FF0X
FF00 13 … …
FF04 14 FFF1 14 FFFF

FF08 11 … …
FF0X 15 NULL
FF0C 17
… …
FF10 15
FF1F 13 FFF1
start
Array representation … …
FFFF 11 FF00
Linked List representation
Linked List
Applications in computer science

• Implementation of stacks and queues


• Implementation of graphs : Adjacency list representation of graphs is most
popular which is uses linked list to store adjacent vertices.
• Dynamic memory allocation : We use linked list of free blocks.
• Maintaining directory of names
• Performing arithmetic operations on long integers
• Manipulation of polynomials by storing constants in the node of linked list
• representing sparse matrices
Linked List
Applications in real life problem

• Image viewer – Previous and next images are linked, hence can be accessed by
next and previous button.
• Previous and next page in web browser – We can access previous and next url
searched in web browser by pressing back and next button since, they are
linked as linked list.
• Music Player – Songs in music player are linked to previous and next song. you
can play songs either from starting or ending of the list.
Linked List
Representation of a node

Representation of a NODE in C/C++


struct ListNode{
int data;
ListNode *next;
};
ListNode node;

node
node
data next
data next
Linked List
Traversal

Address Memory
FF00 17 FF0X
… …
FFF1 14 FFFF
… …
FF0X 15 NULL
… …
FF1F 13 FFF1
start
… …
FFFF 11 FF00
Linked List representation
Linked List
Traversal (Algorithm and simulation)

Algorithm
Input: Head (the address of first node)
Curr = Head
Step 1: if Curr == NULL exit otherwise access current node (with address Curr)
Step 2: move Curr to next node and go to step 1
Curr = node->next

Head
12 3 14 5 16 NULL

Curr Curr Curr Curr Curr Curr


Start=1001 Node 2
Node 1

10 1002 20 NULL

1001 1002
PTR=LINK[PTR]
=> PTR = NULL Print (INFO[PTR]) = = 20
References

1. https://en.wikipedia.org/wiki/Linked_list
Books
 “Schaum's Outline of Data Structures with C++”. By John R. Hubbard
 “Data Structures and Program Design”, Robert L. Kruse, 3rd Edition, 1996.
 “Data structures, algorithms and performance”, D. Wood, Addison-Wesley, 1993
 “Advanced Data Structures”, Peter Brass, Cambridge University Press, 2008
 “Data Structures and Algorithm Analysis”, Edition 3.2 (C++ Version), Clifford A.
Shaffer, Virginia Tech, Blacksburg, VA 24061 January 2, 2012
 “C++ Data Structures”, Nell Dale and David Teague, Jones and Bartlett Publishers,
2001.
 “Data Structures and Algorithms with Object-Oriented Design Patterns in C++”,
Bruno R. Preiss,

You might also like