Project 2 Heap. Out: March 16 In: March Mechanics: Installing, Handing In, Demos, and Location of Documentation

Size: px
Start display at page:

Download "Project 2 Heap. Out: March 16 In: March Mechanics: Installing, Handing In, Demos, and Location of Documentation"

Transcription

1 Project 2 Heap Out: March 16 In: 1 Mechanics: Installing, Handing In, Demos, and Location of Documentation 1. To install, type cs016 install heap into a shell. The script will create the appropriate directories and deposit the stencil code files into them. 2. To compile your code, type make in your heap directory. To run your code, type make run in the same directory. 3. To hand in your project, go to the directory you wish to hand in, and type cs016_handin heap into a shell. Before using this script, make sure that you are in the correct directory! It will hand in the entire current directory, and we don t really want all of your files just the ones pertinent to this project. (So be sure to save your README and any other files you need to hand in in the same directory as your code.) 4. To run a demo of this project, type cs016_rundemo heap into a shell. 5. The Heap documentation can be found here: This is also linked off of the class website on the Assignments page. 2 Introduction 2.1 What You ll Do in this Project In this assignment you will implement a priority queue, using a heap as the underlying data structure. Your heap implementation will be based on a version of a link-based binary tree, which you will modify. 2.2 Purpose The purpose of this assignment is to help you: Understand a link-based binary tree, and its use in implementing a heap-based priority queue. Identify the advantages of the interface provided by a complete binary tree. March 18,

2 Gain experience in implementing and using a heap and a priority queue. Extend your understanding of Positions and how they differ from Entries. Learn about using comparators. Increase your familiarity with throwing exceptions and using try/catch blocks. Practice coding efficiently to meet specific runtime requirements. 3 Overview of Your Tasks We have provided stencil code for the following classes: MyLinkedHeapTree<E>, MyHeap<K,V>, and MyHeapEntry<K,V>. Your job will be to fill in all three classes, which are described below: 1. MyLinkedHeapTree<E>: This class is an implementation of the CompleteBinaryTree<E> interface (from the net.datastructures 4.0 (NDS4) package), and extends the NDS4 LinkedBinaryTree<E> data structure. It will serve as the modified link-based binary tree on top of which your heap will be constructed. Since much of the binary tree functionality of this class is inherited from LinkedBinaryTree<E>, you should read the documentation for this class carefully in order to understand how the class you are extending operates. Note that the generic E represents the type of the elements that the tree is capable of holding. 2. MyHeap<K,V>: This class is an implementation of the interface AdaptablePriorityQueue<K,V>, from the NDS4 package. This class represents the heap itself, relying on an underlying complete binary tree (your MyLinkedHeapTree<E>) to hold its data. The generics K and V represent the types of the keys and values for the key/value pair of each element in the heap. There is an important distinction between normal and adaptable priority queues: adaptable priority queues have the ability to replace the key or value of an entry after it has been added, and additionally have the option of removing from the priority queue an item that is not at the top of the heap. 3. MyHeapEntry<K,V>: This class is an implementation of the Entry<K,V> interface, and represents an element that will be stored in the heap. Such elements of the heap consist of mutable key/value pairs. While classes that hold such pairs are available within NDS4, your implementation will require several additional accessors and mutators, which will allow you to perform all of the actions associated with an adaptable PQ. Think about the relationship between your Entry implementation and the Positions (or nodes, as you may want to think of them), which will hold each element in the binary tree. March 18,

