SlideShare a Scribd company logo
Lecture # 2Lecture # 2
LIST Data StructureLIST Data Structure
 The List is among the most generic of dataThe List is among the most generic of data
structures.structures.
 In Real life:In Real life:
 shopping list,shopping list,
 groceries list,groceries list,
 list of people to invite to dinnerlist of people to invite to dinner

List of presents to getList of presents to get
ListsLists
 AA listlist is collection of items that are all of theis collection of items that are all of the
same typesame type (grocery items, integers, names)(grocery items, integers, names)
 The items, or elements of the list, are stored inThe items, or elements of the list, are stored in
some particular ordersome particular order
 It is possible to insert new elements into variousIt is possible to insert new elements into various
positions in the list and remove any element ofpositions in the list and remove any element of
the listthe list
ListsLists
 List is a set of elements in a linear order.List is a set of elements in a linear order.
For example, data values a1, a2, a3, a4 can be arrangedFor example, data values a1, a2, a3, a4 can be arranged
in a list:in a list:
(a3, a1, a2, a4)(a3, a1, a2, a4)
In this list, a3, is the first element, a1 is the secondIn this list, a3, is the first element, a1 is the second
element, and so onelement, and so on
 The order is important here; this is not just a randomThe order is important here; this is not just a random
collection of elements, it is ancollection of elements, it is an orderedordered collectioncollection
List OperationsList Operations
Useful operationsUseful operations
 createList(): create a new list (presumably empty)createList(): create a new list (presumably empty)
 copy(): set one list to be a copy of anothercopy(): set one list to be a copy of another
 clear(); clear a list (remove all elements)clear(); clear a list (remove all elements)
 insert(X, ?): Insert element X at a particular positioninsert(X, ?): Insert element X at a particular position
in the listin the list
 remove(?): Remove element at some position inremove(?): Remove element at some position in
the listthe list
 get(?): Get element at a given positionget(?): Get element at a given position
 update(X, ?): replace the element at a given positionupdate(X, ?): replace the element at a given position
with Xwith X
 find(X): determine if the element X is in the listfind(X): determine if the element X is in the list
 length(): return the length of the list.length(): return the length of the list.
List OperationsList Operations
 We need to decide what is meant by “particularWe need to decide what is meant by “particular
position”; we have used “?” for this.position”; we have used “?” for this.
 There are two possibilities:There are two possibilities:
 Use the actual index of element: insert after elementUse the actual index of element: insert after element
3, get element number 6. This approach is taken by3, get element number 6. This approach is taken by
arraysarrays
 Use a “current” marker orUse a “current” marker or pointerpointer to refer to ato refer to a
particular position in the list.particular position in the list.
List OperationsList Operations
 If we use the “current” marker, the following fourIf we use the “current” marker, the following four
methods would be useful:methods would be useful:
 start()start(): moves to “current” pointer to the very first: moves to “current” pointer to the very first
element.element.
 tail()tail(): moves to “current” pointer to the very last: moves to “current” pointer to the very last
element.element.
 nextnext(): move the current position forward one(): move the current position forward one
elementelement
 backback(): move the current position backward one(): move the current position backward one
elementelement
Implementing ListsImplementing Lists
 We have designed the interface for the List; weWe have designed the interface for the List; we
now must consider how to implement thatnow must consider how to implement that
interfaceinterface..
 Implementing Lists using an array: for example,Implementing Lists using an array: for example,
the list of integers (2, 6, 8, 7, 1) could bethe list of integers (2, 6, 8, 7, 1) could be
represented as:represented as:
List ImplementationList Implementation
 add(9);add(9); current position is 3. The new list wouldcurrent position is 3. The new list would
thus be: (2, 6, 8, 9, 7, 1)thus be: (2, 6, 8, 9, 7, 1)
 We will need toWe will need to shiftshift everything to the right of 8everything to the right of 8
one place to the right to make place for the newone place to the right to make place for the new
element ‘9’.element ‘9’.
Implementing ListsImplementing Lists
 next():next():
Implementing ListsImplementing Lists
 There are special cases for positioning theThere are special cases for positioning the
current pointer:current pointer:
 past the last array cellpast the last array cell
 before the first cellbefore the first cell
 We will have to worry about these when weWe will have to worry about these when we
write the actual code.write the actual code.
Implementing ListsImplementing Lists
 remove():remove(): removes the element at theremoves the element at the
current indexcurrent index
 We fill the blank spot left by the removal of 7 byWe fill the blank spot left by the removal of 7 by
