SlideShare uma empresa Scribd logo
1 de 17
 A list is a dynamic ordered tuple of
homogeneous elements
Ao, A1, A2, 
, AN-1
where Ai is the i-th element of the list
 The position of element Ai is i; positions
range from 0 to N-1 inclusive
 The size of a list is N ( a list with no elements
is called an “empty list”)
 create an empty list
 printList() – prints all elements in the list
 construct a (deep) copy of a list
 find(x) – returns the position of the first
occurrence of x
 remove(x) – removes x from the list if present
 insert(x, position) – inserts x into the list at the
specified position
 isEmpty( ) – returns true if the list has no
elements
 makeEmpty( ) – removes all elements from the
list
 findKth(int k) – returns the element in the
specified position
 Use an array to store the elements of the list
◩ printList is O(n)
◩ findkth,get and set are constant time
◩ Insert and delete?
 Also, arrays have a fixed capacity, but can fix
with implementation.
int arr[] = new int arr[10];
int newArr[] = new int[arr.length *2];
for(int i = 0; i < arr.length; i++)
newArr[i] = arr[i];
arr = newArr;
 Linked List
Deletion
 Insertion
Notice insert and delete can be
constant time if node is inserted at
beginning of List; however, findkth
is now O(i).
//from Collection interface
int size( );
boolean isEmpty( );
void clear( );
boolean contains( AnyType x );
boolean add( AnyType x );
boolean remove( AnyType x );
java.util.Iterator<AnyType> iterator( );
//from List interface
AnyType get( int idx );
AnyType set( int idx, AnyType newVal );
void add( int idx, AnyType x );
void remove( int idx );
ListIterator<AnyType> listIterator(int pos);
 Supports constant time for
◩ insertion at the “end” of the list using
void add(E element)
◩ deletion from the “end” of the list using
E remove(int index)
◩ access to any element of the list using
E get(int index)
◩ changing value of any element of the list using
E set(int index, E element)
 What is the growth rate for the following?
◩ insertion at the “beginning” of the list using
void add(int index, E element)
◩ deletion from the “beginning” of the list using
E remove(int index)
 s
 Provides doubly linked list implementation
 Supports constant time for
◩ insertion at the “beginning” of the list using
void addFirst(E o)
◩ insertion at the “end” of the list using
void addLast(E o)
◩ deletion from the “beginning” of the list using
E removeFirst()
◩ deletion from the “end” of the list using
E removeLast()
◩ Accessing first element of the list using
E getFirst()
◩ Accessing first element of the list using
E getLast()
 What is the growth rate for the following?
◩ access to the “middle” element of the list using
E get(int index)
 What is the running time for an ArrayList
versus a LinkedList?
public static void
makeList1(List<Integer> list, int N)
{
list.clear();
for(int i = 0; i < N; i++)
list.add(i);
}s
 What do you need?
1. Store elements in a parameterized
array
2. Track number of elements in array
(size) and capacity of array
3. Ability to change capacity of the array
4. get and set Methods
5. size, isEmpty, and clear Methods
6. add Methods
7. remove and iterator Method
8. Iterator class
 Suppose we decided that the data in the lists
should be stored in sorted order.
 How would the sorted order be determined?
 What List code would need to be changed?
 How would sorting the data affect the
performance of
◩ Finding an element in the list
◩ Inserting an element into the list
◩ Removing an element from the list
◩ other List functions

Mais conteĂșdo relacionado

Mais procurados

7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
irdginfo
 

Mais procurados (20)

Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template library
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Lists
Lists Lists
Lists
 
07 java collection
07 java collection07 java collection
07 java collection
 
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsProblem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - Lists
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Data structures2
Data structures2Data structures2
Data structures2
 
The List Data Model
The List Data ModelThe List Data Model
The List Data Model
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
 
Python set
Python setPython set
Python set
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 

Semelhante a List interface

Prompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdfPrompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdf
alsofshionchennai
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
16 containers
16   containers16   containers
16 containers
dhrubo kayal
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
MCCMOTOR
 

Semelhante a List interface (20)

Lecture2
Lecture2Lecture2
Lecture2
 
Ds notes
Ds notesDs notes
Ds notes
 
Prompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdfPrompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdf
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Groovy
GroovyGroovy
Groovy
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
16 containers
16   containers16   containers
16 containers
 
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
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Data Structure
Data StructureData Structure
Data Structure
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
lec4.ppt
lec4.pptlec4.ppt
lec4.ppt
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 

Mais de Daffodil International University

Mais de Daffodil International University (19)

HRM Presentation.pptx
HRM Presentation.pptxHRM Presentation.pptx
HRM Presentation.pptx
 
Presentation on Computer Software.ppt
Presentation on Computer Software.pptPresentation on Computer Software.ppt
Presentation on Computer Software.ppt
 
Wind Turbine(Gravity).pptx
Wind Turbine(Gravity).pptxWind Turbine(Gravity).pptx
Wind Turbine(Gravity).pptx
 
System Analysis And Design Presentation.
System Analysis And Design Presentation.System Analysis And Design Presentation.
System Analysis And Design Presentation.
 
