SlideShare a Scribd company logo
Array
• A data structure that contains a list of elements
accessed by an index
– Array: a set of pairs (index and value)
– For each index, there is a value associated with that index.
• Arrays are generally a fixed size, which means you must
specify the maximum size when the array is created
• Increasing the size of an array normally involves
creating a new array of the desired size and copying
the values from the old array to the new array
Array
• An array of size 5
String arr = new String[5];
Int nextIndex = 0;
• Set some of the values
arr[nextIndex ] = “Hi”
++nextIndex;
arr[nextIndex ] = “there”
++nextIndex;
arr[nextIndex ] = “Bob”
++nextIndex;
arr[nextIndex ] = “.”
++nextIndex;
Hi there Bob .
Array
• Insert into the middle of a array
– Insert “Billy” between “there” and “Bob”
• Push “Bob” and “.” toward the end of the array to make space for “Bob” in
element 2
insertIndex = 2;
for ( int i = nextIndex; i > = insertIndex; --i ) {
arr[i] = arr[i-1];
}
++nextIndex;
• Set the new value for element 2
arr[insertIndex] = “Billy”;
Hi there Bob .
Hi there Bob Bob .
Hi there Billy Bob .
Questions
• What is the complexity of “retrieve” in an
array?
• What is the complexity of “store” in an array?
• What about insertion and deletion for ordered
elements in an arrary?
Linked List
• A linked list is a data structure that contains a set of nodes
linked with pointers.
• Singly-linked list has links in one direction. To the next node in
the list.
• A doubly-linked list had links in both directions. To the next
and previous nodes in the list.
Data
Next
Variable
Variable Data
Next
Prev
Data
Next
Data
Next
Data
Next
Data
Next
Prev
Data
Next
Prev
Data
Next
Prev
Linked List
• A Circularly-linked list has a complete cycles of
links.
Variable Data
Next
Prev
Data
Next
Prev
Data
Next
Prev
Data
Next
Prev
Data
Next
Variable Data
Next
Data
Next
Data
Next
Linked List
• Insert at the end of a linked list
• Create new node
• Change the links to
include the new node
Billy
Next
Hi
Next
Sentence there
Next
Bob
Next
.
Next
Linked List
• Insert into the middle of a linked list
• Create new node
• Change the links to
include the new node
Hi
Next
Sentence there
Next
Bob
Next
.
Next
Billy
Next
Array versus Linked List
• Some operations are faster with one versus the other
– Find element at position X – Array faster
– Find element Y at unknown position – Tie
– Insert element in the middle – Linked list faster
– Insert element at the end – Tie, if doubly-linked and circular, Array
otherwise
– Insert element at the beginning – Linked list
• Arrays are (typically) a fixed size, linked lists are variable
length
• Arrays are defined as holding a specific number of elements
whether or not that many elements are currently in the array.
Doing that wastes space

More Related Content

Similar to 5 data structures-arraysandlinkedlist

ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked lists
AfriyieCharles
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Getachew Ganfur
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
Globalidiots
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
BlueSwede
 
L list
L listL list
Binary search tree
Binary search treeBinary search tree
Binary search tree
Sana Yameen
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptx
wahid431192
 
Linked list ppt
Linked list pptLinked list ppt
Linked list ppt
SiddhiDeshpade
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
2- link-list.ppt
2- link-list.ppt2- link-list.ppt
2- link-list.ppt
zabihniazai1
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
ssuser7922b8
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
MouDhara1
 
1.4 Sorting.pptx
1.4 Sorting.pptx1.4 Sorting.pptx
1.4 Sorting.pptx
Sujan527908
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
AhmedEldesoky24
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
AnuJoseph95
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
Minakshee Patil
 
Unit 4
Unit 4Unit 4

Similar to 5 data structures-arraysandlinkedlist (20)

ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked lists
 
Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
 
L list
L listL list
L list
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptx
 
Linked list ppt
Linked list pptLinked list ppt
Linked list ppt
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
2- link-list.ppt
2- link-list.ppt2- link-list.ppt
2- link-list.ppt
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
tree-160731205832.pptx
tree-160731205832.pptxtree-160731205832.pptx
tree-160731205832.pptx
 
1.4 Sorting.pptx
1.4 Sorting.pptx1.4 Sorting.pptx
1.4 Sorting.pptx
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
Data structures
Data structuresData structures
Data structures
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
 
Unit 4
Unit 4Unit 4
Unit 4
 

More from irdginfo

Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
irdginfo
 
10 merge sort
10 merge sort10 merge sort
10 merge sortirdginfo
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
 
8 elementary sorts-bubble
8 elementary sorts-bubble8 elementary sorts-bubble
8 elementary sorts-bubbleirdginfo
 
8 elementary sorts-shell
8 elementary sorts-shell8 elementary sorts-shell
8 elementary sorts-shellirdginfo
 
8 elementary sorts-insertion
8 elementary sorts-insertion8 elementary sorts-insertion
8 elementary sorts-insertionirdginfo
 
8 elementary sorts-selection
8 elementary sorts-selection8 elementary sorts-selection
8 elementary sorts-selectionirdginfo
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binaryirdginfo
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injavairdginfo
 
5 data structures-hashtable
5 data structures-hashtable5 data structures-hashtable
5 data structures-hashtableirdginfo
 
5 data structures-tree
5 data structures-tree5 data structures-tree
5 data structures-treeirdginfo
 
5 data structures-stack
5 data structures-stack5 data structures-stack
5 data structures-stackirdginfo
 
