Abstract Data Types. EECS 214, Fall 2017

Size: px
Start display at page:

Download "Abstract Data Types. EECS 214, Fall 2017"

Transcription

1 Abstract Data Types EECS 214, Fall 2017

2 2 What is an ADT? An ADT defines: A set of (abstract) values A set of (abstract) operations on those values

3 2 What is an ADT? An ADT defines: A set of (abstract) values A set of (abstract) operations on those values An ADT omits: How the values are concretely represented How the operations work

4 3 ADT: Stack Looks like: 3 4 5

5 3 ADT: Stack Looks like: Signature: push(stack, Element): Void pop(stack): Element isempty(stack): Bool

6 4 ADT: Queue (FIFO) Looks like: 3 4 5

7 4 ADT: Queue (FIFO) Looks like: Signature: enqueue(queue, Element): Void dequeue(queue): Element isempty(queue): Bool

8 5 Stack versus Queue Stack signature: push(stack, Element): Void pop(stack): Element isempty(stack): Bool Queue signature: enqueue(queue, Element): Void dequeue(queue): Element isempty(queue): Bool

9 6 Adding laws {p} f(x) y {q} means that if precondition p is true when we apply f to x then we will get y as a result, and postcondition q will be true afterward.

10 6 Adding laws {p} f(x) y {q} means that if precondition p is true when we apply f to x then we will get y as a result, and postcondition q will be true afterward. Examples: {a = [2, 4, 6, 8]} a[2] 6 {a = [2, 4, 6, 8]} {a = [2, 4, 6, 8]} a[2] = 0 {a = [2, 4, 0, 8]}

11 7 ADT: Stack Looks like: Signature: push(stack, Element): Void pop(stack): Element isempty(stack): Bool Laws: isempty( ) isempty( e 1... e k e k+1 ) {s = e 1... e k } push(s, e) {s = e 1... e k e } {s = e 1... e k e k+1 } pop(s) e k+1 {s = e 1... e k }

12 8 ADT: Queue (FIFO) Looks like: Signature: enqueue(queue, Element): Void dequeue(queue): Element isempty(queue): Bool Laws: isempty( ) isempty( e 1... e k e k+1 ) {q = e 1... e k } enqueue(q, e) {q = e 1... e k e } {q = e 1 e 2... e k } dequeue(q) e 1 {q = e 2... e k }

13 9 Stack implementation: linked list head let s = new_stack()

14 9 Stack implementation: linked list head data 2 let s = new_stack() push(s, 2)

15 9 Stack implementation: linked list head data 3 data 2 let s = new_stack() push(s, 2) push(s, 3)

16 9 Stack implementation: linked list head data 4 data 3 data 2 let s = new_stack() push(s, 2) push(s, 3) push(s, 4)

17 9 Stack implementation: linked list head data 5 data 4 data 3 data 2 let s = new_stack() push(s, 2) push(s, 3) push(s, 4) push(s, 5)

18 9 Stack implementation: linked list head data 4 data 3 data 2 let s = new_stack() push(s, 2) push(s, 3) push(s, 4) push(s, 5) pop(s)

19 9 Stack implementation: linked list head data 3 data 2 let s = new_stack() push(s, 2) push(s, 3) push(s, 4) push(s, 5) pop(s) pop(s)

20 10 Stack implementation: array data len 0 let s = new_stack()

21 10 Stack implementation: array data len 1 let s = new_stack() 2 push(s, 2)

22 10 Stack implementation: array data len 2 let s = new_stack() 2 3 push(s, 2) push(s, 3)

23 10 Stack implementation: array data len 3 let s = new_stack() push(s, 2) push(s, 3) push(s, 4)

24 10 Stack implementation: array data len 4 let s = new_stack() push(s, 2) push(s, 3) push(s, 4) push(s, 5)

25 10 Stack implementation: array data len 4 let s = new_stack() push(s, 2) push(s, 3) push(s, 4) push(s, 5) push(s, 6)

26 11 ADT: Stack Looks like: Signature: push(stack, Element): Void O(1) pop(stack): Element O(1) isempty(stack): Bool O(1) Laws: isempty( ) isempty( e 1... e k e k+1 ) {s = e 1... e k } push(s, e) {s = e 1... e k e } {s = e 1... e k e k+1 } pop(s) e k+1 {s = e 1... e k }

27 12 Trade-offs: linked list stack versus array stack Linked list stack only fills up when memory fills up, whereas array stack has a fixed size (or must reallocate) Array stack has better constant factors: cache locality and no (or rare) allocation Array stack space usage is tighter; linked list is smoother