3 3.1 Requirements 1. Fill in the three classes listed above: MyLinkedHeapTree<E>, MyHeap<K,V>, MyHeapEntry<K,V>. The methods you need to fill in for each class are specified in the stencil code. 2. The methods you write for this project must adhere to strict runtime requirements. These requirements are listed in the Javadocs (more on this in Section 3.10), as well as in the method comments in the stencil code. Running time is a significant portion of your grade, so don t gloss over this requirement! 3. You will need to throw a number of exceptions for this project, each of which is welldefined in the stencil code, and below. Every method that requires an exception is specified in the stencil code, so you do not need to come up with any other times when these exceptions should be thrown. You will, however, need to identify (within a given method) the conditions that will cause a problem which necessitates throwing an exception, and write code to check whether these conditions exist. Here is a list of the exceptions: IllegalStateException: An exception from the java.lang package intended to be thrown when a method has been invoked at an illegal or inappropriate time. In this project, we are using it to signal that a priority queue cannot change the comparator it is using unless it is currently empty. This exception is thrown in MyHeap.setComparator(...). EmptyPriorityQueueException: An exception from NDS4 that indicates that a priority queue cannot fulfill the requested operation because it is empty. This exception is thrown in MyHeap.min() and MyHeap.removeMin() as you would expect, since you can t look at/remove elements from an empty heap. InvalidKeyException: An exception from NDS4 indicating that the key which is being handled has been determined to be invalid. The Comparator in use is the only object that can determine a key s validity. The Comparator has a compare(...) method which can compare two keys. You can use this method to test whether a key is valid: if you pass an invalid key as an argument to your Comparator, it will throw a ClassCastException. Thus, you can use the Comparator to compare a key to itself; if the Comparator throws an exception, you should catch it, and throw your own exception the InvalidKeyException. Don t forget that a null key is also invalid. MyHeap.insert() is the only method with a signature explicity throwing this exception, but you may find that it makes sense to also throw it from MyHeap.replaceKey(...). InvalidEntryException: An exception from NDS4 that is thrown when the Entry<K,V> that is being handled is invalid. For example, an Entry<K,V> that is null would be invalid, as would an Entry<K,V> that is not of the type being used in your heap. (Think about or research ways that you might detect March 18,

4 this.) If you find yourself needing to cast MyHeapEntry<K,V> objects to access additional methods, a helper method in MyHeap<K,V> that first checks validity might be useful to write. This exception is thrown in MyHeap.remove(...), MyHeap.replaceKey(), and MyHeap.replaceValue(...); it should be thrown if you give any of those three methods an invalid Entry<K,V> as a parameter. EmptyTreeException: An exception from NDS4 indicating that the tree cannot fulfill the requested operation because it is empty. Note that this is very similar to the EmptyPriorityQueueException which was described above. In fact, you should never see this exception thrown from your heap, because EmptyPriorityQueueException should intercept the same condition first. However, you still need to throw this exception from your MyLinkedHeapTree.remove() method. This may seem silly, but it is good coding practice to make your code extensible; that is, you know that in this project you are using your MyLinkedHeapTree underneath your MyHeap class, and thus will catch this condition with an EmptyPriorityQueueException, but including this exception will ensure that your CompleteBinaryTree<E> implementation is usable in other contexts in which you may not necessarily catch an empty priority queue condition elsewhere in the code. 4. We are providing you with a visualizer to help you test and debug your code; this visualizer is described in Section 5. You will need to correctly fill in the gettree() and size() methods in the MyHeap class in order for the visualizer to work properly; this is discussed more thoroughly in Section 5 of this handout. 3.2 README The README for this project has some specific points that you need to address. Make a text file entitled README, which should be saved in the same directory as is your project; it will be handed in along with your code. (You can create a text file by opening it in kate or any other editor just cd into the directory in which you want to save the README, then type, for example, kate README & to create the file.) Each of the questions should be answered in about 1-4 lines, unless otherwise stated. Discuss the design choices you made in your MyHeapEntry<K,V> implementation. If you defined your own methods, explain why you chose to add them. Explain how you implemented a CompleteBinaryTree<E>; in particular, you should talk about the connection to LinkedBinaryTree<E>, which should have been your starting point. Describe the method you used to keep track of where to add and remove nodes in the tree. Please characterize the running time of of the MyLinkedHeapTree<E> methods. March 18,

5 Include anything else particularly notable about your implementation. Don t forget to talk about any bugs you are aware of in your code. (And of course, you should thoroughly test your code to find any bugs that exist.) The CS16 staff uses automated testing utilities for Heap that help to assess the functionality of your program; this means that if there is a bug in your code, we will find it. If you find a bug yourself and just can t get it fixed before turning in your project, make sure to let us know in your README you will be rewarded! Tell us what goes wrong, what functionality is affected, and roughly where you think the problem is, and we ll give you some points back. You won t get full credit, but you will lose fewer points than you would if you either pretended the bug wasn t there, or didn t bother to find it in the first place. 4 Reading The in-class lecture slides for Heap and Heap-Sort, which can be found here: 12.pdf. This is also linked off of the class website on the Assignments page. A reference for Adaptable Priority Queues: *Note: You need to have a solid grasp of the information in both of these readings before you begin coding, so make sure that you read and understand them!! If you are confused about anything in either of these readings, go see a TA before you start your project. 5 Visualizer We are providing you with a visualizer that will graphically display your heap. The top portion of the visualizer will display your tree, with a circle representing a node of the tree (so, an entry in your heap) and a black line conneting two nodes representing an edge of the tree. Nodes will display a number and a string of letters; the number in a node represents that heap entry s key and the string in a node represents that heap entry s value. The visualizer will display parent/child relationships by making parents appear higher in the window than their children do. As your tree grows, the scrollable window will shift to accommodate the extra branches. You can select a node in the visualizer by clicking on it; selected nodes are colored pink, while un-selected nodes are colored blue. You can use the visualizer to create heaps with (key, value) pairs stored at the nodes, where keys are numbers and values are combinations of letters. You will have the option to either create entries with random keys and/or values, or to create entries with keys/values that you specify. When you click certain buttons on the visualizer, it will display information to you in a text box at the bottom of the screen; for example, if you click size(), the March 18,

