Introduction to Competitive Programming. Instructor: William W.Y. Hsu

Size: px
Start display at page:

Download "Introduction to Competitive Programming. Instructor: William W.Y. Hsu"

Transcription

1 Introduction to Competitive Programming Instructor: William W.Y. Hsu

2 CONTENTS Linear data structures and built-in libraries Array sorting and searching Non-linear data structures with built-in libraries Binary search tree Heap Hash table Data structures without built-in libraries Graphs Union-find disjoint sets Segment tree Fenwick tree 10/2/2016 PROGRAMMING IN C 2

3 Before we begin Who are you? 1. Pure C coder. 2. Pure C++ coder. 3. C/C++ intermixed coder. 4. Pure Java coder. 5. Other coder. 6. Multilingual coder C/C++/Java. 10/2/2016 PROGRAMMING IN C 3

4 Linear data structures and built-in libraries You must know! 10/2/2016 PROGRAMMING IN C 4

5 Linear DS + built in libraries Static arrays, built in support in C/C++/Java Resize able arrays: C++ STL vector, Java Vector Both are very useful in ICPCs/IOIs PS: Java ArrayList may be slightly faster There are 2 very common operations on Array: Sorting Searching 10/2/2016 PROGRAMMING IN C 5

6 Linear DS + built in libraries Array of Boolean: C++ STL bitset Should be faster than array of Booleans or vector<bool>! No specific API in Java that is similar to this. Bitmask Lightweight set of Boolean or bit string Linked List, C++ STL list, Java LinkedList Usually not used just use vector! Stack, C++ STL stack, Java Stack Used by default in recursion, postfix conversion/calculation, bracket matching, etc Queue, C++ STL queue, Java Queue Used in breadth first search, topological sort, etc Deque, C++ STL deque, Java Deque Used in algorithms for sliding window problem, etc 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 6

7 Array sorting and searching This is fundamental. 10/2/2016 PROGRAMMING IN C 7

8 Sorting Definition: Given unsorted stuffs, sort them Popular Sorting Algorithms OO(nn 2 ) algorithms: Bubble/Selection/Insertion Sort OO(nn log nn) algorithms: Merge/Quick/Heap Sort Special purpose: Counting/Radix/Bucket Sort Take a look at wikipedia 10/2/2016 PROGRAMMING IN C 8

9 Sorting In ICPC, you can forget all these In general, if you need to sort something, just use the O(n log n) sorting library: C stdlib.h qsort() C++ STL algorithm:: sort Java Collections.sort In ICPC, sorting is either used as preliminary step for more complex algorithm or to beautify output Familiarity with sorting libraries is a must! 10/2/2016 PROGRAMMING IN C 9

10 Sorting Sorting routines in C++ STL algorithm sort a bug free implementation of introsort* Fast, it runs in OO(nn log nn). Can sort basic data types (ints, doubles, chars), Abstract Data Types (C++ class), multi field sorting ( 2 criteria) partial_sort implementation of heapsort Can do OO(kk log nn) sorting, if we just need top kk sorted! stable_sort If you need to have the sorting stable, keys with same values appear in the same order as in input. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 10

11 Searching in array Two variants: When the array is sorted versus not sorted. Must do OO(nn) linear scan if not sorted Can use OO(log nn) binary search when sorted PS: must run an OO(nn log nn) sorting algorithm once! Binary search is tricky to code! Instead, use C++ STL algorithm::lower_bound, algorithm::binary_search or Java Collections.binarySearch 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 11

12 Non-linear data structures with built-in libraries More efficient data structures 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 12

13 Binary search tree ADT table (key data) Binary search tree (BST) Advertised OO(log nn) for insert, search, and delete Requirement: the BST must be balanced! AVL tree, Red Black Tree, etc Just use: C++ STL map (Java TreeMap) UVa (Hardwood Species) 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 13

14 Binary search tree ADT Table (key exists or not) Set (Single Set) C++ STL set, similar to C++ STL map map stores a (key, data) pair set stores just the key In Java: TreeSet UVa CD 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 14