Presentation windows operating system
Presentation  windows operating systemPresentation  windows operating system
Presentation windows operating system
 
Os presentation
Os presentationOs presentation
Os presentation
 
Microprocessor presentation
Microprocessor presentationMicroprocessor presentation
Microprocessor presentation
 
Engineering math presentation
Engineering math presentationEngineering math presentation
Engineering math presentation
 
Datacommunication presentation
Datacommunication presentationDatacommunication presentation
Datacommunication presentation
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
Data mining presentation
Data mining presentationData mining presentation
Data mining presentation
 
Computer architecture presentation
Computer architecture presentationComputer architecture presentation
Computer architecture presentation
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
Bangladesh National Cricket
Bangladesh National CricketBangladesh National Cricket
Bangladesh National Cricket
 
Logical operators
Logical operatorsLogical operators
Logical operators
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
 
Mathematics in sports
Mathematics in sportsMathematics in sports
Mathematics in sports
 
Wind turbine(gravity)
Wind turbine(gravity)Wind turbine(gravity)
Wind turbine(gravity)
 
Presentation on computer software
Presentation on computer softwarePresentation on computer software
Presentation on computer software
 

Último

Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar â‰ŒđŸ” Delhi door step de...
Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar  â‰ŒđŸ” Delhi door step de...Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar  â‰ŒđŸ” Delhi door step de...
Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar â‰ŒđŸ” Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night StandCall Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
amitlee9823
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Último (20)

chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar â‰ŒđŸ” Delhi door step de...
Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar  â‰ŒđŸ” Delhi door step de...Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar  â‰ŒđŸ” Delhi door step de...
Call Now ≜ 9953056974 â‰ŒđŸ” Call Girls In New Ashok Nagar â‰ŒđŸ” Delhi door step de...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night StandCall Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 đŸ„” Book Your One night Stand
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 

List interface

  • 1.
  • 2.
  • 3.  A list is a dynamic ordered tuple of homogeneous elements Ao, A1, A2, 
, AN-1 where Ai is the i-th element of the list  The position of element Ai is i; positions range from 0 to N-1 inclusive  The size of a list is N ( a list with no elements is called an “empty list”)
  • 4.  create an empty list  printList() – prints all elements in the list  construct a (deep) copy of a list  find(x) – returns the position of the first occurrence of x  remove(x) – removes x from the list if present  insert(x, position) – inserts x into the list at the specified position  isEmpty( ) – returns true if the list has no elements  makeEmpty( ) – removes all elements from the list  findKth(int k) – returns the element in the specified position
  • 5.  Use an array to store the elements of the list ◩ printList is O(n) ◩ findkth,get and set are constant time ◩ Insert and delete?  Also, arrays have a fixed capacity, but can fix with implementation. int arr[] = new int arr[10]; int newArr[] = new int[arr.length *2]; for(int i = 0; i < arr.length; i++) newArr[i] = arr[i]; arr = newArr;
  • 7.  Insertion Notice insert and delete can be constant time if node is inserted at beginning of List; however, findkth is now O(i).
  • 8. //from Collection interface int size( ); boolean isEmpty( ); void clear( ); boolean contains( AnyType x ); boolean add( AnyType x ); boolean remove( AnyType x ); java.util.Iterator<AnyType> iterator( ); //from List interface AnyType get( int idx ); AnyType set( int idx, AnyType newVal ); void add( int idx, AnyType x ); void remove( int idx ); ListIterator<AnyType> listIterator(int pos);
  • 9.  Supports constant time for ◩ insertion at the “end” of the list using void add(E element) ◩ deletion from the “end” of the list using E remove(int index) ◩ access to any element of the list using E get(int index) ◩ changing value of any element of the list using E set(int index, E element)
  • 10.  What is the growth rate for the following? ◩ insertion at the “beginning” of the list using void add(int index, E element) ◩ deletion from the “beginning” of the list using E remove(int index)  s
  • 11.  Provides doubly linked list implementation
  • 12.  Supports constant time for ◩ insertion at the “beginning” of the list using void addFirst(E o) ◩ insertion at the “end” of the list using void addLast(E o) ◩ deletion from the “beginning” of the list using E removeFirst() ◩ deletion from the “end” of the list using E removeLast() ◩ Accessing first element of the list using E getFirst() ◩ Accessing first element of the list using E getLast()
  • 13.  What is the growth rate for the following? ◩ access to the “middle” element of the list using E get(int index)
  • 14.  What is the running time for an ArrayList versus a LinkedList? public static void makeList1(List<Integer> list, int N) { list.clear(); for(int i = 0; i < N; i++) list.add(i); }s
  • 15.  What do you need? 1. Store elements in a parameterized array 2. Track number of elements in array (size) and capacity of array 3. Ability to change capacity of the array 4. get and set Methods 5. size, isEmpty, and clear Methods
  • 16. 6. add Methods 7. remove and iterator Method 8. Iterator class
  • 17.  Suppose we decided that the data in the lists should be stored in sorted order.  How would the sorted order be determined?  What List code would need to be changed?  How would sorting the data affect the performance of ◩ Finding an element in the list ◩ Inserting an element into the list ◩ Removing an element from the list ◩ other List functions