6 size of your heap will be displayed in the box. You can clear the text box by clicking the Clear Text Area button on the visualizer. The buttons are self-explanatory, but will also be discussed in more detail below. In order for the following functionality of the visualizer to work, you will need to correctly implement the specific methods in the MyHeap class which correspond to the action in the visualizer. For example, in order to be able to check whether the graphical heap is empty, you need to properly implement the isempty() method. check the size of the heap: click on the size() button (requires size()) check whether the heap is empty: click on the isempty() button (requires isempty()) insert a new node into the heap: choose whether you want a random, invalid, or specific key and/or value to be generated for your new node; if you want a specific key and/or value, input appropriate values into the text boxes in the third row of the visualizer. (Note that keys must be integers between 0 and 99, inclusive, and that values should be strings of 1, 2, or 3 letters; the visualizer will not let you input valid keys or values.) If you want a random key or value, check the appropriate box(es) and then click the Make Random Item button. If you want an invalid item, click the Make Invalid Item button. This will create a K,V pair with an invalid key, but a valid value of INV. The visualizer has no way of making a K,V pair with an invalid value, so you can t use the visualizer to trigger an InvalidEntryException. (Creating an entry with an invalid key constitutes an invalid entry, but in this case the InvalidKeyException will be thrown first, and the call will terminate before throwing an InvalidEntryException.) Once you have generated your key and value, click on the insert(key, val) button to make a node with the values currently in the text boxes (requires insert(k,v)) remove the minimum-key entry from the heap: click on the removemin() button (requires removemin()) highlight the minimum of the heap: click on the min() button to print the minimum element to the text window and to highlight the minimum node in pink in your graphical window (requires min()) remove a specific entry from the heap: click on the node in the visualizer window that you want to remove (it should turn pink to indicate that it has been selected), then click the remove(entry) button (requires remove(entry<k,v>)) replace the key of an entry in the heap: click on the node in the visualizer window whose key you want to replace (it should turn pink to indicate that it has been selected), then click the replacekey(entry, key) button (requires replacekey(entry<k,v>,k)) March 18,

7 replace the value of an entry in the heap: click on the node in the visualizer window whose value you want to replace (it should turn pink to indicate that it has been selected), then click the replacevalue(entry, val) button (requires replacevalue(entry(<k,v>), V)) deselect a node: click on the background inside the graphical window of the visualizer (no methods required) In order for the visualizer to function, you will need to correctly implement the following two methods in the MyHeap class: gettree(): necessary in order for the visualizer to access the data in your heap and display it graphically size(): necessary in order to correctly size the visualizer window You should note that the gettree() method breaks encapsulation by allowing the binary tree underlying your heap to be publicly exposed. Violating encapsulation is generally bad design practice, but is necessary in this case in order for our visualizer to know what entries your heap is holding. 6 Application: Fishfood We are also providing you with a more interesting application for your heap: Fishfood. Fishfood animates a race between an octopus and a single flagellum: it generates a random graph of vertices and edges, and then has the two organisms follow specific paths through the graph. Dijkstra s shortest-path-finding algorithm (which you will be learning about in class soon!) uses a min-priority-queue as its underlying data structure. Fishfood uses Dijkstra s algorithm to calculate the optimal (shortest) path from the start node to the finish node in the graph using the TAs version of Heap, and the octopus follows that path. Fishfood also runs Dikjstra s algorithm using your heap as this min-priority-queue, and the single flagellum will follow the path generated by that run of Dijkstra s. If your heap is implemented correctly, the path generated using your heap will be the same as the path generated by the TAs heap. Nodes in the graph are colored yellow, with the start node in pale green and the end node in orange. If your path matches the TAs path completely, optimal path nodes will be shown in dark green. If your path differs from the TAs path, your path will be given in red, the TAs path will be given in blue, and the overlap between your path and the TAs path will be given in purple. To start the race, click the Start button. (You can restart a race at any time.) You can also hit the Reset button to generate a new graph on which to race your octopus and March 18,

8 flagellum. *Note: if you quit Fishfood, it will also close the visualizer, so don t run Fishfood and close it if you don t want to lose whatever you have in your visualizer. (You can, however, work in the visualizer while Fishfood is open.) 7 Design You will construct your heap-based priority queue on top of a link-based binary tree. You should design the program in its entirety before you even think about starting to code it s no fun to be forced to start over after you ve written a significant amount of code because you did not put enough thought into your design! Feel free to come to TA hours if you have questions about your design. When working through the design process, here are a number of things that you should consider: Positions vs. Entries: Before you begin thinking about how to implement your classes, you need to have a solid understanding of the distinction between Positions and Entries in the data structure. A Position is a tree node. It is a container for an Entry: once created, a Position stays in the same place in the tree until it is deleted. However, Entries can be moved among Positions freely. Notice that the NDS4 Position<E> interface contains a generic, E, which is the type of the element that a Position contains. Entry Key/Value Pairs: So what elements do the Positions of your tree contain? They contain references to other Positions (specifically, the Positions of the children and parent) and an Entry<K,V>. Entries contain a key/value pair (hence, K and V) and are the data-containing elements of your heap. For example, the entries used in the visualizer consist of an integer key between 1 and 99 and a string value of three characters. Positions are tied down in a single location on the heap because it s too much work to re-link parent and child nodes every time you want to up-heap or down-heap. Instead, the Entries contained within the Positions move, swapping themselves between Postions when called for in heap-order restoration. It s a subtle distinction, so re-examine the adaptable prioirty queue reference and see a TA if you re still confused. Extra MyHeap Methods: In this project, we ask you to write the class MyHeapEntry<K,V>. This task requires some thinking: you cannot simply implement the two accessor methods getkey() and getvalue() that are defined by the Entry<K,V> interface and be done with it. Think about the replacekey(...) and replacevalue(...) methods of your MyHeap class. It doesn t make sense to simply instantiate a new Entry<K,V> every time you need to alter the contents of an existing one. Perhaps some mutator, or set, methods would be helpful? More substantially, you need to think about the Entry s relationship with the Position holding March 18,