15 Heap Heap C++ STL algorithm has some heap algorithms partial_sort uses heapsort C++ STL priority_queue (Java PriorityQueue) is heap Prim s and Dijkstra s algorithms use priority queue. But, we rarely see pure heap problems in ICPC. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 15

16 Hash table Hash table Advertised OO(1) for insert, search, and delete, but: The hash function must be good! There is no hash table in C++ STL (hashtable in Java API) Nevertheless, OO(log nn) using map is usually ok Direct addressing table (DAT) Rather than hashing, we more frequently use DAT UVa (Newspaper) 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 16

17 Data structures without builtin libraries Here comes the hard part. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 18

18 Range minimum query Range Minimum Query (RMQ) is used on arrays to find the position of an element with the minimum value between two specified indices. Given an array AA[00, NN 11] find the position of the element with the minimum value between two given indices. RMQ AA 2,7 = 3 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] /2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 19

19 Range minimum query Suppose that an algorithm has preprocessing time ff(nn) and query time gg(nn). The notation for the overall complexity for the algorithm is < ff(nn), gg(nn) >. We will note the position of the element with the minimum value in some array AA between indices ii and jj with RMQ AA (ii, jj). 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 20

20 Trivial algorithms for RMQ For every pair of indices (ii, jj) store the value of RMQ AA (ii, jj) in a table MM[00, NN 11][00, NN 11]. Trivial computation will lead us to an < OO(NN 33 ), OO(11) > complexity. However, by using an easy dynamic programming approach we can reduce the complexity to < OO(NN 22 ), OO(11) >. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 21

21 Trivial algorithms for RMQ The preprocessing function will look something like this: void process1(int M[MAXN][MAXN], int A[MAXN], int N) { int i, j; for(i =0; i < N; i++) M[i][i] = i; for(i = 0; i < N; i++) for(j = i + 1; j < N; j++) if(a[m[i][j - 1]] < A[j]) M[i][j] = M[i][j - 1]; else M[i][j] = j; } This trivial algorithm is quite slow and uses OO NN 2 memory, so it won t work for large cases. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 22

22 Better algorithms for RMQ An interesting idea is to split the vector in NN pieces. We will keep in a vector MM[00, NN 11] the position for the minimum value for each section. MM can be easily preprocessed in OO(NN). Here is an example: RMQ AA 2,7 = 3 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] MM 0 = 0 MM 1 = 3 MM 2 = 8 MM 3 =9 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 23

23 Better algorithms for RMQ The idea is to get the overall minimum from the sqrt(nn) sections that lie inside the interval, and from the end and the beginning of the first and the last sections that intersect the bounds of the interval. To get RMQ AA (22, 77) in the above example we should compare AA[22], AA[MM[11]], AA[66] and AA[77] and get the position of the minimum value. It s easy to see that this algorithm doesn t make more than 33 NN operations per query. The main advantages of this approach are that is to quick to code. You can adapt it to the dynamic version of the problem (where you can change the elements of the array between queries). 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 24

24 Sparse table (ST) algorithm for RMQ A better approach is to preprocess RMQ for sub arrays of length 22 kk using dynamic programming. We will keep an array MM[00, NN 11][00, log NN] where MM[ii][jj] is the index of the minimum value in the sub array starting at ii having length 22 jj. Here is an example A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9] MM 1 [0] = 1 MM 1 [1] = 2 MM 1 [2] = 3 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 25

25 Sparse table (ST) algorithm for RMQ For computing MM[ii][jj] we must search for the minimum value in the first and second half of the interval. It s obvious that the small pieces have 22 jj 11 length, so the recurrence is: MM ii jj = MM ii jj 1, AA MM ii jj 1 AA[MM ii + 2jj 1 1 jj 1 ] MM ii + 2 jj 1 1 jj 1, otherwise 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 26