28 13 ADT: Queue (FIFO) Looks like: Signature: enqueue(queue, Element): Void O(1) dequeue(queue): Element O(1) isempty(queue): Bool O(1) Laws: isempty( ) isempty( e 1... e k e k+1 ) {q = e 1... e k } enqueue(q, e) {q = e 1... e k e } {q = e 1 e 2... e k } dequeue(q) e 1 {q = e 2... e k }

29 14 Queue implementation: linked list? head let q = new_queue()

30 14 Queue implementation: linked list? head data 2 let q = new_queue() enqueue(q, 2)

31 14 Queue implementation: linked list? head data 3 data 2 let q = new_queue() enqueue(q, 2) enqueue(q, 3)

32 14 Queue implementation: linked list? head data 4 data 3 data 2 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4)

33 14 Queue implementation: linked list? head data 5 data 4 data 3 data 2 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5)

34 14 Queue implementation: linked list? head data 5 data 4 data 3 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q)

35 14 Queue implementation: linked list? head data 5 data 4 data 3 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) O(n)?

36 15 Queue implementation: array? data len 0 let q = new_queue()

37 15 Queue implementation: array? data len 1 let q = new_queue() 2 enqueue(q, 2)

38 15 Queue implementation: array? data len 2 let q = new_queue() 2 3 enqueue(q, 2) enqueue(q, 3)

39 15 Queue implementation: array? data len 3 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4)

40 15 Queue implementation: array? data len 4 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5)

41 15 Queue implementation: array? data len 4 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) s.dequeue()

42 15 Queue implementation: array? data len 4 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) s.dequeue() O(n)???

43 16 Queue impl.: linked list with tail pointer head tail let q = new_queue()

44 16 Queue impl.: linked list with tail pointer head tail let q = new_queue() enqueue(q, 2) data 2

45 16 Queue impl.: linked list with tail pointer head tail let q = new_queue() enqueue(q, 2) enqueue(q, 3) data 2 data 3

46 16 Queue impl.: linked list with tail pointer head tail data 2 data 3 data 4 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4)

47 16 Queue impl.: linked list with tail pointer head tail data 2 data 3 data 4 data 5 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5)

48 16 Queue impl.: linked list with tail pointer head tail data 3 data 4 data 5 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q)

49 16 Queue impl.: linked list with tail pointer head tail let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) dequeue(q) data 4 data 5

50 17 Queue implementation: ring buffer data start 0 len 0 let q = new_queue()

51 17 Queue implementation: ring buffer data start 0 len 1 let q = new_queue() enqueue(q, 2) 2

52 17 Queue implementation: ring buffer data start 0 len 2 let q = new_queue() enqueue(q, 2) enqueue(q, 3) 2 3

53 17 Queue implementation: ring buffer data start 0 len 3 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) 2 3 4

54 17 Queue implementation: ring buffer data start 0 len 4 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5)

55 17 Queue implementation: ring buffer data start 1 len 3 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q)

56 17 Queue implementation: ring buffer data start 2 len 2 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) dequeue(q)

57 17 Queue implementation: ring buffer data start 2 len 6 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) dequeue(q)

58 17 Queue implementation: ring buffer data start 2 len 7 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) dequeue(q). enqueue(q, 0)

59 17 Queue implementation: ring buffer data start 3 len 6 let q = new_queue() enqueue(q, 2) enqueue(q, 3) enqueue(q, 4) enqueue(q, 5) dequeue(q) dequeue(q). enqueue(q, 0) dequeue(q)

60 18 Trade-offs: linked list queue versus ring buffer Basically the same as for the stack implementations: Ring buffer has better constant factors and uses less space (potentially) Linked list doesn t fill up

61 Ring buffer in DSSL2

62 20 Representation # A QueueOf[X] is # queue(vectorof[x or False], Natural, Natural) # Interpretation: # - `data` contains the elements of the queue, # - `start` is the index of the first element, and # - `size` is the number of elements. defstruct queue(data, start, size)

63 20 Representation # A QueueOf[X] is # queue(vectorof[x or False], Natural, Natural) # Interpretation: # - `data` contains the elements of the queue, # - `start` is the index of the first element, and # - `size` is the number of elements. defstruct queue(data, start, size) let F = False let QUEUE0 = queue([f; 8], 0, 0)) let QUEUE1 = queue([3, F, F, F, F, F], 0, 1) let QUEUE2 = queue([3, 4, F, F, F, F], 0, 2) let QUEUE3 = queue([f, F, 5, 6, 7, F], 2, 3) let QUEUE4 = queue([9, 10, F, F, 7, 8], 4, 4)

64 21 Creating a new queue # new_queue : Natural -> QueueOf[X] def new_queue(capacity): queue([ False; capacity ], 0, 0)

65 22 Finding out the size and capacity # queue_size : QueueOf[X] -> Natural def queue_size(q): q.size # queue_capacity : QueueOf[X] -> Natural def queue_capacity(q): len(q.data)

