Algorithms and Data Structures


 Marvin Edwards
 2 years ago
 Views:
Transcription
1 Basic Data Structures Page 1 BFHTI: Softwareschule Schweiz Basic Data Structures Dr. CAS SD01
2 Basic Data Structures Page 2 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
3 Basic Data Structures Data Structures and Abstract Data Types Page 3 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
4 Basic Data Structures Data Structures and Abstract Data Types Page 4 Data Structures A data structure is a way of storing complex data in a computer so that it can be used efficiently Carefully chosen data structures are crucial for building efficient algorithms Therefore, the quality and performance of large systems depends heavily on choosing the best data structure Different data structures are suited to different kinds of applications, and some are highly specialized to certain tasks Many basic data structures are included in standard libraries of modern programming languages (e.g. Java Collection API) The fundamental building blocks of most data structures are arrays, records, and references
5 Basic Data Structures Data Structures and Abstract Data Types Page 5 Abstract Data Types 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 the data The objectoriented programming paradigm supports the creation of complex ADTs ADTs are specified as interfaces ADTs are implemented as classes (which themselves implement the ADT interface) Concrete data structures are wrapped into objects of corresponding classes
6 Basic Data Structures Data Structures and Abstract Data Types Page 6 Properties of WellDesigned ADTs Universality The same ADT can be used in different programs Encapsulation The interface provides an impenetrable barrier Simplicity The implementation details are entirely hidden Integrity Internal data is protected against improper use or bugs Flexibility The internal implementation can be changed without affecting the main application(s) Modularity Important subproblems are solved independently
7 Basic Data Structures Linear Data Structures Page 7 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
8 Basic Data Structures Linear Data Structures Page 8 Linear Data Structures A linear data structure is a collection of linearly arranged elements with various ways to access its elements Stack Insert/remove elements at one end of the collection Queue Insert/remove elements at different ends of the collection Vector Access elements w.r.t. the rank within the collection List Access elements w.r.t. the position within the collection Sequence Access elements w.r.t. both ranks and positions The elements of a linear data structure have all the same rights (no priorities, no hierarchy)
9 Basic Data Structures Linear Data Structures Page 9 The Stack ADT The stack ADT is a linear data structure that stores arbitrary elements according to the lastinfirstout (LIFO) scheme Thus insertion and deletions take place at the same end of the data structure Think of a springloaded plate dispenser Applications of stacks Visitedpage history in a web browser Undo sequence in a text editor Towers of Hanoi problem Chain of method calls in the Java Virtual Machine (JVM) Parsing of arithmetic expressions
10 Basic Data Structures Linear Data Structures Page 10 The Queue ADT The queue ADT is a linear data structure that stores arbitrary elements according to the firstinfirstout (FIFO) scheme Thus insertion and deletions take place at the opposite ends of the data structure Think of the queue at the airport security check Applications of queues Waiting lists Access to shared resources (e.g. a printer) Multiprogramming
11 Basic Data Structures Linear Data Structures Page 11 The Vector ADT The vector ADT extends the notion of an array by storing a sequence of arbitrary elements An element can be accessed, inserted, or removed by specifying its rank {0, 1, 2,...} = number of elements preceding it The size (number of stored elements) of a vector changes when elements are inserted or deleted Proper vectors have no fixed maximal size The ranks of some elements may change when elements are inserted or deleted Think of a ranking in ski racing events An exception is thrown if an incorrect rank is specified (e.g. a negative rank)
12 Basic Data Structures Linear Data Structures Page 12 The List ADT The list ADT models a linear sequence of positions Each position stores an arbitrary element List manipulations are always performed relative to some given positions Special positions are the first and the last position in the list To be as general as possible, we need a position ADT with two simple operations: getelement(): returns the element stored at the position setelement(e): sets the stored element to e The position ADT gives a unified view of diverse ways of storing data (cell of an array, node of a linked list, etc.) A list establishes a before/after relation between positions
13 Basic Data Structures Linear Data Structures Page 13 The Sequence ADT The sequence ADT is the union of the vector and the list ADT Elements can be accessed by their rank and/or their position To transform ranks into positions and vice versa, two bridge operators are needed atrank(r): returns the position at rank r rankof(p): returns the rank of a position p The sequence ADT is thus a generalpurpose data structure for storing linearly ordered collections of elements Stacks, queues, vectors, and lists are included as special cases
14 Basic Data Structures Linear Data Structures Page 14 Operations for Linear Structures I General Operations All: isempty(), size() Accessing Elements/Positions Stack: top() Queue: front() Vector: elematrank(r) List: first(), last(), before(p), after(p) Inserting Elements Stack: push(e) Queue: enqueue(e) Vector: insertatrank(r,e)
15 Basic Data Structures Linear Data Structures Page 15 Operations for Linear Structures II List: insertfirst(e), insertlast(e), insertbefore(p,e), insertafter(p,e) Removing Elements Stack: pop() Queue: dequeue() Vector: removeatrank(r) List: removeelement(p) Replacing/Swaping Elements Vector: replaceatrank(r,e), swapatranks(r,q) List: replaceelement(p,e), swapelements(p,q) Rank/position conversion Sequence: atrank(r), rankof(p)
16 Basic Data Structures Linear Data Structures Page 16 UML Diagram <<interface>> BasicSequence size() isempty() <<interface>> Position getelement() setelement(e) <<interface>> Stack push(e) pop() top() <<interface>> Queue enqueue(e) dequeue() front() <<interface>> Sequence atrank(r) rankof(p) <<interface>> Vector elematrank(r) insertatrank(r,e) removeatrank(r) replaceatrank(r) swapatranks(r,q) <<interface>> List first() last() before(p) after(p) isfirst(p) islast(p) insertfirst(e) insertlast(e) insertbefore(p,e) insertafter(p,e) removeelement(p) replaceelement(p,e) swapelements(p,q)
17 Basic Data Structures Linear Data Structures Page 17 BasicSequence Interface in Java public interface BasicSequence { public int size(); public boolean isempty(); } For more information on Java interfaces, see 6.10 in Java ist auch eine Insel
18 Basic Data Structures Linear Data Structures Page 18 Stack Interface in Java public interface Stack extends BasicSequence { public Object top() throws EmptyStackException; public void push(object e); public Object pop() throws EmptyStackException; } Stack inherits general methods from BasicSequence Requires the definition of a class EmptyStackException Generic stacks of a particular type can be defined using a technique called Java Generics (see 6.12 in Java ist auch eine Insel )
19 Basic Data Structures Linear Data Structures Page 19 Sequence Interface in Java public interface Sequence extends Vector, List { public Position atrank(int r); public Position rankof(position p); } Example of multiple inheritance of interfaces (not allowed for classes)
20 Basic Data Structures Linear Data Structures Page 20 The Collection Interface The java.util package provides some predefined interfaces and classes <<interface>> Iterable <<interface>> Collection AbstractCollection <<interface>> Queue <<interface>> List AbstractList AbstractSequentialList Vector ArrayList LinkedList Stack AttributeList RoleList See 12 in Java ist auch eine Insel RoleUnsolvedList
21 Basic Data Structures Implementing Linear Data Structures Page 21 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
22 Basic Data Structures Implementing Linear Data Structures Page 22 Implementing Linear Data Structures Linear data structures can be implemented in multiple ways: Arrays Records and references (singly/doublylinked lists) Combinations of arrays and linked lists The choice of the implementation determines the running times and space requirements of the basic operations Choosing the right implementation... depends on the intended application is a tradeoff between running time, memory space, simplicity
23 Basic Data Structures Implementing Linear Data Structures Page 23 Implementing Linear Data Structures in Java In Java, implementing a ADT means to write a class which implements the interface You may have several implementations of the same interface <<interface>> BasicSequence size() isempty() ArrayStack n S size() isempty() push(e) pop() top() <<interface>> Stack push(e) pop() top() LinkedListStack n top size() isempty() push(e) pop() top()
24 Basic Data Structures Implementing Linear Data Structures Page 24 Arrays Most programming languages provide arrays as a simple linear data structure Arrays have a fixed size N The elements are usually indexed by i {0,..., N 1} A[0] = first element A[i] = i+1th element A[N 1] = last element The running time for accessing elements is usually O(1) Random access Arrays are similar to vectors (but not identical)
25 Basic Data Structures Implementing Linear Data Structures Page 25 Linked Lists A linked list is another fundamental data structure which is easy to implement in most programming languages It consists of a linked sequence of nodes Each node is a record (or object) which contains: A data field to store an element (number, string, object, etc.) One or two references (links, pointers) pointing to the next and/or the previous nodes Other than arrays, a linked list detaches the order of the list elements from the one used to store them in memory or disk It allows only sequential (no random) access to its elements Nodes should implement the interface of the position ADT
26 Basic Data Structures Implementing Linear Data Structures Page 26 Singly Linked Lists A singly linked list is the simplest form of a linked list Each node contains a reference to the next node A single reference to the first node is kept in memory Sometimes it is useful to keep a reference to the last node Node Record Main Reference Optional Reference next element A B C
27 Basic Data Structures Implementing Linear Data Structures Page 27 DoublyLinked Lists A doublylinked list is another simple form of a linked list Each node contains two references, one to the next node and one to the previous node Usually references to both ends are kept For simplicity, special header and trailer nodes are often added Node Reference 1 Reference 2 Record prev next element A B C
28 Basic Data Structures Implementation with Arrays Page 28 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
29 Basic Data Structures Implementation with Arrays Page 29 ArrayBased Stacks The elements are added from left to right and removed from right to left A variable n keeps track of the stack size (= next available location in the array) S n N 1 When the array becomes full, i.e. for n = N, a push operation will throw a FullStackException This exception is implementationspecific (not intrinsic to stack ADT)
30 Basic Data Structures Implementation with Arrays Page 30 Implementing ArrayBased Stacks I Algorithm size() // runs in O(1) time return n Algorithm isempty() // runs in O(1) time return (n = 0) Algorithm top() // runs in O(1) time if isempty() then throw EmptyStackException else return S[n 1]
31 Basic Data Structures Implementation with Arrays Page 31 Implementing ArrayBased Stacks II Algorithm push(e) // runs in O(1) time if n = N then throw FullStackException else S[n] e n n + 1 Algorithm pop() // runs in O(1) time if isempty() then throw EmptyStackException else n n 1 return S[n]
32 Basic Data Structures Implementation with Arrays Page 32 ArrayBased Queues To implement the queue ADT, the array should be used in a circular fashion The elements are added and removed from left to right Two variables f and r keep track of the front and rear element s indices (the location r is kept empty) Q Q 0 1 f r N r f N 1 When the array becomes full, a enqueue operation will throw a FullQueueException (implementationspecific exception)
33 Basic Data Structures Implementation with Arrays Page 33 Implementing ArrayBased Queues I Algorithm size() // runs in O(1) time return (N + r f ) mod N Algorithm isempty() // runs in O(1) time return (f = r) Algorithm front() // runs in O(1) time if isempty() then throw EmptyQueueException else return Q[f ]
34 Basic Data Structures Implementation with Arrays Page 34 Implementing ArrayBased Queues II Algorithm enqueue(e) // runs in O(1) time if size() = N 1 then // the capacity is only N 1! throw FullQueueException else Q[r] e r (r + 1) mod N Algorithm dequeue() // runs in O(1) time if isempty() then throw EmptyQueueException else e Q[f ] f (f + 1) mod N return e
35 Basic Data Structures Implementation with Arrays Page 35 ArrayBased Vectors Vectors are most naturally implemented with arrays (i.e. ranks = array indices) A variable n keeps track of the size of the vector (number of elements stored) V r n N 1 Operation elematrank(r) is implemented in O(1) time by returning V [r] When the array becomes full, a insertatrank operation will throw a FullVectorException (implementationspecific exception)
36 Basic Data Structures Implementation with Arrays Page 36 Inserting Elements In the operation insertatrank(r,e), we need to make room for the new element shift forward the n r elements V [r],..., V [n 1] V r n N 1 V r n N 1 V e r n N 1 In the worst case, i.e. for r = 0, this takes O(n) time
37 Basic Data Structures Implementation with Arrays Page 37 Removing Elements In the operation removeatrank(r), we need to fill the hole left by the removed element shift backward the n r 1 elements V [r + 1],..., V [n 1] V r n N 1 V r n N 1 V r n N 1 In the worst case, i.e. for r = 0, this takes O(n) time
38 Basic Data Structures Implementation with Growable Arrays Page 38 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
39 Basic Data Structures Implementation with Growable Arrays Page 39 Growable ArrayBased Stack To solve the FullStackException problem, replace the array with a larger one when necessary Incremental strategy: increase the size by a constant c Doubling strategy: double the size Algorithm push(e) if size() = N then A new array of size... for i 0 to n 1 do A[i] S[i] S A S[n] e n n + 1
40 Basic Data Structures Implementation with Growable Arrays Page 40 Running Times of Strategies Incremental Strategy Doubling Strategy running time of push(e) running time of push(e) current number of elements current number of elements
41 Basic Data Structures Implementation with Growable Arrays Page 41 Comparison of the Strategies Consider the the total time T (n) needed to perform a series of n push operations We assume that we start with an empty stack represented by an array of size c, for the incremental strategy 1, for the doubling strategy We call amortized running time T (n)/n the average time taken by a push operation over the series of operations We only consider one primitive operation: storing an object in the array
42 Basic Data Structures Implementation with Growable Arrays Page 42 Incremental Strategy Let n be a multiple of c, i.e. n = kc The array needs to be replaced k 1 times For the total running time T (n) we get T (n) = n + c + 2c + 3c (k 1)c = n + c( (k 1)) (k 1)k = n + c 2 = = 1 2c n n The total running time for n push operations is O(n 2 ) The amortized running time for a push operation is O(n)
43 Basic Data Structures Implementation with Growable Arrays Page 43 Doubling Strategy Let n be a power of 2, i.e. n = 2 k The array needs to be replaced k = log n times For the total running time T (n) we get T (n) = n k 1 = n + 2 k 1 = 2n 1 The total running time for n push operations is O(n) The amortized running time for a push operation is O(1) As a consequence, the doubling strategy outperforms the incremental strategy for large stacks
44 Basic Data Structures Implementation with Growable Arrays Page 44 Performance Growable arrays can also be used to implement queues and vectors (and lists, but this is not very natural) Operation Doubling Incremental Strategy Strategy size O(1) O(1) isempty O(1) O(1) top, front, elematrank O(1) O(1) push, enqueue O(1) O(n) insertatrank O(n) O(n) pop, dequeue O(1) O(1) removeatrank O(n) O(n)
45 Basic Data Structures Implementation with Linked Lists Page 45 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
46 Basic Data Structures Implementation with Linked Lists Page 46 Stacks and Queues with Singly Linked Lists Stacks and queues are often implemented as singly linked lists Nodes implement the position ADT by storing: Element Reference next to the next node The top/front element is stored at the first node For stacks, only a reference to the first node needs to be kept (called top) For queues, references to both ends of the list needs to be kept (called front and rear) Keep track of the current size n of the stack/queue All operations run in O(1) time, memory grows in O(n)
47 Basic Data Structures Implementation with Linked Lists Page 47 Implementing Stack with Singly Linked Lists Algorithm push(e) // runs in O(1) time new new Node(e) new.next top top new n n + 1 Algorithm pop() // runs in O(1) time if isempty() then throw EmptyStackException else e top.getelement() top top.next n n 1 return e
48 Basic Data Structures Implementation with Linked Lists Page 48 DoublyLinked List Implementation A doublylinked list provides a natural implementation of the list ADT Nodes implement the position ADT by storing Element Reference prev to the previous node Reference next to the next node The list itself stores two references first and last first last A B C D E
49 Basic Data Structures Implementation with Linked Lists Page 49 Inserting Elements All four insertion operations need to create some new and redirect some existing links, i.e. they run in O(1) time p A B C D E A B C D E q X A B C X D E
50 Basic Data Structures Implementation with Linked Lists Page 50 Removing Elements The operation removeelement(p), which needs to redirect some existing links, runs in O(1) time p A B C X D E A B C D E p X A B C D E
51 Basic Data Structures Implementation with Linked Lists Page 51 Running Times Overview Array Doubly Singly Sequence Operation (circular, Linked Linked growable) List List size, isempty insertfirst, insertlast replaceelement, swapelements first, last, isfirst, islast, after before 1 1 n insertafter n 1 1 insertbefore, removeelement n 1 n atrank, rankof, elematrank 1 n n replaceatrank, swapatranks 1 n n insertatrank, removeatrank n n n
52 Basic Data Structures Iterators Page 52 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing Linear Data Structures Implementation with Arrays Implementation with Growable Arrays Implementation with Linked Lists Iterators
53 Basic Data Structures Iterators Page 53 The Iterator ADT An iterator abstracts the process of scanning through a sequence by keeping a pointer to the current element Methods of an iterator ADT element(): returns the current element hasnext(): checks whether the iteration has completed nextelement(): advances the pointer to the next element reset(): resets the iterator Can be realized for array or linkedlist implementations The order in which the elements are traversed is not necessarily the normal rankbased or positionbased order We can use several iterators for the same sequence See in Java ist auch eine Insel (interface iterable)
This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues 1. 2004 Goodrich, Tamassia
This lecture Abstract data types Stacks Queues ADTs, Stacks, Queues 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
More informationSequential Data Structures
Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year
More informationVector ADT. A Vector stores a list of elements: Access via rank/index.
Vector ADT A Vector stores a list of elements: Access via rank/index. Accessor methods: elementatrank(r), Update methods: replaceatrank(r, o), insertatrank(r, o), removeatrank(r) Generic methods: size(),
More informationAbstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types
EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that
More informationStacks & Queues. Data structures and Algorithms
Stacks & Queues Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004) Outline
More informationOutline. The Stack ADT Applications of Stacks Arraybased implementation Growable arraybased stack. Stacks 2
Stacks Outline The Stack ADT Applications of Stacks Arraybased implementation Growable arraybased stack Stacks 2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure
More informationcsci 210: Data Structures Stacks and Queues
csci 210: Data Structures Stacks and Queues Summary Topics stacks and queues as abstract data types implementations arrays linked lists analysis and comparison application: searching with stacks and queues
More informationSTACKS,QUEUES, AND LINKED LISTS
STACKS,QUEUES, AND LINKED LISTS Stacks Queues Linked Lists DoubleEnded Queues Case Study: A Stock Analysis Applet 1 Stacks Astack is a container of objects that are inserted and removed according to the
More informationWhat is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Arraybased Implementation
Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in LastIn InFirstOut (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria
More informationStacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1
Stacks (and Queues) 1 Stacks Stack: what is it? ADT Applications Implementation(s) 2 CSCU9A3 1 Stacks and ueues A stack is a very important data structure in computing science. A stack is a seuence of
More informationUniversidad Carlos III de Madrid
Universidad Carlos III de Madrid Algorithms and Data Structures (ADS) Bachelor in Informatics Engineering Computer Science Department Lists, Stacks and Queues. Authors: Isabel Segura Bedmar April 2011
More informationAnalysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
More informationData Structures and Algorithms Lists
Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 50: Abstract Data Types An
More informationArrays and Linked Lists
Arrays and Linked Lists Data Structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004)
More informationQUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q
QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in realworld, namely,
More informationQueues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to firstin/firstout (FIFO) principle!
More informationData Structures and Algorithms
Data Structures and Algorithms CS2452016S04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 040: Abstract Data Types An Abstract Data Type is a definition of
More informationDictionaries and Hash Tables
Dictionaries and Hash Tables 0 1 2 3 0256120001 9811010002 4 4512290004 Dictionaries and Hash Tables 1 Dictionary ADT ( 8.1.1) The dictionary ADT models a searchable collection of keyelement items
More informationLinked Lists, Stacks, Queues, Deques. It s time for a chainge!
Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems
More informationAnnouncements. FINAL EXAM Monday May 21, 1:30pm Review Session. Wednesday May 16, 79pm
Announcements FINAL EXAM Monday May 21, 1:30pm Review Session Wednesday May 16, 79pm 1 Recitation 12 Root Finding, Sorting, Stacks, Queues 2 Outline Linked Lists Sorting Queues 3 Object References Let
More informationLecture 4. The Java Collections Framework
Lecture 4. The Java s Framework Chapters 6.36.41  The Java s Framework We will consider the Java s Framework as a good example of how apply the principles of objectoriented software engineering (see
More informationData Structures and Algorithms
Data Structures and Algorithms CS2452016S05 Abstract Data Types and Lists David Galles Department of Computer Science University of San Francisco 050: Abstract Data Types Recall that an Abstract Data
More informationChapter 3: Restricted Structures Page 1
Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both
More informationData Structure. Lecture 3
Data Structure Lecture 3 Data Structure Formally define Data structure as: DS describes not only set of objects but the ways they are related, the set of operations which may be applied to the elements
More informationLecture 4. The Java Collections Framework
Lecture 4. The Java s Framework Chapters 6.36.41  Outline Introduction to the Java s Framework Iterators Interfaces Classes Classes  2  The Java s Framework We will consider the Java s Framework as
More informationCourse: Programming II  Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II  Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
More informationLast not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!
ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting
More informationOutline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson
Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications ArrayBased Linked ListBased 4 Additional Information Mike Jacobson (University
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions InformÃ tiques D06 PROGRAMMING with JAVA Ch20 Data Structures I PowerPoint presentation, created by Angel A. Juan  ajuanp(@)gmail.com, for
More informationCollections & Data Structures. CS 3: Computer Programming in Java
Collections & Data Structures CS 3: Computer Programming in Java Objectives The concept of a collection Separating the interface from the implementation Dynamic data structures Linked lists Queues and
More information22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/
22c:31 Algorithms Ch3: Data Structures Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/ Linear Data Structures Now we can now explore some convenient techniques for organizing
More informationOOP A Deeper Look. Iterators, The Collection Hierarchy
OOP A Deeper Look 4B Iterators, The Collection Hierarchy 1 Iterating over a list SinglyLinkedList list = new SinglyLinkedList();... for (int i=0; i
More informationQueues and Stacks. Atul Prakash Downey: Chapter 15 and 16
Queues and Stacks Atul Prakash Downey: Chapter 15 and 16 Queues Queues occur in real life a lot. Queues at checkout Queues in banks In software systems: Queue of requests at a web servers Properties of
More informationLecture 4. The Java Collections Framework
Lecture 4. The Java s Framework Chapters 6.36.41  Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework  2  Outline Introduction to the Java
More informationData Structures Using Java
Data Structures Using Java D. S. Malik P. S. Nair THOMSON COURSE TECHNOLOGY Australia Canada Mexico Singapore Spain United Kingdom United States TABLE OF Contents PREFACE XXV 1.Software Engineering Principles
More informationData Structures in the Java API
Data Structures in the Java API Vector From the java.util package. Vectors can resize themselves dynamically. Inserting elements into a Vector whose current size is less than its capacity is a relatively
More informationData Structures. Topic #4
Topic #4 Today s Agenda Stack and Queue ADTs What are they Like Ordered Lists, are position oriented Use of Data Structures for Stacks and Queues arrays (statically & dynamically allocated) linear linked
More information12 Abstract Data Types
12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).
More informationLINKED DATA STRUCTURES
LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference
More informationChapter 7: Queues and Deques
Chapter 7: Queues and Deques After the stack, the next simplest data abstraction is the queue. As with the stack, the queue can be visualized with many examples you are already familiar with from everyday
More information10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions  a conventional tool for handling a
More informationData Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given
More informationUNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE
STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia
More information7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
More informationBig O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.
Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it
More informationV.S.B. ENGINEERING COLLEGE, KARUR. Academic Year: (ODD Semester) Department of Computer Science and Engineering
V.S.B. ENGINEERING COLLEGE, KARUR Academic Year: 20162017 (ODD Semester) Department of Computer Science and Engineering Question Bank (2013 Regulations) S.No. Name of the Subject / Lab Semester Page No.
More informationLearning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees
Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture
More information1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.
1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated
More information1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++
Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The
More informationJava Software Structures
INTERNATIONAL EDITION Java Software Structures Designing and Using Data Structures FOURTH EDITION John Lewis Joseph Chase This page is intentionally left blank. Java Software Structures,International Edition
More informationUnordered Linked Lists
Unordered Linked Lists Derive class unorderedlinkedlist from the abstract class linkedlisttype Implement the operations search, insertfirst, insertlast, deletenode See code on page 292 Defines an unordered
More informationDATA STRUCTURES USING C
DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give
More informationIntroduction to Stacks
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack. What is a Stack? Stack is a data structure in which data is added
More informationCourse: Programming II  Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1
Definition Course: Programming II  Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition
More informationAlgorithms and Data Structures
Priority Queues and Heaps Page 1  Priority Queues and Heaps Dr. Fall 2008 Priority Queues and Heaps Page 2 Outline Priority Queues Heaps HeapBased Priority Queues BottomUp Heap Construction Priority
More informationJava Collection Framework hierarchy. What is Data Structure? Chapter 20 Lists, Stacks, Queues, and Priority Queues
Chapter 20 Lists, Stacks, Queues, and Priority Queues Objectives q To explore the relationship between interfaces and classes in the Java Collections Framework hierarchy ( 20.2). q To use the common methods
More informationTIE20106 1 TIE20106 2
TIE20106 1 1 List structures In this chapter, a few simple data structures (stack and queue) that can be implemented with arrays and/or lists are covered. Two more complex structures based on lists are
More informationData Structures. value. key. 5 Alpha. 3 Beta. 7 Gamma
Data Structures key value 5 Alpha 10 2 7 5 1 4 9 3 6 8 3 Beta 7 Gamma Sequence Associative e.g., CArrays, std::vector, std::deque, std::list e.g., CArrays, std::map, std::set, std::unordered_map Data
More informationSummary. Pre requisition. Content Details: 1. Basics in C++
Summary C++ Language is one of the approaches to provide objectoriented functionality with C like syntax. C++ adds greater typing strength, scoping and other tools useful in objectoriented programming
More informationJava Collections Framework (JCF): Lists, Stacks, Queues, Priority Queues, Sets, and Maps
Java Collections Framework (JCF): Lists, Stacks, Queues, Priority Queues, Sets, and Maps Slides derived from the work of Dr. Amy McGovern and Dr. Deborah Trytten Andrew H. Fagg: CS 2334: Inheritance and
More information1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: 15.115.3. Data Structures
1.00 Lecture 35 Data Structures: Introduction Stacks, Queues Reading for next time: Big Java: 15.115.3 Data Structures Set of reusable classes used in algorithms, simulations, operating systems, applications
More informationKrishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA213 : DATA STRUCTURES USING C
Tutorial#1 Q 1: Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2: What is a Data Type? Differentiate
More informationADTs,, Arrays, Linked Lists
1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract
More informationQuestions 1 through 25 are worth 2 points each. Choose one best answer for each.
Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in
More informationDATA STRUCTURE  QUEUE
DATA STRUCTURE  QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to
More informationChapter 4: Linked Lists
Chapter 4: Linked Lists Data Abstraction & Problem Solving with C++ Fifth Edition by Frank M. Carrano Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during
More informationJAVA COLLECTIONS FRAMEWORK
http://www.tutorialspoint.com/java/java_collections.htm JAVA COLLECTIONS FRAMEWORK Copyright tutorialspoint.com Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties
More informationProgramming with Data Structures
Programming with Data Structures CMPSCI 187 Spring 2016 Please find a seat Try to sit close to the center (the room will be pretty full!) Turn off or silence your mobile phone Turn off your other internetenabled
More informationAPI for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.
Sequences and Urns 2.7 Lists and Iterators Sequence. Ordered collection of items. Key operations. Insert an item, iterate over the items. Design challenge. Support iteration by client, without revealing
More informationData Structures Using C++ 2E. Chapter 5 Linked Lists
Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of
More informationC++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 8/e 19922012 by Pearson Education, Inc. 19922012 by Pearson Education, Inc. 19922012 by Pearson Education, Inc. We ve studied fixedsize data structures such as onedimensional arrays
More informationLinked Lists Linked Lists, Queues, and Stacks
Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points
More informationKITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact:  8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
More informationDATA STRUCTURE  STACK
DATA STRUCTURE  STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming
More informationCSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping
More informationWhat is a Dictionary? Dictionaries. Dictionary Keys. Dictionary Examples. Log File. Unordered Dictionary ADT. Container class
What is a Dictionary? Dictionaries Container class Stores keyelement element pairs (like priority queue) Allows lookup (find) operation Allows insertion/removal of elements May be unordered or ordered
More informationQuiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s
Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number
More informationINTERNATIONAL EDITION. Problem Solving with C++ Data Abstraction & SIXTH EDITION. Walls and Mirrors. Frank M. Carrano Timothy Henry
INTERNATIONAL EDITION Data Abstraction & Problem Solving with C++ Walls and Mirrors SIXTH EDITION Frank M. Carrano Timothy Henry Operator Meaning Associativity Usage * multiply left expr * expr / divide
More informationCommon Data Structures
Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees
More information4.3 Stacks and Queues. Pushdown Stacks. Data Structures and Data Types. Collections
Data Structures and Data Types 4.3 Stacks and Queues Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack,
More informationCSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Nicki Dell Spring 2014
CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Nicki Dell Spring 2014 Registration We have 140 students registered and 140+ on the wait list! If you re thinking of
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is
More informationChapter 6: Stacks. The Stack Concept and ADT specification
Chapter 6: Stacks You are familiar with the concept of a stack from many everyday examples. For example, you have seen a stack of books on a desk, or a stack of plates in a cafeteria. The common characteristic
More informationLinked Lists and Iterators
Linked Lists and Iterators Chapter 4 Click to proceed How To View This Presentation This presentation is arranged in outline format. To view the slides in proper order For each slide Read the entire slide
More informationModule 2 Stacks and Queues: Abstract Data Types
Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful nonprimitive linear data structure in computer science. It is an ordered collection of items into which
More informationComp 245 Data Structures. Stacks
Comp 245 Data Structures Stacks What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO random access to other elements within the stack An
More informationcsci 210: Data Structures Linked lists
csci 210: Data Structures Linked lists Summary Today linked lists singlelinked lists doublelinked lists circular lists READING: GT textbook chapter 3 Arrays vs. Linked Lists We ve seen arrays: int[]
More informationStacks and queues. Algorithms and Data Structures, Fall 2011. Rasmus Pagh. Based on slides by Kevin Wayne, Princeton
Algorithms and Data Structures, Fall 2011 Stacks and queues Rasmus Pagh Based on slides by Kevin Wayne, Princeton Algorithms, 4 th Edition Robert Sedgewick and Kevin Wayne Copyright 2002 2011 Stacks and
More informationPES Institute of TechnologyBSC QUESTION BANK
PES Institute of TechnologyBSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions
More informationChapter 20 ArrayLists. Java Collection Framework hierarchy. What is Data Structure? CS1: Java Programming Colorado State University
Chapter 20 ArrayLists CS1: Java Programming Colorado State University Objectives q To explore the relationship between interfaces and classes in the Java Collections Framework hierarchy ( 20.2). q To use
More informationClass Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction
Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know
More informationGlossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
More informationNodeBased Structures Linked Lists: Implementation
Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org
More informationChapter 13. Pointers and Linked Lists
Chapter 13 Pointers and Linked Lists Overview 13.1 Nodes and Linked Lists 13.2 Stacks and Queues Slide 132 13.1 Nodes and Linked Lists Nodes and Linked Lists n A linked list is a list that can grow and
More informationData Structures and the Java Collections Framework
Data Structures and the Java Collections Framework Third Edition William J. Collins Lafayette College JOHN WILEY & SONS, INC. CONTENTS Preface xvii CHAPTER 0 Introduction to Java 1 Chapter Objectives 1
More informationOverview of Data Structures
UNIT 3 Concrete Data Types Classification of Data Structures Concrete vs. Abstract Data Structures Most Important Concrete Data Structures Arrays Records Linked Lists Binary Trees Overview of Data Structures
More informationData Structures 2014
Unit1 Introduction Short Questions:1. Define data structure. 2. Define algorithm. 3. List out areas in which data structures are applied. 4. List out structure of algorithm. 5. List out properties of
More informationGenerics. IRS W9 Form
Generics IRS W9 Form Generics Generic class and methods. BNF notation Syntax Nonparametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]
More informationUniversity of Illinois at UrbanaChampaign Department of Computer Science. First Examination
University of Illinois at UrbanaChampaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Fall 2007 7p9p, Thursday, October 4 Name: NetID: Lab Section
More informationCircular Linked List. Algorithms and Data Structures
Circular Linked List EENG212 Algorithms and Data Structures Circular Linked Lists In linear linked lists if a list is traversed (all the elements visited) an external pointer to the listmust be preserved
More information