SlideShare a Scribd company logo
CPEN 204
Data Structures
Lecture 02
ARRAYS AND LINKED LIST
AS ADT
Outline
• What are Data Types ?
• What is Abstact Data Types (ADTs)?
• Why ADT?
• Arrays as an ADT
• Link List as an ADT
• Assignment #2
What are Data Types ?
• Defines a certain domain of values
• Defines operations allowed on those values.
• Eg.
• Int ype
• - takes only integer values
• Operations: addition, subtraction,
multiplication, bitwise operations etc.
What is ADT?
• ADTs are like user defined data types which
defines operations on values using
functions without specifying what is there
inside the function and how the operations are
performed.
What is ADT?
• Eg. Stack ADT
• A stack consists of elements of the same type
arranged in a sequential order.
• Operations: initialize(), push(), pop(),
isEmpty(), isFull()
Why ADTs
• A program which uses data structure is
called a client program.
• It has access to the ADTs ie. Interface
• The program which implements the data
structure is called implementation
Advantages of DTs
• It can be used without knowing the
implementation.
• Implementation can be changed from
one type to the other without affecting
the client program.
Arrays
• The simplest type of data structure is a linear (or
one dimensional) array. E.g.
– A 1, A 2, A 3 . . . . A n
– or by the parenthesis notation
• A (1), A (2), A (3) . . . . . . A (n)
– or by the bracket notation
• A [1], A [2], A [3] . . . . . . A [n]
• A[8] =
Arrays as an ADT
• Arrays are used for implementing a variety of other
data structures.
• string,
• Strings composed of zeros and ones are called
binary strings or bit strings.
• Strings are indispensable for processing textual data,
defining computer languages and compiling programs
written in them, and studying abstract computational
models.
Operations on array
• Traversing: it means processing or visiting each
element in the array exactly once.
• Insertion: means to put values into an array
• Deletion / Remove: to delete a value from an
array.
Operations on array
• Sorting: Re-arrangement of values in an array in
a specific order
• (Ascending / Descending) is called sorting.
• Searching: The process of finding the location of
a particular element in an array is called
searching.
There are two popular searching techniques:
• Linear search and binary search and will be
Limitations of Arrays
• An array has a fixed size which means you
cannot add/delete elements after creation.
• You also cannot resize them dynamically.
• Unlike lists in Python, cannot store values of
different data types in a single array.
Linked List as an ADT
Objectives
–Learn about linked list
– Be aware of basic properties of linked list
– Explore the insertion and deletion operations on
linked list
– Discover how to build and manipulate a linked list
– Learn how to construct a doubly linked list
What is a List
• A list is a finite sequence of data items, i.e., a
collection of data items arranged in a certain linear
order.
Ways of storing list In memory:
• sequential memory locations i.e store the list in
arrays.
• using pointers or links to associate elements
sequentially i.e known as linked list.
Linked Lists
• A linked list is a sequence of zero or more elements
called nodes.
• Each item in the list is called a node.
• Each node contains two kinds of information:
o some data and
o one or more links called pointers to other nodes of the
linked list.
Linked Lists
• Information- contains the item being stored in the
list.
• Next address- contains the address of the next item
in the list.
• The last node in the list contains NULL pointer to
indicate that it is the end of the list.
Linked List
• Linked list is a very flexible dynamic data
structure :
• ie. items may be added to it or deleted from it
at will.
• program will have to accommodate in
advance.
• This allows robust programs which require
much less maintenance.
Types of Linked lists
• Singly Linked List : A singly linked list, or
simply a linked list, is a linear collection of data
items.
•
Singly Linked List
• A singly linked list has the disadvantage that we can
only traverse it in one direction.
• Many applications require searching backwards
and forwards through sections of a list.
Doubly Linked List
•Doubly Linked List permit traversing or searching of
the list in both directions.
•In this linked list each node contains three fields.
– One to store data
– Remaining are self referential pointers which points
to previous and next nodes in the list
Implementation of node using structure
• Method -1:
struct node
{
int data;
struct node *prev; struct node * next;
};
Implementation of node using class
• Method -2:
class node
{
public:
int data; node *prev; node * next;
};
Insertions operation
• To place an elements in the list there are 3 cases
 At the beginning
 End of the list
 At a given position