66 22 Finding out the size and capacity # queue_size : QueueOf[X] -> Natural def queue_size(q): q.size # queue_capacity : QueueOf[X] -> Natural def queue_capacity(q): len(q.data) # queue_empty? : QueueOf[X] -> Bool def queue_empty?(q): queue_size(q) == 0 # queue_full? : QueueOf[X] -> Bool def queue_full?(q): queue_size(q) == queue_capacity(q)

67 23 Enqueueing # enqueue! : QueueOf[X] X -> Void def enqueue!(q, element): if queue_full?(q): error('enqueue!: queue is full') let cap = queue_capacity(q) q.data[(q.size + q.start) % cap] = element q.size = q.size + 1

68 24 Dequeueing # dequeue! : QueueOf[X] -> X def dequeue!(q): if queue_empty?(q): error('dequeue!: queue is empty') let result = q.data[q.start] q.data[q.start] = False q.size = q.size - 1 q.start = (q.start + 1) % queue_capacity(q) result

69 Next time: BSTs and the Dictionary ADT

Queues. Principles of Computer Science II. Basic features of Queues

Queues. Principles of Computer Science II. Basic features of Queues Queues Principles of Computer Science II Abstract Data Types Ioannis Chatzigiannakis Sapienza University of Rome Lecture 9 Queue is also an abstract data type or a linear data structure, in which the first

More information

Lecture 4: Stacks and Queues

