SlideShare a Scribd company logo
Data Structures and
Algorithms
Intro & List
Yang Hu
Feb 2025
Ref: CS1102 - University of Illinois Chicago
What is Data Structure?
•A construct that can be defined within
a programming language to store a
collection of data
- one may store some data in an array of
integers, an array of objects, or an array
of arrays
Abstract Data Type (ADT)
•Definition: a collection of data together with
a set of operations on that data
- specifications indicate what ADT operations
do, but not how to implement them
- data structures are part of an ADT’s
implementation
•Programmer can use an ADT without
knowing its implementation.
Typical Operations on Data
•Add data to a data collection
•Remove data from a data collection
•Ask questions about the data in a data
collection. E.g., what is the value at a
particular location, and is x in the
collection?
Why we need ADT?
•Hide the unnecessary details
•Help manage software complexity
•Easier software maintenance
•Functionalities are less likely to
change
•Localised rather than global changes
Illustration of usage of ADT
List
Array & linked based approaches
Definition and operations of List
• List: a finite sequence of data items
a1, a2, a3, …, an
• List is very general in computing
- e.g. class list, list of characters, list of events
• Typical operations have:
- Creation
- Insert / remove an element
- Test for emptiness
- Find an item/element
- Current element / next / previous
- Find k-th element
- Print the entire list
Array-Based List Implementation
• One simple implementation is to use arrays
• A sequence of n-elements
• Maximum size should be pre-set based on prior knowledge.
• Internal variables:
• Maximum size maxSize (m)
• Current size curSize (n)
• Current index cur
• Array of elements listArray
n
curSize
a1 a2 a3 an
listArray
unused
0 1 2 n-1 m
cur
Inserting Into an Array
• While retrieval is very fast, insertion and deletion are very
slow
• Insert has to shift upwards to create gap
a1 a2 a7 a8
a4 a5 a6
a3
Step 1 : Shift upwards
8
Size arr
8 a1 a2 a3 a7 a8
Size arr
a4 a5 a6
Example : insert(2, it, arr)
Step 2 : Write into gap
it
Step 3 : Update Size
9
Deleting from an Array
• Delete has to shift downwards to close gap of deleted item
Step 1 : Close Gap
9 a1 a2 it a7
a8
size
a5 a6
a3
a8
arr
9 a1 a2 it a7 a8
size
a4 a5 a6
a3
arr
Example: deleteItem(4, arr)
Step 2 : Update Size
8
Not part of list
Linked List Approach
• Main problem of array is the slow deletion/insertion since it
has to shift items in its contiguous memory
• Solution: linked list where items need not be contiguous with
nodes of the form
• Sequence (list) of four items < a1,a2 ,a3 ,a4 > can be
represented by:
item next
ai
a1 a2 a3 a4
head represents
null
Ad

Recommended

8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
unit 1_Linked list.pptx
unit 1_Linked list.pptx
ssuser7922b8
 
Lists
Lists
Ghaffar Khan
 
Adt of lists
Adt of lists
Nivegeetha
 
lecture 02.2.ppt
lecture 02.2.ppt
NathanielAdika
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
AhmedEldesoky24
 
Data structures - unit 1
Data structures - unit 1
SaranyaP45
 
Lecture2
Lecture2
Muhammad Zubair
 
lect 2-DS ALGO(online).pdf
lect 2-DS ALGO(online).pdf
MuhammadUmerIhtisham
 
General Data structures
General Data structures
Youssef Elsalhawy
 
unit 1.pptx
unit 1.pptx
ssuser7922b8
 
Data Structures 01
Data Structures 01
Budditha Hettige
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
Data structures
Data structures
Rokonuzzaman Rony
 
