SlideShare a Scribd company logo
1 of 26
Data Structures
data object
set or collection of instances
integer = {0, +1, -1, +2, -2, +3, -3, …}
daysOfWeek = {S,M,T,W,Th,F,Sa}
Data Object
instances may or may not be related
myDataObject = {apple, chair, 2, 5.2, red, green, Jack}
Data Structure
Data object +
relationships that exist among instances
and elements that comprise an instance
Among instances of integer
369 < 370
280 + 4 = 284
Data Structure
Among elements that comprise an instance
369
3 is more significant than 6
3 is immediately to the left of 6
9 is immediately to the right of 6
The relationships are usually specified by
specifying operations on one or more
instances.
add, subtract, predecessor, multiply
Data Structure
Linear (or Ordered) Lists
instances are of the form
(e0, e1, e2, …, en-1)
where ei denotes a list element
n >= 0 is finite
list size is n
Linear Lists
L = (e0, e1, e2, e3, …, en-1)
relationships
e0 is the zero’th (or front) element
en-1 is the last element
ei immediately precedes ei+1
Linear List Examples/Instances
Students in COP3530 =
(Jack, Jill, Abe, Henry, Mary, …, Judy)
Exams in COP3530 =
(exam1, exam2, exam3)
Days of Week = (S, M, T, W, Th, F, Sa)
Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)
Linear List Operations—size()
determine list size
L = (a,b,c,d,e)
size = 5
Linear List Operations—get(theIndex)
get element with given index
L = (a,b,c,d,e)
get(0) = a
get(2) = c
get(4) = e
get(-1) = error
get(9) = error
Linear List Operations—
indexOf(theElement)
determine the index of an element
L = (a,b,d,b,a)
indexOf(d) = 2
indexOf(a) = 0
indexOf(z) = -1
Linear List Operations—
remove(theIndex)
remove and return element with given
index
L = (a,b,c,d,e,f,g)
remove(2) returns c
and L becomes (a,b,d,e,f,g)
index of d,e,f, and g decrease by 1
Linear List Operations—
remove(theIndex)
remove and return element with given
index
L = (a,b,c,d,e,f,g)
remove(-1) => error
remove(20) => error
Linear List Operations—
add(theIndex, theElement)
add an element so that the new element has
a specified index
L = (a,b,c,d,e,f,g)
add(0,h) => L = (h,a,b,c,d,e,f,g)
index of a,b,c,d,e,f, and g increase by 1
Linear List Operations—
add(theIndex, theElement)
L = (a,b,c,d,e,f,g)
add(2,h) => L = (a,b,h,c,d,e,f,g)
index of c,d,e,f, and g increase by 1
add(10,h) => error
add(-6,h) => error
Data Structure Specification
Language independent
Abstract Data Type
Java
Interface
Abstract Class
Linear List Abstract Data Type
AbstractDataType LinearList
{
instances
ordered finite collections of zero or more elements
operations
isEmpty(): return true iff the list is empty, false otherwise
size(): return the list size (i.e., number of elements in the list)
get(index): return the indexth element of the list
indexO f(x): return the index of the first occurrence of x in
the list, return -1 if x is not in the list
remove(index): remove and return the indexth element,
elements with higher index have their index reduced by 1
add(theIndex, x): insert x as the indexth element, elements
with theIndex >= index have their index increased by 1
output(): output the list elements from left to right
}
Linear List as Java Interface
An interface may include constants
and abstract methods (i.e., methods
for which no implementation is
provided).
Linear List as Java Interface
public interface LinearList
{
public boolean isEmpty();
public int size();
public Object get(int index);
public int indexOf(Object elem);
public Object remove(int index);
public void add(int index, Object obj);
public String toString();
}
Implementing An Interface
public class ArrayLinearList implements LinearList
{
// code for all LinearList methods must be provided here
}
Linear List As An Abstract Class
An abstract class may include
constants, variables, abstract
methods, and nonabstract methods.
Linear List As Java Abstract Class
public abstract class LinearListAsAbstractClass
{
public abstract boolean isEmpty();
public abstract int size();
public abstract Object get(int index);
public abstract int indexOf(Object theElement);
public abstract Object remove(int index);
public abstract void add(int index,
Object theElement);
public abstract String toString();
}
Extending A Java Class
public class ArrayLinearList
extends LinearListAsAbstractClass
{
// code for all abstract classes must come here
}
Implementing Many Interfaces
public class MyInteger implements Operable, Zero,
CloneableObject
{
// code for all methods of Operable, Zero,
// and CloneableObject must be provided
}
Extending Many Classes
NOT PERMITTED IN JAVA
A Java class may implement as many
interfaces as it wants but can extend at most
1 class.
Data Structures In Text
All but 1 of our data structures are specified as Java
interfaces.
Exception is Graph in Chapter 17.
Java specifies all of its data structures as interfaces.
java.util.List

