University of Waterloo CS240 Spring 2018 Help Session Problems

Similar documents
University of Waterloo CS240R Winter 2018 Help Session Problems

University of Waterloo CS240R Fall 2017 Review Problems

University of Waterloo CS240R Fall 2017 Solutions to Review Problems

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Midterm solutions. n f 3 (n) = 3

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

: Fundamental Data Structures and Algorithms. June 06, 2011 SOLUTIONS

Final Examination CSE 100 UCSD (Practice)

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Examination Questions Midterm 2

Fundamentals of Multimedia. Lecture 5 Lossless Data Compression Variable Length Coding

Friday Four Square! 4:15PM, Outside Gates

Course Review for Finals. Cpt S 223 Fall 2008

DATA STRUCTURES AND ALGORITHMS

Module 2: Classical Algorithm Design Techniques

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

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Quiz 1 Practice Problems

Transform & Conquer. Presorting

University of Waterloo CS240, Winter 2010 Assignment 2

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

Analysis of Algorithms

COS 226 Midterm Exam, Spring 2011

Hashing. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

UNIT III BALANCED SEARCH TREES AND INDEXING

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

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

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far

Course Review. Cpt S 223 Fall 2009

1. AVL Trees (10 Points)

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

A Secondary storage Algorithms and Data Structures Supplementary Questions and Exercises

Lecture 7. Transform-and-Conquer

( ) n 5. Test 1 - Closed Book

Sample Exam 1 Questions

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Module Contact: Dr Tony Bagnall, CMP Copyright of the University of East Anglia Version 1

COS 226 Midterm Exam, Spring 2009

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

CPSC 331 Term Test #2 March 26, 2007

CS 206 Introduction to Computer Science II

Lecture 7 February 26, 2010

Data Structures and Algorithms Week 4

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

Practical Session 10 - Huffman code, Sort properties, QuickSort algorithm, Selection

CS301 - Data Structures Glossary By

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms???

CS 3343 (Spring 2013) Exam 2

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

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

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Greedy Algorithms CHAPTER 16

Practice Midterm Exam Solutions

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

Multiple-choice (35 pt.)

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017

END-TERM EXAMINATION

COMP3121/3821/9101/ s1 Assignment 1

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

Indexing and Searching

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

Lempel-Ziv compression: how and why?

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

CS 315 Data Structures mid-term 2

Chapter 7. Space and Time Tradeoffs. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

CSE wi: Practice Midterm

COP 3502 Spring 2018 Study Union Review

Lossless Compression Algorithms

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Material covered. Areas/Topics covered. Logistics. What to focus on. Areas/Topics covered 5/14/2015. COS 226 Final Exam Review Spring 2015

BM267 - Introduction to Data Structures

Balanced Binary Search Trees. Victor Gao

COSC160: Data Structures Hashing Structures. Jeremy Bolton, PhD Assistant Teaching Professor

Balanced Search Trees. CS 3110 Fall 2010

Final Exam Solutions

Solutions to Exam Data structures (X and NV)

Algorithms Lab 3. (a) What is the minimum number of elements in the heap, as a function of h?

CS-301 Data Structure. Tariq Hanif

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

Data Structures and Algorithms. Course slides: Radix Search, Radix sort, Bucket sort, Patricia tree

EE67I Multimedia Communication Systems Lecture 4

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Algorithms and Data Structures Lesson 3

Chapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion,

Programming II (CS300)

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management

Course Review. Cpt S 223 Fall 2010

Algorithms: Design & Practice

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Midterm Exam 2B Answer key

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9)

CSE100. Advanced Data Structures. Lecture 12. (Based on Paul Kube course materials)

Binary Heaps. CpSc 212: Algorithms and Data Structures. School of Computing Clemson University Summer, Raghuveer Mohan. Thanks to Brian C.

Transcription:

