0% found this document useful (0 votes)
81 views41 pages

Definitions: - Lists and Arrays - Nodes and Pointers - Single Linked Lists - Double Linked Lists - Circular Lists

This is suitable for IB Students taking Computer Science HL and SL. It provides Linked Lists points used in the theory of IB.

Uploaded by

Ruthwik H Param
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views41 pages

Definitions: - Lists and Arrays - Nodes and Pointers - Single Linked Lists - Double Linked Lists - Circular Lists

This is suitable for IB Students taking Computer Science HL and SL. It provides Linked Lists points used in the theory of IB.

Uploaded by

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

Introduction

Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Lists and arrays


Lists:

Lists and arrays


Arrays:
{Size of the following array is = 4}

Index
Value

0
44

1
5

2
96

3
3

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Nodes and pointers

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Single linked lists

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Double Linked Lists

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Circular Lists

Introduction
Definitions
Lists and arrays
Nodes and pointers
Single Linked Lists
Double Linked Lists
Circular Lists

Advantages

Advantages
The Linked List advantages are collected because of the
array disadvantages, array disadvantages are:
1. Array Size
2. Memory allocation
3. Insertion and Deletion

Outline

Introduction
Insertion Description
Deletion Description
Basic Node Implementation
Conclusion

Insertion Description
Insertion at the top of the list
Insertion at the end of the list
Insertion in the middle of the list

Insertion Description
Insertion at the top of the list
Insertion at the end of the list
Insertion in the middle of the list

Insertion at the top


Steps:
Create a Node
Set the node data Values
Connect the pointers

Insertion Description
head

48

17

142

//

Follow the previous steps and we get


Step 1

Step 2

Step 3

head

93

Insertion Description
Insertion at the top of the list
Insertion at the end of the list
Insertion in the middle of the list

Insertion at the end


Steps:
Create a Node
Set the node data Values
Connect the pointers

Insertion Description
head

48

17

142

//

Follow the previous steps and we get


Step 1

Step 2

Step 3

Insertion Description
Insertion at the top of the list
Insertion at the end of the list
Insertion in the middle of the list

Insertion in the middle


Steps:
Create a Node
Set the node data Values
Break pointer connection
Re-connect the pointers

Insertion Description
Step 1

Step 3

Step 4

Step 2

Outline
Introduction
Insertion Description
Deletion Description

Deletion Description
Deleting from the top of the list
Deleting from the end of the list
Deleting from the middle of the list

Deletion Description
Deleting from the top of the list
Deleting from the end of the list
Deleting from the middle of the list

Deleting from the top


Steps
Break the pointer connection
Re-connect the nodes
Delete the node

Deletion Description
head
6

17

42

17

42

17

42

head

head

Deletion Description
Deleting from the top of the list
Deleting from the end of the list
Deleting from the middle of the list

Deleting from the end


Steps
Break the pointer connection
Set previous node pointer to NULL
Delete the node

Deletion Description
head
6

head

17

17

17

head

42

42

Deletion Description
Deleting from the top of the list
Deleting from the end of the list
Deleting from the middle of the list

Deleting from the Middle


Steps
Set previous Node pointer to next node
Break Node pointer connection
Delete the node

Deletion Description
head
4

17

42

head
4

17

head
4

42

42

Anatomy of a linked list


A linked list consists of:
A sequence of nodes
myList
a

Each node contains a value


and a link (pointer or reference) to some other node
The last node contains a null link
The list may (or may not) have a header
37

More terminology
A nodes successor is the next node in the
sequence
The last node has no successor

A nodes predecessor is the previous node


in the sequence
The first node has no predecessor

A lists length is the number of elements in


it
A list may be empty (contain no elements)
38

Singly-linked lists
Here is a singly-linked list (SLL):
myList
a

Each node contains a value and a link to its


successor (the last node has no successor)
The header points to the first node in the list (or
contains the null link if the list is empty)
39

Doubly-linked lists
Here is a doubly-linked list (DLL):
myDLL
a

Each node contains a value, a link to its successor (if


any), and a link to its predecessor (if any)
The header points to the first node in the list and to
the last node in the list (or contains null links if the list
is empty)
40

DLLs compared to SLLs


Advantages:
Can be traversed in
either direction (may be
essential for some
programs)
Some operations, such
as deletion and
inserting before a node,
become easier

41

Disadvantages:
Requires more space
List manipulations are
slower (because more
links must be changed)
Greater chance of
having bugs (because
more links must be
manipulated)

You might also like