More Related Content

Similar to lec4.ppt

Similar to lec4.ppt (20)

Lec3
Lec3Lec3
Lec3
 
purrr.pdf
purrr.pdfpurrr.pdf
purrr.pdf
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Lec3
Lec3Lec3
Lec3
 
Abstract Algebra and Category Theory
Abstract Algebra and Category Theory Abstract Algebra and Category Theory
Abstract Algebra and Category Theory
 
Array
ArrayArray
Array
 
Ds notes
Ds notesDs notes
Ds notes
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
Lecture2
Lecture2Lecture2
Lecture2
 
List interface
List interfaceList interface
List interface
 
Can you help me by answering this- The following function defined in c.pdf
Can you help me by answering this- The following function defined in c.pdfCan you help me by answering this- The following function defined in c.pdf
Can you help me by answering this- The following function defined in c.pdf
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Python list
Python listPython list
Python list
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Data structure
Data  structureData  structure
Data structure
 
Engineering lecture ppt by venay magen
Engineering lecture ppt by venay magenEngineering lecture ppt by venay magen
Engineering lecture ppt by venay magen
 

Recently uploaded

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 

lec4.ppt

  • 1. Data Structures data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa}
  • 2. Data Object instances may or may not be related myDataObject = {apple, chair, 2, 5.2, red, green, Jack}
  • 3. Data Structure Data object + relationships that exist among instances and elements that comprise an instance Among instances of integer 369 < 370 280 + 4 = 284
  • 4. Data Structure Among elements that comprise an instance 369 3 is more significant than 6 3 is immediately to the left of 6 9 is immediately to the right of 6
  • 5. The relationships are usually specified by specifying operations on one or more instances. add, subtract, predecessor, multiply Data Structure
  • 6. Linear (or Ordered) Lists instances are of the form (e0, e1, e2, …, en-1) where ei denotes a list element n >= 0 is finite list size is n
  • 7. Linear Lists L = (e0, e1, e2, e3, …, en-1) relationships e0 is the zero’th (or front) element en-1 is the last element ei immediately precedes ei+1
  • 8. Linear List Examples/Instances Students in COP3530 = (Jack, Jill, Abe, Henry, Mary, …, Judy) Exams in COP3530 = (exam1, exam2, exam3) Days of Week = (S, M, T, W, Th, F, Sa) Months = (Jan, Feb, Mar, Apr, …, Nov, Dec)
  • 9. Linear List Operations—size() determine list size L = (a,b,c,d,e) size = 5
  • 10. Linear List Operations—get(theIndex) get element with given index L = (a,b,c,d,e) get(0) = a get(2) = c get(4) = e get(-1) = error get(9) = error
  • 11. Linear List Operations— indexOf(theElement) determine the index of an element L = (a,b,d,b,a) indexOf(d) = 2 indexOf(a) = 0 indexOf(z) = -1
  • 12. Linear List Operations— remove(theIndex) remove and return element with given index L = (a,b,c,d,e,f,g) remove(2) returns c and L becomes (a,b,d,e,f,g) index of d,e,f, and g decrease by 1
  • 13. Linear List Operations— remove(theIndex) remove and return element with given index L = (a,b,c,d,e,f,g) remove(-1) => error remove(20) => error
  • 14. Linear List Operations— add(theIndex, theElement) add an element so that the new element has a specified index L = (a,b,c,d,e,f,g) add(0,h) => L = (h,a,b,c,d,e,f,g) index of a,b,c,d,e,f, and g increase by 1
  • 15. Linear List Operations— add(theIndex, theElement) L = (a,b,c,d,e,f,g) add(2,h) => L = (a,b,h,c,d,e,f,g) index of c,d,e,f, and g increase by 1 add(10,h) => error add(-6,h) => error
  • 16. Data Structure Specification Language independent Abstract Data Type Java Interface Abstract Class
  • 17. Linear List Abstract Data Type AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations isEmpty(): return true iff the list is empty, false otherwise size(): return the list size (i.e., number of elements in the list) get(index): return the indexth element of the list indexO f(x): return the index of the first occurrence of x in the list, return -1 if x is not in the list remove(index): remove and return the indexth element, elements with higher index have their index reduced by 1 add(theIndex, x): insert x as the indexth element, elements with theIndex >= index have their index increased by 1 output(): output the list elements from left to right }
  • 18. Linear List as Java Interface An interface may include constants and abstract methods (i.e., methods for which no implementation is provided).
  • 19. Linear List as Java Interface public interface LinearList { public boolean isEmpty(); public int size(); public Object get(int index); public int indexOf(Object elem); public Object remove(int index); public void add(int index, Object obj); public String toString(); }
  • 20. Implementing An Interface public class ArrayLinearList implements LinearList { // code for all LinearList methods must be provided here }
  • 21. Linear List As An Abstract Class An abstract class may include constants, variables, abstract methods, and nonabstract methods.
  • 22. Linear List As Java Abstract Class public abstract class LinearListAsAbstractClass { public abstract boolean isEmpty(); public abstract int size(); public abstract Object get(int index); public abstract int indexOf(Object theElement); public abstract Object remove(int index); public abstract void add(int index, Object theElement); public abstract String toString(); }
  • 23. Extending A Java Class public class ArrayLinearList extends LinearListAsAbstractClass { // code for all abstract classes must come here }
  • 24. Implementing Many Interfaces public class MyInteger implements Operable, Zero, CloneableObject { // code for all methods of Operable, Zero, // and CloneableObject must be provided }
  • 25. Extending Many Classes NOT PERMITTED IN JAVA A Java class may implement as many interfaces as it wants but can extend at most 1 class.
  • 26. Data Structures In Text All but 1 of our data structures are specified as Java interfaces. Exception is Graph in Chapter 17. Java specifies all of its data structures as interfaces. java.util.List

Editor's Notes

  1. Any set or collection is a data object.
  2. The instances of integer and daysOfWeek are related. In the former, all instances are whole numbers, whereas in the latter all instances name days of the week. The instances of myDataObject don’t seem to be related.
  3. You can have ordering relationships –2 before –1 before 0 before 1 etc (relational operators such as <, >, =, etc). Elements could be related by operations such as add, subtract, etc.
  4. A data object is a set of instances; an instance of a linear list is an ordered set of elements.
  5. Size of Students in COP3530 is 240, Exams is 3, DOW is 7, and Months is 12. Notice that Days of Week is used as an example of both a data object and of a linear list. As a data object, {S, M, T, …} and {M, W, S, …} describe the same data object with 7 allowable instances S, M, T, … As a linear list (S, M, T, …) and (M, W, S, …) are two different instances of a linear list. Linear List itself may be viewed as data object, which is simply the set of all possible linear list instances.
  6. The index of a nonexistent element is defined to be –1. When theElement is in the list an index between 0 and size()-1 is the result. So –1 would be an invalid index and is used to represent the case when theElement is not in the list
  7. Should add comments that describe the parameters, return value, and functionality of each method. Looks a lot like the abstract data type specification but the data types, return type specification, name of output method (toString) are all peculiar to Java.
  8. So an abstract class is more general than an interface. In addition to having the permissible components of an interface (constants and abstract methods), we can have variables and nonabstract methods.
  9. In the case of a linear list, the main difference between the interface and abstract class specification is the use of the keyword interface vs the keywords abstract class. All methods of the abstract class have been declared as abstract to indicate that we are not providing their implementation here. In the case of an interface it isn’t required (though permissible) to declare each method abstract. This is because all methods listed in an interface are, by default, abstract.
  10. Since ArrayLinearList is not declared as an abstract class, it must provide an implementation for all abstract methods of the class it extends (I.e., of LinearListAsAbstractClass).
  11. Since a class can extend only one other class, it is prudent to save your single extension chip for cases when you really need it (I.e., when you must inherit method implementations from an existing class). In the case of the graph data structure, we combine the specification of the data structure with the implementation of some methods and specification of certain variables into an abstract class. Java.util.list is a java interface specification for a linear list. Has all our methods plus more.