© Egon Börger: Linked List 1 Double Linked Lists : Desired Operations Define an ASM which offers the following operations, predicates and functions on.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Singly linked lists Doubly linked lists
Formal Models of Computation Part II The Logic Model
Introduction A function is called higher-order if it takes a function as an argument or returns a function as a result. twice :: (a  a)  a  a twice.
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Singly Linked Lists What is a singly-linked list? Why linked lists?
Linked Lists Chapter 4.
Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
Linear Lists – Linked List Representation
Section 5 Lists again. Double linked lists – insertion, deletion. Trees.
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
CSCI2100B Linked List Jeffrey
Real-Time Process Control Systems (Real-Time Controller ASM for the Railroad Crossing Case Study) Egon Börger Dipartimento di Informatica, Universita di.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 12 Binary Search Trees
Higher-order functions in OCaml. Higher-order functions A first-order function is one whose parameters and result are all "data" A second-order function.
F28PL1 Programming Languages Lecture 14: Standard ML 4.
Primitive Recursive Functions (Chapter 3)
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Chapter Three: Lists, Operators, Arithmetic CS 461.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Asynchronous ASMs Network Leader Election Egon Börger Dipartimento di Informatica, Universita di Pisa
Pointer Review. Node { int value; Node * next; Node( int val =-1, Node * n = NULL) {value = val; next = n;} } Given a ordered linked list pointed to.
Asynchronous ASMs Master/Slave Agreement Egon Börger Dipartimento di Informatica, Universita di Pisa
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
© E. Börger: Ground Model Exercises 1 Exercises in Capturing Requirements Constructing Ground Models ATM (Cash Machine) Vending Machine Password Change.
1 CSE1301 Computer Programming: Lecture 30 Linked Lists (Part 2)
Illustrating Stepwise Refinement Shortest Path ASMs Egon Börger Dipartimento di Informatica, Universita di Pisa
E.G.M. Petrakislists, stacks, queues1 Lists List: finite sequence of data elements –Ordered: each element has a position in list –All elements has the.
Stack and Queue.
Introduction to ASMs Dumitru Roman Digital Enterprise Research Institute
Asynchronous Multi-Agent ASMs An Introduction Egon Börger Dipartimento di Informatica, Universita di Pisa
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Abstract Data Types and a review of C++ programming concepts CS 400/600 – Data Structures.
Data Structures & Algorithms
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Linked List by Chapter 5 Linked List by
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
Linked List Containers. Linked Lists List consists of multiple listnodes List consists of multiple listnodes Each listnode consists of Each listnode consists.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Asynchronous ASMs Echo Algorithm Egon Börger Dipartimento di Informatica, Universita di Pisa
LINKED LISTS.
CS212: Data Structures and Algorithms Lecture # 4 Linked List.
Recursion.
CS 550 Programming Languages Jeremy Johnson
Search Trees.
PROGRAMMING IN HASKELL
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
Queues Queues Queues.
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
CS 270 Math Foundations of CS Jeremy Johnson
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Linked Lists.
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
CS212D: Data Structures Week 5-6 Linked List.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
PROGRAMMING IN HASKELL
Mutators for compound data Stack Queue
CSCE 314: Programming Languages Dr. Dylan Shell
PROGRAMMING IN HASKELL
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

© Egon Börger: Linked List 1 Double Linked Lists : Desired Operations Define an ASM which offers the following operations, predicates and functions on double linked lists, whose elements have values in a given set VALUE: –CreateList (VALUE) : create a new double linked list with elements taking values in Value –Append (L, Val) : append at the end a new element with given value –Insert (L, Val, Elem) : insert after Elem in L a new element with Val –Delete (L, Elem) : delete Elem from L –AccessByValue (L, Val) : return the first element in L with Val –AccessByIndex (L, i) : return the i-th element in L –empty (L), length (L), occurs (L, Elem), position (L, Elem) –Update (L, Elem, Val) : update the the value of Elem in L to Val –Cat (L1,L2) : concatenate two given lists in the given order –Split (L, Elem, L1, L2) : split L into L1, containing L up to including Elem, and L2 containing the rest list of L

© Egon Börger: Linked List 2 Double Linked Lists : Desired Properties Prove that the Linked List ASM has the following properties: –If the next-link of a list element Elem points to Elem, then the previous-link of Elem points to Elem. –L is empty iff the next-link of its head points to its tail. –The set ELEM (L) of elements occurring in a list is the set of all E which can be reached, starting from the list head, by applying next-links until the list tail is encountered. –After applying Append (L, Val), the list is not empty. –A newly created linked list is empty and its length is 0. –By Append/Delete the list length in/de-creases by 1. –For non empty L and arbitrary elements E the following holds: Append (Delete (L,E),E) = Delete (Append (L,E),E)

