Quiz 1 Practice Problems

Similar documents
Quiz 1 Practice Problems

Quiz 1 Solutions. (a) If f(n) = Θ(g(n)) and g(n) = Θ(h(n)), then h(n) = Θ(f(n)) Solution: True. Θ is transitive.

Introduction to Algorithms March 12, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1

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

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

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

Final Exam in Algorithms and Data Structures 1 (1DL210)

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

1. Attempt any three of the following: 15

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

Final Exam. Problem Parts Points Grade Grader Problem Parts Points Grade Grader Total 180. Name: Athena username: Joe WF3a. Joe WF2.

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

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

CPSC 331 Term Test #2 March 26, 2007

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

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

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;

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

Complexity of Algorithms. Andreas Klappenecker

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

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

CSL 201 Data Structures Mid-Semester Exam minutes

Complexity of Algorithms

Final Exam in Algorithms and Data Structures 1 (1DL210)

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

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

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Practice Midterm Exam Solutions

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

ECE250: Algorithms and Data Structures Midterm Review

THE UNIVERSITY OF WESTERN AUSTRALIA

CS 3343 (Spring 2013) Exam 2

Algorithms: Efficiency, Analysis, techniques for solving problems using computer approach or methodology but not programming

CSI33 Data Structures

Part 1: Multiple Choice Circle only ONE answer. Each multiple choice question is worth 3.5 marks.

Section 05: Midterm Review

STA141C: Big Data & High Performance Statistical Computing

Asymptotic Analysis Spring 2018 Discussion 7: February 27, 2018

CSE wi: Practice Midterm

Data Structure and Algorithm Homework #1 Due: 1:20pm, Tuesday, March 21, 2017 TA === Homework submission instructions ===

Lecture 5: Running Time Evaluation

Introduction to Algorithms December 16, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas

CS:3330 (22c:31) Algorithms

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

CS 303 Design and Analysis of Algorithms

DATA STRUCTURES AND ALGORITHMS

Quiz 2 Practice Problems

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

CS S-02 Algorithm Analysis 1

STA141C: Big Data & High Performance Statistical Computing

END-TERM EXAMINATION

Chapter 9: Maps, Dictionaries, Hashing

Midterm 1 for CS 170

CS2 Practical 6 CS2Bh 24 January 2005

CSE Winter 2015 Quiz 1 Solutions

An algorithm is a sequence of instructions that one must perform in order to solve a wellformulated

Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown.

(b) If a heap has n elements, what s the height of the tree?

Test points UTA Student ID #

INSTITUTE OF AERONAUTICAL ENGINEERING

6.006 Introduction to Algorithms Spring 2008

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2

Data Structures and Algorithms CSE 465

Chapter 2: Complexity Analysis

HASH TABLES.

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

DATA STRUCTURES AND ALGORITHMS

2. (a) Explain the concept of virtual functions in C++ with suitable examples. (b) Explain the concept of operator overloading in C++.

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs

Spring 2013 CSE Qualifying Exam Core Subjects. March 23, 2013

Problem Set 4. Problem 4-1. [35 points] Hash Functions and Load

Hashing. Dr. Ronaldo Menezes Hugo Serrano. Ronaldo Menezes, Florida Tech

Algorithm Analysis. Algorithm Efficiency Best, Worst, Average Cases Asymptotic Analysis (Big Oh) Space Complexity

Quiz 1 Solution. Figure 1: grade distribution. Problem Points Grade Initials. Total 80

Hashing Techniques. Material based on slides by George Bebis

Dictionary. Dictionary. stores key-value pairs. Find(k) Insert(k, v) Delete(k) List O(n) O(1) O(n) Sorted Array O(log n) O(n) O(n)

Problem Set 1. Problem 1-1.

CSCI Analysis of Algorithms I

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

Randomized Algorithms, Hash Functions

CSE 101, Winter Discussion Section Week 1. January 8 - January 15

CSC236H Lecture 5. October 17, 2018

Hash Tables. Reading: Cormen et al, Sections 11.1 and 11.2

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

