On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Similar documents
Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

CS473 - Algorithms I

Homework 1 Submission

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

3.1 Asymptotic notation

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

CS 380 ALGORITHM DESIGN AND ANALYSIS

COMP Analysis of Algorithms & Data Structures

IS 709/809: Computational Methods in IS Research Fall Exam Review

Big-O Notation and Complexity Analysis

COMP 9024, Class notes, 11s2, Class 1

COMP Analysis of Algorithms & Data Structures

Homework 1 Solutions

CS 4407 Algorithms Lecture 2: Growth Functions

Computational Complexity

Lecture 2: Asymptotic Notation CSCI Algorithms I

CS Non-recursive and Recursive Algorithm Analysis

University of New Mexico Department of Computer Science. Midterm Examination. CS 361 Data Structures and Algorithms Spring, 2003

Fall 2016 Test 1 with Solutions

Analysis of Algorithms

Homework Assignment 1 Solutions

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 1: Introduction

The Time Complexity of an Algorithm

Module 1: Analyzing the Efficiency of Algorithms

data structures and algorithms lecture 2

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

CPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009

Lynch 2017 Page 1 of 5. Math 150, Fall 2017 Exam 1 Form A Multiple Choice

Review Of Topics. Review: Induction

Ch01. Analysis of Algorithms

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

CS 361, Lecture 14. Outline

Md Momin Al Aziz. Analysis of Algorithms. Asymptotic Notations 3 COMP Computer Science University of Manitoba

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2013

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. January 16, 2019

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

Lecture 3: Big-O and Big-Θ

COMPUTER ALGORITHMS. Athasit Surarerks.

Analysis of Algorithms

Data Structures and Algorithms Running time and growth functions January 18, 2018

Time complexity analysis

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

The Growth of Functions and Big-O Notation

Module 1: Analyzing the Efficiency of Algorithms

The Time Complexity of an Algorithm

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 344 Design and Analysis of Algorithms. Tarek El-Gaaly Course website:

Asymptotic Analysis 1

Data Structures and Algorithms CSE 465

Outline. 1 Introduction. 3 Quicksort. 4 Analysis. 5 References. Idea. 1 Choose an element x and reorder the array as follows:

Cpt S 223. School of EECS, WSU

Written Homework #1: Analysis of Algorithms

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

Spring 2018 Exam 2 MARK BOX HAND IN PART NAME: PIN: INSTRUCTIONS

Introduction to Algorithms 6.046J/18.401J

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Growth of Functions (CLRS 2.3,3)

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

COL106: Data Structures and Algorithms (IIT Delhi, Semester-II )

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

CS 350 Midterm Algorithms and Complexity

CS 61B Asymptotic Analysis Fall 2017

2. ALGORITHM ANALYSIS

Quicksort. Where Average and Worst Case Differ. S.V. N. (vishy) Vishwanathan. University of California, Santa Cruz

Asymptotic Algorithm Analysis & Sorting

HKUST. MATH1013 Calculus IB. Directions:

Data Structures and Algorithms CSE 465

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Submit Growable Array exercise Answer Q1-3 from today's in-class quiz.

Divide and Conquer Strategy

Data Structures and Algorithms Chapter 2

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

Algorithms, CSE, OSU. Introduction, complexity of algorithms, asymptotic growth of functions. Instructor: Anastasios Sidiropoulos

Algorithms and Programming I. Lecture#1 Spring 2015

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Algorithms and Their Complexity

Recommended readings: Description of Quicksort in my notes, Ch7 of your CLRS text.

1 Quick Sort LECTURE 7. OHSU/OGI (Winter 2009) ANALYSIS AND DESIGN OF ALGORITHMS

Ch 01. Analysis of Algorithms

CS483 Design and Analysis of Algorithms

Asymptotic Analysis Cont'd

MA EXAM 2 INSTRUCTIONS VERSION 01 March 10, Section # and recitation time

Algorithms, CSE, OSU Quicksort. Instructor: Anastasios Sidiropoulos

Math 151, Fall 2018 Common Exam 1 Version A

An analogy from Calculus: limits

Math 2114 Common Final Exam May 13, 2015 Form A

ECE250: Algorithms and Data Structures Analyzing and Designing Algorithms

MA EXAM 3 Form A November 12, You must use a #2 pencil on the mark sense sheet (answer sheet).

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation:

