0% found this document useful (0 votes)
40 views16 pages

Data Structures and Algorithms

This document discusses and compares different data structures, including arrays and linked lists. It provides details on array lists as self-resizing arrays that can dynamically grow in size. Linked lists are described as having nodes that contain data and a pointer to the next node, allowing non-contiguous memory allocation. The key operations of linked lists like add, insert, and remove are outlined. Advantages of linked lists over arrays include dynamic sizing and easier insertion/deletion, while arrays allow for faster random access.

Uploaded by

Muhammad Haroon
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)
40 views16 pages

Data Structures and Algorithms

This document discusses and compares different data structures, including arrays and linked lists. It provides details on array lists as self-resizing arrays that can dynamically grow in size. Linked lists are described as having nodes that contain data and a pointer to the next node, allowing non-contiguous memory allocation. The key operations of linked lists like add, insert, and remove are outlined. Advantages of linked lists over arrays include dynamic sizing and easier insertion/deletion, while arrays allow for faster random access.

Uploaded by

Muhammad Haroon
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/ 16

DATA STRUCTURES

AND ALGORITHMS

1
Outline
● Sequential List using Arrays
● Linked List
● Operations
● Array vs. Linked List
○ Pros and Cons
● Types

2
Static vs Dynamic Data Structure
● An array is a structure of fixed-size data records such that each
element can be efficiently located by its index or (equivalently)
address.

Advantages of contiguously-allocated arrays include:


● Constant-time access given the index.
● Arrays consist purely of data, so no space is wasted with
links or other formatting information.

3
Array List
● The array list is basically a self-resizing array or, in other words, a 
dynamic array.
● This means that this data structure can grow as much as it needs —
compared to the classical static array which cannot because it has a
predefined maximum size.
● The need for this data structure is most obvious when you have the urge to
store items without knowing how much space you’ll need in advance.

4
● add(element)

● remove(element)

● resize(element)

5
Array’s Limitation
● Arrays
○ Simple,
○ Fast
but
○ Must specify size at construction time
○ Murphy’s law: Anything that can go wrong, will go wrong!
■ Construct an array with space for n
● n = twice your estimate of largest collection
■ Tomorrow you’ll need n+1
○ More flexible system?

6
Therefore there is need of a data structure that dynamically
allocates space for each element as needed

🡺 Linked List!

7
Linked List
● A linked list is a linear data structure, in which the elements
are not stored at contiguous memory locations. The elements
in a linked list are linked using pointers (entity that point to the
next element)
● In simple words, a linked list consists of nodes where each node
contains a data field and a reference (link) to the next node in
the list.

8
9
Working of Linked List
Linked list consists of nodes where each node contains a data field and a
reference (link) to the next node in the link
● Node/Link/Element/Object – Each node in the linked list consists of two
parts
1. Data
2. Link to the next node
● Next – This points to the next node in the
linked list (since they are not stored in the
contiguous memory locations)

10
Operations on Linked List
● Resize/Add

11
Operations on Linked List
● Insert

12
Operations on Linked List
● Remove

13
14
Linked List vs Arrays
● Advantages of Linked List over Arrays
1. Dynamic size
2. Ease of insertion/deletion
● Disadvantages of Linked List over Arrays
1. Random access is not allowed
2. Extra memory space for pointer
3. No cache friendly (array – contiguous)

15
Types of Linked List

16

You might also like