4 character encoding-unicode
4 character encoding-unicode4 character encoding-unicode
4 character encoding-unicodeirdginfo
 
4 character encoding-ascii
4 character encoding-ascii4 character encoding-ascii
4 character encoding-asciiirdginfo
 
4 character encoding
4 character encoding4 character encoding
4 character encodingirdginfo
 
3 number systems-floatingpoint
3 number systems-floatingpoint3 number systems-floatingpoint
3 number systems-floatingpointirdginfo
 
2 number systems-scientificnotation
2 number systems-scientificnotation2 number systems-scientificnotation
2 number systems-scientificnotationirdginfo
 
1 number systems-hex
1 number systems-hex1 number systems-hex
1 number systems-hexirdginfo
 
1 number systems-unsignedsignedintegers
1 number systems-unsignedsignedintegers1 number systems-unsignedsignedintegers
1 number systems-unsignedsignedintegersirdginfo
 
1 number systems-octal
1 number systems-octal1 number systems-octal
1 number systems-octalirdginfo
 

More from irdginfo (20)

Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
10 merge sort
10 merge sort10 merge sort
10 merge sort
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
8 elementary sorts-bubble
8 elementary sorts-bubble8 elementary sorts-bubble
8 elementary sorts-bubble
 
8 elementary sorts-shell
8 elementary sorts-shell8 elementary sorts-shell
8 elementary sorts-shell
 
8 elementary sorts-insertion
8 elementary sorts-insertion8 elementary sorts-insertion
8 elementary sorts-insertion
 
8 elementary sorts-selection
8 elementary sorts-selection8 elementary sorts-selection
8 elementary sorts-selection
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
5 data structures-hashtable
5 data structures-hashtable5 data structures-hashtable
5 data structures-hashtable
 
5 data structures-tree
5 data structures-tree5 data structures-tree
5 data structures-tree
 
5 data structures-stack
5 data structures-stack5 data structures-stack
5 data structures-stack
 
4 character encoding-unicode
4 character encoding-unicode4 character encoding-unicode
4 character encoding-unicode
 
4 character encoding-ascii
4 character encoding-ascii4 character encoding-ascii
4 character encoding-ascii
 
4 character encoding
4 character encoding4 character encoding
4 character encoding
 
3 number systems-floatingpoint
3 number systems-floatingpoint3 number systems-floatingpoint
3 number systems-floatingpoint
 
2 number systems-scientificnotation
2 number systems-scientificnotation2 number systems-scientificnotation
2 number systems-scientificnotation
 
1 number systems-hex
1 number systems-hex1 number systems-hex
1 number systems-hex
 
1 number systems-unsignedsignedintegers
1 number systems-unsignedsignedintegers1 number systems-unsignedsignedintegers
1 number systems-unsignedsignedintegers
 
1 number systems-octal
1 number systems-octal1 number systems-octal
1 number systems-octal
 

Recently uploaded

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

5 data structures-arraysandlinkedlist

  • 1. Array • A data structure that contains a list of elements accessed by an index – Array: a set of pairs (index and value) – For each index, there is a value associated with that index. • Arrays are generally a fixed size, which means you must specify the maximum size when the array is created • Increasing the size of an array normally involves creating a new array of the desired size and copying the values from the old array to the new array
  • 2. Array • An array of size 5 String arr = new String[5]; Int nextIndex = 0; • Set some of the values arr[nextIndex ] = “Hi” ++nextIndex; arr[nextIndex ] = “there” ++nextIndex; arr[nextIndex ] = “Bob” ++nextIndex; arr[nextIndex ] = “.” ++nextIndex; Hi there Bob .
  • 3. Array • Insert into the middle of a array – Insert “Billy” between “there” and “Bob” • Push “Bob” and “.” toward the end of the array to make space for “Bob” in element 2 insertIndex = 2; for ( int i = nextIndex; i > = insertIndex; --i ) { arr[i] = arr[i-1]; } ++nextIndex; • Set the new value for element 2 arr[insertIndex] = “Billy”; Hi there Bob . Hi there Bob Bob . Hi there Billy Bob .
  • 4. Questions • What is the complexity of “retrieve” in an array? • What is the complexity of “store” in an array? • What about insertion and deletion for ordered elements in an arrary?
  • 5. Linked List • A linked list is a data structure that contains a set of nodes linked with pointers. • Singly-linked list has links in one direction. To the next node in the list. • A doubly-linked list had links in both directions. To the next and previous nodes in the list. Data Next Variable Variable Data Next Prev Data Next Data Next Data Next Data Next Prev Data Next Prev Data Next Prev
  • 6. Linked List • A Circularly-linked list has a complete cycles of links. Variable Data Next Prev Data Next Prev Data Next Prev Data Next Prev Data Next Variable Data Next Data Next Data Next
  • 7. Linked List • Insert at the end of a linked list • Create new node • Change the links to include the new node Billy Next Hi Next Sentence there Next Bob Next . Next
  • 8. Linked List • Insert into the middle of a linked list • Create new node • Change the links to include the new node Hi Next Sentence there Next Bob Next . Next Billy Next
  • 9. Array versus Linked List • Some operations are faster with one versus the other – Find element at position X – Array faster – Find element Y at unknown position – Tie – Insert element in the middle – Linked list faster – Insert element at the end – Tie, if doubly-linked and circular, Array otherwise – Insert element at the beginning – Linked list • Arrays are (typically) a fixed size, linked lists are variable length • Arrays are defined as holding a specific number of elements whether or not that many elements are currently in the array. Doing that wastes space