MA EXAM 3 Form A April 16, You must use a #2 pencil on the mark sense sheet (answer sheet).

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

EECS 477: Introduction to algorithms. Lecture 5

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

MA Exam 1 Fall 2015 VERSION 01

Menu. Lecture 2: Orders of Growth. Predicting Running Time. Order Notation. Predicting Program Properties

Data selection. Lower complexity bound for sorting

MA EXAM 2 INSTRUCTIONS VERSION 01 March 9, Section # and recitation time

Transcription:

CS 2413 Data Structures EXAM 1 Fall 2017, Page 1 of 10 Student Name: Student ID # OU Academic Integrity Pledge On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise. Signature: Date: Notes Regarding this Examination Open Book(s) You may consult any printed textbooks in your immediate possession during the course of this examination. Open Notes You may consult any printed notes in your immediate possession during the course of this examination. No Electronic Devices Permitted You may not use any electronic devices during the course of this examination, including but not limited to calculators, computers, and cellular phones. All electronic devices in the student s possession must be turned off and placed out of sight (for example, in the student s own pocket or backpack) for the duration of the examination. Violations Copying another s work, or possession of electronic computing or communication devices in the testing area, is cheating and grounds for penalties in accordance with school policies.

CS 2413 Data Structures EXAM 1 Fall 2017, Page 2 of 10 Section I. Definitions of Time and Space Complexity Definition of Big O: Let f(n) and g(n) be functions mapping non-negative integers to real numbers. We say that f(n) O(g(n)) if there is a real number c > 0 and a fixed integer n 0 1 such that f(n) cg(n) for every integer n n 0. Definition of Big Ω: Let f(n) and g(n) be functions mapping non-negative integers to real numbers. We say that f(n) Ω(g(n)) if there is a real number c > 0 and a fixed integer n 0 1 such that f(n) cg(n) for every integer n n 0. Definition of Big Θ: Let f(n) and g(n) be functions mapping non-negative integers to real numbers. We say that f(n) Θ(g(n)) if there are real numbers c, d > 0 and a fixed integer n 0 1 such that dg(n) f(n) cg(n) for every integer n n 0. 1. (2 points) If I need to ensure that my program runs efficiently regardless of input values, I need to be concerned about which of the following? A. Big O B. Big Ω C. Big Θ D. A and B E. A, B, and C 2. (2 points) If I want to consider how fast my program might run given the right input values, I should be concerned about which of the following? A. Big O B. Big Ω C. Big Θ D. A and B E. A, B, and C 3. (2 points) If I can characterize my program s runtime as a function of input size to within a constant regardless of input values, I am able to report which of the following? A. Big O B. Big Ω C. Big Θ D. A and B E. A, B, and C 4. (2 points) Which is generally considered to be a better time complexity? A. Θ(n log 2 n) B. Θ(n 2 ) C. Θ(2 n ) D. Θ(log 2 n) E. Θ(n 2 log 2 n) 5. (2 points) Which is generally considered to be a better time complexity? A. Θ(2 n + log 2 n) B. Θ(n 2 ) C. Θ(n + n 2 log 2 n) D. Θ(n 2 + n 2 log 2 n) E. Θ(n + n log 2 n) 6. (2 points) A time complexity of Θ(n 2 log 2 n + log 2 n + n 2 ) can be simplified to which? A. Θ(n log 2 n) B. Θ(n 2 log 2 n) C. Θ(log 2 n) D. Θ(n 2 ) E. Θ(n)

CS 2413 Data Structures EXAM 1 Fall 2017, Page 3 of 10 Section II. Applications of Time and Space Complexity Consider the following pseudocode: Algorithm RecursiveFunction (a) // a is a positive integer b 100 if (a b) return a; else return RecursiveFunction (a / 2); endif 7. (2 points) What is the time complexity of the RecursiveFunction pseudocode shown above? A. Θ(a) B. Θ(log 2 a) D. Θ(b) E. Θ(log 2 b) 8. (2 points) What is the space complexity of the RecursiveFunction pseudocode shown above? A. Θ(a) B. Θ(log 2 a) D. Θ(b) E. Θ(log 2 b) Consider the following pseudocode: Algorithm IterativeFunction (a) b 1 while (b < a) b b 2 endwhile return b; // a is a positive integer 9. (2 points) What is the time complexity of the IterativeFunction pseudocode shown above? A. Θ(a) B. Θ(log 2 a) D. Θ(b) E. Θ(log 2 b) 10. (2 points) What is the space complexity of the IterativeFunction pseudocode shown above? A. Θ(a) B. Θ(log 2 a) D. Θ(b) E. Θ(log 2 b)