Lecture 4: Stacks and Queues Reading materials Goodrich, Tamassia, Goldwasser (6th), chapter 6 OpenDSA (https://opendsa-server.cs.vt.edu/odsa/books/everything/html/): chapter 9.8-13 Contents 1 Stacks ADT 2 1.1 Example: CharStack ADT

More information

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park 1617 Preview Data Structure Review COSC COSC Data Structure Review Linked Lists Stacks Queues Linked Lists Singly Linked List Doubly Linked List Typical Functions s Hash Functions Collision Resolution

More information

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu Linked Lists 1. You are given the linked list: 1 2 3. You may assume that each node has one field

More information

/463 Algorithms - Fall 2013 Solution to Assignment 4

/463 Algorithms - Fall 2013 Solution to Assignment 4 600.363/463 Algorithms - Fall 2013 Solution to Assignment 4 (30+20 points) I (10 points) This problem brings in an extra constraint on the optimal binary search tree - for every node v, the number of nodes

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Introduction

More information

Lists, Stacks, and Queues (plus Priority Queues)

Lists, Stacks, and Queues (plus Priority Queues) Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

ENS Lyon Camp. Day 5. Basic group. C October

ENS Lyon Camp. Day 5. Basic group. C October ENS Lyon Camp. Day 5. Basic group. C++. 30 October Contents 1 Input/Output 1 1.1 C-style.......................................... 1 1. C++-style........................................ Stack Overflow

More information

CS 21 Decidability and Tractability Winter Solution Set 3

CS 21 Decidability and Tractability Winter Solution Set 3 CS 21 Decidability and Tractability Winter 2018 Posted: January 31 Solution Set 3 If you have not yet turned in the Problem Set, you should not consult these solutions. 1. (a) A 2-NPDA is a 7-tuple (Q,,

More information

Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks Stacks Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks Stacks: Definitions and Operations A LIFO list: Last In,

More information

CS 6301 PROGRAMMING AND DATA STRUCTURE II Dept of CSE/IT UNIT V GRAPHS

CS 6301 PROGRAMMING AND DATA STRUCTURE II Dept of CSE/IT UNIT V GRAPHS UNIT V GRAPHS Representation of Graphs Breadth-first search Depth-first search Topological sort Minimum Spanning Trees Kruskal and Prim algorithm Shortest path algorithm Dijkstra s algorithm Bellman-Ford

More information

Solution suggestions for examination of Logic, Algorithms and Data Structures,

Solution suggestions for examination of Logic, Algorithms and Data Structures, Department of VT12 Software Engineering and Managment DIT725 (TIG023) Göteborg University, Chalmers 24/5-12 Solution suggestions for examination of Logic, Algorithms and Data Structures, Date : April 26,

More information

Recent developments in concurrent program logics

Recent developments in concurrent program logics Recent developments in concurrent program logics Viktor Vafeiadis University of Cambridge PSPL 2010 Why program logic? Reasoning framework Capture common reasoning principles Reduce accidental proof complexity

More information

Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures

Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures Christian Scheideler SS 2018 23.04.2018 Chapter 3 1 Overview Basic data structures Search structures (successor searching) Dictionaries

More information

Data Structures and Algorithms Winter Semester

Data Structures and Algorithms Winter Semester Page 0 German University in Cairo December 26, 2015 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2015-2016 Final

More information

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Part IA Algorithms Notes

Part IA Algorithms Notes Part IA Algorithms Notes 1 Sorting 1.1 Insertion Sort 1 d e f i n s e r t i o n S o r t ( a ) : 2 f o r i from 1 i n c l u d e d to l e n ( a ) excluded : 3 4 j = i 1 5 w h i l e j >= 0 and a [ i ] > a

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

More information

Verifying Java-KE Programs

Verifying Java-KE Programs Verifying Java-KE Programs A Small Case Study Arnd Poetzsch-Heffter July 22, 2014 Abstract This report investigates the specification and verification of a simple list class. The example was designed such

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 10 - November 14 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Adding Finding and Removing

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 12

CMSC 132, Object-Oriented Programming II Summer Lecture 12 CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees

More information

Solutions. 9. Ans. C. Memory size. 11. Ans. D. a b c d e f a d e b c f a b d c e f a d b c e f a b d e c f a d b e c f. 13. Ans. D. Merge sort n log n

Solutions. 9. Ans. C. Memory size. 11. Ans. D. a b c d e f a d e b c f a b d c e f a d b c e f a b d e c f a d b e c f. 13. Ans. D. Merge sort n log n Solutions. Ans. B. ~ p q ~ r ~ s ~ p q r s ~ ~ p q r s p ~ q r s ~ p q ~ r v ~ s For x only the above compound preposition is true.. Ans. B. Case I First bit is 0 Case II First bit is 6. Ans. A. # has

More information

Priority queues implemented via heaps

Priority queues implemented via heaps Priority queues implemented via heaps Comp Sci 1575 Data s Outline 1 2 3 Outline 1 2 3 Priority queue: most important first Recall: queue is FIFO A normal queue data structure will not implement a priority

More information

Solutions to EoPL3 Exercises

Solutions to EoPL3 Exercises Solutions to EoPL3 Exercises Release 0.1.0 Cheng Lian May 16, 2017 Contents 1 Contents 3 2 Overview 29 i ii Author Cheng Lian Contents 1 2 Contents CHAPTER 1 Contents Chapter 1.

More information

Register Machines Storing Ordinals and Running for Ordinal Time

Register Machines Storing Ordinals and Running for Ordinal Time 2488 Register Machines Storing Ordinals and Running for Ordinal Time Ryan Siders 6/106 0 Outline Assumptions about Motion and Limits on Programming Without well-structured programming: Well-Structured

More information

Theoretical Computer Science 124 (1994) Elsevier. Laboratoire d'informatique, Universit4 de Caen, F Caen Cedex, France

Theoretical Computer Science 124 (1994) Elsevier. Laboratoire d'informatique, Universit4 de Caen, F Caen Cedex, France Theoretical Computer Science 124 (1994) 343-350 343 Elsevier Note A linear algorithm for a set of clauses as a Horn renaming set* Jean-Jacques H6brard Laboratoire d'informatique, Universit4 de Caen, F-14032

More information

Single Source Shortest Paths

Single Source Shortest Paths CMPS 00 Fall 015 Single Source Shortest Paths Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 Paths in graphs Consider a digraph G = (V, E) with an edge-weight

More information

Nontrivial and Universal Helping for Wait-Free Queues and Stacks

Nontrivial and Universal Helping for Wait-Free Queues and Stacks Nontrivial and Universal Helping for Wait-Free Queues and Stacks Hagit Attiya 1, Armando Castañeda 2, and Danny Hendler 3 1 Technion 2 UNAM 3 BGU Abstract This paper studies two approaches to formalize

More information

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Searching, mainly via Hash tables

Searching, mainly via Hash tables Data structures and algorithms Part 11 Searching, mainly via Hash tables Petr Felkel 26.1.2007 Topics Searching Hashing Hash function Resolving collisions Hashing with chaining Open addressing Linear Probing

More information

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes )

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes ) CSE613: Parallel Programming, Spring 2012 Date: May 11 Final Exam ( 11:15 AM 1:45 PM : 150 Minutes ) This exam will account for either 10% or 20% of your overall grade depending on your relative performance

More information

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2. March 30, Please write your name in the upper corner of each page.

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2. March 30, Please write your name in the upper corner of each page. 6.045J/18.400J: Automata, Computability and Complexity March 30, 2005 Quiz 2 Prof. Nancy Lynch Please write your name in the upper corner of each page. Problem Score 1 2 3 4 5 6 Total Q2-1 Problem 1: True

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

Problem Set 4 Solutions

Problem Set 4 Solutions Introduction to Algorithms October 8, 2001 Massachusetts Institute of Technology 6.046J/18.410J Singapore-MIT Alliance SMA5503 Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson Handout 18

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 14 Shortest Paths I Properties of shortest paths Dijkstra s algorithm Correctness Analysis Breadth-first search Prof. Charles E. Leiserson Paths in graphs