Module 5: Hashing. CS Data Structures and Data Management. Reza Dorrigiv, Daniel Roche. School of Computer Science, University of Waterloo

[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview

CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points]

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

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

Algorithms and Data Structures

CISC 320 Midterm Exam

of characters from an alphabet, then, the hash function could be:

Introduction to Computers & Programming

CS 3114 Data Structures and Algorithms READ THIS NOW!

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

Problem Set 6 Due: 11:59 Sunday, April 29

Transcription:

Introduction to Algorithms: 6.006 Massachusetts Institute of Technology March 7, 2008 Professors Srini Devadas and Erik Demaine Handout 6 1 Asymptotic Notation Quiz 1 Practice Problems Decide whether these statements are True or False. You must briefly justify all your answers to receive full credit. 1. If f(n) = Θ(g(n)) and g(n) = Θ(h(n)), then h(n) = Θ(f(n)) 2. If f(n) = O(g(n)) and g(n) = O(h(n)), then h(n) = Ω(f(n)) 3. If f(n) = O(g(n)) and g(n) = O(f(n)) then f(n) = g(n) 4. n 100 = Ω(n)

2 Handout 6: Quiz 1 Practice Problems 5. f(n) = Θ(n 2 ), where f(n) is defined to be the running time of the program A(n): def A(n): atuple = tuple(range(0, n)) # a tuple is an immutable version of a # list, so we can hash it S = set() for i in range(0, n): for j in range(i+1, n): S.add(atuple[i:j]) # add tuple (i,...,j-1) to set S 2 Linked List Equivalence Let S and T be two sets of numbers, represented as unordered linked lists of distinct numbers. All you have are pointers to the heads of the lists, but you do not know the list lengths. Describe an O(min { S, T })-expected-time algorithm to determine whether S = T. You may assume that any operation on one or two numbers can be performed in constant time.

Handout 6: Quiz 1 Practice Problems 3 3 Hash Table Analysis You are given a hash table with n keys and m slots, with the simple uniform hashing assumption (each key is equally likely to be hashed into each slot). Collisions are resolved by chaining. What is the probability that the first slot ends up empty? 4 Heaps 1. The sequence 20, 15, 18, 7, 9, 5, 12, 3, 6, 2 is a max-heap. 2. Where in a max-heap can the smallest element reside, assuming all elements are distinct? Include both the location in the array and the location in the implicit tree structure. 3. Suppose that instead of using Build-Heap to build a max-heap in place, the Insert operation is used n times. Starting with an empty heap, for each element, use Insert to insert it into the heap. After each insertion, the heap still has the max-heap property, so after n Insert operations, it is a max-heap on the n elements. (i) Argue that this heap construction runs in O(n log n) time. (ii) Argue that in the worst case, this heap construction runs in Ω(n log n) time.

4 Handout 6: Quiz 1 Practice Problems 5 Python and Asymptotics 1. Give an example of a built-in Python operation that does not take constant time in the size of its input(s). What time does it take? 2. Since dictionary lookup takes constant expected time, one can output all n keys in a dictionary in sorted order in expected time O(n). 3. Write a recurrence for the running time T (n) of f(n), and solve that recurrence. Assume that addition can be done in constant time. def f(n): if n == 1: return 1 else: return f(n-1)+f(n-1) 4. Write a recurrence for the running time of g(n), and solve that recurrence. Assume that addition can be done in constant time. def g(n): if n == 1: return 1 else: x = g(n-1) return x+x 5. Now assume addition takes time Θ(b) where b is the number of bits in the larger number. Write a new recurrence for the running time of g(n), and solve that recurrence. Express your final answer in Θ-notation.

Handout 6: Quiz 1 Practice Problems 5 6 Hashing 1. Given a hash table with more slots than keys, and collision resolution by chaining, the worst case running time of a lookup is constant time. 2. Linear probing satisfies the assumption of uniform hashing. 3. Assume that m = 2 r for some integer r > 1. We map a key k into one of the m slots using the hash function h(k) = k mod m. Give one reason why this might be a poorly chosen hash function.