shifting the values to the right of position 5 overshifting the values to the right of position 5 over
to the left one spaceto the left one space
Implementing ListsImplementing Lists
 find(X):find(X): traverse the array until X is located.traverse the array until X is located.
int find(int X)int find(int X)
{{
int j;int j;
for(j=1; j < size+1; j++ )for(j=1; j < size+1; j++ )
if( A[j] == X ) break;if( A[j] == X ) break;
if( j < size+1 )if( j < size+1 )
{ // found X{ // found X
current = j; // current points to where X foundcurrent = j; // current points to where X found
return 1; // 1 for truereturn 1; // 1 for true
}}
return 0; // 0 (false) indicates not foundreturn 0; // 0 (false) indicates not found
}}
Implementing ListsImplementing Lists
 Other operations:Other operations:
get()get()  return A[current];return A[current];
update(X)update(X)  A[current] = X;A[current] = X;
length()length()  return size;return size;
back()back()  current--;current--;
start()start()  current = 1;current = 1;
end()end()  current = size;current = size;
Assignment # 1Assignment # 1
 Implement aImplement a List Data StructureList Data Structure discussed above includingdiscussed above including
following operations using Array ADT.following operations using Array ADT.
 get()get()
 update()update()
 length()length()
 back()back()
 Next()Next()
 start()start()
 end()end()
 Remove()Remove()
 Add()Add()
 NOTE:NOTE: Implement above operations only usingImplement above operations only using PointersPointers
withoutwithout using anyusing any indexesindexes of arrays.of arrays.
 Assignment will be graded on the basis of relevant quiz ofAssignment will be graded on the basis of relevant quiz of
this assignment.this assignment.
List UsingList Using Linked MemoryLinked Memory
 Various cells of memory areVarious cells of memory are not allocatednot allocated
consecutivelyconsecutively in memory.in memory.
 Array is Not enough to store the future elements ofArray is Not enough to store the future elements of
the list after full exhaust of array locations.the list after full exhaust of array locations.
 With arrays, the second element was right next toWith arrays, the second element was right next to
the first element.the first element.
 Now inNow in Linked Memory approach,Linked Memory approach, the first elementthe first element
mustmust explicitlyexplicitly tell us where to look for the secondtell us where to look for the second
element.element.
 Do this by holding the memory address of theDo this by holding the memory address of the
second elementsecond element

More Related Content

What's hot

Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
Teksify
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
naymulhaque
 
Circular linked list
Circular linked listCircular linked list
Circular linked listdchuynh
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Linked list
Linked listLinked list
Linked listVONI
 
Linklist
LinklistLinklist
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
Data Structure lec#2
Data Structure lec#2Data Structure lec#2
Data Structure lec#2
University of Gujrat, Pakistan
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Linked list
Linked listLinked list
Linked list
Shashank Shetty
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 

What's hot (20)

Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Linked list
Linked listLinked list
Linked list
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
Linklist
LinklistLinklist
Linklist
 
Team 10
Team 10Team 10
Team 10
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Data Structure lec#2
Data Structure lec#2Data Structure lec#2
Data Structure lec#2
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 

Viewers also liked

La vision de la supervision libre en entreprise
La vision de la supervision libre en entrepriseLa vision de la supervision libre en entreprise
La vision de la supervision libre en entreprise
Romuald FRONTEAU
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
Muhammad Zubair
 
Lecture8
Lecture8Lecture8
Lecture8
Muhammad Zubair
 
Why do m tech
Why do m techWhy do m tech
Why do m tech
RASMI SAMANTRAY
 
Lecture7
Lecture7Lecture7
Lecture7
Muhammad Zubair
 
Why do m tech
Why do m techWhy do m tech
Why do m tech
RASMI SAMANTRAY
 
Hobijeve pustolovine
Hobijeve pustolovineHobijeve pustolovine
Hobijeve pustolovine
Sandra Borbaš
 
Pjesmarica DZ Zvončići
Pjesmarica DZ ZvončićiPjesmarica DZ Zvončići
Pjesmarica DZ Zvončići
Sandra Borbaš
 
Lecture10
Lecture10Lecture10
Lecture10
Muhammad Zubair
 
Cloud computing
Cloud computingCloud computing
Cloud computing
Muhammad Zubair
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
Muhammad Zubair
 
Lecture1
Lecture1Lecture1
Lecture1
Muhammad Zubair
 
Moti_중간발표
Moti_중간발표Moti_중간발표
Moti_중간발표
Sam Jin
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
Muhammad Zubair
 
