TIE TIE


 Robert Cole
 2 years ago
 Views:
Transcription
1 TIE 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 discussed: the hash table and the skiplist. In addition a data abstraction called a dynamic set is defined. TIE Definition of a dynamic set A dynamic set maintains a collection of elements. Elements can be added, removed and searched according to different principles. From the user s point of view an element consists of two parts: a key and satellite data a student number is the key and the satellite data contains the name, the department, credits etc. in a phonebook both the name and the telephone number can act as keys, so that searches can be done according to either of them the implementation usually contains extra fields in the structure that are used to maintain the data structure TIE In dynamic sets, searching for data is done according to the key. satellite data is handled only through its key and a handle the satellite data is insignificant from the point of view of the algorithms. since satellite data may be moved around with the key, large payload should be stored with a pointer to the data two elements can or cannot have the same key value, depending on the situation if several elements have the same key, an element can be chosen arbitrarily according to secondary criteria TIE the set of possible key values can be sorted the smallest element or an element larger than a given value can be searched for some data structures cannot handle the order information efficiently (hash table) whereas others actually insist that the set of elements is sorted (binary trees) The search usually returns a handle to the element which indentifies the element unambiguously from the others, even though they might have the same key. pointers, iterators and indices are typical handles
2 TIE The operations of a dynamic set can be grouped into two categories: queries, which don t change the structure but only return information and modifying operations The queries: SEARCH S k) returns a handle to an element x in the set S such that x.key = k, or NIL if no such element exists MINIMUM S) returns a handle to the element of the set S with the smallest key value sensible only if the set of keys is ordered MAXIMUM S) cmp. MINIMUM SUCCESSOR S x) returns a handle to the element with the next largest key to the element x PREDECESSOR S x) cmp. SUCCESSOR TIE The elements can be stepped through e.g. with SUCCESSOR it s worth a mention that minimum, maximum and scan operations are not necessarily unambiguous if several elements have the same key The modifying operations: INSERT S x) add the element x to the set S DELETE S x) removes an element from the set S with the handle x. TIE The best way to implement a dynamic set depends on the operations needed and which of the operations need to be fast and which can be slow. it s usefull to define some special cases that don t allow all operations to be performed for example a dictionary provides only only the operations SEARCH, INSERT and DELETE the value set of the keys does not need to be sorted a priority queue is a dynamic set that provides operations INSERT and MAXIMUM in addition with the operation EXTRACTMAX, that can be used to remove elements in a limited situation the queue can be seen as a dynamic set where the key has been selected in a unique way only the operations INSERT and EXTRACTMIN the key is a running sequence of numbers which are incremented by one each time INSERT is performed (does in reality work exactly like this) TIE Occasionally we want to be able to search for the elements according to more than one key. This can be done with a dynamic set with multiple keys. in practise this is usually implemented with several separate sets, each with a key of their own. the multiplication of the satellite data must be avoided by storing the data in one place and accessing it with pointers elsewhere. In the next chapters we ll discuss methods to implement a dynamic set so that the operations are as efficient as possible.
3 TIE Pointers and lists One of the simplest dynamic sets is a linked list. It s easy to implement records or objects in several programming languages and then handle them through pointers. the pointer indicates where the object can be found a pointer can be seen as an arrow pointing to the object a pointer can also point nowhere: NIL in linked structures there are pointer fields in the objects pointing to other objects the fields in the objects can be read and changed through the pointer when the value of the pointer is changed it turns to point to another object a structure that uses pointers can be stepped through the entire structure can be changed by changing the pointer fields of an element in the structure TIE A doubly linked list is a basic linked structure. each element contains the fields next, prev and the actual payload for simplicity in the examples the only payload is the key Search is n), Insert Θ 1) and Delete Θ 1) TIE A singly linked list has no back links. Handling the first and the last element in the list often need to be handled as special cases. this makes the algorithm more complex sometimes it s usefull to add an extra object the sentinel to the end of the list. The sentinel is not used to store any payload a similar solution is a circular list TIE Typically the list elements need to be reserved before calling LISTINSERT freed after calling LISTDELETE unless it needs to be saved for some other purpose some programming languages take care of the allocation and deallocation of objects automatically e.g. Smalltalk, Java, Haskell, Ruby, Python garbage collection algorithms are often heavy and may cause longish, unexpected delays
4 TIE in some cases and with some programming languages the programmer must take care of the allocation and freeing of objects manually this may cause errors that are difficult to find and may have unpleasant consequences a object is freed too early the memory of the object may be reallocated creating two uses for the same memory segments wrong data is changed freeing the object is forgotten causing a memory leak the amount of free memory slowly decreases until it runs out eventually the program crashes or starts acting weirdly TIE In general, reusing objects freed by the programmer is difficult and the implementation of the language may handle it badly. It may be worth organizing the recycling of free objects by maintainig a list of free objects, a free list. the idea is not to free the objects with delete but collect the unused objects into a list once a new object is needed, it is taken from the free list provided it s not empty objects are allocated with new only when the free list is empty a suitable pointer field is chosen from the objects for maintaing the free list TIE allocating an object: ALLOCATEOBJECT 1 if free = NIL then if the free list is empty, allocate a new object) 2 new x) else... ) 4 x := free 5 free := x next... make the second element in the list the first... ) 6 return x... and return the first) freeing an object: FREEOBJECT x) 1 x next := free link the new element infront of the first) 2 free := x make the new element the first in the free list) TIE Stack and Queue A linked list can be used in the implementation of a stack. a data abstraction with operations STACKEMPTY S) tests whether the stack is empty PUSH S x) adds the element x to the top of the stack POP S) removes and returns the topmost element in the stack there may be other operations depending on the circumstances STACKFULL S) STACKCOUNT S) returns the amount of elements in the stack implements a lifo (last in, first out) policy each operation has always Θ 1) running time there is no need to predefine a maximum size, the stack can get larger as long as there is memory available
5 TIE TIE STACKEMPTY S) 1 if S.top = NIL then if the topmost element is NIL... ) 2 return TRUE... stack is empty) 4 return FALSE PUSH S x) 1 r := ALLOCATEOBJECT allocate a list object) 2 if r = NIL then memory allocation failed) 3 error out of memory 4 else 5 r payload := x copy the data into the list object) 6 r next := S.top mark the topmost element as next) 7 S.top := r set the new element to the top of the stack) POP S) 1 if STACKEMPTY S) then empty is empty) 2 error underflow 4 x := S.top payload copy the payload of the topmost element) 5 r := S.top next store the location of the next element) 6 FREEOBJECT S.top) free the popped element) 7 S.top := r make the next element topmost) 8 return x return the payload of the popped element) An array can be used in the implementation of the stack. each operation has always Θ 1) runningtime the downsize is that the maximum size needs to be fixed beforehand or a flexible sized array must be used STACKEMPTY S) 1 if S.top = 0 then if the topmost element is at index 0... ) 2 return TRUE... the stack is empty) 4 return FALSE PUSH S x) 1 if S.top S.size then the stack is full) 2 error overflow 4 S.top := S.top + 1 increment the index of the topmost element) 5 S[S.top] := x copy the element to the top of the stack) TIE POP S) 1 if STACKEMPTY S) then empty is empty) 2 error underflow 4 S.top := S.top 1 decrement the top of the stack by one) 5 return S[S.top + 1] return the popped element) The asymptotic runningtime is the same in both cases but the constant coefficient is usually smaller in the array implementation. The memory consumption of the solutions may the decisive factor in choosing between the alternatives. if the elements stored in the stack are large the list implementation uses less memory provided that an exact size is not known for the array if the elements are small, the list is better only if the array is kept less than 50% full if the elements exist anyway the stack can be created by adding an extra field into each object for maintaining the stack order TIE Another common data structure implemented with a singly linked list is a queue. a data abstraction with operations QUEUEEMPTY Q) tests whether the queue is empty ENQUEUE Q x) adds the element x to the end of the queue DEQUEUE Q) removes and returns the first element in the queue implements a fifo (first in, first out) policy each operations has always Θ 1) running time there is no need to predefine the maximum size, the queue can get larger as long as there is memory available QUEUEEMPTY Q) 1 if Q.head = NIL then there is no first element) 2 return TRUE 4 return FALSE
6 TIE ENQUEUE Q x) 1 r := ALLOCATEOBJECT allocate a list object) 2 if r = NIL then memory allocation failed) 3 error out of memory 4 else 5 r payload := x copy the data into the list object) 6 r next := NIL 7 if Q.head = NIL then if adding to an empty queue... ) 8 Q.head := r... make the new element the first) 9 else 10 Q.tail next := r else make it the last) 11 Q.tail := r DEQUEUE Q) 1 if QUEUEEMPTY Q) then empty is empty) 2 error underflow 4 x := Q.head payload store the data we re removing) 5 r := Q.head next store the location of the next element) 6 FREEOBJECT Q.head) free the element) 7 Q.head := r make the second element topmost) 8 return x return the removed data) TIE The queue can also be implemented with an array as a ring buffer. each operation has always Θ 1) runningtime the downsize is that the maximum size needs to be know beforehand or a flexible sized array must be used. QUEUEEMPTY Q) 1 if Q.head = Q.tail then if the first and the last index are the same... ) 2 return TRUE... queue is empty) 4 return FALSE TIE ENQUEUE Q x) 1 if Q.head = Q.tail mod Q.length + 1 then if the tail has reached the head... ) 2 error overflow... the queue is full) 4 Q[Q.tail] := x add the new element to the end) 5 Q.tail := Q.tail mod Q.length + 1 move the tail... )... rotate to beginning if necessary) DEQUEUE Q) 1 if QUEUEEMPTY S) then empty is empty) 2 error underflow 4 x := Q[Q.head] store the data we re removing) 5 Q.head := Q.head mod Q.length + 1 move the head of the queue... )... rotate to the beginning is necessary) 6 return x return the removed element) TIE Hash table The basic idea behind hash tables is to reduce the range of possible key values in a dynamic set by using a hash function h so that the keys can be stored in an array. the advantatage of an array is the efficient, constanttime indexing it provides Reducing the range of the keys creates a problem: collisions. more than one element can hash into the same slot in the hash table The relations between the time and memory consumption of the list and array implementations is the same as with the stack implementation
7 TIE The most common way to solve the problem is called chaining. all the elements that hash to the same slot are put into a linked list there are other alternatives in open addressing the element is put into a secondary slot if the primary slot is unavailable in some situations the range of key values is so small, that it doesn t need to be reduced and therefore there are no collisions either this directaccess table is very simple and efficient this course covers hashing with chaining only TIE The picture below shows a chained hash table, whose keys have been hashed based on the first letter according the the table given. Is this a good hash? No. Let s see why. h k) first letter 0 H P X 1 A I Q Y 2 B J R Z 3 C K S Ä 4 D L T Ö 5 E M U Å 6 F N V 7 G O W TIE The chained hash table provides the dictionary operations only, but those are very simple: CHAINEDHASHSEARCH T k) find the element with key k from the list T [h k)] CHAINEDHASHINSERT T x) add x to the beginning of the list T [h x key)] CHAINEDHASHDELETE T x) remove x from the list T [h x key)] TIE Runningtimes: addition: Θ 1) search: worstcase Θ n) removal: if the list is doublylinked Θ 1); with a singly linked list worstcase Θ n), since the predecessor of the element under removal needs to be searched from the list in practise the difference is not significant since usually the element to be removed needs to be searched from the list anyway The average runningtimes of the operations of a chained hash table depend on the lengths of the lists.
8 TIE in the worstcase all elements end up in the same list and the runningtimes are Θ n) to determine the averagecase running time we ll use the following: m = size of the hash table n = amount of elements in the table α = n m = load factor i.e. the average length of the list in addition, in order to evaluate the averagecase efficiency an estimate on how well the hash function h hashes the elements is needed if for example h k) = the 3 highest bits in the name, all elements hash into the same list it is often assumed that all elements are equally likely to hash into any of the slots simple uniform hashing we ll also assume that evaluating h k) is Θ 1) TIE if an element that is not in the table is searched for, the entire list needs to be scanned through on average α elements need to be investigated the runningtime is on average Θ 1 + α) if we assume that any of the elements in the list is the key with the same likelyhood, on average half of the list needs to be searched through in the case where the key is found in the list the runningtime is Θ 1 + α 2 ) = Θ 1 + α) on average if the load factor is kept under some fixed constant (e.g. α < 50 %), then Θ 1 + α) = Θ 1) all operations of a chained hash table can be implemented in Θ 1) runningtime on average this requires that the size of the hash table is around the same as the amount of elements stored in the table TIE When evaluating the averagecase runningtime we assumed that the hashfunction hashes evenly. However, it is in no way obvious that this actually happens. The quality of the hash function is the most critical factor in the efficiency of the hash table. Properties of a good hash function: the hash function must be deterministic otherwise an element once placed into the hash table may never be found despite this, it would be good that the hash function is as random as possible of the keys should be hashed into each slot as closely as possible m TIE unfortunately implementing a completely evenly hashing hash function is most of the time impossible the probability distribution of the keys is not usually known the data is usually not evenly distributed almost any sensible hash function hashes an evenly distributed data perfectly Often the hash function is created so that it is independent of any patterns occuring in the input data, i.e. such patterns are broken by the function for example, single letters are not investigated when hashing names but all the bits in the name are taken into account
9 TIE two methods for creating hash functions that usually behave well are introduced here lets assume that the keys are natural numbers 0, 1, 2,... if this is not the case the key can be interpreted as a natural number e.g. a name can be converted into a number by calculating the ASCIIvalues of the letters and adding them together with appropriate weights TIE Creating hash functions with the division method is simple and fast. h k) = k mod m it should only be used if the value of m is suitable e.g. if m = 2 b for some b = }, then h k) = k s b lowest bits the function doesn t even take a look at all the bits in k the function probably hashes binary keys poorly TIE for the same reason, values of m in the format m = 10 b should be avoided with decimal keys if the keys have been formed by interpreting a character string as a value in the 128system, then m = 127 is a poor choise, as then all the permutations of the same string end up into the same slot prime numbers are usually good choises for m, provided they are not close to a power of two e.g. 700 lists is needed 701 is OK it s worth checking with a small real input data set whether the function hashes efficiently TIE The multiplication method for creating hash functions doesn t have large requirements for the values of m. the constant A is chosen so that 0 < A < 1 h k) = m ka ka ) if m = 2 b, the word length of the machine is w, and k and 2 w A fit into a single word, then h k) can be calculated easily as follows: h k) = 2w A) k) mod 2 w ) 2 w b which value should be chosen for A? all of the values of A work at least somehow the rumor has it that A 5 2 often works quite well
10 TIE Skiplist Skip list is a randomized ordered linked list that can be used to implement the operations of a dynamic set efficicently it s a relatively new idea: the main publication is from the year 1990 each object has a height that is chosen randomly as follows: height propability etc. 6 etc. the is a list for each height k containing the objects whose height is k TIE search is done by first stepping through the highest list until the next element is too large or NIL, then the next highest etc. finally the element is found in the lowest list or we re sure the element doesn t exist the average runningtime O lg n) in the addition a height k is ramdomly selected for the element the correct location is found: O lg n) the element is linked into the lists: 1... k: O k) k is on average 2 the average running time is O lg n) TIE removal let the height of the element we re removing be k find the predecessor based on the lists1... k: k O lg n) link away from the lists: O k), on average O 2) all basic operations are O lg n) on average In tests skip lists have proven as efficient as many balanced tree structures but easier to implement.
Introduction to Data Structures and Algorithms
Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures
More informationStacks, Queues and Linked Lists
Stacks, Queues and Linked Lists Adnan Aziz 1 Dynamic sets CLRS Part III, page 197 In mathematics, a set is a welldefined collection of elements (elements could be numbers, functions, geometric shapes);
More informationSymbol Tables. IE 496 Lecture 13
Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and
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 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 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 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 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 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 informationData Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets
Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets We ve been talking a lot about efficiency in computing and run time. But thus far mostly ignoring data
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 information\Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,
Elementary Data Structures \Mankinds's progress is measured by the number of things we can do without thinking." Elementary data structures such as stacks, queues, lists, and heaps will be the \oftheshelf"
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 informationChapter Objectives. Chapter 9. Sequential Search. Search Algorithms. Search Algorithms. Binary Search
Chapter Objectives Chapter 9 Search Algorithms Data Structures Using C++ 1 Learn the various search algorithms Explore how to implement the sequential and binary search algorithms Discover how the sequential
More informationData Structures and Algorithms Stacks and Queues
Data Structures and Algorithms Stacks and Queues Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/23 60: Stacks and
More informationData Structures and Data Manipulation
Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval
More informationSymbol Tables. Introduction
Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The
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 informationChapter 7 Linked Lists
Chapter 7 Linked Lists In order to use linked lists, you need to learn how to allocate memory dynamically on the heap and you need to learn about objects. Recall that local variables are temporary which
More informationHeap. Binary Search Tree. Heaps VS BSTs. < el el. Difference between a heap and a BST:
Heaps VS BSTs Difference between a heap and a BST: Heap el Binary Search Tree el el el < el el Perfectly balanced at all times Immediate access to maximal element Easy to code Does not provide efficient
More informationRecord Storage and Primary File Organization
Record Storage and Primary File Organization 1 C H A P T E R 4 Contents Introduction Secondary Storage Devices Buffering of Blocks Placing File Records on Disk Operations on Files Files of Unordered Records
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 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 informationBinary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( BST) are of the form. P parent. Key. Satellite data L R
Binary Search Trees A Generic Tree Nodes in a binary search tree ( BST) are of the form P parent Key A Satellite data L R B C D E F G H I J The BST has a root node which is the only node whose parent
More informationMemory Management. Memory Areas and their use. Memory Manager Tasks: Free List Implementations. acquire release
Memory Management Memory Areas and their use Memory Manager Tasks: acquire release Free List Implementations Singly Linked List Doubly Linked List Buddy Systems Memory Management Memory areas: In languages
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 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 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 informationBM267  Introduction to Data Structures
BM267  Introduction to Data Structures 3. Elementary Data Structures Ankara University Computer Engineering Department BLM267 1 Objectives Learn about elementary data structures  Data structures that
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 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 informationCompiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 02 Lecture No. # 05 Runtime EnvironmentsPart 3 and Local Optimizations
More informationLecture 6. Randomized data structures Random number generation Skip lists: ideas and implementation Skip list time costs. Reading:
Lecture 6 Randomized data structures Random number generation Skip lists: ideas and implementation Skip list time costs Reading: Skip Lists: A Probabilistic Alternative to Balanced Trees (author William
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 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 informationApplication of Stacks: Postfix Expressions Calculator (cont d.)
Application of Stacks: Postfix Expressions Calculator (cont d.) Postfix expression: 6 3 + 2 * = FIGURE 715 Evaluating the postfix expression: 6 3 + 2 * = Data Structures Using C++ 2E 1 Application of
More informationLecture 1: Data Storage & Index
Lecture 1: Data Storage & Index R&G Chapter 811 Concurrency control Query Execution and Optimization Relational Operators File & Access Methods Buffer Management Disk Space Management Recovery Manager
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 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 informationAnalysis of Algorithms I: Binary Search Trees
Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary
More informationCHAPTER 4 ESSENTIAL DATA STRUCTRURES
CHAPTER 4 ESSENTIAL DATA STRUCTURES 72 CHAPTER 4 ESSENTIAL DATA STRUCTRURES In every algorithm, there is a need to store data. Ranging from storing a single value in a single variable, to more complex
More informationSearching and Hashing
Searching and Hashing Sequential Search Property: Sequential search (array implementation) uses N+1 comparisons for an unsuccessful search (always). Unsuccessful Search: (n) Successful Search: item is
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 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 informationCS104: Data Structures and ObjectOriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team
CS104: Data Structures and ObjectOriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A
More informationStacks, Queues & Trees. The Stack Interface. The Stack Interface. Prof. Dr. Harald Gall. Institut für Informatik Universität Zürich
Stacks, Queues & Trees Prof. Dr. Harald Gall Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch The Stack Interface!! Stack!! Data structure holding several items.!! New items added to the
More information6. Storage and File Structures
ECS165A WQ 11 110 6. Storage and File Structures Goals Understand the basic concepts underlying different storage media, buffer management, files structures, and organization of records in files. Contents
More information10/24/16. Journey of Byte. BBM 371 Data Management. Disk Space Management. Buffer Management. All Data Pages must be in memory in order to be accessed
Journey of Byte BBM 371 Management Lecture 4: Basic Concepts of DBMS 25.10.2016 Application byte/ record File management page, page num Buffer management physical adr. block Disk management Request a record/byte
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 informationAlgorithms. Theresa MiglerVonDollen CMPS 5P
Algorithms Theresa MiglerVonDollen CMPS 5P 1 / 32 Algorithms Write a Python function that accepts a list of numbers and a number, x. If x is in the list, the function returns the position in the list
More informationData Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015
Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may
More information Easy to insert & delete in O(1) time  Don t need to estimate total memory needed.  Hard to search in less than O(n) time
Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits:  Easy to insert & delete in O(1) time  Don t need to estimate total memory needed Drawbacks:  Hard to search in less than O(n) time (binary
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 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 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 informationINTRODUCTION The collection of data that makes up a computerized database must be stored physically on some computer storage medium.
Chapter 4: Record Storage and Primary File Organization 1 Record Storage and Primary File Organization INTRODUCTION The collection of data that makes up a computerized database must be stored physically
More informationLecture 2 February 12, 2003
6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.
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 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 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 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 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 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 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 informationThis 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 informationCMPS 102 Solutions to Homework 1
CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem.. p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which
More informationMemory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation
Dynamic Storage Allocation CS 44 Operating Systems Fall 5 Presented By Vibha Prasad Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need
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 informationDATABASE DESIGN  1DL400
DATABASE DESIGN  1DL400 Spring 2015 A course on modern database systems!! http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn! Uppsala Database Laboratory! Department of Information
More informationHome Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit
Data Structures Page 1 of 24 A.1. Arrays (Vectors) nelement vector start address + ielementsize 0 +1 +2 +3 +4... +n1 start address continuous memory block static, if size is known at compile time dynamic,
More informationFundamental Algorithms
Fundamental Algorithms Chapter 7: Hash Tables Michael Bader Winter 2014/15 Chapter 7: Hash Tables, Winter 2014/15 1 Generalised Search Problem Definition (Search Problem) Input: a sequence or set A 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 informationCSE373: Data Structures & Algorithms Lecture 14: Hash Collisions. Linda Shapiro Spring 2016
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions Linda Shapiro Spring 2016 Announcements Friday: Review List and go over answers to Practice Problems 2 Hash Tables: Review Aim for constanttime
More informationChapter 8: Bags and Sets
Chapter 8: Bags and Sets In the stack and the queue abstractions, the order that elements are placed into the container is important, because the order elements are removed is related to the order in which
More informationIntroduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.
Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed
More informationReview of Hashing: Integer Keys
CSE 326 Lecture 13: Much ado about Hashing Today s munchies to munch on: Review of Hashing Collision Resolution by: Separate Chaining Open Addressing $ Linear/Quadratic Probing $ Double Hashing Rehashing
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 informationAlgorithms and Data Structures
Basic Data Structures Page 1 BFHTI: Softwareschule Schweiz Basic Data Structures Dr. CAS SD01 Basic Data Structures Page 2 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing
More informationTables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)
Hash Tables Tables so far set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation
More informationChapter 3. Linked Lists. Data Structures and Algorithms in Java
Chapter 3 Linked Lists Data Structures and Algorithms in Java Objectives Discuss the following topics: Singly Linked Lists Doubly Linked Lists Circular Lists Skip Lists SelfOrganizing Lists Sparse Tables
More informationLecture 7: Hashing III: Open Addressing
Lecture 7: Hashing III: Open Addressing Lecture Overview Open Addressing, Probing Strategies Uniform Hashing, Analysis Cryptographic Hashing Readings CLRS Chapter.4 (and.3.3 and.5 if interested) Open Addressing
More informationUniversal hashing. In other words, the probability of a collision for two different keys x and y given a hash function randomly chosen from H is 1/m.
Universal hashing No matter how we choose our hash function, it is always possible to devise a set of keys that will hash to the same slot, making the hash scheme perform poorly. To circumvent this, we
More informationIntermezzo: A typical database architecture
Intermezzo: A typical database architecture 136 SQL SQL SQL SQL SQL Query Evaluation Engine Parser Optimizer Physical operators Transaction Manager Lock Manager Concurrency control File & Access Methods
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 informationChapter 13. Chapter Outline. Disk Storage, Basic File Structures, and Hashing
Chapter 13 Disk Storage, Basic File Structures, and Hashing Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files
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 informationLinear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta
Linear DT1: Restricted Lists Stacks, Queues tul Gupta Restricted Lists Stack Queue Circular queue Priority queue General Lists rrays Linked list Circular list Doubly linked list Linear DTs 1 Stacks Using
More informationVimal P.Parmar Research Scholar, Department of Computer Science Saurashtra University, Rajkot Gujarat, INDIA
Comparing Linear Search and Binary Search Algorithms to Search an Element from a Linear List Implemented through Static Array, Dynamic Array and Linked List Vimal P.Parmar Research Scholar, Department
More informationProblem. Indexing with Btrees. Indexing. Primary Key Indexing. Btrees. Btrees: Example. primary key indexing
Problem Given a large collection of records, Indexing with Btrees find similar/interesting things, i.e., allow fast, approximate queries Anastassia Ailamaki http://www.cs.cmu.edu/~natassa 2 Indexing Primary
More informationAlgorithms. Margaret M. Fleck. 18 October 2010
Algorithms Margaret M. Fleck 18 October 2010 These notes cover how to analyze the running time of algorithms (sections 3.1, 3.3, 4.4, and 7.1 of Rosen). 1 Introduction The main reason for studying bigo
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More information406 memory pool memory allocation handle memory deallocation dynamic storage allocation
406 Chap. 12 Lists and Arrays Revisited 12.4 Memory Management Most of the data structure implementations described in this book store and access objects all of the same size, such as integers stored in
More informationrecursion, O(n), linked lists 6/14
recursion, O(n), linked lists 6/14 recursion reducing the amount of data to process and processing a smaller amount of data example: process one item in a list, recursively process the rest of the list
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 informationAS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm
AS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A
More informationData Structure [Question Bank]
Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:
More informationLecture 12 Doubly Linked Lists (with Recursion)
Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)
More informationPersistent Binary Search Trees
Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents
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 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 information