University of Waterloo CS240 Spring 2018 Help Session Problems Reminder: Final on Wednesday, August 1 2018 Note: This is a sample of problems designed to help prepare for the final exam. These problems do not encompass the entire coverage of the final exam, and should not be used as a reference for what the final exam contains. True/False For each statement below, write true or false. Justify three of them. a) Open addressing hashing that uses linear probing will require two hash functions. b) Run length encoding may result in text expansion on some strings. c) When doing range search on a quad tree, if there is no point within the range specified, the worst case runtime complexity is Θ(h). d) Suffix trees for pattern matching require preprocessing the pattern. e) If the bubble-up version of heapify is used in Heapsort, then the worst-case runtime of Heapsort will be Ω(n 2 ). f) The runtime complexity of range query for kd-trees depends on the spread factor of points. g) When searching for a pattern P in some text T, it is possible for the Boyer- Moore Bad Character heuristic to perform more character comparisons than the Brute Force algorithm. h) Rehashing may be required in Cuckoo Hashing even if the load factor is at an acceptable value. i) If an AVL tree node has balance 2 and its right child has balance 1, then a double left rotation is required. j) Move-to-front compression uses adaptive instead of fixed dictionaries. 1

Multiple Choice Pick the best answer for each question. 1. The last occurrence function for the pattern MELSMEMES would contain the following values for each character: a) E = 8, L = 3, M = 7, S = 9 b) E = 3, L = 1, M = 3, S = 2 c) E = 1, L = 6, M = 2, S = 0 d) E = 7, L = 2, M = 6, S = 8 2. The minimum number of nodes in an AVL Tree of height 3 is: a) 5 b) 6 c) 7 d) 8 3. Using LZW decoding, the last code 132 decodes to what? a) CCCCCC b) CCCCCCC c) CCCCCCCC d) CCCCCCCCC 67 128 129 130 131 132 4. A quadtree with bounding box [0, 8) [0, 8) over the following points has a height of. a) 2 b) 3 c) 4 d) 5 (6, 2), (0, 1), (3, 4), (7, 5), (1, 0) 2

5. Suppose we have an array of n numbers where each number is no larger than n 3, and assume that n is a perfect square. Consider running HeapSort, QuickSort, and RadixSort with radix base R = n on this array. The worst-case asymptotic runtimes for each sorting algorithm, from best to worst, is: a) HeapSort, QuickSort, RadixSort b) RadixSort, HeapSort, QuickSort c) QuickSort, RadixSort, HeapSort d) RadixSort, QuickSort, HeapSort 6. Which one of the following statements about compressed tries is false? a) Every internal node stores an index indicating the bit position to be tested on a search. b) The root of the compressed trie always tests the first bit. c) A compressed trie that stores n keys always contains less than n internal nodes. d) The height of a compressed trie never exceeds the length of the longest string it stores. 7. Which of the following search operations on a non-dictionary structure has the most efficient worst-case runtime? a) Searching for a specific key in a max-heap. b) Searching for a specific point in a kd-tree. c) Searching for any occurrence of a specific character in a text using a suffix tree. d) Searching for a specific character in a decoding trie of characters. 8. CS240 is a course about a) Data structures and algorithms b) Unreasonable time management c) Reconsidering academic/life choices d) All of the above 3

Hashing Let h 1 (k) = k mod 7, h 2 (k) = k 2 mod 7, and h 3 (k) = k, with a table size 7 of 7. a) Using h(k, i) = h 1 (k) + i(h 2 (k) + 1), fill the table with correctly hashed values such that a call to search(6) succeeds at the end of a probe sequence of length four. b) Repeat part (a) using h(k, i) = h 1 (k) + i(h 3 (k) + 1). c) Repeat part (a) using h(k, i) = h 2 (k) + i(h 3 (k) + 1). Huffman Compression a) The following message was compressed using Huffman encoding and transmitted together with its dictionary: 0010000111010101110001011010010 = 100 (blank space) : = 1011 (colon) d = 1010 l = 010 p = 001 s = 000 u = 11 w = 011 Decompress the string using the dictionary and write the final message. b) Agent Frenette doesn t know the password beforehand, but upon seeing the decoded string, he immediately realizes that the message has been tampered with. Explain how Zach determined this. 4

