How many times is the loop executed? middle = (left+right)/2; if (value == arr[middle]) return true;

Size: px
Start display at page:

Download "How many times is the loop executed? middle = (left+right)/2; if (value == arr[middle]) return true;"

Transcription

1 This lectue Complexity o binay seach Answes to inomal execise Abstact data types Stacks ueues ADTs, Stacks, ueues 1 binayseach(int[] a, int value) { while (ight >= let) { { i (value < a[middle]) ight = middle-1; let = middle+1; etun alse; ADTs, Stacks, ueues 2 Complexity o binay seach Complexity o binay seach binayseach(int[] a, int value) { Let n be the size o aay while (ight >= let) { How many times is the loop executed? { i (value < a[middle]) ight = middle-1; let = middle+1; etun alse; ADTs, Stacks, ueues 3 binayseach(int[] a, int value) { Let n be the size o aay while (ight let) { How many times is the loop executed? n { n/2 (n/2)/2 i (value < a[middle]) ight = middle-1; ((n/2)/2)/2 let = middle+1; In the wost case, until ((n/2) )/2 = 1 x times, whee 2 x n and 2 x-1 < n etun alse; x is log 2 n, ounded up to an intege ADTs, Stacks, ueues 4 Example: n = 10, value = 19 Complexity o binay seach let = 0, binayseach(int[] a, int value) { Let n be the size o aay ight= 9, middle = 4 constant time let = 0, opeations: c ight= 3, middle = 1 while (ight >= let) { loop executed log 2 n times let = 2, ight= 3, middle = 2 { constant time 19 let = 3, i (value < a[middle]) ight = middle-1; opeations: c 2 ight= 3, let = middle+1; middle = 3 n = 10, log 2 10 ounded up to an intege is 4. t(n) = c 1 + c 2 log 2 n+ c 3 Hint: given n, look o the next lagest powe o 2 etun alse; constant time opeation: c 3 and take log 2 o that. ADTs, Stacks, ueues 5 ADTs, Stacks, ueues 6 1

2 Finally Pove that c 1 + c 2 log 2 n+ c 3 O(log 2 n). Need to ind n 0 and c such that o all n n 0, c 1 + c 2 log 2 n+ c 3 c log 2 n Let n 0 be 2; then o all n n 0, log 2 n 1. So, o all n n 0, c 1 + c 2 log 2 n+ c 3 c 1 log 2 n+ c 2 log 2 n+ c 3 log 2 n and o all n n 0, c 1 + c 2 log 2 n+ c 3 (c 1 + c 2 + c 3 ) log 2 n Set n 0 = 2 and c = c 1 + c 2 + c 3. n O(n 2 ) Pove that n is in O(n 2 ). Need to ind n 0 and c such that o all n n 0, n c n 2 Let n 0 be 1; then o all n n 0, log 2 n n and n n 2 So, o all n n 0, n 7n n 2 + n 2 and o all n n 0, n ( ) n 2 Set n 0 = 1 and c = 18. ADTs, Stacks, ueues 7 ADTs, Stacks, ueues 8 n O(n) I we wee to pove that n is in O(n), we d need to ind n 0 and c such that o all n n 0, n c n Fo all such n 0 and c it will also hold that o all n n 0, 7n n c n (note o n 1, log 2 n is positive) 7n + 10 c n (c-10)/7 Thee is obviously no such n 0 and c: whateve values o n 0 and c we ix, we can also ind n n 0 which is lage than (c-10)/7. O(log a n) = O(log b n) Suppose (n) is in O(log a n). We pove that it is in O(log b n). I (n) is in O(log a n), thee exist n 0 and c such that o all n n 0, (n) c log a n. We know that log a n = log a b log b n (see Math to eview) Fo example, log 2 64 = log 2 8 log = 3 2 So, i (n) c log a n, then (n) c log a b log b n log a b is a constant acto, so we can deine a new constant c =clog a b and we have: o all n n 0, (n) c log b n, hence (n) is in O(log b n). ADTs, Stacks, ueues 9 ADTs, Stacks, ueues 10 Abstact Data Types (ADTs) Stacks An abstact data type (ADT) is an abstaction o a data stuctue An ADT speciies: Data stoed Opeations on the data Eo conditions associated with opeations Example: ADT modeling a simple stock tading system The data stoed ae buy/sell odes The opeations suppoted ae ode buy(stock, shaes, pice) ode sell(stock, shaes, pice) void cancel(ode) Eo conditions: Buy/sell a nonexistent stock Cancel a nonexistent ode ADTs, Stacks, ueues 11 ADTs, Stacks, ueues 12 2

3 The Stack ADT ( 4.2) The Stack ADT stoes abitay objects Insetions and deletions ollow the last-in ist-out scheme Think o a sping-loaded plate dispense Main stack opeations: push(object): insets an element object pop(): emoves and etuns the last inseted element Auxiliay stack opeations: object top(): etuns the last inseted element without emoving it intege size(): etuns the numbe o elements stoed boolean isempty(): indicates whethe no elements ae stoed Stack Inteace in Java Java inteace coesponding to ou Stack ADT Requies the deinition o class EmptyStackException Dieent om the built-in Java class java.util.stack public inteace Stack { public int size(); public boolean isempty(); public Object top() thows EmptyStackException; public void push(object o); public Object pop() thows EmptyStackException; ADTs, Stacks, ueues 13 ADTs, Stacks, ueues 14 Exceptions Attempting the execution o an opeation o ADT may sometimes cause an eo condition, called an exception Exceptions ae said to be thown by an opeation that cannot be executed In the Stack ADT, opeations pop and top cannot be peomed i the stack is empty Attempting the execution o pop o top on an empty stack thows an EmptyStackException Applications o Stacks Diect applications Page-visited histoy in a Web bowse Undo sequence in a text edito Chain o method calls in the Java Vitual Machine Indiect applications Auxiliay data stuctue o algoithms Component o othe data stuctues ADTs, Stacks, ueues 15 ADTs, Stacks, ueues 16 Method Stack in the JVM The Java Vitual Machine (JVM) keeps tack o the chain o active methods with a stack When a method is called, the JVM pushes on the stack a ame containing Local vaiables and etun value Pogam counte, keeping tack o the statement being executed When a method ends, its ame is popped om the stack and contol is passed to the method on top o the stack Allows o ecusion main() { int i = 5; oo(i); oo(int j) { int k; k = j+1; ba(k); ba(int m) { ba PC = 1 m = 6 oo PC = 3 j = 5 k = 6 main PC = 2 i = 5 ADTs, Stacks, ueues 17 Aay-based Stack A simple way o implementing the Stack ADT uses an aay We add elements om let to ight A vaiable keeps tack o the index o the top element S Algoithm size() etun t +1 Algoithm pop() i isempty() then thow EmptyStackException t t 1 etun S[t +1] t ADTs, Stacks, ueues 18 3

4 Aay-based Stack (cont.) The aay stoing the stack elements may become ull A push opeation will then thow a FullStackException Limitation o the aaybased implementation Not intinsic to the Stack ADT S Algoithm push(o) i t = S.length 1 then thow FullStackException t t +1 S[t] o t ADTs, Stacks, ueues 19 Peomance and Limitations Peomance Let n be the numbe o elements in the stack The space used is O(n) Each opeation uns in time O(1) Limitations The maximum size o the stack must be deined a pioi and cannot be changed Tying to push a new element into a ull stack causes an implementation-speciic exception ADTs, Stacks, ueues 20 Aay-based Stack in Java Paentheses Matching public class AayStack implements Stack { // holds the stack elements pivate Object S[ ]; // index to top element pivate int top = -1; // constucto public AayStack(int capacity) { S = new Object[capacity]); public Object pop() thows EmptyStackException { i isempty() thow new EmptyStackException ( Empty stack: cannot pop ); Object temp = S[top]; // acilitates gabage collection S[top] = null; top = top 1; etun temp; Each (, {, o [ must be paied with a matching ),, o [ coect: ( )(( )){([( )]) coect: ((( )(( )){([( )]) incoect: )(( )){([( )]) incoect: ({[ ]) incoect: ( ADTs, Stacks, ueues 21 ADTs, Stacks, ueues 22 Paentheses Matching Algoithm Algoithm PaenMatch(X,n): Input: An aay X o n tokens, each o which is eithe a gouping symbol, a vaiable, an aithmetic opeato, o a numbe Output: tue i and only i all the gouping symbols in X match Let S be an empty stack o i=0 to n-1 do i X[i] is an opening gouping symbol then S.push(X[i]) i X[i] is a closing gouping symbol then i S.isEmpty() then etun alse {nothing to match with i S.pop() does not match the type o X[i] then etun alse {wong type i S.isEmpty() then etun tue {evey symbol matched etun alse {some symbols wee neve matched ueues ADTs, Stacks, ueues 23 ADTs, Stacks, ueues 24 4

5 The ueue ADT ( 4.3) The ueue ADT stoes abitay objects Insetions and deletions ollow the ist-in ist-out scheme Insetions ae at the ea o the queue and emovals ae at the ont o the queue Main queue opeations: enqueue(object): insets an element at the end o the queue object dequeue(): emoves and etuns the element at the ont o the queue Auxiliay queue opeations: object ont(): etuns the element at the ont without emoving it intege size(): etuns the numbe o elements stoed boolean isempty(): indicates whethe no elements ae stoed Exceptions Attempting the execution o dequeue o ont on an empty queue thows an EmptyueueException ueue Example Opeation Output enqueue(5) (5) enqueue(3) (5, 3) dequeue() 5 (3) enqueue(7) (3, 7) dequeue() 3 (7) ont() 7 (7) dequeue() 7 () dequeue() eo () isempty() tue () enqueue(9) (9) enqueue(7) (9, 7) size() 2 (9, 7) enqueue(3) (9, 7, 3) enqueue(5) (9, 7, 3, 5) dequeue() 9 (7, 3, 5) ADTs, Stacks, ueues 25 ADTs, Stacks, ueues 26 Applications o ueues Diect applications Waiting lists, bueaucacy Access to shaed esouces (e.g., pinte) Multipogamming Indiect applications Auxiliay data stuctue o algoithms Component o othe data stuctues ADTs, Stacks, ueues 27 Aay-based ueue Use an aay o size N in a cicula ashion Two vaiables keep tack o the ont and ea index o the ont element index immediately past the ea element Aay location is kept empty nomal coniguation wapped-aound coniguation 012 ADTs, Stacks, ueues 28 ueue Opeations We use the modulo opeato (emainde o division) Algoithm size() etun (N + ) mod N Algoithm isempty() etun ( = ) ueue Opeations (cont.) Opeation enqueue thows an exception i the aay is ull This exception is implementationdependent Algoithm enqueue(o) i size() = N 1 then thow FullueueException [] o ( + 1) mod N ADTs, Stacks, ueues 29 ADTs, Stacks, ueues 30 5

6 ueue Opeations (cont.) Opeation dequeue thows an exception i the queue is empty This exception is speciied in the queue ADT 012 Algoithm dequeue() i isempty() then thow EmptyueueException o [] ( + 1) mod N etun o ueue Inteace in Java Java inteace coesponding to ou ueue ADT Requies the deinition o class EmptyueueException No coesponding built-in Java class public inteace ueue { public int size(); public boolean isempty(); public Object ont() thows EmptyueueException; public void enqueue(object o); public Object dequeue() thows EmptyueueException; ADTs, Stacks, ueues 31 ADTs, Stacks, ueues 32 Application: Round Robin Schedules We can implement a ound obin schedule using a queue,, by epeatedly peoming the ollowing steps: 1. e =.dequeue() 2. Sevice element e 3..enqueue(e) The ueue 1. Deque the next element 2. Sevice the next element 3. Enqueue the seviced element Shaed Sevice ADTs, Stacks, ueues 33 6

This lecture. Abstract Data Types (ADTs) The Stack ADT ( 4.2) Stacks. Stack Interface in Java. Exceptions. Abstract data types Stacks Queues

This lecture. Abstract Data Types (ADTs) The Stack ADT ( 4.2) Stacks. Stack Interface in Java. Exceptions. Abstract data types Stacks Queues This lectue Abstact data types Stacks ueues Abstact Data Types (ADTs) An abstact data type (ADT) is an abstaction o a data stuctue An ADT speciies: Data stoed Opeations on the data Eo conditions associated

More information

Outline and Reading. The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.

Outline and Reading. The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1. Stacks Outline and Reading The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.5) Stacks 2 Abstract Data Types (ADTs) An abstract data

More information

Outline and Reading. The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack.

Outline and Reading. The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack. Stacks Outline and Reading The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack Stacks 2 Abstract Data Types (ADTs) An abstract data type

More information

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University

1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Chapter 5: Stacks, ueues and Deques Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,

More information

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011 Stacks (5.1) CSE 2011 Winter 2011 26 January 2011 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error

More information

Foundations of Data Structures

Foundations of Data Structures Foundations of Data Structures Lecture 4 Elementary Abstract Data Types (ADT): Stack Queue 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies:

More information

Stacks Goodrich, Tamassia

Stacks Goodrich, Tamassia Stacks Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error conditions associated with operations Example:

More information

COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)

COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004) COMP250: Stacks Jérôme Waldispühl School of Computer Science McGill University Based on slides from (Goodrich & Tamassia, 2004) 2004 Goodrich, Tamassia The Stack ADT A Stack ADT is a list that allows only

More information

HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS

HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS SYLLABUS ABSTRACT DATA TYPES (ADTS) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations

More information

COMP9024: Data Structures and Algorithms

COMP9024: Data Structures and Algorithms COMP9024: Data Structures and Algorithms Week Four: Stacks and Queues Hui Wu Session 2, 2015 http://www.cse.unsw.edu.au/~cs9024 1 Outline Stacks Queues 2 Stacks 3 Abstract Data Types (ADTs) An abstract

More information

Stacks Goodrich, Tamassia Stacks

Stacks Goodrich, Tamassia Stacks Stacks Stacks 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error conditions associated with operations

More information

Stacks. Lecture6: Stacks. Stack Operations. Stack Interface in Java

Stacks. Lecture6: Stacks. Stack Operations. Stack Interface in Java Stacks (01F) Lecture6: Stacks What is stack? An abstract data type storing arbitrary objects. An ordered list in which all insertions and deletions are made at one end, called top Push Pop Top Bohyung

More information

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER

More information

Data Structures Lecture 5

Data Structures Lecture 5 Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 5 Announcement Project Proposal due on Nov. 9 Remember to bring a hardcopy

More information

Stacks Goodrich, Tamassia, Goldwasser Stacks

Stacks Goodrich, Tamassia, Goldwasser Stacks Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Stacks Stacks 1 The Stack ADT The Stack ADT

More information

Lecture 3 Linear Data Structures: Arrays, Array Lists, Stacks, Queues and Linked Lists

Lecture 3 Linear Data Structures: Arrays, Array Lists, Stacks, Queues and Linked Lists Lecture 3 Linear Data Structures: Arrays, Array Lists, Stacks, Queues and Linked Lists Chapters 3.1-3.3, 5.1-5.2, 6.1-1 - Core Collection Interfaces - 2 - The Java Collections Framework Interface Abstract

More information

Lecture 3 Linear Data Structures

Lecture 3 Linear Data Structures Lecture 3 Linear Data Structures - 1 - Learning Outcomes Based on this lecture, you should: Know the basic linear data structures Be able to express each as an Abstract Data Type (ADT) Be able to specify

More information

Lecture 3 Linear Data Structures

Lecture 3 Linear Data Structures Lecture 3 Linear Data Structures Chapters 3.1-3.3, 5.1-5.2, 6.1-1 - Outline Our goal in this lecture is to Review the basic linear data structures Demonstrate how each can be defined as an Abstract Data

More information

csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks

More information

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified. The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO - last in, first out Stacks 2 The

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a

More information

The Java Virtual Machine. Compiler construction The structure of a frame. JVM stacks. Lecture 2

The Java Virtual Machine. Compiler construction The structure of a frame. JVM stacks. Lecture 2 Compile constuction 2009 Lectue 2 Code geneation 1: Geneating code The Java Vitual Machine Data types Pimitive types, including intege and floating-point types of vaious sizes and the boolean type. The

More information

a Not yet implemented in current version SPARK: Research Kit Pointer Analysis Parameters Soot Pointer analysis. Objectives

a Not yet implemented in current version SPARK: Research Kit Pointer Analysis Parameters Soot Pointer analysis. Objectives SPARK: Soot Reseach Kit Ondřej Lhoták Objectives Spak is a modula toolkit fo flow-insensitive may points-to analyses fo Java, which enables expeimentation with: vaious paametes of pointe analyses which

More information

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal Queues COL 106 Slides by Amit Kumar, Shweta Agrawal The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out (FIFO) scheme Insertions are at the rear

More information

Lecture 3 Linear Data Structures

Lecture 3 Linear Data Structures Lecture 3 Linear Data Structures - 1 - Learning Outcomes Based on this lecture, you should: Know the basic linear data structures Be able to express each as an Abstract Data Type (ADT) Be able to specify

More information

GARBAGE COLLECTION METHODS. Hanan Samet

GARBAGE COLLECTION METHODS. Hanan Samet gc0 GARBAGE COLLECTION METHODS Hanan Samet Compute Science Depatment and Cente fo Automation Reseach and Institute fo Advanced Compute Studies Univesity of Mayland College Pak, Mayland 07 e-mail: hjs@umiacs.umd.edu

More information

Monitors. Lecture 6. A Typical Monitor State. wait(c) Signal and Continue. Signal and What Happens Next?

Monitors. Lecture 6. A Typical Monitor State. wait(c) Signal and Continue. Signal and What Happens Next? Monitos Lectue 6 Monitos Summay: Last time A combination of data abstaction and mutual exclusion Automatic mutex Pogammed conditional synchonisation Widely used in concuent pogamming languages and libaies

More information

DataStruct 5. Stacks, Queues, and Deques

DataStruct 5. Stacks, Queues, and Deques 2013-2 DataStruct 5. Stacks, Queues, and Deques Michael T. Goodrich, et. al, Data Structures and Algorithms in C++, 2 nd Ed., John Wiley & Sons, Inc., 2011. October 30, 2013 Advanced Networking Technology

More information

dc - Linux Command Dc may be invoked with the following command-line options: -V --version Print out the version of dc

dc - Linux Command Dc may be invoked with the following command-line options: -V --version Print out the version of dc - CentOS 5.2 - Linux Uses Guide - Linux Command SYNOPSIS [-V] [--vesion] [-h] [--help] [-e sciptexpession] [--expession=sciptexpession] [-f sciptfile] [--file=sciptfile] [file...] DESCRIPTION is a evese-polish

More information

3/1/18. Overview. Program Representations. Abstract Syntax Tree (AST) Eclipse JDT. Java Model. The Tree Structure of Java Project[2]

3/1/18. Overview. Program Representations. Abstract Syntax Tree (AST) Eclipse JDT. Java Model. The Tree Structure of Java Project[2] Oveview Pogam Reesentations Abstact Syntax Tee Eclise JDT Java Model Eclise JDT AST Contol Flow Gah Pogam Deendence Gah Points-to Gah Call Gah 2 Abstact Syntax Tee (AST) Ceated by the comile at the end

More information

DYNAMIC STORAGE ALLOCATION. Hanan Samet

DYNAMIC STORAGE ALLOCATION. Hanan Samet ds0 DYNAMIC STORAGE ALLOCATION Hanan Samet Compute Science Depatment and Cente fo Automation Reseach and Institute fo Advanced Compute Studies Univesity of Mayland College Pak, Mayland 07 e-mail: hjs@umiacs.umd.edu

More information

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.

More information

Elementary Data Structures. Stacks, Queues, & Lists Amortized analysis Trees

Elementary Data Structures. Stacks, Queues, & Lists Amortized analysis Trees Elementary Data Structures Stacks, Queues, & Lists Amortized analysis Trees The Stack ADT ( 2.1.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in first-out scheme Think

More information

CT 229 Object-Oriented Programming Continued

CT 229 Object-Oriented Programming Continued CT 229 Object-Oriented Programming Continued 24/11/2006 CT229 Summary - Inheritance Inheritance is the ability of a class to use the attributes and methods of another class while adding its own functionality

More information

Query Language #1/3: Relational Algebra Pure, Procedural, and Set-oriented

Query Language #1/3: Relational Algebra Pure, Procedural, and Set-oriented Quey Language #1/3: Relational Algeba Pue, Pocedual, and Set-oiented To expess a quey, we use a set of opeations. Each opeation takes one o moe elations as input paamete (set-oiented). Since each opeation

More information

CMSC 132: Object-Oriented Programming II. Stack and Queue

CMSC 132: Object-Oriented Programming II. Stack and Queue CMSC 132: Object-Oriented Programming II Stack and Queue 1 Stack Allows access to only the last item inserted. An item is inserted or removed from the stack from one end called the top of the stack. This

More information

THE THETA BLOCKCHAIN

THE THETA BLOCKCHAIN THE THETA BLOCKCHAIN Theta is a decentalized video steaming netwok, poweed by a new blockchain and token. By Theta Labs, Inc. Last Updated: Nov 21, 2017 esion 1.0 1 OUTLINE Motivation Reputation Dependent

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very

More information

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

More information

CS 5114: Theory of Algorithms. Sorting. Insertion Sort. Exchange Sorting. Clifford A. Shaffer. Spring 2010

CS 5114: Theory of Algorithms. Sorting. Insertion Sort. Exchange Sorting. Clifford A. Shaffer. Spring 2010 Depatment of Compute Science Viginia Tech Backsbug, Viginia Copyight c 10 by Ciffod A. Shaffe 3 4 5 7 : Theoy of Agoithms Tite page : Theoy of Agoithms Ciffod A. Shaffe Sping 10 Ciffod A. Shaffe Depatment

More information

CSE Data Structures and Algorithms... In Java! Stacks. CSE2100 DS & Algorithms 1

CSE Data Structures and Algorithms... In Java! Stacks. CSE2100 DS & Algorithms 1 CSE 2100 Data Structures and Algorithms... In Java Stacks 1 What is Stack A stack is a collection of objects that are inserted and removed according to the last-in, first-out (LIFO) principle. Internet

More information

Lecture #22 Pipelining II, Cache I

Lecture #22 Pipelining II, Cache I inst.eecs.bekeley.edu/~cs61c CS61C : Machine Stuctues Lectue #22 Pipelining II, Cache I Wiewold cicuits 2008-7-29 http://www.maa.og/editoial/mathgames/mathgames_05_24_04.html http://www.quinapalus.com/wi-index.html

More information

A Memory Efficient Array Architecture for Real-Time Motion Estimation

A Memory Efficient Array Architecture for Real-Time Motion Estimation A Memoy Efficient Aay Achitectue fo Real-Time Motion Estimation Vasily G. Moshnyaga and Keikichi Tamau Depatment of Electonics & Communication, Kyoto Univesity Sakyo-ku, Yoshida-Honmachi, Kyoto 66-1, JAPAN

More information

2D Transformations. Why Transformations. Translation 4/17/2009

2D Transformations. Why Transformations. Translation 4/17/2009 4/7/9 D Tansfomations Wh Tansfomations Coodinate sstem tansfomations Placing objects in the wold Move/animate the camea fo navigation Dawing hieachical chaactes Animation Tanslation + d 5,4 + d,3 d 4,

More information

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. Stacks 1 Stacks The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. 2 Main stack operations Insertion and removal are defined by: push(e): inserts

More information

COEN-4730 Computer Architecture Lecture 2 Review of Instruction Sets and Pipelines

COEN-4730 Computer Architecture Lecture 2 Review of Instruction Sets and Pipelines 1 COEN-4730 Compute Achitectue Lectue 2 Review of nstuction Sets and Pipelines Cistinel Ababei Dept. of Electical and Compute Engineeing Maquette Univesity Cedits: Slides adapted fom pesentations of Sudeep

More information

You Are Here! Review: Hazards. Agenda. Agenda. Review: Load / Branch Delay Slots 7/28/2011

You Are Here! Review: Hazards. Agenda. Agenda. Review: Load / Branch Delay Slots 7/28/2011 CS 61C: Geat Ideas in Compute Achitectue (Machine Stuctues) Instuction Level Paallelism: Multiple Instuction Issue Guest Lectue: Justin Hsia Softwae Paallel Requests Assigned to compute e.g., Seach Katz

More information

Apply to be a Meiklejohn! tinyurl.com/meikapply

Apply to be a Meiklejohn! tinyurl.com/meikapply Apply to be a Meiklejohn! tinyurl.com/meikapply Seeking a community to discuss the intersections of CS and positive social change? Interested in facilitating collaborations between students and non-profit

More information

DYNAMIC STORAGE ALLOCATION. Hanan Samet

DYNAMIC STORAGE ALLOCATION. Hanan Samet ds0 DYNAMIC STORAGE ALLOCATION Hanan Samet Compute Science Depatment and Cente fo Automation Reseach and Institute fo Advanced Compute Studies Univesity of Mayland College Pak, Mayland 074 e-mail: hjs@umiacs.umd.edu

More information

ADT Stack. Inserting and deleting elements occurs at the top of Stack S. top. bottom. Stack S

ADT Stack. Inserting and deleting elements occurs at the top of Stack S. top. bottom. Stack S Stacks Stacks & Queues A linear sequence, or list, is an ordered collection of elements: S = (s 1, s 2,..., s n ) Stacks and queues are finite linear sequences. A Stack is a LIFO (Last In First Out) list.

More information

Basic Data Structures

Basic Data Structures Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1

More information

Getting Started PMW-EX1/PMW-EX3. 1 Rotate the grip with the RELEASE button pressed. Overview. Connecting the Computer and PMW-EX1/EX3

Getting Started PMW-EX1/PMW-EX3. 1 Rotate the grip with the RELEASE button pressed. Overview. Connecting the Computer and PMW-EX1/EX3 A PMW-EX1/PMW-EX3 Getting Stated Oveview This document descibes how to use the XDCAM EX Vesion Up Tool (heeafte Vesion Up Tool ) to upgade the PMW-EX1 and PMW-EX3 to vesion 1.20 (PMW-EX1) o vesion 1.10

More information

CENG 3420 Computer Organization and Design. Lecture 07: MIPS Processor - II. Bei Yu

CENG 3420 Computer Organization and Design. Lecture 07: MIPS Processor - II. Bei Yu CENG 3420 Compute Oganization and Design Lectue 07: MIPS Pocesso - II Bei Yu CEG3420 L07.1 Sping 2016 Review: Instuction Citical Paths q Calculate cycle time assuming negligible delays (fo muxes, contol

More information

Basic Data Structures 1 / 24

Basic Data Structures 1 / 24 Basic Data Structures 1 / 24 Outline 1 Some Java Preliminaries 2 Linked Lists 3 Bags 4 Queues 5 Stacks 6 Performance Characteristics 2 / 24 Some Java Preliminaries Generics (aka parametrized types) is

More information

Building Java Programs

Building Java Programs Building Java Programs Appendix Q Lecture Q-1: stacks and queues reading: appendix Q 2 Runtime Efficiency (13.2) efficiency: measure of computing resources used by code. can be relative to speed (time),

More information

Lecture 27: Voronoi Diagrams

Lecture 27: Voronoi Diagrams We say that two points u, v Y ae in the same connected component of Y if thee is a path in R N fom u to v such that all the points along the path ae in the set Y. (Thee ae two connected components in the

More information

Time allowed : 3 hours Maximum Marks: 70

Time allowed : 3 hours Maximum Marks: 70 SAMPLE PAPER-2015 CLASS-XII COMPUTER SCIENCE(C++) Time allowed : 3 hous Maximum Maks: 70 Geneal Instuction 1. Please check that this question pape contains 7 questions. 2. Please wite down seial numbe

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Queues ArrayQueue Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 10, 2014 Abstract These lecture notes are meant to be looked

More information

IT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science

IT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1 Syllabus Introduction to DSA Abstract Data Types List Operation Using Arrays Stacks Queues Recursion Link List Sorting

More information

Data Abstraction and Specification of ADTs

Data Abstraction and Specification of ADTs CITS2200 Data Structures and Algorithms Topic 4 Data Abstraction and Specification of ADTs Example The Reversal Problem and a non-adt solution Data abstraction Specifying ADTs Interfaces javadoc documentation

More information

Pledge: Signature:

Pledge: Signature: S/PM 0 Final Exam 7 May 005 Name: KEY E-mail ID: @viginia.edu Pledge: Signatue: Thee ae 80 minutes 3 hous fo this exam and 80 oints on the test; don t send too long on any one uestion! Thee is an exam

More information

Linked Structures. See Section 3.2 of the text.

Linked Structures. See Section 3.2 of the text. Linked Structures See Section 3.2 of the text. First, notice that Java allows classes to be recursive, in the sense that a class can have an element which is itself an object of that class: class Person

More information

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request. University of Toronto CSC148 Introduction to Computer Science Fall 2001 Mid Term Test Section L5101 Duration: 50 minutes Aids allowed: none Make sure that your examination booklet has 8 pages (including

More information

Any modern computer system will incorporate (at least) two levels of storage:

Any modern computer system will incorporate (at least) two levels of storage: 1 Any moden compute system will incopoate (at least) two levels of stoage: pimay stoage: andom access memoy (RAM) typical capacity 32MB to 1GB cost pe MB $3. typical access time 5ns to 6ns bust tansfe

More information

CSE 143. Lecture 4: Stacks and Queues

CSE 143. Lecture 4: Stacks and Queues CSE 143 Lecture 4: Stacks and Queues Stacks and queues Sometimes it is good to have a collection that is less powerful, but is optimized to perform certain operations very quickly. Today we will examine

More information

Image Enhancement in the Spatial Domain. Spatial Domain

Image Enhancement in the Spatial Domain. Spatial Domain 8-- Spatial Domain Image Enhancement in the Spatial Domain What is spatial domain The space whee all pixels fom an image In spatial domain we can epesent an image by f( whee x and y ae coodinates along

More information

ACT GLOBAL OPTIMIZATION COMPETITION

ACT GLOBAL OPTIMIZATION COMPETITION ACT GLOBAL OPTIMIZATION COMPETITION Page 1 Team 14: Alcatel Alenia Space Vincent Matinot Mission Analysis in the Science and Obsevation Diectoate Thiey Dagent Reseach goup on Platom & Satellite 02/02/2006,

More information

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

More information

CS 2461: Computer Architecture 1 Program performance and High Performance Processors

CS 2461: Computer Architecture 1 Program performance and High Performance Processors Couse Objectives: Whee ae we. CS 2461: Pogam pefomance and High Pefomance Pocessos Instucto: Pof. Bhagi Naahai Bits&bytes: Logic devices HW building blocks Pocesso: ISA, datapath Using building blocks

More information

Configuring RSVP-ATM QoS Interworking

Configuring RSVP-ATM QoS Interworking Configuing RSVP-ATM QoS Intewoking Last Updated: Januay 15, 2013 This chapte descibes the tasks fo configuing the RSVP-ATM QoS Intewoking featue, which povides suppot fo Contolled Load Sevice using RSVP

More information

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Instruc>on Level Parallelism

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Instruc>on Level Parallelism Agenda CS 61C: Geat Ideas in Compute Achitectue (Machine Stuctues) Instuc>on Level Paallelism Instuctos: Randy H. Katz David A. PaJeson hjp://inst.eecs.bekeley.edu/~cs61c/fa10 Review Instuc>on Set Design

More information

CSC148 Week 2. Larry Zhang

CSC148 Week 2. Larry Zhang CSC148 Week 2 Larry Zhang 1 Admin Discussion board is up (link on the course website). 2 Outline for this week Abstract Data Type Stack Queue 3 Abstract Data Type (ADT) 4 What is an abstract data type

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

Lecture # 04. Image Enhancement in Spatial Domain

Lecture # 04. Image Enhancement in Spatial Domain Digital Image Pocessing CP-7008 Lectue # 04 Image Enhancement in Spatial Domain Fall 2011 2 domains Spatial Domain : (image plane) Techniques ae based on diect manipulation of pixels in an image Fequency

More information

COSC 6385 Computer Architecture. - Pipelining

COSC 6385 Computer Architecture. - Pipelining COSC 6385 Compute Achitectue - Pipelining Sping 2012 Some of the slides ae based on a lectue by David Culle, Pipelining Pipelining is an implementation technique wheeby multiple instuctions ae ovelapped

More information

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

CS 61C: Great Ideas in Computer Architecture Instruc(on Level Parallelism: Mul(ple Instruc(on Issue

CS 61C: Great Ideas in Computer Architecture Instruc(on Level Parallelism: Mul(ple Instruc(on Issue CS 61C: Geat Ideas in Compute Achitectue Instuc(on Level Paallelism: Mul(ple Instuc(on Issue Instuctos: Kste Asanovic, Randy H. Katz hbp://inst.eecs.bekeley.edu/~cs61c/fa12 1 Paallel Requests Assigned

More information

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues INFO1x05 Tutorial 6 Heaps and Priority Queues Exercise 1: 1. How long would it take to remove the log n smallest elements from a heap that contains n entries, using the operation? 2. Suppose you label

More information

Lecture 8 Introduction to Pipelines Adapated from slides by David Patterson

Lecture 8 Introduction to Pipelines Adapated from slides by David Patterson Lectue 8 Intoduction to Pipelines Adapated fom slides by David Patteson http://www-inst.eecs.bekeley.edu/~cs61c/ * 1 Review (1/3) Datapath is the hadwae that pefoms opeations necessay to execute pogams.

More information

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

== isn t always equal?

== isn t always equal? == isn t always equal? In Java, == does the expected for primitives. int a = 26; int b = 26; // a == b is true int a = 13; int b = 26; // a == b is false Comparing two references checks if they are pointing

More information

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10 Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()

More information

Assignment 1. Check your mailbox on Thursday! Grade and feedback published by tomorrow.

Assignment 1. Check your mailbox on Thursday! Grade and feedback published by tomorrow. Assignment 1 Check your mailbox on Thursday! Grade and feedback published by tomorrow. COMP250: Queues, deques, and doubly-linked lists Lecture 20 Jérôme Waldispühl School of Computer Science McGill University

More information

Conversion Functions for Symmetric Key Ciphers

Conversion Functions for Symmetric Key Ciphers Jounal of Infomation Assuance and Secuity 2 (2006) 41 50 Convesion Functions fo Symmetic Key Ciphes Deba L. Cook and Angelos D. Keomytis Depatment of Compute Science Columbia Univesity, mail code 0401

More information

n If S is in convex position, then thee ae exactly k convex k-gons detemined by subsets of S. In geneal, howeve, S may detemine fa fewe convex k-gons.

n If S is in convex position, then thee ae exactly k convex k-gons detemined by subsets of S. In geneal, howeve, S may detemine fa fewe convex k-gons. Counting Convex Polygons in Plana Point Sets Joseph S. B. Mitchell a;1, Günte Rote b, Gopalakishnan Sundaam c, and Gehad Woeginge b a Applied Mathematics and Statistics, SUNY Stony Book, NY 11794-3600.

More information

4.2. Co-terminal and Related Angles. Investigate

4.2. Co-terminal and Related Angles. Investigate .2 Co-teminal and Related Angles Tigonometic atios can be used to model quantities such as

More information

Class 21. N -body Techniques, Part 4

Class 21. N -body Techniques, Part 4 Class. N -body Techniques, Pat Tee Codes Efficiency can be inceased by gouping paticles togethe: Neaest paticles exet geatest foces diect summation. Distant paticles exet smallest foces teat in goups.

More information

In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions.

In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions. In ode to lean which questions have been answeed coectly: 1. Pint these pages. 2. Answe the questions. 3. Send this assessment with the answes via: a. FAX to (212) 967-3498. O b. Mail the answes to the

More information

More Data Structures (Part 1) Stacks

More Data Structures (Part 1) Stacks More Data Structures (Part 1) Stacks 1 Stack examples of stacks 2 Top of Stack top of the stack 3 Stack Operations classically, stacks only support two operations 1. push 2. pop add to the top of the stack

More information

Finding point-pairs. Find Closest Point from Dense Cloud

Finding point-pairs. Find Closest Point from Dense Cloud Finding point-pais Given an a, find a coesponding b on the suface. Then one appoach would be to seach evey possible tiangle o suface point and then take the closest point. The key is to find a moe efficient

More information

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11. Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code

More information

Modeling a shared medium access node with QoS distinction

Modeling a shared medium access node with QoS distinction Modeling a shaed medium access node with QoS distinction Matthias Gies, Jonas Geutet Compute Engineeing and Netwoks Laboatoy (TIK) Swiss Fedeal Institute of Technology Züich CH-8092 Züich, Switzeland email:

More information

CS61B Spring 2016 Guerrilla Section 2 Worksheet

CS61B Spring 2016 Guerrilla Section 2 Worksheet Spring 2016 27 February 2016 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer

More information

arxiv: v4 [cs.ds] 7 Feb 2018

arxiv: v4 [cs.ds] 7 Feb 2018 Dynamic DFS in Undiected Gaphs: beaking the O(m) baie Suende Baswana Sheejit Ray Chaudhuy Keeti Choudhay Shahbaz Khan axiv:1502.02481v4 [cs.ds] 7 Feb 2018 Depth fist seach (DFS) tee is a fundamental data

More information

Data Structures G5029

Data Structures G5029 Data Structures G5029 Lecture 2 Kingsley Sage Room 5C16, Pevensey III khs20@sussex.ac.uk University of Sussex 2006 Lecture 2 Stacks The usual analogy is the stack of plates. A way of buffering a stream

More information

data structures and algorithms lecture 6

data structures and algorithms lecture 6 data structures and algorithms 2017 09 21 lecture 6 overview lower bound counting sort radix sort stacks queues material question we have seen for example insertion sort: worst-case in O(n 2 ) merge sort:

More information

UNION FIND. naïve linking link-by-size link-by-rank path compression link-by-rank with path compression context. An Improved Equivalence Algorithm

UNION FIND. naïve linking link-by-size link-by-rank path compression link-by-rank with path compression context. An Improved Equivalence Algorithm Disjoint-sets data type Lectue slides by Kevin Wayne Copyight 5 Peason-Addison Wesley http://www.cs.pinceton.edu/~wayne/kleinbeg-tados UNION FIND naïve linking link-by-size link-by-ank path compession

More information

Accelerating Storage with RDMA Max Gurtovoy Mellanox Technologies

Accelerating Storage with RDMA Max Gurtovoy Mellanox Technologies Acceleating Stoage with RDMA Max Gutovoy Mellanox Technologies 2018 Stoage Develope Confeence EMEA. Mellanox Technologies. All Rights Reseved. 1 What is RDMA? Remote Diect Memoy Access - povides the ability

More information

Stacks and Queues

Stacks and Queues Stacks and Queues 2-25-2009 1 Opening Discussion Let's look at solutions to the interclass problem. Do you have any questions about the reading? Do you have any questions about the assignment? Minute Essays

More information