Sie sind auf Seite 1von 29

DFC2023 – ALGORITHM

AND DATA STRUCTURE


CHAPTER 2 :
LIST AND LINKED LIST
LIST
• a list or sequence is an abstract data structure that implements
an ordered collection of values, where the same value may occur
more than once
• value is often called an item, entry, or element of the list

• Definition :
• List is a collection of data, element, component or objects with similar
data type
!
List is a collection of data, element, component or objects with similar data
type

Give any example that you


can relate to List based on
the definition
EXAMPLE OF LIST
CHARACTERISTIC OF LIST
LIST OPERATION
• Operations involved in implementing list :
• Insertion
• Deletion
• Traversal
• Retrieval
• Example, if want to create list of 10 number, declared as
• #define maxSize 10 // used to declare maximum size of array
• int listNumber[maxSize]; // declaration of an array
• int NoOfItem; // used to store no. of item in an array
PROBLEM WITH ARRAY

• Array implementations of lists use a static data structure. Often


defined at compile-time. Cannot be altered while program is
running.
• This means we usually waste space rather than have program run
out.
• It also means that it is difficult to construct ordered lists. In our
implementation, data must be added to the end. If inserted before
the end, all others beneath it must shuffle down. This is slow and
inefficient.
EXAMPLE OF PROBLEM IN ARRAY

Insertion and deletion will cause a lot of movement


LINKED LIST

• a linked list is data structure that consists of a sequence of data records such
that in each record there is a field that contains a reference to the next record
in the sequence

• benefit of a linked list over a conventional array is that the order of the linked
items may be different from the order that the data items are stored in
memory or on disk.
• linked lists allow insertion and removal of nodes at any point in the list
EXAMPLE OF LINKED LIST
BASIC CONCEPT OF LINKED LIST

• A linked list is an ordered series of connected data / nodes


• Each element of the linked list has
• Some data
• A link to the next element
• The link is used to chain the data
EXAMPLE
OPERATION IN LINKED LIST
1. Create node
- To create one new source for connect between items in linked list.
2. Create linked list
- Create new one linked list.
3. Check the linked list : full/empty
- Check either linked list full or empty.
4. Insertion node in the list in front

- Add an item on linked list. in middle

5. Delete node in the list at last

- Delete one item from linked list.


OPERATION IN LINKED LIST
1. Create node
- To create one new source for connect between items in linked
list.

Structure of a node

data link

address for the next node


OPERATION IN LINKED LIST
2. Create linked list
- Create new one linked list.

Structure of a linked list

45 65 38 76
head tail

The address of the first node in the list is stored in a separate location called head / first
OPERATION IN LINKED LIST
3. Check the linked list : full/empty
- Check either linked list full or empty.
Structure of a linked list = FULL

45 65 38 76
head tail
Structure of a linked list = EMPTY

head tail
OPERATION IN LINKED LIST
4. Insertion node in the list
- Add an item on linked list.
Structure of a linked list = Insert 50 (in front)
head
45 65 38 76
tail

45
OPERATION IN LINKED LIST
4. Insertion node in the list
- Add an item on linked list.
Structure of a linked list = Insert 80 (in middle)
head
45 65 38 76
tail

80
OPERATION IN LINKED LIST
4. Insertion node in the list
- Add an item on linked list.
Structure of a linked list = Insert 102 (at last)
head tail
45 65 38 76

102
OPERATION IN LINKED LIST
5. Delete node in the list
- Delete one item from linked list.
head tail
45 65 38 76

102
Structure of a linked list = Delete 65
head
45 38 76 102
LINKED LIST STRUCTURE
OPERATION IN LINKED LIST :
DECLARING LINKED LIST
OPERATION IN LINKED LIST: CREATE
HEAD & NODE
OPERATION IN LINKED LIST: INSERT
OPERATION IN LINKED LIST: DELETE
ADVANTAGES OF LINKED LIST

• Dynamic data structure, and therefore the size of the linked list
can grow or shrink in size during execution of the program.
• Does not require any extra space therefore it does not waste extra
memory.
• Provide flexibility in rearranging the items efficiently.
DISADVANTAGES OF LINKED LIST

• Complex programming processed.


• High in computerizing time and memory management.
• Not suitable for simple list with minimal size.
• Complex in updating of program.
DIFFERENCES BETWEEN LIST &
LINKED LIST
List Linked List
 Static size of list.  Dynamic size of list.

 Add & delete item required uch  Add & delete item required less
steps. steps.
 Suitable for less of list.  Suitable for larger of list.

 Easy programming processes.  Complex programming processes.

 Easy program update.  Complicated program update.

 Low of memory and computerizing  High of memory and computerizing


time. time.
LAB ACTIVITY

Das könnte Ihnen auch gefallen