Deletions operation
Removing an element from the list, without destroying
the integrity of the list itself.
To place an element from the list there are 3 cases :
Delete a node at beginning of the list
Delete a node at end of the list
Delete a node at a given position
lecture 02.2.ppt
Circularly Linked List
• Simply circular list, is a linked list in which the last
node always points to the first node.
• It can be built by replacing the NULL pointer at the
end of the list with a pointer which points to the first
node.
• There is no first or last node in the circular list.
Advantages
Any node can be traversed starting from any other
node in the list.
There is no need of NULL pointer to signal the end
of the list and hence, all pointers contain valid
addresses.
In contrast to singly linked list, deletion operation
in circular list is simplified as the search for the
previous node of an element to be deleted can be
started from that item itself.
Applications of the Linked List
• It can be used to represent polynomials.
• Using a linked list, we can perform the
polynomial manipulation.
• performed addition or subtraction of long
integers arithmetic operations.
• To implement stacks and queues.
Limitations of Linked List
The linked allocation has the following draw backs:
• No direct access to a particular element.
• Additional memory required for pointers.
• Searching must be done sequentially, however,
when the list is large, it becomes time consuming.
Basic Operations
• 1. Initialize the list.
• 2. Determine whether the list is empty.
• 3. Print the list.
• 4. Find the length of the list.
• 5. Destroy the list
Basic Operations
• 16. Retrieve the info contained in the first node.
• 7. Retrieve the info contained in the last node.
• 8. Search the list for a given item.
• 9. Insert an item in the list.
• 10. Delete an item from the list.
• 11. Make a copy of the linked list
Operations of Linked List
• Operations on Doubly linked list:
 Insertion of a node
 Deletions of a node
 Traversing the list
Assignment 02
1. Write the algorithm and a program to determine the
median of the array given below: (9, 4, 5, 1, 7, 78,
22, 15, 96, 45,25)
Note that the median of an array is the middle element
of a sorted array.
2. Discuss 4 differences between Circular Array and
Linked List

More Related Content

PPTX
EC2311 – Data Structures and C Programming
PPTX
unit 1.pptx
PPTX
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
PPT
Lecture 2b lists
PPTX
Data structures and Algorithm analysis_Lecture 2.pptx
PDF
lect 2-DS ALGO(online).pdf
PPTX
Linked lists linked lists vs Arrays.pptx
PPTX
DATA STRUCTURE AND ALGORITHM with linked list
EC2311 – Data Structures and C Programming
unit 1.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
Lecture 2b lists
Data structures and Algorithm analysis_Lecture 2.pptx
lect 2-DS ALGO(online).pdf
Linked lists linked lists vs Arrays.pptx
DATA STRUCTURE AND ALGORITHM with linked list

Similar to lecture 02.2.ppt (20)

PPTX
Data Structure
PPTX
Linked list (1).pptx
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
PDF
ds-lecture-4-171012041008 (1).pdf
PPTX
linked list in data structure
PPTX
DS_LinkedList.pptx
PDF
Data structure
PPT
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
PPTX
Data_structure.pptx
PPTX
Lecture 2 - Linear Data Structures & Implementation.pptx
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
PPT
Data Structures 3
PPT
Lecture 3 List of Data Structures & Algorithms
PPTX
Introduction to linked list in data structure.pptx
PPT
Unit 1 linked list
PPT
2- link-list.ppt
PPTX
Linked list
PPT
PPT
Data Structure
Linked list (1).pptx
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
ds-lecture-4-171012041008 (1).pdf
linked list in data structure
DS_LinkedList.pptx
Data structure
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Data_structure.pptx
Lecture 2 - Linear Data Structures & Implementation.pptx
Data Structure and Algorithms by Sabeen Memon03.pptx
Data Structures 3
Lecture 3 List of Data Structures & Algorithms
Introduction to linked list in data structure.pptx
Unit 1 linked list
2- link-list.ppt
Linked list
Ad

Recently uploaded (20)

PDF
Sunset Boulevard Student Revision Booklet
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
PDF
Landforms and landscapes data surprise preview
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PPTX
An introduction to Prepositions for beginners.pptx
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PPTX
How to Manage Bill Control Policy in Odoo 18
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
ACUTE NASOPHARYNGITIS. pptx
Sunset Boulevard Student Revision Booklet
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Landforms and landscapes data surprise preview
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
An introduction to Prepositions for beginners.pptx
Software Engineering BSC DS UNIT 1 .pptx
How to Manage Bill Control Policy in Odoo 18
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
vedic maths in python:unleasing ancient wisdom with modern code
How to Manage Loyalty Points in Odoo 18 Sales
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
ACUTE NASOPHARYNGITIS. pptx
Ad