9 it. Why does an Entry need to know its location in the heap? What should happen when an Entry s key is changed? See the description of location-aware entry in the adaptable priority queue reference. First and Last Nodes: One of your major tasks in this project is to adapt the NDS4 class LinkedBinaryTree<E> so that it represents a complete binary tree your MyLinkedHeapTree class. Doing so means ensuring that the tree always knows where its last node is (the node to be moved to a different position within the tree in case of a remove() call), and where the next node to be inserted should go. This is far more complicated than it may first appear, as not only are the two nodes not necessarily close to each other, but the stringent running time requirements of the methods in MyHeap<K,V> depend on the MyLinkedHeapTree s add(...) and remove() methods being implemented efficiently. This means that the methods you implement in the MyLinkedHeapTree<E> must run in (amortized) O(1) time! More on this in the next two bullets... Node-Tracking Algorithms: We re not explicity going to tell you how to implement your node-tracking in MyLinkedHeapTree<E>, so you have some options. The in-class slides on Heaps and Heap-Sort, as well as the adaptable priority queue reference, contain the sketch of an algorithm for finding the parent under which to insert new nodes given the current last node. Note that the algorithm sketch does not handle all insertion cases in particular, you should think about what to do when you ve inserted a node in the right-most position in a given level of a tree. This algorithm runs in worst-case time proportional to the height of the tree (i.e., O(nlogn)), but over a series of insertions and deletions, its amortized running time is in fact O(1). Put plainly, this means that, yes, you can use it in your MyLinkedHeapTree<E>. The question now becomes, how do I track the last node as I insert and remove elements? A fundamental data structure may help you with this... perhaps something in which you can push and pop nodes? Alternative Node-Tracking : There are, in fact, more efficient (and more elegant) ways to keep track of your last node and your insertion parent node than the algorithm we ve hinted at above. (In fact, you can implement a clever algorithm that will run in worst-case rather than amortized O(1) time!) Think about what types of data structures might be useful here, and remember that your choice of implementation is completely up to you. All the classes of the NDS4 package are at your disposal, and anything that will make the add(...) and remove() methods of MyLinkedHeapTree run in O(1) time and with reasonable space usage is acceptable. Feel free to do a sanity check with a TA if you d like to try a more ambituous method. Creativity will be rewarded! (Hint: the Deque variety of a standard queue in NDS4 may be helpful for one approach to solving the problem.) Understanding MyHeap: This class will contain the majority of the code you write, but writing that code does not have to be too difficult. In Section 3.1, we March 18,

10 discussed the distinction between an adaptable priority queue (which you are implementing) and a normal priority queue (which the Goodrich and Tamassia textbook explores in depth, including code samples.) If you re confused by the big picture idea of adaptable priority queues, we encourage you to do the reading in the book; you won t be able to just copy the code, but doing the reading will certainly get you started on modifying the heap for adaptable methods. 8 Testing We are not requiring you to turn in test cases for this project. However, that does not mean that you don t have to test your project! While you don t have to explicitly write up a file of test cases, we want you to think about testing just as thoroughly as you would otherwise this means that you need to come up with a list of all functionality that needs to be tested, and figure out all of the edge cases, etc., that you need to test in order to be sure that each specific part of the functionality was implemented correctly. The visualizer will be a very helpful debugging tool once you start going through your functionality checklist! 9 What to Hand In 1. Code for the classes MyHeap, MyHeapEntry, and MyLinkedHeapTree. 2. A README as described in Section Support Code Instead of providing you with a list of method signatures and running time requirements for the classes you will implement in this project, we are asking you to examine the Javadocs for Heap. (The documentation is linked off of the class website on the Assignments page; the URL is also given in Section 1 of this handout.) These documents contain all of the information you ll need, so if you haven t used Javadocs before, now is a great time to learn. (And it s a valuable skill to have! Being able to look up this information yourself will make you a more independent programmer, which will be especially important as you move on to upper-level CS classes.) If you re new to Javadocs, feel free to drop by TA hours, and we ll get you started. Javadocs are highly self-explanatory and are quite useful for linking together information such as the classes that implement certain interfaces, what parameters need to be passed to methods, the return type and exception-throwing signature of a method, etc. The documentation is automatically generated from comments in the stencil code, so you ll have a ready reference in the Java files as you write your code as well. We re expecting you to concentrate on the classes in the heap package (rather than the support.heap package) while browsing the Javadocs, as the former is where the essential March 18,

11 information is. The latter is simply the classes we use to launch the visualizer, so it probably won t be especially useful for you to go through the support.heap documentation but feel free to do so if you re curious! March 18,

Stores a collection of elements each with an associated key value

Stores a collection of elements each with an associated key value CH9. PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 201) PRIORITY QUEUES Stores a collection

More information

Describe how to implement deque ADT using two stacks as the only instance variables. What are the running times of the methods