26 Code void process2(int M[MAXN][LOGMAXN], int A[MAXN], int N) { int i, j; } //initialize M for the intervals with length 1 for(i = 0; i < N; i++) M[i][0] = i; //compute values from smaller to bigger intervals for(j = 1; 1 << j <= N; j++) for(i = 0; i + (1 << j) - 1 < N; i++) if(a[m[i][j - 1]] < A[M[i + (1 << (j - 1))][j - 1]]) M[i][j] = M[i][j - 1]; else M[i][j] = M[i + (1 << (j - 1))][j - 1]; 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 27

27 Usage Once we have these values preprocessed, let s show how we can use them to calculate RMQ AA (ii, jj). The idea is to select two blocks that entirely cover the interval [ii.. jj] and find the minimum between them. Let kk = [log(jj ii + 11)]. For computing RMQ AA (ii, jj) we can use the following formula: RMQ AA = MM ii kk, AA MM ii kk AA[MM jj 2kk + 1 ll ] MM jj 2 kk + 1 kk, otherwise So, the overall complexity of the algorithm is < OO(NN log NN), OO(11) >. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 28

28 Segment trees for RMQ For solving the RMQ problem we can also use segment trees. A segment tree is a heap-like data structure that can be used for making update/query operations upon array intervals in logarithmical time. We define the segment tree for the interval [ii, jj] in the following recursive manner: The first node will hold the information for the interval ii, jj. If ii < jj the left and right son will hold the information for the intervals [ii, (ii + jj)/22] and [(ii + jj)/ , jj]. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 29

29 Segment trees for RMQ The height of a segment tree for an interval with NN elements is [log NN] Here is how a segment tree for the interval [00, 99] would look like: 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 30

30 Segment trees for RMQ The segment tree has the same structure as a heap, so if we have a node numbered xx that is not a leaf: Left son of xx is Right son of xx is For solving the RMQ problem using segment trees we should use an array MM[11, log nn +11 ] where MM[ii] holds the minimum value position in the interval assigned to node ii. At the beginning all elements in MM should be 11. The tree should be initialized with the following function (bb and ee are the bounds of the current interval): 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 31