More information

Distributed Systems Part II Solution to Exercise Sheet 10

Distributed Systems Part II Solution to Exercise Sheet 10 Distributed Computing HS 2012 Prof. R. Wattenhofer / C. Decker Distributed Systems Part II Solution to Exercise Sheet 10 1 Spin Locks A read-write lock is a lock that allows either multiple processes to

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

Finding similar items

Finding similar items Finding similar items CSE 344, section 10 June 2, 2011 In this section, we ll go through some examples of finding similar item sets. We ll directly compare all pairs of sets being considered using the

More information

Syntax: form ::= A: lin j E: lin ::= 3 lin j lin ^ lin j :lin j bool lin lin is a temporal formula dened over a global sequence. bool is true in g if

Syntax: form ::= A: lin j E: lin ::= 3 lin j lin ^ lin j :lin j bool lin lin is a temporal formula dened over a global sequence. bool is true in g if Introduction 1 Goals of the lecture: Weak Conjunctive Predicates Logic for global predicates Weak conjunctive algorithm References: Garg and Waldecker 94 Syntax: form ::= A: lin j E: lin ::= 3 lin j lin

More information

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro. CMPS 00 Fall 01 Single Source Shortest Paths Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk 1 Paths in graphs Consider a digraph G = (V, E) with edge-weight function

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/8.40J/SMA550 Lecture 7 Prof. Erik Demaine Paths in graphs Consider a digraph G = (V, E) with edge-weight function w : E R. The weight of path p = v v L v k is defined

More information

Amortized analysis. Amortized analysis

Amortized analysis. Amortized analysis In amortized analysis the goal is to bound the worst case time of a sequence of operations on a data-structure. If n operations take T (n) time (worst case), the amortized cost of an operation is T (n)/n.

More information

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification

More information

Discrete Event Simulation. Motive

Discrete Event Simulation. Motive Discrete Event Simulation These slides are created by Dr. Yih Huang of George Mason University. Students registered in Dr. Huang's courses at GMU can make a single machine-readable copy and print a single

More information

CS 410/584, Algorithm Design & Analysis: Lecture Notes 3

CS 410/584, Algorithm Design & Analysis: Lecture Notes 3 CS 410/584, : Lecture Notes 3 Amortized Cost Not an algorithm design mechanism per se For analyzing cost of algorithms - - Example: Exercise 17.3-6 Implement a queue with two stacks Why? 1 enqueue(x, Q)

More information

Tute 10. Liam O'Connor. May 23, 2017

Tute 10. Liam O'Connor. May 23, 2017 Tute 10 Liam O'Connor May 23, 2017 proc Search(value g : G, value s : V g, value k : K, result v : T, result f : B) Where a graph g : G is dened as a 4-tuple (V, Γ, κ, λ) containing a set of vertices V,

More information

Equality to Equals and Unequals: A Revisit of the Equivalence and Nonequivalence Criteria in Class-Level Testing of Object-Oriented Software*

Equality to Equals and Unequals: A Revisit of the Equivalence and Nonequivalence Criteria in Class-Level Testing of Object-Oriented Software* Postprint of article in IEEE Transactions on Software Engineering 39 (11): 1549 1563 (2013) Equality to Equals and Unequals: A Revisit of the Equivalence and Nonequivalence Criteria in Class-Level Testing

More information

Equality to equals and unequals: a revisit of the equivalence and nonequivalence criteria in object-oriented software testing.

Equality to equals and unequals: a revisit of the equivalence and nonequivalence criteria in object-oriented software testing. Title Equality to equals and unequals: a revisit of the equivalence and nonequivalence criteria in object-oriented software testing Author(s) Chen, HY; Tse, TH Citation IEEE Transactions on Software Engineering,

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 17 Shortest Paths I Properties of shortest paths Dijkstra s algorithm Correctness Analysis Breadth-first search Prof. Erik Demaine November 14, 005 Copyright

More information

Quantitative Relaxation of Concurrent Data Structures

Quantitative Relaxation of Concurrent Data Structures Quantitative Relaxation of Concurrent Data Structures Thomas A. Henzinger a Ali Sezgin a Christoph M. Kirsch Hannes Payer Ana Sokolova a IST Austria Technical Report 2012-03 May 2012 Department of Computer

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures, Divide and Conquer Albert-Ludwigs-Universität Freiburg Prof. Dr. Rolf Backofen Bioinformatics Group / Department of Computer Science Algorithms and Data Structures, December

More information

Verifying Concurrent Memory Reclamation Algorithms with Grace