Project ISR - Mary HPDG-JL14-1132
Project ISR - Mary HPDG-JL14-1132 Project ISR - Mary HPDG-JL14-1132
Project ISR - Mary HPDG-JL14-1132 Mary Kannampuzha
 

Viewers also liked (15)

La vision de la supervision libre en entreprise
La vision de la supervision libre en entrepriseLa vision de la supervision libre en entreprise
La vision de la supervision libre en entreprise
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
 
Lecture8
Lecture8Lecture8
Lecture8
 
Why do m tech
Why do m techWhy do m tech
Why do m tech
 
Lecture7
Lecture7Lecture7
Lecture7
 
Why do m tech
Why do m techWhy do m tech
Why do m tech
 
Hobijeve pustolovine
Hobijeve pustolovineHobijeve pustolovine
Hobijeve pustolovine
 
Pjesmarica DZ Zvončići
Pjesmarica DZ ZvončićiPjesmarica DZ Zvončići
Pjesmarica DZ Zvončići
 
Lecture10
Lecture10Lecture10
Lecture10
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
 
Lecture1
Lecture1Lecture1
Lecture1
 
Moti_중간발표
Moti_중간발표Moti_중간발표
Moti_중간발표
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
 
Project ISR - Mary HPDG-JL14-1132
Project ISR - Mary HPDG-JL14-1132 Project ISR - Mary HPDG-JL14-1132
Project ISR - Mary HPDG-JL14-1132
 

Similar to Lecture2

List interface
List interfaceList interface
Lecture5
Lecture5Lecture5
Lecture5
Muhammad Zubair
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AmuthachenthiruK
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
HammadTariq51
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
SARAVANAN GOPALAKRISHNAN
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
Intro C# Book
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
ManojKandhasamy1
 
lec4.ppt
lec4.pptlec4.ppt
lec4.ppt
RajKamal95773
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Celine George
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Lec3
Lec3Lec3
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 

Similar to Lecture2 (20)

List interface
List interfaceList interface
List interface
 
Lecture5
Lecture5Lecture5
Lecture5
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
07 java collection
07 java collection07 java collection
07 java collection
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
16 containers
16   containers16   containers
16 containers
 
Python list
Python listPython list
Python list
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
lec4.ppt
lec4.pptlec4.ppt
lec4.ppt
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Data structures1
Data structures1Data structures1
Data structures1
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Lec3
Lec3Lec3
Lec3
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 

Recently uploaded

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
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
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
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
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)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
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
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
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
 

Recently uploaded (20)

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
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
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
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
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
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
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
 