Describe how to implement deque ADT using two stacks as the only instance variables. What are the running times of the methods Describe how to implement deque ADT using two stacks as the only instance variables. What are the running times of the methods 1 2 Given : Stack A, Stack B 3 // based on requirement b will be reverse of

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

Project #1 Seam Carving

Project #1 Seam Carving Project #1 Seam Carving Out: Fri, Jan 19 In: 1 Installing, Handing In, Demos, and Location of Documentation 1. To install, type cs016 install seamcarve into a shell in the directory in which you want the

More information

CH 8. HEAPS AND PRIORITY QUEUES

CH 8. HEAPS AND PRIORITY QUEUES CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

Classes, interfaces, & documentation. Review of basic building blocks

Classes, interfaces, & documentation. Review of basic building blocks Classes, interfaces, & documentation Review of basic building blocks Objects Data structures literally, storage containers for data constitute object knowledge or state Operations an object can perform

More information

CH. 8 PRIORITY QUEUES AND HEAPS

CH. 8 PRIORITY QUEUES AND HEAPS CH. 8 PRIORITY QUEUES AND HEAPS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) CSE 11 Winter 2017 Program Assignment #2 (100 points) START EARLY! Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) PROGRAM #2: DoubleArray11 READ THE ENTIRE ASSIGNMENT BEFORE STARTING In lecture,

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 20 Priority Queues Today we are going to look at the priority

More information

HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES

HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES 2 5 6 9 7 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H., Wiley, 2014

More information

Priority Queues 3/19/14

Priority Queues 3/19/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Priority Queues Priority Queues 1 Priority

More information

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue Agenda hw4 being graded hw5 may be graded first, for feedback to be used on hw6 hw6 due next week Today hw6 BFS Debugging hashcode()

More information

Priority Queues. Outline. COMP9024: Data Structures and Algorithms. Priority Queue ADT. Total Order Relations. Entry ADT

Priority Queues. Outline. COMP9024: Data Structures and Algorithms. Priority Queue ADT. Total Order Relations. Entry ADT COMP0: Data Structures and Algorithms Week Seven: Priority Queues Hui Wu Outline Priority Queues Heaps Adaptable Priority Queues Session, 0 http://www.cse.unsw.edu.au/~cs0 Priority Queue ADT Priority Queues

More information

Priority Queues & Heaps. Chapter 9

Priority Queues & Heaps. Chapter 9 Priority Queues & Heaps Chapter 9 The Java Collections Framework (Ordered Data Types) Interface Abstract Class Class Iterable Collection Queue Abstract Collection List Abstract Queue Abstract List Priority

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,

More information

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation Chapter 1 CS488/688 F17 Assignment Format I take off marks for anything... A CS488 TA Assignments are due at the beginning of lecture on the due date specified. More precisely, all the files in your assignment

More information

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

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

More information

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 104 (Spring 2014) Final Exam 05/09/2014 CS 104 (Spring 2014) Final Exam 05/09/2014 G o o d L u c k Your Name, USC username, and Student ID: This exam has 8 pages and 8 questions. If yours does not, please contact us immediately. Please read

More information

Project 1 Balanced binary

Project 1 Balanced binary CMSC262 DS/Alg Applied Blaheta Project 1 Balanced binary Due: 7 September 2017 You saw basic binary search trees in 162, and may remember that their weakness is that in the worst case they behave like

More information

CSE 100 Advanced Data Structures

CSE 100 Advanced Data Structures CSE 100 Advanced Data Structures Overview of course requirements Outline of CSE 100 topics Review of trees Helpful hints for team programming Information about computer accounts Page 1 of 25 CSE 100 web

More information

Introduction to Programming

Introduction to Programming CHAPTER 1 Introduction to Programming Begin at the beginning, and go on till you come to the end: then stop. This method of telling a story is as good today as it was when the King of Hearts prescribed

More information

CMPSCI 187 / Spring 2015 Sorting Kata

CMPSCI 187 / Spring 2015 Sorting Kata Due on Thursday, April 30, 8:30 a.m Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 Contents Overview 3 Learning Goals.................................................

More information

Lecture 17 Priority Queues

Lecture 17 Priority Queues Lecture 17 Priority Queues 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning, Rob Simmons In this lecture we will look at priority queues as an abstract type and discuss several

More information

Homework 5. Due Friday, March 1 at 5:00 PM

Homework 5. Due Friday, March 1 at 5:00 PM WRITTEN PROBLEMS Homework 5 Due Friday, March at 5:00 PM I think we can all agree that junior high is filled with embarrassing and awkward and downright humiliating moments, right? - Lizzie McGuire Handing

More information

Project 3: Implementing a List Map

Project 3: Implementing a List Map Project 3: Implementing a List Map CSCI 245 Programming II: Object-Oriented Design Spring 2017 Devin J. Pohly (adapted from Thomas VanDrunen) This project has two main goals: To give you practice in implementing

More information

CS 283: Assignment 1 Geometric Modeling and Mesh Simplification

CS 283: Assignment 1 Geometric Modeling and Mesh Simplification CS 283: Assignment 1 Geometric Modeling and Mesh Simplification Ravi Ramamoorthi 1 Introduction This assignment is about triangle meshes as a tool for geometric modeling. As the complexity of models becomes