CS 2413 Data Structures EXAM 1 Fall 2017, Page 4 of 10 Consider the following pseudocode: Algorithm DoubleIterativeFunction (n) i 1 while (i < n) do print i j n while (j > 0) do print j j j - 2 endwhile i i + 1 endwhile // n is a positive integer 11. (2 points) What is the time complexity of the DoubleIterativeFunction pseudocode shown above? D. Θ(n 2 ) E. Θ(n log 2 n) 12. (2 points) What is the space complexity of the DoubleIterativeFunction pseudocode shown above? D. Θ(n 2 ) E. Θ(n log 2 n) Consider the following pseudocode: Algorithm DoubleIterativeFunction2 (n) // n is a positive integer i 1 while (i < n) do print i j n while (j > 0) do print j j j / 2 // note the change in this line endwhile i i + 1 endwhile 13. (2 points) What is the time complexity of the DoubleIterativeFunction2 pseudocode shown above? D. Θ(n 2 ) E. Θ(n log 2 n) 14. (2 points) What is the space complexity of the DoubleIterativeFunction2 pseudocode shown above? D. Θ(n 2 ) E. Θ(n log 2 n)

CS 2413 Data Structures EXAM 1 Fall 2017, Page 5 of 10 Section III. Complexity of Array Operations 15. (2 points) Starting from two sorted arrays with a combined total of n items, what is the time complexity for the most time-efficient algorithm for combining them into a new sorted array of those same n items? 16. (2 points) Starting from two unsorted arrays with a combined total of n items, what is the time complexity for the most time-efficient algorithm for combining them into a new sorted array of those same n items? 17. (2 points) Starting from two sorted arrays with a combined total of n items, what is the time complexity for the most time-efficient algorithm for finding the lowest valued item from either array? 18. (2 points) Starting from two unsorted arrays with a combined total of n items, what is the time complexity for the most time-efficient algorithm for finding the lowest valued item from either array? 19. (2 points) Starting from one unsorted array of n items, what is the space complexity of the additional space needed for the most space-efficient algorithm for sorting the array? 20. (2 points) Starting from one sorted array of n items, what is the space complexity of the most space- and time-efficient algorithm for finding an arbitrary key value in the array? Exam continues with short answer questions.

CS 2413 Data Structures EXAM 1 Fall 2017, Page 6 of 10 Short Answer Question 1: Straight Insertion Sort (10 points) A. What is the Big O time complexity of Straight Insertion Sort? B. Explain why Straight Insertion Sort has the time complexity you listed above in Part A.

CS 2413 Data Structures EXAM 1 Fall 2017, Page 7 of 10 Short Answer Question 2: Straight Insertion Sort (10 points) A. What is the Big Ω time complexity of Straight Insertion Sort? B. Explain why Straight Insertion Sort has the Big Ω time complexity you listed above in Part A.

CS 2413 Data Structures EXAM 1 Fall 2017, Page 8 of 10 Short Answer Question 3: Quick Sort (10 points) A. What is the Big O time complexity of Quicksort using the first (or last) element of the array to sort as the pivot point? B. Explain why Quicksort has the Big O time complexity you listed above in Part A.

CS 2413 Data Structures EXAM 1 Fall 2017, Page 9 of 10 Short Answer Question 4: Quicksort (30 points) Algorithm Quicksort (A, left, right) if (left < right) pivotpoint (left+right)/2 // note central pivot i left - 1 j right + 1 do do i i + 1 while (i < A.size) and (A[i] A[pivotPoint]) do j j - 1 while (j i) and (A[j] A[pivotPoint]) if (i < j) then swap (A[i], A[j]) while (i < j) if (i < pivotpoint) then j i swap (A[pivotPoint], A[j]) Quicksort (A, left, j-1) Quicksort (A, j+1, right) endif Show the steps followed by the Quicksort algorithm given above in pseudocode when sorting the following array. Draw one figure for each call to Quicksort. You may omit calls where left right. value 84 27 59 31 78 73 30 38 39 37 index 0 1 2 3 4 5 6 7 8 9

CS 2413 Data Structures EXAM 1 Fall 2017, Page 10 of 10 Additional space to answer Short Answer Question 4