lecture 02.2.ppt

  • 1. CPEN 204 Data Structures Lecture 02 ARRAYS AND LINKED LIST AS ADT
  • 2. Outline • What are Data Types ? • What is Abstact Data Types (ADTs)? • Why ADT? • Arrays as an ADT • Link List as an ADT • Assignment #2
  • 3. What are Data Types ? • Defines a certain domain of values • Defines operations allowed on those values. • Eg. • Int ype • - takes only integer values • Operations: addition, subtraction, multiplication, bitwise operations etc.
  • 4. What is ADT? • ADTs are like user defined data types which defines operations on values using functions without specifying what is there inside the function and how the operations are performed.
  • 5. What is ADT? • Eg. Stack ADT • A stack consists of elements of the same type arranged in a sequential order. • Operations: initialize(), push(), pop(), isEmpty(), isFull()
  • 6. Why ADTs • A program which uses data structure is called a client program. • It has access to the ADTs ie. Interface • The program which implements the data structure is called implementation
  • 7. Advantages of DTs • It can be used without knowing the implementation. • Implementation can be changed from one type to the other without affecting the client program.
  • 8. Arrays • The simplest type of data structure is a linear (or one dimensional) array. E.g. – A 1, A 2, A 3 . . . . A n – or by the parenthesis notation • A (1), A (2), A (3) . . . . . . A (n) – or by the bracket notation • A [1], A [2], A [3] . . . . . . A [n] • A[8] =
  • 9. Arrays as an ADT • Arrays are used for implementing a variety of other data structures. • string, • Strings composed of zeros and ones are called binary strings or bit strings. • Strings are indispensable for processing textual data, defining computer languages and compiling programs written in them, and studying abstract computational models.
  • 10. Operations on array • Traversing: it means processing or visiting each element in the array exactly once. • Insertion: means to put values into an array • Deletion / Remove: to delete a value from an array.
  • 11. Operations on array • Sorting: Re-arrangement of values in an array in a specific order • (Ascending / Descending) is called sorting. • Searching: The process of finding the location of a particular element in an array is called searching. There are two popular searching techniques: • Linear search and binary search and will be
  • 12. Limitations of Arrays • An array has a fixed size which means you cannot add/delete elements after creation. • You also cannot resize them dynamically. • Unlike lists in Python, cannot store values of different data types in a single array.
  • 13. Linked List as an ADT Objectives –Learn about linked list – Be aware of basic properties of linked list – Explore the insertion and deletion operations on linked list – Discover how to build and manipulate a linked list – Learn how to construct a doubly linked list
  • 14. What is a List • A list is a finite sequence of data items, i.e., a collection of data items arranged in a certain linear order. Ways of storing list In memory: • sequential memory locations i.e store the list in arrays. • using pointers or links to associate elements sequentially i.e known as linked list.
  • 15. Linked Lists • A linked list is a sequence of zero or more elements called nodes. • Each item in the list is called a node. • Each node contains two kinds of information: o some data and o one or more links called pointers to other nodes of the linked list.
  • 16. Linked Lists • Information- contains the item being stored in the list. • Next address- contains the address of the next item in the list. • The last node in the list contains NULL pointer to indicate that it is the end of the list.
  • 17. Linked List • Linked list is a very flexible dynamic data structure : • ie. items may be added to it or deleted from it at will. • program will have to accommodate in advance. • This allows robust programs which require much less maintenance.
  • 18. Types of Linked lists • Singly Linked List : A singly linked list, or simply a linked list, is a linear collection of data items. •
  • 19. Singly Linked List • A singly linked list has the disadvantage that we can only traverse it in one direction. • Many applications require searching backwards and forwards through sections of a list.
  • 20. Doubly Linked List •Doubly Linked List permit traversing or searching of the list in both directions. •In this linked list each node contains three fields. – One to store data – Remaining are self referential pointers which points to previous and next nodes in the list
  • 21. Implementation of node using structure • Method -1: struct node { int data; struct node *prev; struct node * next; };
  • 22. Implementation of node using class • Method -2: class node { public: int data; node *prev; node * next; };
  • 23. Insertions operation • To place an elements in the list there are 3 cases  At the beginning  End of the list  At a given position
  • 24. Deletions operation Removing an element from the list, without destroying the integrity of the list itself. To place an element from the list there are 3 cases : Delete a node at beginning of the list Delete a node at end of the list Delete a node at a given position
  • 26. Circularly Linked List • Simply circular list, is a linked list in which the last node always points to the first node. • It can be built by replacing the NULL pointer at the end of the list with a pointer which points to the first node. • There is no first or last node in the circular list.
  • 27. Advantages Any node can be traversed starting from any other node in the list. There is no need of NULL pointer to signal the end of the list and hence, all pointers contain valid addresses. In contrast to singly linked list, deletion operation in circular list is simplified as the search for the previous node of an element to be deleted can be started from that item itself.
  • 28. Applications of the Linked List • It can be used to represent polynomials. • Using a linked list, we can perform the polynomial manipulation. • performed addition or subtraction of long integers arithmetic operations. • To implement stacks and queues.
  • 29. Limitations of Linked List The linked allocation has the following draw backs: • No direct access to a particular element. • Additional memory required for pointers. • Searching must be done sequentially, however, when the list is large, it becomes time consuming.
  • 30. Basic Operations • 1. Initialize the list. • 2. Determine whether the list is empty. • 3. Print the list. • 4. Find the length of the list. • 5. Destroy the list
  • 31. Basic Operations • 16. Retrieve the info contained in the first node. • 7. Retrieve the info contained in the last node. • 8. Search the list for a given item. • 9. Insert an item in the list. • 10. Delete an item from the list. • 11. Make a copy of the linked list
  • 32. Operations of Linked List • Operations on Doubly linked list:  Insertion of a node  Deletions of a node  Traversing the list
  • 33. Assignment 02 1. Write the algorithm and a program to determine the median of the array given below: (9, 4, 5, 1, 7, 78, 22, 15, 96, 45,25) Note that the median of an array is the middle element of a sorted array. 2. Discuss 4 differences between Circular Array and Linked List