More information

Lecture 17 Notes Priority Queues

Lecture 17 Notes Priority Queues Lecture 17 Notes Priority Queues 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons 1 Introduction In this lecture we will look at priority queues as an abstract type

More information

3 ADT Implementation in Java

3 ADT Implementation in Java Object-Oriented Design Lecture 3 CS 3500 Spring 2010 (Pucella) Tuesday, Jan 19, 2010 3 ADT Implementation in Java Last time, we defined an ADT via a signature and a specification. We noted that the job

More information

Project #1 Seamcarve

Project #1 Seamcarve Project #1 Seamcarve Out: Thursday, January 25 In: It s no use, it s no use, we are doomed! You did it! You saved us, Perry the...cs16 Student -Doofenshmirtz 1 Installing, Handing In, Demos 1. To install,

More information

Project #1 Seamcarve

Project #1 Seamcarve Project #1 Seamcarve Out: Thursday, January 24 In: This is real, this is me Im exactly where I m supposed to be, now Gonna let the light, shine on me Now I ve found, who I am There s no way to hold it

More information

Data Structures and Algorithms " Priority Queues!

Data Structures and Algorithms  Priority Queues! Data Structures and Algorithms " Priority Queues! Outline" Priority Queues! Heaps! Adaptable Priority Queues! Priority Queues" Priority Queue ADT" A priority queue stores a collection of entries! Each

More information

Shadows in the graphics pipeline

Shadows in the graphics pipeline Shadows in the graphics pipeline Steve Marschner Cornell University CS 569 Spring 2008, 19 February There are a number of visual cues that help let the viewer know about the 3D relationships between objects

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

Priority queues. Priority queues. Priority queue operations

Priority queues. Priority queues. Priority queue operations Priority queues March 8, 08 Priority queues The ADT priority queue stores arbitrary objects with priorities. An object with the highest priority gets served first. Objects with priorities are defined by

More information

Priority Queues. INFO0902 Data Structures and Algorithms. Priority Queues (files à priorités) Keys. Priority Queues

Priority Queues. INFO0902 Data Structures and Algorithms. Priority Queues (files à priorités) Keys. Priority Queues Priority Queues INFO0902 Data Structures and Algorithms Priority Queues Justus H. Piater Priority Queues (files à priorités) Keys Extract the top-priority element at any time. No notion of order, positions,

More information

Interface. 2. Interface Adobe InDesign CS2 H O T

Interface. 2. Interface Adobe InDesign CS2 H O T 2. Interface Adobe InDesign CS2 H O T 2 Interface The Welcome Screen Interface Overview The Toolbox Toolbox Fly-Out Menus InDesign Palettes Collapsing and Grouping Palettes Moving and Resizing Docked or

More information

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel Jerry Cain Handout #5 CS 106AJ September 30, 2017 Using JSKarel This handout describes how to download and run the JavaScript version of Karel that we ll be using for our first assignment. 1. Getting started

More information

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical Choose It Maker 2 Quick Guide Created 09/06 Updated SM Overview/Introduction This is a simple to use piece of software that can be tailored for use by children as an alternative to a pencil and paper worksheet,

More information

Heaps and Priority Queues

Heaps and Priority Queues Heaps and Priority Queues Lecture delivered by: Venkatanatha Sarma Y Assistant Professor MSRSAS-Bangalore 11 Objectives To introduce Priority Queue ADT To discuss and illustrate Priority Queues for sorting

More information

Heaps 2. Recall Priority Queue ADT. Heaps 3/19/14

Heaps 2. Recall Priority Queue ADT. Heaps 3/19/14 Heaps 3// Presentation for use with the textbook Data Structures and Algorithms in Java, th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 0 Heaps Heaps Recall Priority Queue ADT

More information

CMPSCI 187 / Spring 2015 Hanoi

CMPSCI 187 / Spring 2015 Hanoi Due on Thursday, March 12, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 Contents Overview 3 Learning Goals.................................................

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Binary Search Trees Treesort

Binary Search Trees Treesort Treesort CS 311 Data Structures and Algorithms Lecture Slides Friday, November 13, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009

More information

StoryStylus Scripting Help

StoryStylus Scripting Help StoryStylus Scripting Help Version 0.9.6 Monday, June 29, 2015 One More Story Games, Inc. 2015 Contents Versions... 3 Scripting User Interface... 4 Script Triggers... 5 If-Then Scripting Language... 6

More information

PATH FINDING AND GRAPH TRAVERSAL

PATH FINDING AND GRAPH TRAVERSAL PATH FINDING AND GRAPH TRAVERSAL PATH FINDING AND GRAPH TRAVERSAL Path finding refers to determining the shortest path between two vertices in a graph. We discussed the Floyd Warshall algorithm previously,

More information

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0. CSCI0330 Intro Computer Systems Doeppner Lab 02 - Tools Lab Due: Sunday, September 23, 2018 at 6:00 PM 1 Introduction 0 2 Assignment 0 3 gdb 1 3.1 Setting a Breakpoint 2 3.2 Setting a Watchpoint on Local

More information

CREATING CONTENT WITH MICROSOFT POWERPOINT