Verifying Concurrent Memory Reclamation Algorithms with Grace Verifying Concurrent Memory Reclamation Algorithms with Grace Alexey Gotsman, Noam Rinetzky, and Hongseok Yang 1 IMDEA Software Institute 2 Tel-Aviv University 3 University of Oxford Abstract. Memory management

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS6000: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Paths in graphs Consider a digraph G = (V, E) with edge-weight function w : E R. The weight of path p = v 1 v L v k

More information

Amortized Complexity Verified

Amortized Complexity Verified Amortized Complexity Verified Tobias Nipkow Technische Universität München Abstract A framework for the analysis of the amortized complexity of (functional) data structures is formalized in Isabelle/HOL

More information

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Prof. Martha A. Kim Columbia University Due October 10, 2013 at 10:10 AM Write your name and UNI on your solutions Show your work for each

More information

Probabilistic Aspects of Computer Science: Probabilistic Automata

Probabilistic Aspects of Computer Science: Probabilistic Automata Probabilistic Aspects of Computer Science: Probabilistic Automata Serge Haddad LSV, ENS Paris-Saclay & CNRS & Inria M Jacques Herbrand Presentation 2 Properties of Stochastic Languages 3 Decidability Results

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26 Homework #2 ( Due: Nov 8 ) Task 1. [ 80 Points ] Average Case Analysis of Median-of-3 Quicksort Consider the median-of-3 quicksort algorithm

More information

Compositional Verification of Termination-Preserving Refinement of Concurrent Programs (Technical Report)

Compositional Verification of Termination-Preserving Refinement of Concurrent Programs (Technical Report) Compositional Verification of Termination-Preserving Refinement of Concurrent Programs (Technical Report) Hongjin Liang 1, Xinyu Feng 1, and Zhong Shao 2 1 University of Science and Technology of China

More information

Analysis of Algorithms Fall Basics of Algorithm Analysis Computational Tractability

Analysis of Algorithms Fall Basics of Algorithm Analysis Computational Tractability Analysis of Algorithms Fall 2017 Basics of Algorithm Analysis Computational Tractability Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University A Strikingly

More information

Trace semantics: towards a unification of parallel paradigms Stephen Brookes. Department of Computer Science Carnegie Mellon University

Trace semantics: towards a unification of parallel paradigms Stephen Brookes. Department of Computer Science Carnegie Mellon University Trace semantics: towards a unification of parallel paradigms Stephen Brookes Department of Computer Science Carnegie Mellon University MFCSIT 2002 1 PARALLEL PARADIGMS State-based Shared-memory global

More information

Tutorial 4. Dynamic Set: Amortized Analysis

Tutorial 4. Dynamic Set: Amortized Analysis Tutorial 4 Dynamic Set: Amortized Analysis Review Binary tree Complete binary tree Full binary tree 2-tree P115 Unlike common binary tree, the base case is not an empty tree, but a external node Heap Binary

More information

Reversing Lists Haskell: The craft of functional programming, by Simon Thompson, page 140

Reversing Lists Haskell: The craft of functional programming, by Simon Thompson, page 140 Reversing Lists Haskell: The craft of functional programming, by Simon Thompson, page 14 Reverse.hs rev :: [t] -> [t] rev [] = [] rev (e:l) = (rev l) ++ [e] 6 5 rev [1..n] n**2/2 4 3 2 1 2 4 6 8 1 1 Array

More information

CSE 332. Data Structures and Parallelism

CSE 332. Data Structures and Parallelism Aam Blak Lecture 6a Witer 2017 CSE 332 Data Structures a Parallelism CSE 332: Data Structures a Parallelism More Recurreces T () T (/2) T (/2) T (/4) T (/4) T (/4) T (/4) P1 De-Brief 1 You i somethig substatial!

More information

C6.2 Push-Down Automata

C6.2 Push-Down Automata Theory of Computer Science April 5, 2017 C6. Context-free Languages: Push-down Automata Theory of Computer Science C6. Context-free Languages: Push-down Automata Malte Helmert University of Basel April

More information

An Improved Schedulability Test for Uniprocessor. Periodic Task Systems

An Improved Schedulability Test for Uniprocessor. Periodic Task Systems An Improved Schedulability Test for Uniprocessor Periodic Task Systems UmaMaheswari C. Devi Department of Computer Science, University of North Carolina, Chapel Hill, NC 27599-375 December 2002 Abstract

More information

MIT Loop Optimizations. Martin Rinard

MIT Loop Optimizations. Martin Rinard MIT 6.035 Loop Optimizations Martin Rinard Loop Optimizations Important because lots of computation occurs in loops We will study two optimizations Loop-invariant code motion Induction variable elimination

More information

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions Prof. Martha A. Kim Columbia University Due October 10, 2013 at 10:10 AM Write your name and UNI on your solutions Show your