31 Code void initialize(intnode, int b, int e, int M[MAXIND], int A[MAXN], int N) { if(b == e) M[node] = b; else { //compute the values in the left and right subtrees initialize(2 * node, b, (b + e) / 2, M, A, N); initialize(2 * node + 1, (b + e) / 2 + 1, e, M, A, N); //search for the minimum value in the first and //second half of the interval if(a[m[2 * node]] <= A[M[2 * node + 1]]) M[node] = M[2 * node]; else M[node] = M[2 * node + 1]; } } 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 32

32 Segment trees for RMQ The function above reflects the way the tree is constructed. When calculating the minimum position for some interval we should look at the values of the sons. You should call the function with node = 1, b = 0 and e = N-1. We can now start making queries. If we want to find the position of the minimum value in some interval [ii, jj] we should use the next easy function: 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 33

33 Code int query(int node, int b, int e, int M[MAXIND], int A[MAXN], int i, int j) { int p1, p2; //if the current interval doesn't intersect //the query interval return -1 if(i > e j < b) return -1; //if the current interval is included in //the query interval return M[node] if(b >= i && e <= j) return M[node]; //compute the minimum position in the //left and right part of the interval p1 = query(2 * node, b, (b + e) / 2, M, A, i, j); p2 = query(2 * node + 1, (b + e) / 2 + 1, e, M, A, i, j); } //return the position where the overall //minimum is if(p1 == -1) return M[node] = p2; if(p2 == -1) return M[node] = p1; if(a[p1] <= A[p2]) return M[node] = p1; return M[node] = p2; 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 34

34 Please survey LCA Lowest Common Ancestor (LCA): Given a rooted tree T and two nodes u and v, find the furthest node from the root that is an ancestor for both u and v. Here is an example (the root of the tree will be node 1 for all examples in this editorial): 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 36

35 Fenwick tree Basics The problem: Suppose there are NN boxes labeled from 1 to NN. We can add(x) marbles to the ii th box. box(i) now has a frequency xx. We want to know the total number of marbles from box(1) to box(n). 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 37

36 First analysis Operation complexities: void create(int n); O(N) void update(int idx, int val); O(log N) int freqto(int idx); O(log N) int freqat(int idx); O(log N) 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 38

37 Storage complexity Data An int array of size NN. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 39

38 Fenwick trees How it works? Each element in the array stores cumulative frequency of consecutive list of boxes. Range of boxes that is stored is related to binary value of the index. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 40

39 Definitions ff(xx) = number of marble in box xx. cc(xx) = summation of number of marble in box 1 to box xx. cc xx = xx ii=1 ff(ii) tree[xx] = element xx in the array. 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 41

40 Storage solution tree 16 = ff 1 + ff ff(16) tree 12 = ff 9 + ff 10 + ff 11 + ff(12) tree 6 = ff 5 + ff(6) tree 3 = ff(3) 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 42

41 Cumulative frequency f(16) = 2 Actual frequency tree[16] = 29 Cumulative frequency From 1 to 16 Index of the array tree[14] Cumulative frequency From 13 to 14 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 43

42 The last 1 A node at the index XX will store frequency of boxes in the range of XX 2 rr + 1 to XX. Where rr is the position of the last digit of 1 (in binary mode). Example: XX = 12 (1100) 2 Node will store frequency from 9 to 12 The last 1 of 12 is at position 2 (0-indexed) = 9 = (1001) 2 10/2/2016 PROGRAMMING IN C 44

43 Reading cumulative frequency c(13) = tree[13] + tree[12] + tree[8] In base-2: c( ) = tree[ ] +tree[ ] + tree[ ] 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 45

44 Updating frequency Update ff(5) by -1 involve: Tree[5] ( ) Tree[6] ( ) Tree[8] ( ) Tree[16] ( ) 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 46

45 Reading actual frequency What is ff(12)? Easy, it s cc(12) cc(11). Easier way: Tree[12] = ff(9) + ff(10) + ff(11) + ff(12) Tree[11] = ff(11) Tree[10] = ff(9) + ff(10) Hence: ff(12) = Tree[12] Tree[11] Tree[10] 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 47

46 Two s compliment A method to represent negative numbers. A two s compliment of XX is (compliment of XX) s Compliment of 7 is Finding the last 1 xx = aaaaa bb = consecutive of 0 XX = 4 = 0100 aa = 0 bb = /2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 48

47 Two s compliment xx = (aaaaa) + 1 = aa 0bb + 1 = aa 0(0 0) + 1 = aa 0(1 1) + 1 = aa 1(0 0) = aa 1bb So, if we & xx and xx: aa 1bb & aaaaa. We got the last /2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 49

48 Code int freqto(int idx) { int sum = 0; while (idx > 0) { sum += tree[idx]; idx -= (idx & -idx); } return sum; } void update(int idx,int val) { while (idx <= MaxVal) { tree[idx] += val; idx += (idx & -idx); } } 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 50

49 Code int freqat(int idx){ int sum = tree[idx]; if (idx > 0) { int z = idx - (idx & -idx); y = idx - 1; while (y!= z){ sum -= tree[y]; y -= (y & -y); } } return sum; } 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 51

50 Extension 2D bits? 10/2/2016 INTRODUCTION TO COMPETITIVE PROGRAMMING 53

Competitive Programming

Competitive Programming This course material is now made available for public usage. Special acknowledgement to School of Computing, National University of Singapore for allowing Steven to prepare and distribute these teaching

More information

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions. DATA STRUCTURES COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book. Data

More information

Lecture 13: AVL Trees and Binary Heaps

Lecture 13: AVL Trees and Binary Heaps Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally

More information

DATA STRUCTURES + SORTING + STRING

DATA STRUCTURES + SORTING + STRING DATA STRUCTURES + SORTING + STRING COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Solutions to Exam Data structures (X and NV)

Solutions to Exam Data structures (X and NV) Solutions to Exam Data structures X and NV 2005102. 1. a Insert the keys 9, 6, 2,, 97, 1 into a binary search tree BST. Draw the final tree. See Figure 1. b Add NIL nodes to the tree of 1a and color it

More information

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell Hash Tables CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 22, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005

More information

Topics for CSCI 151 Final Exam Wednesday, May 10

Topics for CSCI 151 Final Exam Wednesday, May 10 Topics for CSCI 151 Final Exam Wednesday, May 10 Java and Programming Techniques Types Inheritance Generics Abstract classes and interfaces Exceptions Recursion Writing recursive methods Dynamic Programming

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

Data Structures and Algorithms Lecture 7 DCI FEEI TUKE. Balanced Trees

Data Structures and Algorithms Lecture 7 DCI FEEI TUKE. Balanced Trees Balanced Trees AVL trees reconstruction of perfect balance can be quite expensive operation less rigid criteria of balance (e.g. AVL) [2] inorder, self-balancing binary search tree (BST) Definition: AVL

More information

- Alan Perlis. Topic 24 Heaps

- Alan Perlis. Topic 24 Heaps Topic 24 Heaps "You think you know when you can learn, are more sure when you can write even more when you can teach, but certain when you can program." - Alan Perlis Recall priority queue Priority Queue

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

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

The smallest element is the first one removed. (You could also define a largest-first-out priority queue) Priority Queues Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The smallest element is the first one removed (You could also define a largest-first-out

More information

School of Computing and Information Sciences. Course Title: Data Structures Date: 3/30/2010 Course Number: COP 3530 Number of Credits: 3

School of Computing and Information Sciences. Course Title: Data Structures Date: 3/30/2010 Course Number: COP 3530 Number of Credits: 3 Course Title: Date: 3/30/2010 Course Number: Number of Credits: 3 Subject Area: Programming Subject Area Coordinator: Tim Downey email: downeyt@cis.fiu.edu Catalog Description: Basic concepts of data organization,

More information

Priority Queues Heaps Heapsort

Priority Queues Heaps Heapsort Priority Queues Heaps Heapsort After this lesson, you should be able to apply the binary heap insertion and deletion algorithms by hand implement the binary heap insertion and deletion algorithms explain

More information

COMP 251 Winter 2017 Online quizzes with answers

COMP 251 Winter 2017 Online quizzes with answers COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots

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

AP Computer Science 4325

AP Computer Science 4325 4325 Instructional Unit Algorithm Design Techniques -divide-and-conquer The students will be -Decide whether an algorithm -classroom discussion -backtracking able to classify uses divide-and-conquer, -worksheets

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

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

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 (Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.

More information

Data structures and libraries

Data structures and libraries Data structures and libraries Bjarki Ágúst Guðmundsson Tómas Ken Magnússon Árangursrík forritun og lausn verkefna School of Computer Science Reykjavík University Today we re going to cover Basic data types

More information

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please

More information

CompSci 201 Tree Traversals & Heaps

CompSci 201 Tree Traversals & Heaps CompSci 201 Tree Traversals & Heaps Jeff Forbes March 28, 2018 3/28/18 CompSci 201, Spring 2018, Heaps 1 R is for R Programming language of choice in Stats Random From Monte-Carlo to [0,1) Recursion Base

More information

Lecture 2 Data Structures & Libraries

Lecture 2 Data Structures & Libraries CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 2 Data Structures & Libraries Victor Gao University of Illinois at Urbana-Champaign September 8, 2017 Updates ICPC tryouts start Sept. 23

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

Priority Queues. 04/10/03 Lecture 22 1

Priority Queues. 04/10/03 Lecture 22 1 Priority Queues It is a variant of queues Each item has an associated priority value. When inserting an item in the queue, the priority value is also provided for it. The data structure provides a method

More information

CSE 373: Data Structures and Algorithms

CSE 373: Data Structures and Algorithms CSE 373: Data Structures and Algorithms Lecture 19: Comparison Sorting Algorithms Instructor: Lilian de Greef Quarter: Summer 2017 Today Intro to sorting Comparison sorting Insertion Sort Selection Sort

More information

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

CS 216 Fall 2007 Final Exam Page 1 of 10 Name:  ID: Page 1 of 10 Name: Email ID: You MUST write your name and e-mail ID on EACH page and bubble in your userid at the bottom of EACH page including this page. If you do not do this, you will receive a zero

More information

Lecture 7. Transform-and-Conquer

Lecture 7. Transform-and-Conquer Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

182 review 1. Course Goals

182 review 1. Course Goals Course Goals 182 review 1 More experience solving problems w/ algorithms and programs minimize static methods use: main( ) use and overload constructors multiple class designs and programming solutions

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

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees Linked representation of binary tree Again, as with linked list, entire tree can be represented with a single pointer -- in this

More information

CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013

CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013 CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting Dan Grossman Fall 2013 Introduction to Sorting Stacks, queues, priority queues, and dictionaries all focused on providing one element

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

CSE 332: Data Structures & Parallelism Lecture 3: Priority Queues. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 3: Priority Queues. Ruth Anderson Winter 2019 CSE 332: Data Structures & Parallelism Lecture 3: Priority Queues Ruth Anderson Winter 201 Today Finish up Intro to Asymptotic Analysis New ADT! Priority Queues 1/11/201 2 Scenario What is the difference

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2008S-19 B-Trees David Galles Department of Computer Science University of San Francisco 19-0: Indexing Operations: Add an element Remove an element Find an element,

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

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

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019 CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting Ruth Anderson Winter 2019 Today Sorting Comparison sorting 2/08/2019 2 Introduction to sorting Stacks, queues, priority queues, and

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00 University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides: none 18 pages Final Examination

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

kd-trees Idea: Each level of the tree compares against 1 dimension. Let s us have only two children at each node (instead of 2 d )

kd-trees Idea: Each level of the tree compares against 1 dimension. Let s us have only two children at each node (instead of 2 d ) kd-trees Invented in 1970s by Jon Bentley Name originally meant 3d-trees, 4d-trees, etc where k was the # of dimensions Now, people say kd-tree of dimension d Idea: Each level of the tree compares against

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

Advanced Set Representation Methods

Advanced Set Representation Methods Advanced Set Representation Methods AVL trees. 2-3(-4) Trees. Union-Find Set ADT DSA - lecture 4 - T.U.Cluj-Napoca - M. Joldos 1 Advanced Set Representation. AVL Trees Problem with BSTs: worst case operation

More information

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University Cpt S 223 Course Overview 1 Course Goals Learn about new/advanced data structures Be able to make design choices on the suitable data structure for different application/problem needs Analyze (objectively)

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

More information

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Merge Sort & Quick Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm

More information

COMP 103 Introduction to Data Structures and Algorithms

COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data

More information

HEAPS & PRIORITY QUEUES

HEAPS & PRIORITY QUEUES HEAPS & PRIORITY QUEUES Lecture 13 CS2110 Spring 2018 Announcements 2 A4 goes out today! Prelim 1: regrades are open a few rubrics have changed No Recitations next week (Fall Break Mon & Tue) We ll spend

More information

CSC 421: Algorithm Design Analysis. Spring 2013

CSC 421: Algorithm Design Analysis. Spring 2013 CSC 421: Algorithm Design Analysis Spring 2013 Transform & conquer transform-and-conquer approach presorting balanced search trees, heaps Horner's Rule problem reduction 1 Transform & conquer the idea

More information

Computer Science E-22 Practice Final Exam

Computer Science E-22 Practice Final Exam name Computer Science E-22 This exam consists of three parts. Part I has 10 multiple-choice questions that you must complete. Part II consists of 4 multi-part problems, of which you must complete 3, and

More information

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees Linked representation of binary tree Again, as with linked list, entire tree can be represented with a single pointer -- in this

More information

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012 CS 223: Data Structures and Programming Techniques. Exam 2 April 19th, 2012 Instructor: Jim Aspnes Work alone. Do not use any notes or books. You have approximately 75 minutes to complete this exam. Please

More information

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance Course goals exposure to another language C++ Object-oriented principles knowledge of specific data structures lists, stacks & queues, priority queues, dynamic dictionaries, graphs impact of DS design

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS CHAPTER 11 SORTING 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 M. AMATO AND

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

CSE 5311 Notes 4a: Priority Queues

CSE 5311 Notes 4a: Priority Queues Chart on p., CLRS (binary, Fibonacci heaps) CSE Notes a: Priority Queues (Last updated 9// : AM) MAKE-HEAP INSERT MINIMUM EXTRACT-MIN UNION (MELD/MERGE) DECREASE-KEY DELETE Applications - sorting (?),

More information

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6

More information

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures Announcements A due TOMORROW. Late deadline is Sunday. A5 released. Due next Thursday. Deadline for Prelim 1 regrade requests is tomorrow. Remember to complete your TA evaluations by tonight. HEAPS & PRIORITY

More information

Data Structures and Abstractions with Java

Data Structures and Abstractions with Java Global edition Data Structures and Abstractions with Java Fourth edition Frank M. Carrano Timothy M. Henry Data Structures and Abstractions with Java TM Fourth Edition Global Edition Frank M. Carrano University

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:

More information

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum Table ADT and Sorting Algorithm topics continuing (or reviewing?) CS 24 curriculum A table ADT (a.k.a. Dictionary, Map) Table public interface: // Put information in the table, and a unique key to identify

More information

Transform & Conquer. Presorting

Transform & Conquer. Presorting Transform & Conquer Definition Transform & Conquer is a general algorithm design technique which works in two stages. STAGE : (Transformation stage): The problem s instance is modified, more amenable to

More information

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms. Next 1. Covered basics of a simple design technique (Divideand-conquer) Ch. 2 of the text. 2. Next, more sorting algorithms. Sorting Switch from design paradigms to applications. Sorting and order statistics

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

Lecture 9 March 4, 2010

Lecture 9 March 4, 2010 6.851: Advanced Data Structures Spring 010 Dr. André Schulz Lecture 9 March 4, 010 1 Overview Last lecture we defined the Least Common Ancestor (LCA) and Range Min Query (RMQ) problems. Recall that an

More information

CSE 373: Data Structures and Algorithms

CSE 373: Data Structures and Algorithms CSE 373: Data Structures and Algorithms Lecture 19: Comparison Sorting Algorithms Instructor: Lilian de Greef Quarter: Summer 2017 Today Intro to sorting Comparison sorting Insertion Sort Selection Sort

More information

CS 3410 Ch 7 Recursion

CS 3410 Ch 7 Recursion CS 3410 Ch 7 Recursion Sections Pages 7.1-7.4, 7.7 93-319, 333-336 7.1 Introduction 1. A recursive method is a method that either directly or indirectly makes a call to itself. [Weiss]. It does this by

More information

6.7 b. Show that a heap of eight elements can be constructed in eight comparisons between heap elements. Tournament of pairwise comparisons

6.7 b. Show that a heap of eight elements can be constructed in eight comparisons between heap elements. Tournament of pairwise comparisons Homework 4 and 5 6.7 b. Show that a heap of eight elements can be constructed in eight comparisons between heap elements. Tournament of pairwise comparisons 6.8 Show the following regarding the maximum

More information

CS 223: Data Structures and Programming Techniques. Exam 2

CS 223: Data Structures and Programming Techniques. Exam 2 CS 223: Data Structures and Programming Techniques. Exam 2 Instructor: Jim Aspnes Work alone. Do not use any notes or books. You have approximately 75 minutes to complete this exam. Please write your answers

More information

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs Lecture 5 Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs Reading: Randomized Search Trees by Aragon & Seidel, Algorithmica 1996, http://sims.berkeley.edu/~aragon/pubs/rst96.pdf;

More information

CS 445: Data Structures Final Examination: Study Guide

CS 445: Data Structures Final Examination: Study Guide CS 445: Data Structures Final Examination: Study Guide Java prerequisites Classes, objects, and references Access modifiers Arguments and parameters Garbage collection Self-test questions: Appendix C Designing

More information

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

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial Week 7 General remarks Arrays, lists, pointers and 1 2 3 We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for

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

Advanced Tree Data Structures

Advanced Tree Data Structures Advanced Tree Data Structures Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park Binary trees Traversal order Balance Rotation Multi-way trees Search Insert Overview

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

ECE 122. Engineering Problem Solving Using Java

ECE 122. Engineering Problem Solving Using Java ECE 122 Engineering Problem Solving Using Java Lecture 27 Linear and Binary Search Overview Problem: How can I efficiently locate data within a data structure Searching for data is a fundamental function

More information

1. The Sets ADT. 1. The Sets ADT. 1. The Sets ADT 11/22/2011. Class Assignment Set in STL

1. The Sets ADT. 1. The Sets ADT. 1. The Sets ADT 11/22/2011. Class Assignment Set in STL 1. Sets 2. Sorting 1. The Sets ADT A set is a container of distinct objects. no duplicate no notation of key, or order. The operation of the set ADT: union: A B = {x:x A or x B} intersection: A B = {x:x

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

CPSC 490 Problem Solving in Computer Science

CPSC 490 Problem Solving in Computer Science CPSC 490 Problem Solving in Computer Science Lecture 14: Binary Indexed Tree Jason Chiu and Raunak Kumar Based on slides by Paul Liu (2014), Kuba Karpierz and Bruno Vacherot (2015), TopCoder Tutorial 2017/02/05

More information

CS302 Data Structures using C++

CS302 Data Structures using C++ CS302 Data Structures using C++ Study Guide for the Final Exam Fall 2018 Revision 1.1 This document serves to help you prepare towards the final exam for the Fall 2018 semester. 1. What topics are to be

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

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

CSE 241 Class 17. Jeremy Buhler. October 28, Ordered collections supported both, plus total ordering operations (pred and succ)

CSE 241 Class 17. Jeremy Buhler. October 28, Ordered collections supported both, plus total ordering operations (pred and succ) CSE 241 Class 17 Jeremy Buhler October 28, 2015 And now for something completely different! 1 A New Abstract Data Type So far, we ve described ordered and unordered collections. Unordered collections didn

More information

CSC 421: Algorithm Design Analysis. Spring 2017

CSC 421: Algorithm Design Analysis. Spring 2017 CSC 421: Algorithm Design Analysis Spring 2017 Transform & conquer transform-and-conquer approach presorting, balanced search trees, heaps, Horner's Rule problem reduction space/time tradeoffs heap sort,

More information

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019 CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees Ruth Anderson Winter 2019 Today Dictionaries Trees 1/23/2019 2 Where we are Studying the absolutely essential ADTs of

More information

Data Structures Brett Bernstein

Data Structures Brett Bernstein Data Structures Brett Bernstein Final Review 1. Consider a binary tree of height k. (a) What is the maximum number of nodes? (b) What is the maximum number of leaves? (c) What is the minimum number of

More information

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. 3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues

More information

COMP171. AVL-Trees (Part 1)

COMP171. AVL-Trees (Part 1) COMP11 AVL-Trees (Part 1) AVL Trees / Slide 2 Data, a set of elements Data structure, a structured set of elements, linear, tree, graph, Linear: a sequence of elements, array, linked lists Tree: nested

More information

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; } if (n

More information

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

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

More information

Data Structures and Algorithms 1

Data Structures and Algorithms 1 CS Content Academy: Data Structures Outline 1. How Does Data Structures Fit into CS What Is CS? 2. What Are Data Structures and Algorithms? 3. The Structure of Data Structures and Algorithms 3.1 Part A:

More information

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

( ). Which of ( ) ( )  #& ( )  # g( n) ( )  # f ( n) Test 1 CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.

More information

13 A: External Algorithms II; Disjoint Sets; Java API Support

13 A: External Algorithms II; Disjoint Sets; Java API Support 13 A: External Algorithms II; ; Java API Support Martin Henz April 15, 2009 Generated on Friday 13 17 A: th External April, 2009, Algorithms 12:37 II; ; Java API Support 1 1 External Sorting 2 3 4 13 A:

More information