CREATING CONTENT WITH MICROSOFT POWERPOINT CREATING CONTENT WITH MICROSOFT POWERPOINT Simple Tips And Tricks Presented by TABLE OF CONTENTS Introduction... 2 Design Tips... 3 Advanced Tips... 4 ShortCut Keys for Microsoft PowerPoint... 5 How-Tos...

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps CS 240 Fall 2015 Mike Lam, Professor Priority Queues and Heaps Priority Queues FIFO abstract data structure w/ priorities Always remove item with highest priority Store key (priority) with value Store

More information

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via  by Friday, Mar. 18, 2016 Math 304 - Dr. Miller - Constructing in Sketchpad (tm) - Due via email by Friday, Mar. 18, 2016 As with our second GSP activity for this course, you will email the assignment at the end of this tutorial

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java 15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java Dates of Interest Assigned: During class, Friday, January 26, 2007 Due: 11:59PM, Friday, February 13, 2007 Credits

More information

Total Score /20 /20 /20 /25 /15 Grader

Total Score /20 /20 /20 /25 /15 Grader NAME: NETID: CS2110 Fall 2009 Final Exam December 16, 2009 Write your name and Cornell netid. There are 5 questions on 10 numbered pages. Check now that you have all the pages. Write your answers in the

More information

In this lesson, you ll learn how to:

In this lesson, you ll learn how to: LESSON 5: ADVANCED DRAWING TECHNIQUES OBJECTIVES In this lesson, you ll learn how to: apply gradient fills modify graphics by smoothing, straightening, and optimizing understand the difference between

More information

COMP 250 Fall recurrences 2 Oct. 13, 2017

COMP 250 Fall recurrences 2 Oct. 13, 2017 COMP 250 Fall 2017 15 - recurrences 2 Oct. 13, 2017 Here we examine the recurrences for mergesort and quicksort. Mergesort Recall the mergesort algorithm: we divide the list of things to be sorted into

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

Keep Track of Your Passwords Easily

Keep Track of Your Passwords Easily Keep Track of Your Passwords Easily K 100 / 1 The Useful Free Program that Means You ll Never Forget a Password Again These days, everything you do seems to involve a username, a password or a reference

More information

Priority Queues Goodrich, Tamassia. Priority Queues 1

Priority Queues Goodrich, Tamassia. Priority Queues 1 Priority Queues Priority Queues 1 Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue ADT insert(k, x) inserts an entry

More information

CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O

CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O Introduction The WRITE and READ ADT Operations Case Studies: Arrays Strings Binary Trees Binary Search Trees Unordered Search Trees Page 1 Introduction

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM Introduction to the Assignment In this lab, you will finish the program to allow a user to solve Sudoku puzzles.

More information

Chapter 6 Heapsort 1

Chapter 6 Heapsort 1 Chapter 6 Heapsort 1 Introduce Heap About this lecture Shape Property and Heap Property Heap Operations Heapsort: Use Heap to Sort Fixing heap property for all nodes Use Array to represent Heap Introduce

More information

Applied Algorithm Design Lecture 3

Applied Algorithm Design Lecture 3 Applied Algorithm Design Lecture 3 Pietro Michiardi Eurecom Pietro Michiardi (Eurecom) Applied Algorithm Design Lecture 3 1 / 75 PART I : GREEDY ALGORITHMS Pietro Michiardi (Eurecom) Applied Algorithm

More information

Second Examination Solution

Second Examination Solution University of Illinois at Urbana-Champaign Department of Computer Science Second Examination Solution CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, November 8 Name: NetID: Lab

More information

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise If you re not already crazy about Scheme (and I m sure you are), then here s something to get

More information

n! = 1 * 2 * 3 * 4 * * (n-1) * n

n! = 1 * 2 * 3 * 4 * * (n-1) * n The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are

More information

Total Score /15 /20 /30 /10 /5 /20 Grader

Total Score /15 /20 /30 /10 /5 /20 Grader NAME: NETID: CS2110 Fall 2009 Prelim 2 November 17, 2009 Write your name and Cornell netid. There are 6 questions on 8 numbered pages. Check now that you have all the pages. Write your answers in the boxes

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

CS 4349 Lecture October 18th, 2017

CS 4349 Lecture October 18th, 2017 CS 4349 Lecture October 18th, 2017 Main topics for #lecture include #minimum_spanning_trees. Prelude Homework 6 due today. Homework 7 due Wednesday, October 25th. Homework 7 has one normal homework problem.

More information

Entry and Priority Queue ADTs

Entry and Priority Queue ADTs Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Adaptable Priority Queues 3 a 5 g 4 e Adaptable

More information

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5 - The Meta-Circular

More information

CS 051 Homework Laboratory #2

CS 051 Homework Laboratory #2 CS 051 Homework Laboratory #2 Dirty Laundry Objective: To gain experience using conditionals. The Scenario. One thing many students have to figure out for the first time when they come to college is how

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

Adding content to your Blackboard 9.1 class

Adding content to your Blackboard 9.1 class Adding content to your Blackboard 9.1 class There are quite a few options listed when you click the Build Content button in your class, but you ll probably only use a couple of them most of the time. Note

More information