Lecture2

  • 2. LIST Data StructureLIST Data Structure  The List is among the most generic of dataThe List is among the most generic of data structures.structures.  In Real life:In Real life:  shopping list,shopping list,  groceries list,groceries list,  list of people to invite to dinnerlist of people to invite to dinner  List of presents to getList of presents to get
  • 3. ListsLists  AA listlist is collection of items that are all of theis collection of items that are all of the same typesame type (grocery items, integers, names)(grocery items, integers, names)  The items, or elements of the list, are stored inThe items, or elements of the list, are stored in some particular ordersome particular order  It is possible to insert new elements into variousIt is possible to insert new elements into various positions in the list and remove any element ofpositions in the list and remove any element of the listthe list
  • 4. ListsLists  List is a set of elements in a linear order.List is a set of elements in a linear order. For example, data values a1, a2, a3, a4 can be arrangedFor example, data values a1, a2, a3, a4 can be arranged in a list:in a list: (a3, a1, a2, a4)(a3, a1, a2, a4) In this list, a3, is the first element, a1 is the secondIn this list, a3, is the first element, a1 is the second element, and so onelement, and so on  The order is important here; this is not just a randomThe order is important here; this is not just a random collection of elements, it is ancollection of elements, it is an orderedordered collectioncollection
  • 5. List OperationsList Operations Useful operationsUseful operations  createList(): create a new list (presumably empty)createList(): create a new list (presumably empty)  copy(): set one list to be a copy of anothercopy(): set one list to be a copy of another  clear(); clear a list (remove all elements)clear(); clear a list (remove all elements)  insert(X, ?): Insert element X at a particular positioninsert(X, ?): Insert element X at a particular position in the listin the list  remove(?): Remove element at some position inremove(?): Remove element at some position in the listthe list  get(?): Get element at a given positionget(?): Get element at a given position  update(X, ?): replace the element at a given positionupdate(X, ?): replace the element at a given position with Xwith X  find(X): determine if the element X is in the listfind(X): determine if the element X is in the list  length(): return the length of the list.length(): return the length of the list.
  • 6. List OperationsList Operations  We need to decide what is meant by “particularWe need to decide what is meant by “particular position”; we have used “?” for this.position”; we have used “?” for this.  There are two possibilities:There are two possibilities:  Use the actual index of element: insert after elementUse the actual index of element: insert after element 3, get element number 6. This approach is taken by3, get element number 6. This approach is taken by arraysarrays  Use a “current” marker orUse a “current” marker or pointerpointer to refer to ato refer to a particular position in the list.particular position in the list.
  • 7. List OperationsList Operations  If we use the “current” marker, the following fourIf we use the “current” marker, the following four methods would be useful:methods would be useful:  start()start(): moves to “current” pointer to the very first: moves to “current” pointer to the very first element.element.  tail()tail(): moves to “current” pointer to the very last: moves to “current” pointer to the very last element.element.  nextnext(): move the current position forward one(): move the current position forward one elementelement  backback(): move the current position backward one(): move the current position backward one elementelement
  • 8. Implementing ListsImplementing Lists  We have designed the interface for the List; weWe have designed the interface for the List; we now must consider how to implement thatnow must consider how to implement that interfaceinterface..  Implementing Lists using an array: for example,Implementing Lists using an array: for example, the list of integers (2, 6, 8, 7, 1) could bethe list of integers (2, 6, 8, 7, 1) could be represented as:represented as:
  • 9. List ImplementationList Implementation  add(9);add(9); current position is 3. The new list wouldcurrent position is 3. The new list would thus be: (2, 6, 8, 9, 7, 1)thus be: (2, 6, 8, 9, 7, 1)  We will need toWe will need to shiftshift everything to the right of 8everything to the right of 8 one place to the right to make place for the newone place to the right to make place for the new element ‘9’.element ‘9’.
  • 11. Implementing ListsImplementing Lists  There are special cases for positioning theThere are special cases for positioning the current pointer:current pointer:  past the last array cellpast the last array cell  before the first cellbefore the first cell  We will have to worry about these when weWe will have to worry about these when we write the actual code.write the actual code.
  • 12. Implementing ListsImplementing Lists  remove():remove(): removes the element at theremoves the element at the current indexcurrent index  We fill the blank spot left by the removal of 7 byWe fill the blank spot left by the removal of 7 by shifting the values to the right of position 5 overshifting the values to the right of position 5 over to the left one spaceto the left one space
  • 13. Implementing ListsImplementing Lists  find(X):find(X): traverse the array until X is located.traverse the array until X is located. int find(int X)int find(int X) {{ int j;int j; for(j=1; j < size+1; j++ )for(j=1; j < size+1; j++ ) if( A[j] == X ) break;if( A[j] == X ) break; if( j < size+1 )if( j < size+1 ) { // found X{ // found X current = j; // current points to where X foundcurrent = j; // current points to where X found return 1; // 1 for truereturn 1; // 1 for true }} return 0; // 0 (false) indicates not foundreturn 0; // 0 (false) indicates not found }}
  • 14. Implementing ListsImplementing Lists  Other operations:Other operations: get()get()  return A[current];return A[current]; update(X)update(X)  A[current] = X;A[current] = X; length()length()  return size;return size; back()back()  current--;current--; start()start()  current = 1;current = 1; end()end()  current = size;current = size;
  • 15. Assignment # 1Assignment # 1  Implement aImplement a List Data StructureList Data Structure discussed above includingdiscussed above including following operations using Array ADT.following operations using Array ADT.  get()get()  update()update()  length()length()  back()back()  Next()Next()  start()start()  end()end()  Remove()Remove()  Add()Add()  NOTE:NOTE: Implement above operations only usingImplement above operations only using PointersPointers withoutwithout using anyusing any indexesindexes of arrays.of arrays.  Assignment will be graded on the basis of relevant quiz ofAssignment will be graded on the basis of relevant quiz of this assignment.this assignment.
  • 16. List UsingList Using Linked MemoryLinked Memory  Various cells of memory areVarious cells of memory are not allocatednot allocated consecutivelyconsecutively in memory.in memory.  Array is Not enough to store the future elements ofArray is Not enough to store the future elements of the list after full exhaust of array locations.the list after full exhaust of array locations.  With arrays, the second element was right next toWith arrays, the second element was right next to the first element.the first element.  Now inNow in Linked Memory approach,Linked Memory approach, the first elementthe first element mustmust explicitlyexplicitly tell us where to look for the secondtell us where to look for the second element.element.  Do this by holding the memory address of theDo this by holding the memory address of the second elementsecond element