© Egon Börger: Linked List 3 A Problem Solution E. Börger, R. Stärk: Abstract State Machines. A Method for High-Level System Design and Analysis Springer-Verlag 2003, see –See exercise in Chapter 2

© Egon Börger: Linked List 4 Double Linked Lists : Signature LINKED-LIST (VALUE) : dynamic set, with fcts pointing to structures of the following form (often VALUE suppressed) : –dynamic set ELEM (L) of objects currly listed in L –distinguished elems Head (L), Tail (L) ELEM (L) –previous (L), next (L): ELEM (L) ELEM (L) dyn link fcts –cont (L) : ELEM (L) VALUE yields curr value of list elems initialize(L) for L LINKED-LIST (as usual, L is suppressed) as empty linked list with values in VALUE, defined as follows : –ELEM := { Head, Tail } next (Head) := Tail previous (Tail) := Head –previous (Head) := next (Tail) := null (ELEM) Head/Tail start/end the list –cont (Head) := cont (Tail) := null (VALUE) Head/Tail have no content NULLnullNULLnullHeadTail cont previous next

© Egon Börger: Linked List 5 Double Linked Lists : Definition of Operations (1) CreateList (VALUE) let L = new (LINKED-LIST ( VALUE )) in initialize (L) Val Elem Append (L, Val) let e = new (ELEM (L)) in Link previous (Tail) & e Link e &Tail cont (e) := Val with Link a&b next (a) := b previous (b) := a Insert (L, Val, Elem) let e = new (ELEM (L)) in cont (e) := Val Link Elem & e Link e & next (Elem)

© Egon Börger: Linked List 6 Double Linked Lists : Operations & Derived Fcts (2) Delete (L, e) v vVal e vv Link previous (e) & next (e) length (L) m ( next m+1 (Head) = Tail ) well defined by initialization occurs (L, e) i length (L) : next i (Head) = e (e ELEM(L))) position (L, Elem) m ( next m (Head) = Elem ) if occurs (L, Elem) AccessByIndex (L, i) next i (Head) if i length (L) AccessByValue (L, Val) next m (Head) fst occ of Val where m= min { i | cont (next i (Head)) = Val } is defined

© Egon Börger: Linked List 7 Double Linked Lists : Definition of Operations (3) Update (L, Elem, Val) If occurs (L, Elem) then cont (Elem) := Val else error msg Elem does not occur in L Cat (L 1, L 2 ) let L = new (LINKED-LIST) in Head (L) := Head (L 1 ) Tail (L) := Tail (L 2 ) Link (L) previous (L 1 ) ( Tail (L 1 )) & next (L 2 ) ( Head (L 2 ) ) forall e ELEM (L) - {previous (L 1 ) ( Tail (L 1 )),Tail (L 1 ) } Link (L) e & next (L 1 ) ( e ) forall e ELEM (L 2 ) - { Head (L 2 ),Tail (L 2 ) } Link (L) e & next (L 2 ) ( e )...last 1 Tail fst 2 Head 2...last fst 2

© Egon Börger: Linked List 8 Double Linked Lists : Definition of Operations (4) Split (L, e, L 1, L 2 ) let e 1 = new-tail, e 2 = new-head in Head (L 1 ) := Head (L) Tail (L 1 ) := e 1 Link (L 1 ) e & e 1 forall E ELEM (L) if position (L, E) < position (L, e) then Link (L 1 ) E & next (L) ( E ) Head (L 2 ) := e 2 Link (L 2 ) e 2 & next (L) (e) Tail (L 2 ) := Tail (L) forall E ELEM (L) if position (L, e) < position (L, E) then Link (L 2 ) E & next (L) ( E ) where e = new-tail/head cont ( e ) := null (VALUE) next/previous ( e ) := null (ELEM)... e eTail (L 1 ) Head (L 2 )

© Egon Börger: Linked List 9 Double Linked Lists : Proving the Properties (1) If the next-link of a list element Elem points to Elem, then the previous-link of Elem points to Elem. –Initially true by defn of initialize (L), preserved by each opn due to the defn of Link (L) and the fact that next/previous are modified only using this macro. L is empty iff the next-link of its head points to its tail. A newly created linked list is empty and its length is 0. After applying Append (L, Val), the list is not empty. By Append/Delete the list length in/de-creases by 1.

© Egon Börger: Linked List 10 Double Linked Lists : Proving the Properties (2) For L [ ]: Append (Delete (L,E),E) = Delete (Append (L,E),E) –Follow from the defn of initialize (L), length (L), Append, Delete & the fact that Append/Insert yield a non null cont. The set ELEM (L) of elements occurring in a list is the set of all E which can be reached, starting from the list head, by applying next- links until the list tail is encountered. –Follows from the defn of ELEM(L).