Data Structures ADT List 1 ADT List Elements
![Data Structures ADT List 1 Data Structures ADT List 1](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-1.jpg)
![ADT List Elements Structure Domain User of an ADT must only know this Operations ADT List Elements Structure Domain User of an ADT must only know this Operations](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-2.jpg)
![ADT List: Specification Elements: The elements are of type <Type>. The elements are placed ADT List: Specification Elements: The elements are of type <Type>. The elements are placed](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-3.jpg)
![ADT List: Specification Structure: the elements are linearly arranged, the first element is called ADT List: Specification Structure: the elements are linearly arranged, the first element is called](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-4.jpg)
![ADT List: Specification Operations: We assume all operations operate on a list L. 1. ADT List: Specification Operations: We assume all operations operate on a list L. 1.](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-5.jpg)
![ADT List: Specification Operations: 4. Method Update (Type e). requires: list L is not ADT List: Specification Operations: 4. Method Update (Type e). requires: list L is not](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-6.jpg)
![ADT List: Specification Operations: 6. Method Remove ( ) requires: list L is not ADT List: Specification Operations: 6. Method Remove ( ) requires: list L is not](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-7.jpg)
![ADT List: Specification Operations: 8. Method Empty (boolean flag). input: none. results: if the ADT List: Specification Operations: 8. Method Empty (boolean flag). input: none. results: if the](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-8.jpg)
![Implementation • Programmers have to deal with the questions: – How to represent lists? Implementation • Programmers have to deal with the questions: – How to represent lists?](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-9.jpg)
![Linked List nil head node current node 10 Linked List nil head node current node 10](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-10.jpg)
![Array Based List 0 head node 1 2 3 4 5 6 n-2 n-1 Array Based List 0 head node 1 2 3 4 5 6 n-2 n-1](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-11.jpg)
![ADT List – Linked List Representation: public class Link. List<T> extends Object { private ADT List – Linked List Representation: public class Link. List<T> extends Object { private](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-12.jpg)
![ADT List: Implementation public boolean full () { return false; } public void findfirst ADT List: Implementation public boolean full () { return false; } public void findfirst](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-13.jpg)
![ADT List: Implementation public void insert (T val) { Node<T> tmp; if (empty()){ current ADT List: Implementation public void insert (T val) { Node<T> tmp; if (empty()){ current](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-14.jpg)
![ADT List: Implementation public void remove () { if (current == head) { head ADT List: Implementation public void remove () { if (current == head) { head](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-15.jpg)
![ADT List – Array public class Array. List<T> { private int maxsize; private int ADT List – Array public class Array. List<T> { private int maxsize; private int](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-16.jpg)
![ADT List Implementation public boolean full () { public return size == maxsize; } ADT List Implementation public boolean full () { public return size == maxsize; }](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-17.jpg)
![ADT List Implementation public T retrieve () { return nodes[current]; } public void update ADT List Implementation public T retrieve () { return nodes[current]; } public void update](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-18.jpg)
![ADT List Implementation public void remove () { for (int i = current + ADT List Implementation public void remove () { for (int i = current +](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-19.jpg)
![ADT List • How to use the ADT List? • Example: You are required ADT List • How to use the ADT List? • Example: You are required](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-20.jpg)
![Using ADT List public class Test. Array. List { public static void main ( Using ADT List public class Test. Array. List { public static void main (](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-21.jpg)
![Using ADT List public static <T> int length(Array. List<T> l) { int count = Using ADT List public static <T> int length(Array. List<T> l) { int count =](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-22.jpg)
![Comparison: Linked & Array Based Lists • Comparison on the basis of worst case Comparison: Linked & Array Based Lists • Comparison on the basis of worst case](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-23.jpg)
![List: Singly Linked Head Current Singly-Linked List Size Head Current 24 List: Singly Linked Head Current Singly-Linked List Size Head Current 24](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-24.jpg)
![List: Singly Linked & Circular Tail Head Nil Current Head Current Circular List 25 List: Singly Linked & Circular Tail Head Nil Current Head Current Circular List 25](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-25.jpg)
- Slides: 25
![Data Structures ADT List 1 Data Structures ADT List 1](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-1.jpg)
Data Structures ADT List 1
![ADT List Elements Structure Domain User of an ADT must only know this Operations ADT List Elements Structure Domain User of an ADT must only know this Operations](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-2.jpg)
ADT List Elements Structure Domain User of an ADT must only know this Operations Specification Representation Implementer must know all these. Implementation 2
![ADT List Specification Elements The elements are of type Type The elements are placed ADT List: Specification Elements: The elements are of type <Type>. The elements are placed](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-3.jpg)
ADT List: Specification Elements: The elements are of type <Type>. The elements are placed in nodes for linked list implementation. public class Node<T> extends Object { public T data; public Node<T> next; public Node () { data = null; next = null; } public Node (T val) { data = val; next = null; } } 3
![ADT List Specification Structure the elements are linearly arranged the first element is called ADT List: Specification Structure: the elements are linearly arranged, the first element is called](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-4.jpg)
ADT List: Specification Structure: the elements are linearly arranged, the first element is called head, there is a element called current, and there is a last element. Domain: the number of elements in the list is bounded therefore the domain is finite. Type name of elements in the domain: List 4
![ADT List Specification Operations We assume all operations operate on a list L 1 ADT List: Specification Operations: We assume all operations operate on a list L. 1.](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-5.jpg)
ADT List: Specification Operations: We assume all operations operate on a list L. 1. Method Find. First ( ) requires: list L is not empty. input: none results: first element set as the current element. output: none. 2. Method Find. Next ( ) requires: list L is not empty. Cur is not last. input: none results: element following the current element is made the current element. output: none. 3. Method Retrieve (Type e) requires: list L is not empty. input: none results: current element is copied into e. output: element e. 5
![ADT List Specification Operations 4 Method Update Type e requires list L is not ADT List: Specification Operations: 4. Method Update (Type e). requires: list L is not](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-6.jpg)
ADT List: Specification Operations: 4. Method Update (Type e). requires: list L is not empty. input: e. results: the element e is copied into the current node. output: none. 5. Method Insert (Type e). requires: list L is not full. input: e. results: a new node containing element e is created and inserted after the current element in the list. The new element e is made the current element. If the list is empty e is also made the head element. output: none. 6
![ADT List Specification Operations 6 Method Remove requires list L is not ADT List: Specification Operations: 6. Method Remove ( ) requires: list L is not](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-7.jpg)
ADT List: Specification Operations: 6. Method Remove ( ) requires: list L is not empty. input: none results: the current element is removed from the list. If the resulting list is empty current is set to NULL. If successor of the deleted element exists it is made the new current element otherwise first element is made the new current element. output: none. 7. Method Full (boolean flag) input: none. returns: if the number of elements in L has reached the maximum number allowed then flag is set to true otherwise false. output: flag. 7
![ADT List Specification Operations 8 Method Empty boolean flag input none results if the ADT List: Specification Operations: 8. Method Empty (boolean flag). input: none. results: if the](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-8.jpg)
ADT List: Specification Operations: 8. Method Empty (boolean flag). input: none. results: if the number of elements in L is zero, then flag is set to true otherwise false. Output: flag. 9. Method Last (boolean flag). input: none. requires: L is not empty. Results: if the last element is the current element then flag is set to true otherwise false. Output: flag 8
![Implementation Programmers have to deal with the questions How to represent lists Implementation • Programmers have to deal with the questions: – How to represent lists?](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-9.jpg)
Implementation • Programmers have to deal with the questions: – How to represent lists? Storage structure affects the efficiency of the operations. – How to implement the operations? Algorithm chosen must be efficient. • Lists can represented as – Linked List – Array based List 9
![Linked List nil head node current node 10 Linked List nil head node current node 10](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-10.jpg)
Linked List nil head node current node 10
![Array Based List 0 head node 1 2 3 4 5 6 n2 n1 Array Based List 0 head node 1 2 3 4 5 6 n-2 n-1](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-11.jpg)
Array Based List 0 head node 1 2 3 4 5 6 n-2 n-1 current node 11
![ADT List Linked List Representation public class Link ListT extends Object private ADT List – Linked List Representation: public class Link. List<T> extends Object { private](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-12.jpg)
ADT List – Linked List Representation: public class Link. List<T> extends Object { private Node<T> head; private Node<T> current; public Link. List () { head = current = null; } public boolean empty () { return head == null; } public boolean last () { return current. next == null; } 12
![ADT List Implementation public boolean full return false public void findfirst ADT List: Implementation public boolean full () { return false; } public void findfirst](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-13.jpg)
ADT List: Implementation public boolean full () { return false; } public void findfirst () { current = head; } public void findnext () { current = current. next; } public T retrieve () { return current. data; } public void update (T val) { current. data = val; } 13
![ADT List Implementation public void insert T val NodeT tmp if empty current ADT List: Implementation public void insert (T val) { Node<T> tmp; if (empty()){ current](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-14.jpg)
ADT List: Implementation public void insert (T val) { Node<T> tmp; if (empty()){ current = head = new Node<T> (val); } else { tmp = current. next; current. next = new Node<T> (val); current = current. next; current. next = tmp; } } 14
![ADT List Implementation public void remove if current head head ADT List: Implementation public void remove () { if (current == head) { head](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-15.jpg)
ADT List: Implementation public void remove () { if (current == head) { head = head. next; } else { Node<T> tmp = head; while (tmp. next != current) tmp = tmp. next; tmp. next = current. next; } if (current. next == null) { current = head; } else { current = current. next; } } } 15
![ADT List Array public class Array ListT private int maxsize private int ADT List – Array public class Array. List<T> { private int maxsize; private int](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-16.jpg)
ADT List – Array public class Array. List<T> { private int maxsize; private int current; private T[] nodes; /** Creates a new instance of Array. List */ public Array. List(int n) { maxsize = n; size = 0; current = -1; nodes = (T[]) new Object[n]; } 16
![ADT List Implementation public boolean full public return size maxsize ADT List Implementation public boolean full () { public return size == maxsize; }](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-17.jpg)
ADT List Implementation public boolean full () { public return size == maxsize; } boolean empty () return size == 0; } boolean last () { return current == (size-1); } void findfirst () { current = 0; } void findnext () { current++; } 17
![ADT List Implementation public T retrieve return nodescurrent public void update ADT List Implementation public T retrieve () { return nodes[current]; } public void update](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-18.jpg)
ADT List Implementation public T retrieve () { return nodes[current]; } public void update (T val) { nodes[current] = val; } public void insert (T val) { for (int i = size-1; i > current; --i) { nodes[i+1] = nodes[i]; } current++; nodes[current] = val; size++; } 18
![ADT List Implementation public void remove for int i current ADT List Implementation public void remove () { for (int i = current +](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-19.jpg)
ADT List Implementation public void remove () { for (int i = current + 1; i < size; i++) { nodes[i-1] = nodes[i]; } size--; if (size == 0) current = -1; else if (current == size) current = 0; } } 19
![ADT List How to use the ADT List Example You are required ADT List • How to use the ADT List? • Example: You are required](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-20.jpg)
ADT List • How to use the ADT List? • Example: You are required to implement a static method to search for an element e in a list L, and if e is present make current pointer point to e. Use operations of ADT List. • The implementation of ADT is available to you as a Java class. 20
![Using ADT List public class Test Array List public static void main Using ADT List public class Test. Array. List { public static void main (](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-21.jpg)
Using ADT List public class Test. Array. List { public static void main ( String[] args ) { Array. List<String> al = new Array. List<String>(10); String s 1= "xyz", s 2 = "abc"; al. insert(s 1); al. insert(s 2); al. findfirst(); System. out. println(al. retrieve()); System. out. println(al. full()); System. out. println(length(al)); System. out. println("Hello, World"); } 21
![Using ADT List public static T int lengthArray ListT l int count Using ADT List public static <T> int length(Array. List<T> l) { int count =](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-22.jpg)
Using ADT List public static <T> int length(Array. List<T> l) { int count = 0; A static method l. findfirst(); to find the length while (l. last() == false){ of a list. count++; Note: it has been l. findnext(); implemented using } the methods of return count; ADT List } } 22
![Comparison Linked Array Based Lists Comparison on the basis of worst case Comparison: Linked & Array Based Lists • Comparison on the basis of worst case](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-23.jpg)
Comparison: Linked & Array Based Lists • Comparison on the basis of worst case time complexity of insert & remove operations. All other operations have time complexity O(1). • Linked List: insert– O(1); remove – O(n). • Array List: insert – O(n); remove – O(n). • Best case time complexities? 23
![List Singly Linked Head Current SinglyLinked List Size Head Current 24 List: Singly Linked Head Current Singly-Linked List Size Head Current 24](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-24.jpg)
List: Singly Linked Head Current Singly-Linked List Size Head Current 24
![List Singly Linked Circular Tail Head Nil Current Head Current Circular List 25 List: Singly Linked & Circular Tail Head Nil Current Head Current Circular List 25](https://slidetodoc.com/presentation_image_h2/a50d965f62047ecb20bff2d8dfa11d46/image-25.jpg)
List: Singly Linked & Circular Tail Head Nil Current Head Current Circular List 25
Homologous structures
List adt
Read that
Adt linked list
Array based implementation of list adt
List adt
List adt java
Polynomial representation using linked list
Java list adt
List adt
List adt
List adt
Collection (abstract data type)
Abstract data type adt
Ps2-1 lewis structure
Urban structure model
Btech smart class.com
Data structures in r
Oblivious data structures
Linux kernel data structures
Introduction to data structures
Introduction to data structures
Data structures and algorithms iit bombay
Esoteric data structures
Geometric data structures
Cos 423 princeton