CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

Size: px
Start display at page:

Download "CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial"

Transcription

1 Week 7 General remarks Arrays, lists, pointers and We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for reading; sections and slides marked with Background are for additional information, and queried in the exam). We also consider binary. 4 5 Reading from CLRS for week 7 1 Chapter 10, Sections 10.2, 10.3, Arrays Vectors Arrays are the most fundamental data structure: An array A is a static data-structure, with a fixed length n N 0, holding n objects of the same type. Access to elements happens via A[i] for indices i, typically 0-based (C-based languages), that is, i { 0,..., n 1, or 1-based, that is, i { 1,..., n. This access, called random access, happens in constant time, and can be used for reading and writing. Due to the fixed length of arrays, one cannot really speak of insertion and deletion for arrays. Search in general is slow (one has to run through all elements in the worst case), however fast in sorted arrays, via binary. The dynamic form of an array (i.e., it can grow) can be called a vector (as for C++; or dynamic array): The growth of the vector happens by internally holding an array, and when the need arises, to allocate a new, bigger array, copy the old content, and delete the old array. When done infrequently, insertions (and deletions) at the end of the vector require only amortised constant time; see the tutorial. However insertions and deletions at the beginning of the vector (or somewhere else) needs time linear in the current size of the vector, since the elements need to be shifted. A vector with additional structure, where also insertions and deletions at the beginning happens in amortised constant time, is typically called a deque (a double-ended queue ).

2 Searching in sorted vectors Searching in general vectors takes linear time (running through all elements): 1 However, if the vector is sorted (we assume, as it is the default, ascending order), then it can be done in logarithmic time (in the length n of the vector). 2 We present the Java-function binary, which es for an element x in an array A. 3 Instead of just returning true or false (for found or not), it is more informative to return an index i with A[i] = x, if found, and to return 1 otherwise. 4 Since it might not be so easy to (efficiently) form sub-arrays, our version of binary allows to specify a sub-array by its indices begin and end. 5 As it is usually best, this so-called range is right-open, i.e., the beginning is included, but the ending excluded. 6 The role model for that is begin = 0 and end = n. c l a s s B i n a r y S e a r c h { p u b l i c s t a t i c i n t b i n a r y s e a r c h ( f i n a l i n t [ ] A, i n t begin, i n t end, f i n a l i n t x ) { i f (A == n u l l ) return 1; i f ( b e g i n == end ) return 1; while ( true ) { f i n a l i n t mid = b e g i n +(end b e g i n ) / 2 ; i f (A[ mid ] == x ) return mid ; i f ( b e g i n+1 == end ) return 1; i f (A[ mid ] < x ) { b e g i n = mid+1; i f ( b e g i n == end ) return 1; e l s e end = mid ; (cont.) with assertions p u b l i c s t a t i c i n t b i n a r y s e a r c h ( f i n a l i n t [ ] A, f i n a l i n t x ) { i f (A == n u l l ) return 1; return b i n a r y s e a r c h (A, 0, A. l e n g t h, x ) ; p u b l i c s t a t i c i n t b i n a r y s e a r c h ( f i n a l i n t [ ] A, i n t begin, i n t end, f i n a l i n t x ) { i f (A == n u l l ) return 1; a s s e r t (0 <= b e g i n <= end <= A. l e n g t h ) ; i f ( b e g i n == end ) return 1; while ( true ) { a s s e r t (0 <= b e g i n < end <= A. l e n g t h ) ; f i n a l i n t mid = b e g i n +(end b e g i n ) / 2 ; a s s e r t ( b e g i n <= mid < end ) ; i f (A[ mid ] == x ) return mid ; i f ( b e g i n+1 == end ) return 1; a s s e r t ( b e g i n < mid ) ; i f (A[ mid ] < x ) { b e g i n = mid+1; i f ( b e g i n == end ) return 1; e l s e end = mid ;

3 Analysing binary Analysing binary (cont.) We have a divide-and-conquer algorithm, with the characteristic recurrence T (n) = T (n/2) + 1. We obtain the second case of the Master Theorem (log 2 (1) = 0), whence T (n) = Θ(lg n). That s because we divide the array into two (nearly) equal parts, i.e., b = 2 in the standard form of the recurrence for the Master Theorem. While we only need to investigate one of the two parts (due to the sorting!), i.e., a = 1 for the Master Theorem. Finally the work done for splitting happens in constant time, and thus c = 0 for the Master Theorem. Recall that this actually only implies an upper bound for the run-time of binary the lower bound implied by the implicit Ω holds only for the recurrence, but not necessarily for the run-time. However, it is not too hard to see that also for the algorithm, and actually for every possible algorithm, we need at least lg(n) comparisons. Removing random access from vectors, gaining fast general insertion and deletion: Linked lists to next and previous elements Like a vector, the elements of a list are arranged in a linear order. With vectors we obtain random access via indices, which are just natural numbers, and thus arbitrary arithmetic can be performed with them due to the contiguous and uniform storage scheme: underlying is an array, which is stored as one contiguous block of memory cells, all of the same size. But to maintain contiguity, only deletions and insertions at the end of the vector are efficient (amortised constant-time) if we give up contiguity, then we loose random access, but we gain efficient arbitrary deletions and insertions: (linked) lists. formally implement a dictionary (, insertion, deletion), but, different from real dictionaries, is slow, while insertion and deletion is very fast, i.e., constant-time. The basic idea here is that each elements contains a pointer to the next and the previous element of the list. So a list-object x is a triple: x.prev is a pointer to the previous element in the list; x.next is a pointer to the next element in the list; x.key contains the key (or the data, if there is no key ). For the first element of the list, x.prev is NIL, and for the last element, x.next is NIL. The whole list is represented by a pointer L to the first element (as usual, NIL if the list is empty).

4 Searching Excursion Searching, in C++ For comparison, the same code in C++: The SEARCH-function in Java-like code, using List as the pointer-type (recall nearly everything in Java is a pointer!): s t a t i c L i s t s e a r c h ( L i s t L, f i n a l Key k ) { while ( L!= n u l l && L. key!= k ) L = L. next ; return L ; Note that if x is not found, then L will automatically finally become NIL (that is, null for Java). const L i s t s e a r c h ( const L i s t L, const Key k ) { while ( L!= n u l l p t r and L. key!= k ) L = L. next ; return L ; We see that in C/C++ we not only have pointers, but also values (as the ints!), and thus one can distinguish between pointers and values: The *-operator makes pointer-types from value-types, and dereferences pointers (to values). Further remarks: const List means that we do not change the values. More idiomatic would be the use of the > operator, which makes for example L >key instead of L.key. Insertion Deletion Inserting a list-object x into list L, at the beginning, again as Java-code: s t a t i c L i s t i n s e r t ( L i s t L, f i n a l L i s t x ) { a s s e r t ( x!= n u l l ) ; x. next = L ; x. p r e v = n u l l ; i f ( L!= n u l l ) L. p r e v = x ; L = x ; return L ; Deleting the list-element x from list L: s t a t i c L i s t d e l e t e ( L i s t L, f i n a l L i s t x ) { a s s e r t ( x!= n u l l ) ; a s s e r t ( L!= n u l l ) ; i f ( x. p r e v!= n u l l ) x. p r e v. next = x. next ; e l s e L = x. next ; i f ( x. next!= n u l l ) x. next. p r e v = x. p r e v ; return L ; Note that the return-value is the new list. Again the return-value is the new list.

5 Other forms of linked lists Final remarks on lists Our form of a linked list (the standard form) is more precisely called doubly linked list, since we have back- and forth-pointers for every node. In a singly linked list we only have the next-pointer; see the tutorial for a discussion. A list can be sorted or unsorted, if a linear order on the keys is given. Finally we can also have a circular list, if we link first and last element appropriately. What we have outlined as the class List (see the lab session for the full implementation) would typically be considered as a type ListNode, while the List-class itself would be kind of a manager-class, with class ListNode as private type hidden in it. This yields finally more user-convenience. The usage of the field L.head in the book is a faint move in that direction. Our approach is more rough, kind of swiss-army-knife approach (as one would do it in a simple-minded C-implementation). But this has also its advantages... The concept of pointer The concept of pointer (cont.) A pointer as a value is typically a memory address, and thus points to some value (at that memory address). are the basic means for indirection. In Java nearly everything (that is, besides the primitive types like int) is a pointer so you can t see them! The situation is much better in C/C++, where we have full duality between pointers and values: For a type T we construct the pointer type T. For a pointer p of type T, via the dereference operator p we get a value of type T (pointed to by p). Variables for objects are always pointers. If you for example compare two such variables via x == y, the compiler assumes you mean the pointers x, y themselves. If one the other hand you write something like x.prev, then the value pointed to by x is taken. For a value v of type T, via the reference operator &v we get a pointer of type T (pointing to v). So in C/C++ we have full control on values versus pointers. On the contrary, in Java it is the compiler which decides for you:

6 Simulating pointers Allocation and deletion of objects The basic technique to simulate pointers of type T is to use arrays, with indices replacing the pointers: 1 The objects (for example the list-objects) can be distributed over several arrays (in this case three arrays, two for the pointers (i.e., indices), one for the key), each array holding some part of the data, and with data belonging to the same object using the same index. 2 Or the objects can be put into a single array, of type T (which might have advantages for caching). 3 Going to a more basic level, the single array might hold basic memory units (like real memory), where then an object of type T uses several units, and via an offset (stored in an offset-table) one accesses the parts (data members) of an object. In Java, allocation of new objects (on the so-called heap ) happens via the operator new, however deallocation is not under the control of the programmer, but happens via the garbage collection. In C++, one has symmetry between allocation (operator new) and deallocation (operator delete), and furthermore new objects don t have to be created on the (program-)heap, but can also be created on the (program-)stack, namely using values (the slogan is when in C++, do like the ints do ). Accordingly, Java only knows constructors, but no destructors, while C++ has both. C++ allows much more fine-grained memory-control. Especially the time of deletion is under full control of the programmer (which is important for time-critical applications, where garbage collection must not kick-in). The notion of a tree : origins The notion of a tree : roots In Week 4 we defined the notion of a tree (see Sections B.5.1, B.5.2 and B.5.3 in CLRS for more information on this topic). This original notion of a tree (in our context) comes from mathematics, where a tree is a connected undirected graph without cycles, e.g. T = We have vertices 1,..., 7 and edges between them. From any vertices we can reach every other vertex, and this essentially in a unique way (this is the special property of trees). To obtain a rooted tree, one of the vertices of the tree has to be distinguished as a root (recall BFS and DFS), and then the tree is typically drawn growing downwards (in the direction of reading). For our example T we can make seven out of T, for example choosing vertex 1 resp. vertex 6 as the root: (T, 1) = (T, 6) = The leaves of (T, 1) are 4, 6, 7, the leaves of (T, 6) are 7, 4, 1. 1

7 The height of The notion of a tree : order Given a rooted tree T, its height ht(t ) is the length of the longest path from the root to some leaf, where the length of a path is the number of edges on it. The recursive definition is as follows: the trivial tree, just consisting of the root, has height 0; if a rooted tree T has subtrees T 1,..., T m for m 1 (always at the root), then ht(t ) = 1 + m max i=1 ht(t i). The same two as before can be drawn differently, since there is no order on the children of a node, for example: (T, 1) = (T, 6) = However, if we consider ordered, then the order of the children of a node is part of the tree, and the above re-drawings are different ordered. 1 The notion of a tree : binary trees Nodes and pointers To begin with, a binary tree is a rooted ordered tree, where every node which is not a leaf has either one or two children. But that s not quite complete: In case a node has one child, then for this child it must be said whether it is a left child or a right child. For example, the ordered rooted tree (T, 1) as given on the previous slide has 2 4 = 16 different versions as binary tree, e.g A node of a binary tree has the following information naturally associated with it: its parent node its left and its right child its label. There are four special cases: 1 the root has no parent node 2 a node may have only one child, left or right 3 a leaf has no children. The links to parents and children can be represented by pointers (possibly the null pointer), while the label is just an attribute (a data member or instance variable of the class).

8 Representing the example Using as label just the key, we arrive at a class with four data members: p is the pointer to the parent left and right are pointers to left resp. right child key is the key. Considering the first binary tree from two slides before, we can represent the tree by 7 nodes v 1,..., v 7, where each node is a pointer and where the data members are given in order p, left, right, key: v 1 = (NIL, v 2, NIL, 1), v 2 = (v 1, NIL, v 3, 2), v 3 = (v 2, v 5, v 4, 3), v 4 = (v 3, NIL, NIL, 4), v 5 = (v 3, v 6, v 7, 5), v 6 = (v 5, NIL, NIL, 6), v 7 = (v 5, NIL, NIL, 7). Remark on pointers Since in a Java-environment students typically don t get a good understanding on pointers, here some remarks we ve already seen: Note that dereferenciation of pointers v is denoted by *v (the object to which it points). Since Java is purely pointer-based, one can not get at the address of an object, or to the object of a pointer: Every variable is a pointer, and using it in most cases(!) means to dereference it (an exception is for example when using ==). Another exception in Java is the handling of primitive types, where we can not have pointers. C and C++ have both values (objects) and pointers, and we have full symmetry (and full control): For an object x the address is &x. For a pointer p the object is *p. Rooted trees with unbounded branching Searching A few remarks in case there are more than two children: For k-ary trees (generalised binary trees) we just need to add further data members to the class, with appropriate names. This works best for small k. For large k or unbounded k (not known in advance) an easy way is to store the children in a list. Assume you have a sorted list of product numbers, and a heap of receipts with product numbers, and the task is to determine how much of each product was ordered how to do this? Answer: Run through the receipts, find its product number in the sorted list via binary, and accrue the numbers. Section 10.4 of CLRS contains a variation, where each element of the (singly-linked) list of children also contains a pointer to its parent.

9 Height of (rooted) trees How to implement vectors (dynamic arrays) For the tree given at the beginning of the section on rooted trees, which choice of a root yields the minimum height? Vertex 3, yielding height 2. We already said that we could implement vectors by holding arrays which are replaced by bigger arrays when needed (copying the old values over). For algorithmic purposes, is a small or a large height better? In general, a small height is better, since otherwise the tree degenerates into a path. We also said we could do this in a such a way that insertion becomes amortised constant time how is this possible?? Answer: However this holds only for restricted number of children, for example binary trees otherwise you can just trivially always obtain a height at most 1 (how?). Always double the available memory, once capacity is exceeded. Remember: m = 2 m+1 1. So the total effort before just equals the effort for the last step. On deletion in linked lists A more powerful insertion Our insert -function inserts at the beginning how to insert anywhere? We have handled the case of insertion right at the beginning: Our implementation of delete returns the new value of the list L when is this different from the original value? Answer: When we delete the first element of the list. 1 In general, instead of L, we need a pointer p to a list-element, after which we insert. 2 The case p == L has been handled; indeed we better assume that we do not handle this case here (since it modifies the handle to the list itself), and thus assume that p.prev is not null. 3 Another special case is if p is the last element. 4 For the remaining cases no need to worry about null. Just remember to set the prev and next pointers (where changed).

10 in linked lists Singly linked lists Can we perform binary for a sorted linked list? If yes, with what complexity? Yes, but the movement has to be done step-by-step. The number of comparisons is now only lg n. But the total number of operations is still linear, as in trivial sequential, and in fact has increased, namely doubled, if we don t know n in advance: A singly linked list has no prev-pointer (only the next-pointer): What are the advantages and disadvantages? = 2.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT. Week 10 1 Binary s 2 3 4 5 6 Sorting Binary s 7 8 General remarks Binary s We return to sorting, considering and. Reading from CLRS for week 7 1 Chapter 6, Sections 6.1-6.5. 2 Chapter 7, Sections 7.1,

More information

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT. Week 10 1 2 3 4 5 6 Sorting 7 8 General remarks We return to sorting, considering and. Reading from CLRS for week 7 1 Chapter 6, Sections 6.1-6.5. 2 Chapter 7, Sections 7.1, 7.2. Discover the properties

More information

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion.

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion. Week 8 Binarys 1 2 of 3 4 of 5 6 7 General remarks We consider, another important data structure. We learn how to use them, by making efficient queries. And we learn how to build them. Reading from CLRS

More information

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion.

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion. Week 8 Binarys 1 2 3 4 5 6 7 General remarks We consider, another important data structure. We learn how to use them, by making efficient queries. And we learn how to build them. Reading from CLRS for

More information

Week 6. Data structures

Week 6. Data structures 1 2 3 4 5 n Week 6 Data structures 6 7 n 8 General remarks We start considering Part III Data Structures from CLRS. As a first example we consider two special of buffers, namely stacks and queues. Reading

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 2018 Part 2: Data Structures PD Dr.

More information

1 Interlude: Is keeping the data sorted worth it? 2 Tree Heap and Priority queue

1 Interlude: Is keeping the data sorted worth it? 2 Tree Heap and Priority queue TIE-0106 1 1 Interlude: Is keeping the data sorted worth it? When a sorted range is needed, one idea that comes to mind is to keep the data stored in the sorted order as more data comes into the structure

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

Lecture 5: Sorting Part A

Lecture 5: Sorting Part A Lecture 5: Sorting Part A Heapsort Running time O(n lg n), like merge sort Sorts in place (as insertion sort), only constant number of array elements are stored outside the input array at any time Combines

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Lecture Notes for Advanced Algorithms

Lecture Notes for Advanced Algorithms Lecture Notes for Advanced Algorithms Prof. Bernard Moret September 29, 2011 Notes prepared by Blanc, Eberle, and Jonnalagedda. 1 Average Case Analysis 1.1 Reminders on quicksort and tree sort We start

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Trees, Part 1: Unbalanced Trees

Trees, Part 1: Unbalanced Trees Trees, Part 1: Unbalanced Trees The first part of this chapter takes a look at trees in general and unbalanced binary trees. The second part looks at various schemes to balance trees and/or make them more

More information

Unit 8: Analysis of Algorithms 1: Searching

Unit 8: Analysis of Algorithms 1: Searching P Computer Science Unit 8: nalysis of lgorithms 1: Searching Topics: I. Sigma and Big-O notation II. Linear Search III. Binary Search Materials: I. Rawlins 1.6 II. Rawlins 2.1 III. Rawlins 2.3 IV. Sigma

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

CSCI2100B Data Structures Trees

CSCI2100B Data Structures Trees CSCI2100B Data Structures Trees Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Introduction General Tree

More information

Lecture 15 Binary Search Trees

Lecture 15 Binary Search Trees Lecture 15 Binary Search Trees 15-122: Principles of Imperative Computation (Fall 2017) Frank Pfenning, André Platzer, Rob Simmons, Iliano Cervesato In this lecture, we will continue considering ways to

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary

More information

Technical University of Denmark

Technical University of Denmark Technical University of Denmark Written examination, May 7, 27. Course name: Algorithms and Data Structures Course number: 2326 Aids: Written aids. It is not permitted to bring a calculator. Duration:

More information

CS24 Week 8 Lecture 1

CS24 Week 8 Lecture 1 CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes

More information

( ) n 3. n 2 ( ) D. Ο

( ) n 3. n 2 ( ) D. Ο CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.

More information

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke 403: Algorithms and Data Structures Heaps Fall 20 UAlbany Computer Science Some slides borrowed by David Luebke Birdseye view plan For the next several lectures we will be looking at sorting and related

More information

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology Introduction Chapter 4 Trees for large input, even linear access time may be prohibitive we need data structures that exhibit average running times closer to O(log N) binary search tree 2 Terminology recursive

More information

lecture notes September 2, How to sort?

lecture notes September 2, How to sort? .30 lecture notes September 2, 203 How to sort? Lecturer: Michel Goemans The task of sorting. Setup Suppose we have n objects that we need to sort according to some ordering. These could be integers or

More information

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file.

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Large Trees 1 Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Trees can also be used to store indices of the collection

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

Lecture 15 Notes Binary Search Trees

Lecture 15 Notes Binary Search Trees Lecture 15 Notes Binary Search Trees 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, André Platzer, Rob Simmons 1 Introduction In this lecture, we will continue considering ways

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 16 March 17, 2015 1 Introduction In this lecture, we will continue considering ways

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate

More information

Topic: Heaps and priority queues

Topic: Heaps and priority queues David Keil Data Structures 8/05 1 Topic: Heaps and priority queues The priority-queue problem The heap solution Binary trees and complete binary trees Running time of heap operations Array implementation

More information

DDS Dynamic Search Trees

DDS Dynamic Search Trees DDS Dynamic Search Trees 1 Data structures l A data structure models some abstract object. It implements a number of operations on this object, which usually can be classified into l creation and deletion

More information

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1 Algorithms and Data Structures: Lower Bounds for Sorting ADS: lect 7 slide 1 ADS: lect 7 slide 2 Comparison Based Sorting Algorithms Definition 1 A sorting algorithm is comparison based if comparisons

More information

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree Chapter 4 Trees 2 Introduction for large input, even access time may be prohibitive we need data structures that exhibit running times closer to O(log N) binary search tree 3 Terminology recursive definition

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss another important ADT: PriorityQueue. Like stacks and queues, priority queues store arbitrary collections

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

CS2 Algorithms and Data Structures Note 1

CS2 Algorithms and Data Structures Note 1 CS2 Algorithms and Data Structures Note 1 Analysing Algorithms This thread of the course is concerned with the design and analysis of good algorithms and data structures. Intuitively speaking, an algorithm

More information

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

( ) ( ) C.  1 n. ( ) $ f n. ( ) B.  log( n! ) ( ) and that you already know ( ) ( )  % g( n) ( )  #& CSE 0 Name Test Summer 008 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time for the following code is in which set? for (i=0; i

More information

Heaps & Priority Queues. (Walls & Mirrors - Remainder of Chapter 11)

Heaps & Priority Queues. (Walls & Mirrors - Remainder of Chapter 11) Heaps & Priority Queues (Walls & Mirrors - Remainder of Chapter 11) 1 Overview Array-Based Representation of a Complete Binary Tree Heaps The ADT Priority Queue Heap Implementation of the ADT Priority

More information

Lecture 4: Elementary Data Structures Steven Skiena

Lecture 4: Elementary Data Structures Steven Skiena Lecture 4: Elementary Data Structures Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Find two

More information

Properties of a heap (represented by an array A)

Properties of a heap (represented by an array A) Chapter 6. HeapSort Sorting Problem Input: A sequence of n numbers < a1, a2,..., an > Output: A permutation (reordering) of the input sequence such that ' ' ' < a a a > 1 2... n HeapSort O(n lg n) worst

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Binary heaps (chapters ) Leftist heaps

Binary heaps (chapters ) Leftist heaps Binary heaps (chapters 20.3 20.5) Leftist heaps Binary heaps are arrays! A binary heap is really implemented using an array! 8 18 29 20 28 39 66 Possible because of completeness property 37 26 76 32 74

More information

CS171 Final Practice Exam

CS171 Final Practice Exam CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your

More information

Throughout this course, we use the terms vertex and node interchangeably.

Throughout this course, we use the terms vertex and node interchangeably. Chapter Vertex Coloring. Introduction Vertex coloring is an infamous graph theory problem. It is also a useful toy example to see the style of this course already in the first lecture. Vertex coloring

More information

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

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

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

Learning Goals. CS221: Algorithms and Data Structures Lecture #3 Mind Your Priority Queues. Today s Outline. Back to Queues. Priority Queue ADT

Learning Goals. CS221: Algorithms and Data Structures Lecture #3 Mind Your Priority Queues. Today s Outline. Back to Queues. Priority Queue ADT CS: Algorithms and Data Structures Lecture # Mind Your Priority Queues Steve Wolfman 0W Learning Goals Provide examples of appropriate applications for priority queues. Describe efficient implementations

More information

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Sample Exam 1 75 minutes permitted Print your name, netid, and

More information

Fundamentals of Data Structure

Fundamentals of Data Structure Fundamentals of Data Structure Set-1 1. Which if the following is/are the levels of implementation of data structure A) Abstract level B) Application level C) Implementation level D) All of the above 2.

More information

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge. Binary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from

More information

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms Comparison Based Sorting Algorithms Algorithms and Data Structures: Lower Bounds for Sorting Definition 1 A sorting algorithm is comparison based if comparisons A[i] < A[j], A[i] A[j], A[i] = A[j], A[i]

More information

Maintain binary search tree property nodes to the left are less than the current node, nodes to the right are greater

Maintain binary search tree property nodes to the left are less than the current node, nodes to the right are greater CS61B, Summer 2002 Lecture #8 Barath Raghavan UC Berkeley Topics: Binary Search Trees, Priority queues 1 Binary search trees (BSTs) Represented as ordinary binary trees Maintain binary search tree property

More information

Data Structure. Recitation III

Data Structure. Recitation III Data Structure Recitation III Topic Binary Search Abstract Data types Java Interface Linked List Binary search Searching a sorted collection is a common task. A dictionary is a sorted list of word definitions.

More information

7.3 Spanning trees Spanning trees [ ] 61

7.3 Spanning trees Spanning trees [ ] 61 7.3. Spanning trees [161211-1348 ] 61 7.3 Spanning trees We know that trees are connected graphs with the minimal number of edges. Hence trees become very useful in applications where our goal is to connect

More information

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University NAME: STUDENT NUMBER:. Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University Examimer: Prof. Mathieu Blanchette December 8 th 2005,

More information

2. Sorting. 2.1 Introduction

2. Sorting. 2.1 Introduction 2. Sorting 2.1 Introduction Given a set of n objects, it is often necessary to sort them based on some characteristic, be it size, importance, spelling, etc. It is trivial for a human to do this with a

More information

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions. CS251-SE1 Midterm 2 Tuesday 11/1 8:00pm 9:00pm There are 16 multiple-choice questions and 6 essay questions. Answer the multiple choice questions on your bubble sheet. Answer the essay questions in the

More information

DATA STRUCTURE AND ALGORITHM USING PYTHON

DATA STRUCTURE AND ALGORITHM USING PYTHON DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting

More information

CS 234. Module 8. November 15, CS 234 Module 8 ADT Priority Queue 1 / 22

CS 234. Module 8. November 15, CS 234 Module 8 ADT Priority Queue 1 / 22 CS 234 Module 8 November 15, 2018 CS 234 Module 8 ADT Priority Queue 1 / 22 ADT Priority Queue Data: (key, element pairs) where keys are orderable but not necessarily distinct, and elements are any data.

More information

6.001 Notes: Section 31.1

6.001 Notes: Section 31.1 6.001 Notes: Section 31.1 Slide 31.1.1 In previous lectures we have seen a number of important themes, which relate to designing code for complex systems. One was the idea of proof by induction, meaning

More information

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort? So far we have studied: Comparisons Insertion Sort Merge Sort Worst case Θ(n 2 ) Θ(nlgn) Best case Θ(n) Θ(nlgn) Sorting Revisited So far we talked about two algorithms to sort an array of numbers What

More information

( D. Θ n. ( ) f n ( ) D. Ο%

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

CSE 100: C++ TEMPLATES AND ITERATORS

CSE 100: C++ TEMPLATES AND ITERATORS CSE 100: C++ TEMPLATES AND ITERATORS Announcements iclickers: Please register at ted.ucsd.edu. Start ASAP!! For PA1 (Due next week). 10/6 grading and 10/8 regrading How is Assignment 1 going? A. I haven

More information

Binary Search Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250

Binary Search Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250 Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Standard reminder to set phones to silent/vibrate mode, please! Previously, on ECE-250... We discussed trees (the

More information

Department of Computer Science and Technology

Department of Computer Science and Technology UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

Linked Lists and Abstract Data Structures A brief comparison

Linked Lists and Abstract Data Structures A brief comparison Linked Lists and Abstract Data A brief comparison 24 March 2011 Outline 1 2 3 4 Data Data structures are a key idea in programming It s just as important how you store the data as it is what you do to

More information

) $ f ( n) " %( g( n)

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss priority queues, another important ADT. As stacks and queues, priority queues store arbitrary collections

More information

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF

More information

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers So far we have studied: Comparisons Tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point Insertion Sort Merge Sort Worst case Θ(n ) Θ(nlgn) Best

More information

Pointers and References. 8-Aug-11

Pointers and References. 8-Aug-11 Pointers and References 8-Aug-11 Machine addresses Computer memory consists of one long list of addressable bytes A pointer is a data item that contains an address 3FA71CF6 A reference is a data item that

More information

CS Fall 2010 B-trees Carola Wenk

CS Fall 2010 B-trees Carola Wenk CS 3343 -- Fall 2010 B-trees Carola Wenk 10/19/10 CS 3343 Analysis of Algorithms 1 External memory dictionary Task: Given a large amount of data that does not fit into main memory, process it into a dictionary

More information

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D. CSE 0 Name Test Fall 00 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to convert an array, with priorities stored at subscripts through n,

More information

Announcements. Reading Material. Recap. Today 9/17/17. Storage (contd. from Lecture 6)

Announcements. Reading Material. Recap. Today 9/17/17. Storage (contd. from Lecture 6) CompSci 16 Intensive Computing Systems Lecture 7 Storage and Index Instructor: Sudeepa Roy Announcements HW1 deadline this week: Due on 09/21 (Thurs), 11: pm, no late days Project proposal deadline: Preliminary

More information

Heap sort. Carlos Moreno uwaterloo.ca EIT

Heap sort. Carlos Moreno uwaterloo.ca EIT Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 http://xkcd.com/835/ https://ece.uwaterloo.ca/~cmoreno/ece250 Standard reminder to set phones to silent/vibrate mode, please! Last time, on ECE-250... Talked

More information

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved. Data Structures Outline Introduction Linked Lists Stacks Queues Trees Introduction dynamic data structures - grow and shrink during execution Linked lists - insertions and removals made anywhere Stacks

More information

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

III Data Structures. Dynamic sets

III Data Structures. Dynamic sets III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations

More information

6. Asymptotics: The Big-O and Other Notations

6. Asymptotics: The Big-O and Other Notations Chapter 7 SEARCHING 1. Introduction, Notation 2. Sequential Search 3. Binary Search 4. Comparison Trees 5. Lower Bounds 6. Asymptotics: The Big-O and Other Notations Outline Transp. 1, Chapter 7, Searching

More information

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CS8391-DATA STRUCTURES QUESTION BANK UNIT I CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Define data structure. The data structure can be defined as the collection of elements and all the possible operations which are required for those

More information

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have encountered on homeworks, the midterm, and on this practice

More information

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa. Code No: RR210504 Set No. 1 1. (a) Order the following functions according to their order of growth (from the lowest to the highest). (n-2)!, 5 log (n+100) 10,2 2n, 0.001n 4 +3n 3 +1, ln 2 n, n 1/3, 3

More information

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1 Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm ADS: lects 14 & 15 slide 1 Weighted Graphs Definition 1 A weighted (directed or undirected graph) is a pair (G, W ) consisting

More information

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012 Data Abstractions National Chiao Tung University Chun-Jen Tsai 05/23/2012 Concept of Data Structures How do we store some conceptual structure in a linear memory? For example, an organization chart: 2/32

More information

Dictionaries. 2/17/2006 Dictionaries 1

Dictionaries. 2/17/2006 Dictionaries 1 Dictionaries < 6 > 1 4 = 8 9 /17/006 Dictionaries 1 Outline and Reading Dictionary ADT ( 9.3) Log file ( 9.3.1) Binary search ( 9.3.3) Lookup table ( 9.3.3) Binary search tree ( 10.1) Search ( 10.1.1)

More information

UNIVERSITY REGULATIONS

UNIVERSITY REGULATIONS CPSC 221: Algorithms and Data Structures Midterm Exam, 2013 February 15 Name: Student ID: Signature: Section (circle one): MWF(201) TTh(202) You have 60 minutes to solve the 5 problems on this exam. A

More information

Discrete mathematics

Discrete mathematics Discrete mathematics Petr Kovář petr.kovar@vsb.cz VŠB Technical University of Ostrava DiM 470-2301/02, Winter term 2018/2019 About this file This file is meant to be a guideline for the lecturer. Many

More information

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are

More information

Overview of Presentation. Heapsort. Heap Properties. What is Heap? Building a Heap. Two Basic Procedure on Heap

Overview of Presentation. Heapsort. Heap Properties. What is Heap? Building a Heap. Two Basic Procedure on Heap Heapsort Submitted by : Hardik Parikh(hjp0608) Soujanya Soni (sxs3298) Overview of Presentation Heap Definition. Adding a Node. Removing a Node. Array Implementation. Analysis What is Heap? A Heap is a

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 15 March 6, 2014 1 Introduction In this lecture, we will continue considering associative

More information