linked list (c#)
linked list (c#)
swajahatr
 
UNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
AntareepMajumder
 
Funddamentals of data structures
Funddamentals of data structures
Globalidiots
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
UsriDevi1
 
ds bridge.pptx
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
JasmineJinitha
 
DSA Leactrure # 1! Explaining abstract data types
DSA Leactrure # 1! Explaining abstract data types
amazonventuresinfo
 
Introduction in Data Structure - stack, Queue
Introduction in Data Structure - stack, Queue
BharathiKrishna6
 
A singly linked list is a linear data structure
A singly linked list is a linear data structure
sangeethavinoth
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 

More Related Content

Similar to Data Structures and Algorithms: introduction (20)

Lecture2
Lecture2
Muhammad Zubair
 
lect 2-DS ALGO(online).pdf
lect 2-DS ALGO(online).pdf
MuhammadUmerIhtisham
 
General Data structures
General Data structures
Youssef Elsalhawy
 
unit 1.pptx
unit 1.pptx
ssuser7922b8
 
Data Structures 01
Data Structures 01
Budditha Hettige
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
Data structures
Data structures
Rokonuzzaman Rony
 
linked list (c#)
linked list (c#)
swajahatr
 
UNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
AntareepMajumder
 
Funddamentals of data structures
Funddamentals of data structures
Globalidiots
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
UsriDevi1
 
ds bridge.pptx
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
JasmineJinitha
 
DSA Leactrure # 1! Explaining abstract data types
DSA Leactrure # 1! Explaining abstract data types
amazonventuresinfo
 
Introduction in Data Structure - stack, Queue
Introduction in Data Structure - stack, Queue
BharathiKrishna6
 
A singly linked list is a linear data structure
A singly linked list is a linear data structure
sangeethavinoth
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
linked list (c#)
linked list (c#)
swajahatr
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
AntareepMajumder
 
Funddamentals of data structures
Funddamentals of data structures
Globalidiots
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
UsriDevi1
 
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
JasmineJinitha
 
DSA Leactrure # 1! Explaining abstract data types
DSA Leactrure # 1! Explaining abstract data types
amazonventuresinfo
 
Introduction in Data Structure - stack, Queue
Introduction in Data Structure - stack, Queue
BharathiKrishna6
 
A singly linked list is a linear data structure
A singly linked list is a linear data structure
sangeethavinoth
 

Recently uploaded (20)

最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
jed P
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
Mynd company all details what they are doing a
Mynd company all details what they are doing a
AniketKadam40952
 
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
taqyea
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Allotted-MBBS-Student-list-batch-2021.pdf
Allotted-MBBS-Student-list-batch-2021.pdf
subhansaifi0603
 
PPT2 W1L2.pptx.........................................
PPT2 W1L2.pptx.........................................
palicteronalyn26
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Presentation by Tariq & Mohammed (1).pptx
Presentation by Tariq & Mohammed (1).pptx
AbooddSandoqaa
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
jed P
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
Mynd company all details what they are doing a
Mynd company all details what they are doing a
AniketKadam40952
 
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
最新版意大利米兰大学毕业证(UNIMI毕业证书)原版定制
taqyea
 
Informatics Market Insights AI Workforce.pdf
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Allotted-MBBS-Student-list-batch-2021.pdf
Allotted-MBBS-Student-list-batch-2021.pdf
subhansaifi0603
 
PPT2 W1L2.pptx.........................................
PPT2 W1L2.pptx.........................................
palicteronalyn26
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Presentation by Tariq & Mohammed (1).pptx
Presentation by Tariq & Mohammed (1).pptx
AbooddSandoqaa
 
Ad

Data Structures and Algorithms: introduction

  • 1. Data Structures and Algorithms Intro & List Yang Hu Feb 2025 Ref: CS1102 - University of Illinois Chicago
  • 2. What is Data Structure? •A construct that can be defined within a programming language to store a collection of data - one may store some data in an array of integers, an array of objects, or an array of arrays
  • 3. Abstract Data Type (ADT) •Definition: a collection of data together with a set of operations on that data - specifications indicate what ADT operations do, but not how to implement them - data structures are part of an ADT’s implementation •Programmer can use an ADT without knowing its implementation.
  • 4. Typical Operations on Data •Add data to a data collection •Remove data from a data collection •Ask questions about the data in a data collection. E.g., what is the value at a particular location, and is x in the collection?
  • 5. Why we need ADT? •Hide the unnecessary details •Help manage software complexity •Easier software maintenance •Functionalities are less likely to change •Localised rather than global changes
  • 7. List Array & linked based approaches
  • 8. Definition and operations of List • List: a finite sequence of data items a1, a2, a3, …, an • List is very general in computing - e.g. class list, list of characters, list of events • Typical operations have: - Creation - Insert / remove an element - Test for emptiness - Find an item/element - Current element / next / previous - Find k-th element - Print the entire list
  • 9. Array-Based List Implementation • One simple implementation is to use arrays • A sequence of n-elements • Maximum size should be pre-set based on prior knowledge. • Internal variables: • Maximum size maxSize (m) • Current size curSize (n) • Current index cur • Array of elements listArray n curSize a1 a2 a3 an listArray unused 0 1 2 n-1 m cur
  • 10. Inserting Into an Array • While retrieval is very fast, insertion and deletion are very slow • Insert has to shift upwards to create gap a1 a2 a7 a8 a4 a5 a6 a3 Step 1 : Shift upwards 8 Size arr 8 a1 a2 a3 a7 a8 Size arr a4 a5 a6 Example : insert(2, it, arr) Step 2 : Write into gap it Step 3 : Update Size 9
  • 11. Deleting from an Array • Delete has to shift downwards to close gap of deleted item Step 1 : Close Gap 9 a1 a2 it a7 a8 size a5 a6 a3 a8 arr 9 a1 a2 it a7 a8 size a4 a5 a6 a3 arr Example: deleteItem(4, arr) Step 2 : Update Size 8 Not part of list
  • 12. Linked List Approach • Main problem of array is the slow deletion/insertion since it has to shift items in its contiguous memory • Solution: linked list where items need not be contiguous with nodes of the form • Sequence (list) of four items < a1,a2 ,a3 ,a4 > can be represented by: item next ai a1 a2 a3 a4 head represents null