Rabin-Karp For Rabin-Karp pattern matching, consider the following hash function for strings over the alphabet {A, C, G, T}: h(p ) =(# of occurrences of A) + 2 (# of occurrences of C) + 3 (# of occurrences of G) + 4 (# of occurrences of T) a) Given the pattern P = TAGCAT and sequence T = TGCCGATGTAGCTAGCAT, use the table below to show all the character comparisons performed during Rabin-Karp pattern matching. Start a new pattern shift (in which character comparison occurs) in a new row. You may not need all the available space. T G C C G A T G T A G C T A G C A T Table 1: Table for Rabin-Karp problem. b) Suppose we are searching for a length-m pattern P in a length-n sequence T. After computing the hash value of T [i... i + m 1] (the length-m substring beginning at index i) for i < n m, explain how to compute the hash value of the next substring T [i + 1... i + m] in O(1) time. c) Give a length-m pattern P and a length-n sequence T, with n > m, such that the Rabin-Karp algorithm achieves the worst-case number of character comparisons. 5

Encoding Schemes Suppose you need design an encoding algorithm for source texts of length n over the alphabet {0, 1, 2, 3}, given that all source texts begin with an even digit and alternate between even and odd digits. There are no constraints on the alphabet of the coded text, but the encoding must be lossless. a) Design an encoding scheme (i.e. both an encoding algorithm and a decoding algorithm) that achieves the lowest best-case compression ratio. b) Design an encoding scheme that achieves the lowest worst-case compression ratio. c) Prove that the worst-case compression ratio in part (b) is optimal, i.e. there is no encoding scheme that achieves a lower worst-case compression ratio. Suffix Trees A secret message, in the form of a Suffix Tree S, is slipped under the door of the CS240 ISA office. Give an algorithm to help Jean determine the mystery text T used to generate S. The algorithm should use O(n) space and run in O(n) time. KD-Trees Consider the following set of points: (80, 3, 44), (52, 70, 8), (70, 96, 12), (94, 20, 15), (65, 98, 54), (41, 26, 58), (28, 84, 91), (63, 32, 99), (36, 87, 72), (39, 90, 40). a) Draw the kd-tree corresponding to these points. b) Draw the subset of the tree that is visited during a range query in the rectangular box [60, 70] [90, 100] [50, 90]. 6

(7, 10) (4, 8) (9, 5) (2, 9) (5, 7) (8, 3) (11, 1) (1, 13) (3, 12) (6, 6) (10, 4) (12, 2) Figure 1: Range Tree x-bst Range Trees Consider the x-bst of a range tree in Figure 1. a) Draw the y-bsts at nodes (2, 9), (5, 7), and (9, 5). b) For the query range R = [0, 7.5] [9, 14], identify the boundary nodes, inside nodes, and outside nodes for just the x-dimension. Tries Given a compressed trie T that stores a list of binary strings, write an algorithm Consecutive(b 1, b 2 ) that takes two binary strings in T as input, and outputs true if the strings are consecutive in an in-order traversal of the trie, and outputs false otherwise. Assume that branches are ordered as $, 0, 1. The runtime should be bounded by O( b 1 + b 2 ). For example, suppose T stores {000, 01, 0110, 101, 11}. Consecutive(0110, 101) outputs true. Consecutive(01, 000) outputs true. Consecutive(11, 000) outputs false. 7

Run-Length Encoding a) Give a string of n bits that achieves the best compression ratio with Run- Length Encoding from all n-bit strings, and state the exact compression ratio achieved. b) Same question, but for the worst compression ratio. You may assume that n is divisible by 4. Lempel-Ziv-Welch Encoding Encode the following string using LZW compression: DARK DAN BARKS DANK Add new entries to the encoding dictionary starting at value 128. Char ASCII value A 65 B 66 D 68 K 75 N 78 R 82 S 83 95 Burrows-Wheeler Transform The following key was encoded by the Burrows-Wheeler Transform. EPESLPP$ASEAR Decrypt it using the method outlined in the slides, showing the array of tuples A, sort(a), and each value of j. 8

Range Query Consider an array A of n integers. We want to implement a range query called MaxDiff(i, j) which will find the maximal difference between two elements from A[i] to A[j] inclusive, for i < j. For example, if you run the query MaxDiff(3, 7) on the array below: A = 5 0 2 8 9 4 6 7 6 1 3 Between indices 3 and 7 in the array above, the largest number is 9 and the smallest number is 4, so the maximal difference is 9 4 = 5. Using a data structure with space complexity O(n), implement M axdif f(i, j) to answer queries in O(log n) time. There are no limits on the runtime for preprocessing the array into the data structure, but it should not be a randomized algorithm. 9