COMP 105 Homework: Type Systems

COMP 105 Homework: Type Systems Due Tuesday, March 29, at 11:59 PM (updated) The purpose of this assignment is to help you learn about type systems. Setup Make a clone of the book code: git clone linux.cs.tufts.edu:/comp/105/build-prove-compare

More information

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 CS17 Integrated Introduction to Computer Science Klein Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 Contents 1 Reverse (Practice) 4 2 Main Diagonal (Practice) 5 3 Horizontal Flip 6 4 Vertical Flip

More information

Intro to Algorithms. Professor Kevin Gold

Intro to Algorithms. Professor Kevin Gold Intro to Algorithms Professor Kevin Gold What is an Algorithm? An algorithm is a procedure for producing outputs from inputs. A chocolate chip cookie recipe technically qualifies. An algorithm taught in

More information

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections Thread Safety Today o Confinement o Threadsafe datatypes Required reading Concurrency Wrapper Collections Optional reading The material in this lecture and the next lecture is inspired by an excellent

More information

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1 COMP 210: Object-Oriented Programming Lecture Notes 1 Java Program Structure and Eclipse Robert Utterback In these notes we talk about the basic structure of Java-based OOP programs and how to setup and

More information

Binary Trees Due Sunday March 16, 2014

Binary Trees Due Sunday March 16, 2014 Problem Description Binary Trees Due Sunday March 16, 2014 Recall that a binary tree is complete if all levels in the tree are full 1 except possibly the last level which is filled in from left to right.

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Programming Standards: You must conform to good programming/documentation standards. Some specifics: CS3114 (Spring 2011) PROGRAMMING ASSIGNMENT #3 Due Thursday, April 7 @ 11:00 PM for 100 points Early bonus date: Wednesday, April 6 @ 11:00 PM for a 10 point bonus Initial Schedule due Thursday, March

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof. Priority Queues 1 Introduction Many applications require a special type of queuing in which items are pushed onto the queue by order of arrival, but removed from the queue based on some other priority

More information

Data structures. Priority queues, binary heaps. Dr. Alex Gerdes DIT961 - VT 2018

Data structures. Priority queues, binary heaps. Dr. Alex Gerdes DIT961 - VT 2018 Data structures Priority queues, binary heaps Dr. Alex Gerdes DIT961 - VT 2018 Announcements Course representatives - Mohamad Qutbuddin Habib - Carl Agrell - Gunnar Stenlund Kunsulttid: jag är på kontor

More information

Drawing Hands, by M. C. Escher (lithograph, 1948)

Drawing Hands, by M. C. Escher (lithograph, 1948) Drawing Hands, by M. C. Escher (lithograph, 1948) 12 The Leap of Faith In the combining method, we build up to a recursive procedure by writing a number of special-case nonrecursive procedures, starting

More information

COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING. 1 Introduction. 2 Huffman Coding. Due Thursday, March 8, 11:59pm

COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING. 1 Introduction. 2 Huffman Coding. Due Thursday, March 8, 11:59pm COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING Due Thursday, March 8, 11:59pm Reminder regarding intellectual responsibility: This is an individual assignment, and the work you submit should be your own.

More information

1. O(log n), because at worst you will only need to downheap the height of the heap.

1. O(log n), because at worst you will only need to downheap the height of the heap. These are solutions for the practice final. Please note that these solutions are intended to provide you with a basis to check your own answers. In order to get full credit on the exam, you must show all

More information

COS 226 Midterm Exam, Spring 2009

COS 226 Midterm Exam, Spring 2009 NAME: login ID: precept: COS 226 Midterm Exam, Spring 2009 This test is 10 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators

More information

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

COMP 250 Fall priority queues, heaps 1 Nov. 9, 2018

COMP 250 Fall priority queues, heaps 1 Nov. 9, 2018 COMP 250 Fall 2018 26 - priority queues, heaps 1 Nov. 9, 2018 Priority Queue Recall the definition of a queue. It is a collection where we remove the element that has been in the collection for the longest

More information

CS 112 Project Assignment: Visual Password

CS 112 Project Assignment: Visual Password CS 112 Project Assignment: Visual Password Instructor: Dan Fleck Overview In this project you will use Python to implement a visual password system. In the industry today there is ongoing research about

More information

Cache Coherence Tutorial

Cache Coherence Tutorial Cache Coherence Tutorial The cache coherence protocol described in the book is not really all that difficult and yet a lot of people seem to have troubles when it comes to using it or answering an assignment

More information

Principles of Algorithm Design

Principles of Algorithm Design Principles of Algorithm Design When you are trying to design an algorithm or a data structure, it s often hard to see how to accomplish the task. The following techniques can often be useful: 1. Experiment

More information

Programming Project 4: COOL Code Generation

Programming Project 4: COOL Code Generation CS 331 Compilers Fall 2017 Programming Project 4: COOL Code Generation Prof. Szajda Due Tuesday, December 5, 11:59:59 pm NOTE: There will be no extensions whatsoever given for this project! So, begin it

More information

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Integrated Introduction to Computer Science Hughes (Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Contents 1 Announcements 1 2 Evaluation Correction 1 3 Lists 2

More information