Data Structures and Algorithms: Linked Lists - Lecture 02, Schemes and Mind Maps of Computer Applications

is an important concept in object-oriented programming. ADTs give us a way to describe and use abstract objects in programming. With ADTs, we can define new data types and methods to manipulate them. Some examples of ADTs include data structures such as stacks, queues, linked lists, and binary search trees. ADTs are an important tool for creating highly reusable programs that are easy to maintain and develop.

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 02/27/2023

ahihi2
ahihi2 🇻🇳

4 documents

1 / 37

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures and
Algorithms
Data Structures and
Algorithms
LECTURE 02: LINKED LIST
LECTURE 02: LINKED LIST
1
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

Partial preview of the text

Download Data Structures and Algorithms: Linked Lists - Lecture 02 and more Schemes and Mind Maps Computer Applications in PDF only on Docsity!

Data Structures and

Algorithms

Data Structures and

Algorithms

LECTURE 02: LINKED LIST LECTURE 02: LINKED LIST

1

OVERVIEWOVERVIEW

Describe List structures

Describe self-referential structures

Explain types of linked lists

Singly Linked Lists

Doubly Linked Lists

Circular Lists

Lists in java.util

Reading at home

Describe List structures

Describe self-referential structures

Explain types of linked lists

Singly Linked Lists

Doubly Linked Lists

Circular Lists

Lists in java.util

Reading at home

ListsLists

It’s difficult to specify a single list Abstract Data Type (ADT) that covers

both arrays and linked lists

One issue is the representation of position

Array position is represented by integer

Linked list position is represented by pointer

In case of an array with n elements, a “position” is simply an integer in

the range from 0 to n-1.

In linked list, a position can be a pointer to one of the nodes in the list,

but there are some subtleties involved (see later)

It’s difficult to specify a single list Abstract Data Type (ADT) that covers

both arrays and linked lists

One issue is the representation of position

Array position is represented by integer

Linked list position is represented by pointer

In case of an array with n elements, a “position” is simply an integer in

the range from 0 to n-1.

In linked list, a position can be a pointer to one of the nodes in the list,

but there are some subtleties involved (see later)

Operations of the ADTOperations of the ADT

 getFirst()

 getLast()

 getNext(p)

 getPrev(p)

 get(p)

 set(p, x)

 insert(p, x)

 getFirst()

 getLast()

 getNext(p)

 getPrev(p)

 get(p)

 set(p, x)

 insert(p, x)

 remove(p)

 removeFirst()

 removeLast()

 removeNext(p)

 removePrev(p)

 find(x)

 size()

 remove(p)

 removeFirst()

 removeLast()

 removeNext(p)

 removePrev(p)

 find(x)

 size()

Self-referential structuresSelf-referential structures

Many dynamic data structures

are implemented through the

use of a self-referential structure

A self-referential structure is an

object, one of this object

member is a reference to

another object of its own type.

With this arrangement, it’s

possible to create ‘chains’ of

data of varying form:

Many dynamic data structures

are implemented through the

use of a self-referential structure

A self-referential structure is an

object, one of this object

member is a reference to

another object of its own type.

With this arrangement, it’s

possible to create ‘chains’ of

data of varying form:

Employee

String name;

int age;

DataNode

Employee

info;

DataNode

next;

Linked List

Tree

Linked ListsLinked Lists

 A collection of nodes storing data and links to other nodes

 A linear DS composed of nodes

Each node holds some info and reference to another node in the

list

 Types of linked lists

Singly-linked list

Doubly-linked list

 A collection of nodes storing data and links to other nodes

 A linear DS composed of nodes

Each node holds some info and reference to another node in the

list

 Types of linked lists

Singly-linked list

Doubly-linked list

Singly linked listsSingly linked lists

 Its node contains two data fields: info and next.

Info stores information which is usable by user

Next links it to its successor in the sequence

 Its node contains two data fields: info and next.

Info stores information which is usable by user

Next links it to its successor in the sequence

12 99 37 null

head tail

Node.javaNode.java

MyList.java (cont’)MyList.java (cont’)

Main.javaMain.java

Deleting node at beginning & endDeleting node at beginning & end

ExerciseExercise

 Implementing java code for

Inserting node at the beginning and end

Deleting node at the beginning and end

 Implementing java code for

Inserting node at the beginning and end

Deleting node at the beginning and end

IntroIntro

 In doubly linked list, each node has two

reference fields

one to the successor and

one to the predecessor

 In doubly linked list, each node has two

reference fields

one to the successor and

one to the predecessor

Node.javaNode.java