More information

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk CMPS 6610 Fall 018 Shortest Paths Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk Paths in graphs Consider a digraph G = (V, E) with an edge-weight function w

More information

Lecture 7: Amortized analysis

Lecture 7: Amortized analysis Lecture 7: Amortized analysis In many applications we want to minimize the time for a sequence of operations. To sum worst-case times for single operations can be overly pessimistic, since it ignores correlation

More information

Unifying Theories of Programming

Unifying Theories of Programming 1&2 Unifying Theories of Programming Unifying Theories of Programming 3&4 Theories Unifying Theories of Programming designs predicates relations reactive CSP processes Jim Woodcock University of York May

More information

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida Algorithms Jordi Planes Escola Politècnica Superior Universitat de Lleida 2016 Syllabus What s been done Formal specification Computational Cost Transformation recursion iteration Divide and conquer Sorting

More information

Supplementary Materials to Learning Sparse Causal Gaussian Networks With Experimental Intervention: Regularization and Coordinate Descent

Supplementary Materials to Learning Sparse Causal Gaussian Networks With Experimental Intervention: Regularization and Coordinate Descent Supplementary Materials to Learning Sparse Causal Gaussian Networks With Experimental Intervention: Regularization and Coordinate Descent Fei Fu and Qing Zhou 1 Proofs 1.1 Proof of Proposition 1 [ ( We

More information

I Credit I Max I Problem 1 20 Problem 2 20 Problem 3 20 Problem 4 20

I Credit I Max I Problem 1 20 Problem 2 20 Problem 3 20 Problem 4 20 ICOT5405: ANALYSIS OF ALGORITHMSI IMid-Term Exam U Date: Feb 16, 2006, Thursday Time: 10:40am - 12:40pm Professor: Alpe~ :Ungar (Office CSE 430) This is a closed book exam. No collaborations are allowed.

More information

Declarative Programming Techniques

Declarative Programming Techniques Declarative Programming Techniques Accumulators (CTM 3.4.3) Difference Lists (CTM 3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL December 1, 2015 C. Varela; Adapted

More information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Data Structures and Algorithm Xiaoqing Zheng zhengxq@fudan.edu.cn MULTIPOP top[s] = 6 top[s] = 2 3 2 8 5 6 5 S MULTIPOP(S, x). while not STACK-EMPTY(S) and k 0 2. do POP(S) 3. k k MULTIPOP(S, 4) Analysis

More information

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ;

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ; CPSC 490 Input Input will always arrive on stdin. You may assume input is well-formed with respect to the problem specification; inappropriate input (e.g. text where a number was specified, number out

More information

Array-based Hashtables

Array-based Hashtables Array-based Hashtables For simplicity, we will assume that we only insert numeric keys into the hashtable hash(x) = x % B; where B is the number of 5 Implementation class Hashtable { int [B]; bool occupied[b];

More information

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Salil Vadhan October 4, 2012 Reading: Sipser, 2.2. Another example of a CFG (with proof) L = {x {a, b} : x has the same # of a s and

More information

Relaying Information Streams

Relaying Information Streams Relaying Information Streams Anant Sahai UC Berkeley EECS sahai@eecs.berkeley.edu Originally given: Oct 2, 2002 This was a talk only. I was never able to rigorously formalize the back-of-the-envelope reasoning

More information

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton

More information

Computer Science. Questions for discussion Part II. Computer Science COMPUTER SCIENCE. Section 4.2.

Computer Science. Questions for discussion Part II. Computer Science COMPUTER SCIENCE. Section 4.2. COMPUTER SCIENCE S E D G E W I C K / W A Y N E PA R T I I : A L G O R I T H M S, T H E O R Y, A N D M A C H I N E S Computer Science Computer Science An Interdisciplinary Approach Section 4.2 ROBERT SEDGEWICK

More information

On Reducing Linearizability to State Reachability 1

On Reducing Linearizability to State Reachability 1 On Reducing Linearizability to State Reachability 1 Ahmed Bouajjani a, Michael Emmi b, Constantin Enea a, Jad Hamza a a LIAFA, Université Paris Diderot b IMDEA Software Institute, Spain Abstract Ecient

More information

Declarative Programming Techniques

Declarative Programming Techniques Declarative Programming Techniques Accumulators and Difference Lists (CTM 3.4.3-3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL February 12, 2015 C. Varela; Adapted

More information

Equivalence Relations. Equivalence Classes. A new question. Building Equivalence Classes. CSE 326: Data Structures Disjoint Union/Find

Equivalence Relations. Equivalence Classes. A new question. Building Equivalence Classes. CSE 326: Data Structures Disjoint Union/Find Equivalence Relations CE : Data tructures Disjoint Union/Find Relation R : For every pair of elements (a, b) in a set, a R b is either true or false If a R b is true, then a is related to b An equivalence

More information

CPS 220 Theory of Computation Pushdown Automata (PDA)

CPS 220 Theory of Computation Pushdown Automata (PDA) CPS 220 Theory of Computation Pushdown Automata (PDA) Nondeterministic Finite Automaton with some extra memory Memory is called the stack, accessed in a very restricted way: in a First-In First-Out fashion

More information

Binary Search Trees. Motivation

Binary Search Trees. Motivation Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary

More information

Heaps and Priority Queues

Heaps and Priority Queues Heaps and Priority Queues Motivation Situations where one has to choose the next most important from a collection. Examples: patients in an emergency room, scheduling programs in a multi-tasking OS. Need

More information

that shows the semi-decidability of the problem (i.e. a semi-decision procedure for EXISTS-HALTING) and argue that it is correct.

that shows the semi-decidability of the problem (i.e. a semi-decision procedure for EXISTS-HALTING) and argue that it is correct. Exercise 1 (15) Consider the following problem: EXISTS-HALTING INSTANCE: A program Π, which takes as input a string over the alphabet {a, b, c,..., z}. QUESTION: Does there exist an input I, such that

More information

Algorithms Theory. 08 Fibonacci Heaps

Algorithms Theory. 08 Fibonacci Heaps Algorithms Theory 08 Fibonacci Heaps Prof. Dr. S. Albers Priority queues: operations Priority queue Q Operations: Q.initialize(): initializes an empty queue Q Q.isEmpty(): returns true iff Q is empty Q.insert(e):

More information

Queueing Theory and Simulation. Introduction

Queueing Theory and Simulation. Introduction Queueing Theory and Simulation Based on the slides of Dr. Dharma P. Agrawal, University of Cincinnati and Dr. Hiroyuki Ohsaki Graduate School of Information Science & Technology, Osaka University, Japan

More information

TIME BOUNDS FOR SHARED OBJECTS IN PARTIALLY SYNCHRONOUS SYSTEMS. A Thesis JIAQI WANG

TIME BOUNDS FOR SHARED OBJECTS IN PARTIALLY SYNCHRONOUS SYSTEMS. A Thesis JIAQI WANG TIME BOUNDS FOR SHARED OBJECTS IN PARTIALLY SYNCHRONOUS SYSTEMS A Thesis by JIAQI WANG Submitted to the Office of Graduate Studies of Texas A&M University in partial fulfillment of the requirements for

More information

CS213d Data Structures and Algorithms

CS213d Data Structures and Algorithms CS21d Data Structures and Algorithms Heaps and their Applications Milind Sohoni IIT Bombay and IIT Dharwad March 22, 2017 1 / 18 What did I see today? March 22, 2017 2 / 18 Heap-Trees A tree T of height

More information

Bloom Filter Redux. CS 270 Combinatorial Algorithms and Data Structures. UC Berkeley, Spring 2011

Bloom Filter Redux. CS 270 Combinatorial Algorithms and Data Structures. UC Berkeley, Spring 2011 Bloom Filter Redux Matthias Vallentin Gene Pang CS 270 Combinatorial Algorithms and Data Structures UC Berkeley, Spring 2011 Inspiration Our background: network security, databases We deal with massive

More information

Part III. Data Structures. Abstract Data Type. Dynamic Set Operations. Dynamic Set Operations

Part III. Data Structures. Abstract Data Type. Dynamic Set Operations. Dynamic Set Operations Abstract Data Type Part III Data Structures An abstract data type (ADT) is defined by an interface of operations or methods that can be performed and that have a defined behavior. The data types in this

More information

Regulating the Pace of von Neumann Correctors

Regulating the Pace of von Neumann Correctors Regulating the Pace of von Neumann Correctors Houda Ferradi 1, Rémi Géraud 1,2, Diana Maimuţ 1, David Naccache 1, and Amaury de Wargny 2 1 École normale supérieure 45 rue d Ulm, f-75230 Paris cedex 05,

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and

More information

QUEUING SYSTEM. Yetunde Folajimi, PhD

QUEUING SYSTEM. Yetunde Folajimi, PhD QUEUING SYSTEM Yetunde Folajimi, PhD Part 2 Queuing Models Queueing models are constructed so that queue lengths and waiting times can be predicted They help us to understand and quantify the effect of

More information

DES. 4. Petri Nets. Introduction. Different Classes of Petri Net. Petri net properties. Analysis of Petri net models

DES. 4. Petri Nets. Introduction. Different Classes of Petri Net. Petri net properties. Analysis of Petri net models 4. Petri Nets Introduction Different Classes of Petri Net Petri net properties Analysis of Petri net models 1 Petri Nets C.A Petri, TU Darmstadt, 1962 A mathematical and graphical modeling method. Describe

More information