CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points]
|
|
- Liliana Griffin
- 6 years ago
- Views:
Transcription
1 CS 360 Exam 1 Fall 2014 Name 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v<=n; v++) for (w=1; w<=v; w++) for (x=v; x<=n; x++) for (y=w; y<=x; y++) z++; for (r=1; r<=n; r++) for (s=n+1; s<=2*n; s++) for (t=r; t<=s; t++) u++; If n=3, how many total times is z incremented? If n=2, how many total times is z incremented? If n=2, how many total times is u incremented? If n=3, how many total times is u incremented? class A { int F( ) { return 3; } int G( ) { return 3 + F( ); } int H( ) { return 6 + G( ); } } class B extends A { int H( ) { return 7 + G( ); } } class C extends B { int G( ) { return 5 + F( ); } } class D extends C { int F( ) { return 6; } } class E extends D { int H( ) { return 9 + G( ); } } A b, c, d, e; b = new B( ); b.h( ); c = new C( ); c.h( ); d = new D( ); d.h( ); e = new E( ); e.h( ); This code is object-oriented. Therefore it uses both inheritance and late method binding (also known as dynamic method binding or dynamic dispatch). What value is returned from the call b.h( )? What value is returned from the call c.h( )? What value is returned from the call d.h( )? What value is returned from the call e.h( )?
2 2. Evaluate each expression and write the answer in simplest form. [12 points] 100 mod 13 = 13 mod 100 = mod 25 = 3 lg 256 = lg 80 + lg 48 lg 30 = 100 mod 25 = k=0 = k=100 k = k=0 2kk = 4 kk log3 243 = log = log16 2 = 3. Questions about running times. [4 points] First suppose we run a program, and we find that T(2) = 0.01 seconds and T(8) = seconds. a. If T(n) = c k n, determine the value of constant k. b. If T(n) = c n k, determine the value of constant k. Next we run a different program using an input of size 100, and we find that T(100) = 5 seconds. c. If T(n) = c n 3 for some constant c, then determine T(200). d. If T(n) = c n for some constant c, determine the value of n0 such that T(n0) = 15 seconds.
3 4. Suppose f(n) and g(n) are related by at least one of the relations O, o, θ, Ω, ω. Match each condition below to its equivalent relation. [13 points] A. f(n) is O(g(n)) B. f(n) is o(g(n)) C. f(n) is θ(g(n)) D. f(n) is Ω(g(n)) E. f(n) is ω(g(n)) F. Contradictory or impossible situation f(n) is θ(g(n)) or f(n) is not Ω(g(n)). f(n) is not o(g(n)) and f(n) is not ω(g(n)). f(n) is Ο(g(n)) and f(n) is ω(g(n)). f(n) is Ο(g(n)) and f(n) is Ω(g(n)). f(n) is Ω(g(n)) and f(n) is o(g(n)). f(n) is θ(g(n)) or f(n) is o(g(n)). f(n) is θ(g(n)) or f(n) is ω(g(n)). f(n) is not θ(g(n)) and f(n) is not o(g(n)). f(n) is not θ(g(n)) and f(n) is not ω(g(n)). f(n) is not Ο(g(n)) and f(n) is not Ω(g(n)). f(n) is not O(g(n)). f(n) is not Ω(g(n)). f(n) is θ(g(n)) or f(n) is not Ο(g(n)).
4 5. State the running time of each code fragment as a simplest θ function of n. [9 points] for (k=1; k<=n*n*n; k++) for (k=1; k*k*k <=n; k++) for (k=2; k<=n; k*=k) for (k=1; k<=n; k+=k) for (j=1; j<=n; j++) if (j>100 && j<n 100) for (k=1; k<=n; k++) print (j, k); for (j=1; j<=n; j++) if (j<100 j>n 100) for (k=1; k<=n; k++) print (j, k); m=1; for (j=1; j<=n; j++) m*=m; for (k=1; k<=m; k++) m=2; for (j=1; j<=n; j++) m*=m; for (k=1; k<=m; k++) x=0; y=1; for (z=1; z<=n; x+=6, y+=x, z+=y) print (z);
5 6. Questions about divide-and-conquer recurrences. [9 points] Solve each recurrence, and write the solution as a simplest θ function of n: a. T(n) = 625 T(n/5) + n 4. b. T(n) = 1000 T(n/10) + n 4. c. T(n) = 32 T(n/2) + n 4. Toom-k is a divide-and-conquer algorithm for polynomial multiplication that works as follows: Split each n-term polynomial into k pieces that each have n/k terms. Perform 2k 1 recursive multiplications, along with a constant number of additions and/or subtractions on polynomials that each have n/k terms. d. When k=3, we have Toom-3 or Toom-Cook. Write a recurrence for T(n), and also solve for T(n). e. Next consider Toom-k with arbitrary k. Write a recurrence for T(n), and also solve for T(n). f. Show that for each ε>0 there exist values of k such that Toom-k has running time o(n 1+ε ). Also determine such values of k expressed in terms of ε.
6 7. Use the array [9, 5, 8, 4, 7, 3, 6, 2] as input for each sorting algorithm below. [6 points] Which choice shows the array contents after two passes of insertion sort? Which choice shows the array contents after four passes of insertion sort? Which choice shows the array contents after two passes of selection sort? Which choice shows the array contents after four passes of selection sort? A. [5, 8, 9, 4, 7, 3, 6, 2] B. [4, 3, 5, 2, 6, 7, 8, 9] C. [4, 5, 3, 6, 2, 7, 8, 9] D. [2, 3, 8, 4, 7, 5, 6, 9] E. [2, 3, 4, 5, 7, 8, 6, 9] F. [4, 5, 8, 9, 7, 3, 6, 2] G. [5, 4, 7, 3, 6, 2, 8, 9] H. [4, 5, 7, 8, 9, 3, 6, 2] I. [9, 5, 8, 4, 2, 3, 6, 7] J. [2, 3, 4, 8, 7, 5, 6, 9] K. None of the above Which choice shows the array contents after two passes of bubble sort? Which choice shows the array contents after four passes of bubble sort? 8. Use the input array [237, 564, 267, 534, 567, 234, 537, 264]. [4 points] Which choice shows the array after the first iteration of an (ascending-order) radix sort using radix r=10? Which choice shows the array after the second iteration of an (ascending-order) radix sort using radix r=10? Which choice shows the array after the first iteration of a descending-order radix sort using radix r=10? Which choice shows the array after the second iteration of a descending-order radix sort using radix r=10? A. [264, 537, 234, 567, 534, 267, 564, 237] B. [237, 267, 567, 537, 564, 534, 234, 264] C. [564, 534, 234, 264, 237, 267, 567, 537] D. [267, 567, 564, 264, 237, 537, 534, 234] E. [534, 234, 237, 537, 564, 264, 267, 567] F. [237, 267, 234, 264, 564, 534, 567, 537] G. [237, 234, 534, 537, 267, 264, 564, 567] H. [564, 534, 567, 537, 237, 267, 234, 264] I. [564, 567, 267, 264, 534, 537, 237, 234] J. [234, 237, 264, 267, 534, 537, 564, 567] K. [567, 564, 537, 534, 267, 264, 237, 234] L. None of the above
7 9. Use the array [7, 5, 8, 4, 1, 6, 2, 0, 3] as input for each sorting algorithm below. [7 points] Which choice shows the two subarray parameters sent to the two recursive calls of merge sort? Which choice shows the two subarrays returned from the two recursive calls of merge sort? For the following, choose the pivot using median-of- 3 with the low, middle, and high indexes. What is the pivot value? Which choice shows the two subarray parameters sent to the two recursive calls of (not-in-place) quick sort? A. [0, 1, 2, 3] and [4, 5, 6, 7, 8] B. [0, 1, 2, 3] and [5, 6, 7, 8] C. [1, 2, 0] and [7, 5, 8, 4, 6] D. [4, 5, 7, 8] and [0, 1, 2, 3, 6] E. [7, 5, 8, 4, 1] and [6, 2, 0, 3] F. [3, 0, 2, 1] and [4, 6, 8, 5, 7] G. [1, 4, 5, 7, 8] and [0, 2, 3, 6] H. [0, 1, 2, 3, 4] and [5, 6, 7, 8] I. [7, 5, 8, 4] and [1, 6, 2, 0, 3] J. [0, 1, 2] and [4, 5, 6, 7, 8] K. None of the above Which choice shows the two subarrays returned from the two recursive calls of (not-in-place) quick sort? Which choice shows the two subarray parameters sent to the two recursive calls of in-place quick sort? Which choice shows the two subarrays returned from the two recursive calls of in-place quick sort? 10. Questions about sorting algorithms. [4 points] Which algorithm has θ(n lg n) worst-case running time and is also stable? Which algorithm has θ(n lg n) worst-case running time and is also in-place? Which two algorithms are simultaneously both stable and in-place? A. Heap sort B. Counting sort C. Bin sort D. Insertion sort E. Selection sort F. Bubble sort G. Merge sort H. Quick sort I. Radix sort J. None of the above
8 11. Use the input array [5, 7, 3, 6, 8, 4, 2]. [4 points] Which choice shows the result after inserting each given array element (in the given order) into an array-based minordered binary heap? Which choice shows the result after inserting each given array element (in the given order) into an array-based maxordered binary heap? Which choice shows the result after applying Build-Min- Heap to the given input array? Which choice shows the result after applying Build-Max- Heap to the given input array? A. [2, 4, 8, 6, 3, 7, 5] B. [2, 3, 4, 5, 6, 7, 8] C. [8, 7, 6, 5, 4, 3, 2] D. [2, 6, 3, 7, 8, 4, 5] E. [2, 6, 3, 7, 8, 5, 4] F. [8, 7, 4, 6, 5, 3, 2] G. [8, 7, 4, 5, 6, 3, 2] H. [2, 3, 6, 4, 5, 7, 8] I. [2, 3, 6, 5, 4, 7, 8] J. [8, 4, 7, 3, 2, 6, 5] K. [8, 4, 7, 3, 2, 5, 6] L. None of the above
9 12. Suppose you are given a sorted list of n elements followed by f(n) additional randomly ordered elements. Make no assumptions about the type or range of the elements. [10 points] a. Explain how to sort the entire list in O(n) time when f(n) is O(1). Justify your answer. b. Explain how to sort the entire list in O(n) time when f(n) is O( n). Justify your answer. c. How large can f(n) be for the entire list still to be sortable in O(n) time? Justify your answer.
10 13. Divide-and-conquer: [15 points] a. First write the in-place partition function that is used by the in-place quick sort algorithm. You may then call this function as a helper function in parts (b) and (c) below. b. Write a recursive divide-and-conquer algorithm for the selection problem that runs in O(n) average-case time and that uses O(lg n) average-case extra space beyond the input array. c. Write an algorithm for the selection problem that runs in O(n) average-case time and that uses O(1) extra space beyond the input array. Hint: each function call uses some space.
1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v
More informationCS 360 Exam 1 Fall 2014 Solution. 1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (v=1; v
More information1. Answer the following questions about each code fragment below. [8 points]
CS 360 Exam 1 Fall 2014 Solution 1. Answer the following questions about each code fragment below. [8 points] for (r=1; r
More informationWe can use a max-heap to sort data.
Sorting 7B N log N Sorts 1 Heap Sort We can use a max-heap to sort data. Convert an array to a max-heap. Remove the root from the heap and store it in its proper position in the same array. Repeat until
More informationThe Limits of Sorting Divide-and-Conquer Comparison Sorts II
The Limits of Sorting Divide-and-Conquer Comparison Sorts II CS 311 Data Structures and Algorithms Lecture Slides Monday, October 12, 2009 Glenn G. Chappell Department of Computer Science University of
More informationCS 303 Design and Analysis of Algorithms
Mid-term CS 303 Design and Analysis of Algorithms Review For Midterm Dong Xu (Based on class note of David Luebke) 12:55-1:55pm, Friday, March 19 Close book Bring your calculator 30% of your final score
More information[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview
400 lecture note #0 [.2,.3,.4] Analysis of Algorithms Complexity of Algorithms 0. Overview The complexity of an algorithm refers to the amount of time and/or space it requires to execute. The analysis
More informationSorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?
Sorting Binary search works great, but how do we create a sorted array in the first place? Sorting in Arrays Sorting algorithms: Selection sort: O(n 2 ) time Merge sort: O(nlog 2 (n)) time Quicksort: O(n
More informationCSC 273 Data Structures
CSC 273 Data Structures Lecture 6 - Faster Sorting Methods Merge Sort Divides an array into halves Sorts the two halves, Then merges them into one sorted array. The algorithm for merge sort is usually
More information4.4 Algorithm Design Technique: Randomization
TIE-20106 76 4.4 Algorithm Design Technique: Randomization Randomization is one of the design techniques of algorithms. A pathological occurence of the worst-case inputs can be avoided with it. The best-case
More informationChapter 2: Complexity Analysis
Chapter 2: Complexity Analysis Objectives Looking ahead in this chapter, we ll consider: Computational and Asymptotic Complexity Big-O Notation Properties of the Big-O Notation Ω and Θ Notations Possible
More informationCS 171: Introduction to Computer Science II. Quicksort
CS 171: Introduction to Computer Science II Quicksort Roadmap MergeSort Recursive Algorithm (top-down) Practical Improvements Non-recursive algorithm (bottom-up) Analysis QuickSort Algorithm Analysis Practical
More informationAnother Sorting Algorithm
1 Another Sorting Algorithm What was the running time of insertion sort? Can we do better? 2 Designing Algorithms Many ways to design an algorithm: o Incremental: o Divide and Conquer: 3 Divide and Conquer
More informationSorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements.
Sorting Sorting is ordering a list of elements. Types of sorting: There are many types of algorithms exist based on the following criteria: Based on Complexity Based on Memory usage (Internal & External
More informationAnalysis of Algorithms. Unit 4 - Analysis of well known Algorithms
Analysis of Algorithms Unit 4 - Analysis of well known Algorithms 1 Analysis of well known Algorithms Brute Force Algorithms Greedy Algorithms Divide and Conquer Algorithms Decrease and Conquer Algorithms
More informationPseudo code of algorithms are to be read by.
Cs502 Quiz No1 Complete Solved File Pseudo code of algorithms are to be read by. People RAM Computer Compiler Approach of solving geometric problems by sweeping a line across the plane is called sweep.
More informationCS:3330 (22c:31) Algorithms
What s an Algorithm? CS:3330 (22c:31) Algorithms Introduction Computer Science is about problem solving using computers. Software is a solution to some problems. Algorithm is a design inside a software.
More informationDesign and Analysis of Algorithms - - Assessment
X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise.
More informationData Structures and Algorithms
Data Structures and Algorithms Session 24. Earth Day, 2009 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3137 Announcements Homework 6 due before last class: May 4th Final Review May
More informationQuiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:
Introduction to Algorithms October 15, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 1 Solutions Problem 1. Asymptotic growth [10 points]
More informationCSC Design and Analysis of Algorithms
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationFaster Sorting Methods
Faster Sorting Methods Chapter 9 Contents Merge Sort Merging Arrays Recursive Merge Sort The Efficiency of Merge Sort Iterative Merge Sort Merge Sort in the Java Class Library Contents Quick Sort The Efficiency
More informationCS S-11 Sorting in Θ(nlgn) 1. Base Case: A list of length 1 or length 0 is already sorted. Recursive Case:
CS245-2015S-11 Sorting in Θ(nlgn) 1 11-0: Merge Sort Recursive Sorting Base Case: A list of length 1 or length 0 is already sorted Recursive Case: Split the list in half Recursively sort two halves Merge
More informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationPROGRAM EFFICIENCY & COMPLEXITY ANALYSIS
Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?
More information17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer
Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are
More information1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1
Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)
More informationJana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides
Jana Kosecka Linear Time Sorting, Median, Order Statistics Many slides here are based on E. Demaine, D. Luebke slides Insertion sort: Easy to code Fast on small inputs (less than ~50 elements) Fast on
More informationLecture 9: Sorting Algorithms
Lecture 9: Sorting Algorithms Bo Tang @ SUSTech, Spring 2018 Sorting problem Sorting Problem Input: an array A[1..n] with n integers Output: a sorted array A (in ascending order) Problem is: sort A[1..n]
More informationFinal Exam in Algorithms and Data Structures 1 (1DL210)
Final Exam in Algorithms and Data Structures 1 (1DL210) Department of Information Technology Uppsala University February 0th, 2012 Lecturers: Parosh Aziz Abdulla, Jonathan Cederberg and Jari Stenman Location:
More informationCS 171: Introduction to Computer Science II. Quicksort
CS 171: Introduction to Computer Science II Quicksort Roadmap MergeSort Analysis of Recursive Algorithms QuickSort Algorithm Analysis Practical improvements Java Array.sort() methods Quick Sort Partition
More information4. Sorting and Order-Statistics
4. Sorting and Order-Statistics 4. Sorting and Order-Statistics The sorting problem consists in the following : Input : a sequence of n elements (a 1, a 2,..., a n ). Output : a permutation (a 1, a 2,...,
More informationFinal Exam in Algorithms and Data Structures 1 (1DL210)
Final Exam in Algorithms and Data Structures 1 (1DL210) Department of Information Technology Uppsala University February 30th, 2012 Lecturers: Parosh Aziz Abdulla, Jonathan Cederberg and Jari Stenman Location:
More informationIntroduction to Algorithms March 12, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1
Introduction to Algorithms March 12, 2008 Massachusetts Institute of Technology 6.006 Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed
More informationAlgorithms and Data Structures
Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................
More informationChapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more
More informationEECS 2011M: Fundamentals of Data Structures
M: Fundamentals of Data Structures Instructor: Suprakash Datta Office : LAS 3043 Course page: http://www.eecs.yorku.ca/course/2011m Also on Moodle Note: Some slides in this lecture are adopted from James
More informationCOT 5407: Introduction to Algorithms. Giri Narasimhan. ECS 254A; Phone: x3748
COT 5407: Introduction to Algorithms Giri Narasimhan ECS 254A; Phone: x3748 giri@cis.fiu.edu http://www.cis.fiu.edu/~giri/teach/5407s17.html https://moodle.cis.fiu.edu/v3.1/course/view.php?id=1494 8/28/07
More informationBig-O-ology. Jim Royer January 16, 2019 CIS 675. CIS 675 Big-O-ology 1/ 19
Big-O-ology Jim Royer January 16, 2019 CIS 675 CIS 675 Big-O-ology 1/ 19 How do you tell how fast a program is? Answer? Run some test cases. Problem You can only run a few test cases. There will be many
More informationHow 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 informationCS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014
CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 Study: Chapter 4 Analysis of Algorithms, Recursive Algorithms, and Recurrence Equations 1. Prove the
More informationO(n): printing a list of n items to the screen, looking at each item once.
UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))
More informationCSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment.
CSE 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875 Lectures: Tues, BC 215, 7 10 PM Office hours: Wed 4-6 pm (CSEB 3043), or by
More informationDivide and Conquer. Algorithm D-and-C(n: input size)
Divide and Conquer Algorithm D-and-C(n: input size) if n n 0 /* small size problem*/ Solve problem without futher sub-division; else Divide into m sub-problems; Conquer the sub-problems by solving them
More informationThe divide-and-conquer paradigm involves three steps at each level of the recursion: Divide the problem into a number of subproblems.
2.3 Designing algorithms There are many ways to design algorithms. Insertion sort uses an incremental approach: having sorted the subarray A[1 j - 1], we insert the single element A[j] into its proper
More informationECE250: Algorithms and Data Structures Midterm Review
ECE250: Algorithms and Data Structures Midterm Review Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo
More informationCeng 111 Fall 2015 Week 12b
Ceng 111 Fall 2015 Week 12b Complexity and ADT Credit: Some slides are from the Invitation to Computer Science book by G. M. Schneider, J. L. Gersting and some from the Digital Design book by M. M. Mano
More informationDivide and Conquer Algorithms: Advanced Sorting
Divide and Conquer Algorithms: Advanced Sorting (revisit) Properties of Growth-rate functions(1/3) 1. You can ignore low-order terms in an algorithm's growth-rate function. O(n 3 +4n 2 +3n) it is also
More informationAlgorithms in Systems Engineering ISE 172. Lecture 12. Dr. Ted Ralphs
Algorithms in Systems Engineering ISE 172 Lecture 12 Dr. Ted Ralphs ISE 172 Lecture 12 1 References for Today s Lecture Required reading Chapter 6 References CLRS Chapter 7 D.E. Knuth, The Art of Computer
More informationUniversity of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2017
University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 207 Midterm Examination Instructor: Dr. Ladan Tahvildari, PEng, SMIEEE Date: Wednesday,
More informationAlgorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms
Algorithm Efficiency & Sorting Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms Overview Writing programs to solve problem consists of a large number of decisions how to represent
More informationINTRODUCTION. Analysis: Determination of time and space requirements of the algorithm
INTRODUCTION A. Preliminaries: Purpose: Learn the design and analysis of algorithms Definition of Algorithm: o A precise statement to solve a problem on a computer o A sequence of definite instructions
More informationDivide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions
Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary
More informationCS302 Topic: Algorithm Analysis #2. Thursday, Sept. 21, 2006
CS302 Topic: Algorithm Analysis #2 Thursday, Sept. 21, 2006 Analysis of Algorithms The theoretical study of computer program performance and resource usage What s also important (besides performance/resource
More informationCS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK
CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Page 1 UNIT I INTRODUCTION 2 marks 1. Why is the need of studying algorithms? From a practical standpoint, a standard set of algorithms from different
More informationData Structures and Algorithms CSE 465
Data Structures and Algorithms CSE 465 LECTURE 4 More Divide and Conquer Binary Search Exponentiation Multiplication Sofya Raskhodnikova and Adam Smith Review questions How long does Merge Sort take on
More informationSorting Algorithms. + Analysis of the Sorting Algorithms
Sorting Algorithms + Analysis of the Sorting Algorithms Insertion Sort What if first k elements of array are already sorted? 4, 7, 12, 5, 19, 16 We can shift the tail of the sorted elements list down and
More informationCS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Wednesday, October 17, 2012.
CS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions The Midterm Exam was given in class on Wednesday, October 17, 2012. A1. Time Complexity. In each part, indicate the (time) order of a fast
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS Fast sorting algorithms Shellsort, Mergesort, Quicksort Summary of the previous lecture Why sorting is needed? Examples from everyday life What are the basic operations in
More information1. 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 informationCS61BL. Lecture 5: Graphs Sorting
CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)
More informationDivide and Conquer 4-0
Divide and Conquer 4-0 Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain
More informationProgramming in Haskell Aug-Nov 2015
Programming in Haskell Aug-Nov 2015 LECTURE 11 SEPTEMBER 10, 2015 S P SURESH CHENNAI MATHEMATICAL INSTITUTE Measuring efficiency Measuring efficiency Computation is reduction Application of definitions
More informationQuestion 7.11 Show how heapsort processes the input:
Question 7.11 Show how heapsort processes the input: 142, 543, 123, 65, 453, 879, 572, 434, 111, 242, 811, 102. Solution. Step 1 Build the heap. 1.1 Place all the data into a complete binary tree in the
More informationCS141: Intermediate Data Structures and Algorithms Analysis of Algorithms
CS141: Intermediate Data Structures and Algorithms Analysis of Algorithms Amr Magdy Analyzing Algorithms 1. Algorithm Correctness a. Termination b. Produces the correct output for all possible input. 2.
More informationCS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005
CS302 Topic: Algorithm Analysis Thursday, Sept. 22, 2005 Announcements Lab 3 (Stock Charts with graphical objects) is due this Friday, Sept. 23!! Lab 4 now available (Stock Reports); due Friday, Oct. 7
More informationCS S-02 Algorithm Analysis 1
CS245-2008S-02 Algorithm Analysis 1 02-0: Algorithm Analysis When is algorithm A better than algorithm B? 02-1: Algorithm Analysis When is algorithm A better than algorithm B? Algorithm A runs faster 02-2:
More informationIntroduction to Computers and Programming. Today
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 10 April 8 2004 Today How to determine Big-O Compare data structures and algorithms Sorting algorithms 2 How to determine Big-O Partition
More informationCSE 247 Data Structures and Algorithms Fall Exam I
CSE 247 Data Structures and Algorithms Fall 2016 Given: 29 February 2016 Exam I Due: End of session This exam is closed-book, closed-notes. No electronic devices or resources of any kind are allowed. The
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 8 Sorting in Linear Time Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Sorting So Far
More informationCSE Winter 2015 Quiz 1 Solutions
CSE 101 - Winter 2015 Quiz 1 Solutions January 12, 2015 1. What is the maximum possible number of vertices in a binary tree of height h? The height of a binary tree is the length of the longest path from
More informationSorting is ordering a list of objects. Here are some sorting algorithms
Sorting Sorting is ordering a list of objects. Here are some sorting algorithms Bubble sort Insertion sort Selection sort Mergesort Question: What is the lower bound for all sorting algorithms? Algorithms
More informationThe divide and conquer strategy has three basic parts. For a given problem of size n,
1 Divide & Conquer One strategy for designing efficient algorithms is the divide and conquer approach, which is also called, more simply, a recursive approach. The analysis of recursive algorithms often
More informationClassic Data Structures Introduction UNIT I
ALGORITHM SPECIFICATION An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. All algorithms must satisfy the following criteria: Input. An algorithm has zero
More informationData 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 informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conuer Algorithm Design Techniue Divide-and-Conuer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationCS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example
Announcements: CS6B Lectures #27 28 We ll be runningapreliminarytestingrun for Project #2 on Tuesday night. Today: Sorting algorithms: why? Insertion, Shell s, Heap, Merge sorts Quicksort Selection Distribution
More informationCS141: Intermediate Data Structures and Algorithms Analysis of Algorithms
CS141: Intermediate Data Structures and Algorithms Analysis of Algorithms Amr Magdy Analyzing Algorithms 1. Algorithm Correctness a. Termination b. Produces the correct output for all possible input. 2.
More informationAlgorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs
Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to
More informationCS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics
CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to
More informationNext. 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 informationSAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6. Sorting Algorithms
SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6 6.0 Introduction Sorting algorithms used in computer science are often classified by: Computational complexity (worst, average and best behavior) of element
More informationAlgorithm Analysis. Spring Semester 2007 Programming and Data Structure 1
Algorithm Analysis Spring Semester 2007 Programming and Data Structure 1 What is an algorithm? A clearly specifiable set of instructions to solve a problem Given a problem decide that the algorithm is
More informationSorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort
Principles of Imperative Computation V. Adamchik CS 15-1 Lecture Carnegie Mellon University Sorting Sorting Sorting is ordering a list of objects. comparison non-comparison Hoare Knuth Bubble (Shell, Gnome)
More informationParallel Sorting Algorithms
CSC 391/691: GPU Programming Fall 015 Parallel Sorting Algorithms Copyright 015 Samuel S. Cho Sorting Algorithms Review Bubble Sort: O(n ) Insertion Sort: O(n ) Quick Sort: O(n log n) Heap Sort: O(n log
More informationCS211 Spring 2005 Prelim 2 April 19, Instructions
CS211 Spring 2005 Prelim 2 April 19, 2005 Name NetId Instructions Write your name and Cornell netid above. There are 8 questions on 11 numbered pages. Check now that you have all the pages. Write your
More informationData Structures and Algorithms. Part 2
1 Data Structures and Algorithms Part 2 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples displayed
More informationRemember to also pactice: Homework, quizzes, class examples, slides, reading materials.
Exam 1 practice problems Remember to also pactice: Homework, quizzes, class examples, slides, reading materials. P1 (MC) For all the questions below (except for the True or False questions), the answer
More informationAlgorithms and Data Structures (INF1) Lecture 7/15 Hua Lu
Algorithms and Data Structures (INF1) Lecture 7/15 Hua Lu Department of Computer Science Aalborg University Fall 2007 This Lecture Merge sort Quick sort Radix sort Summary We will see more complex techniques
More informationCpt S 122 Data Structures. Sorting
Cpt S 122 Data Structures Sorting Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Sorting Process of re-arranging data in ascending or descending order Given
More informationDivide and Conquer Algorithms: Advanced Sorting. Prichard Ch. 10.2: Advanced Sorting Algorithms
Divide and Conquer Algorithms: Advanced Sorting Prichard Ch. 10.2: Advanced Sorting Algorithms 1 Sorting Algorithm n Organize a collection of data into either ascending or descending order. n Internal
More informationQuiz 1 Practice Problems
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
More informationPractice Problems for the Final
ECE-250 Algorithms and Data Structures (Winter 2012) Practice Problems for the Final Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each
More informationHow many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.
Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based
More informationLecture 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 informationExamination Questions Midterm 2
CS1102s Data Structures and Algorithms 12/3/2010 Examination Questions Midterm 2 This examination question booklet has 6 pages, including this cover page, and contains 12 questions. You have 30 minutes
More informationCISC 320 Midterm Exam
Name: CISC 320 Midterm Exam Wednesday, Mar 25, 2015 There are 19 questions. The first 15 questions count 4 points each. For the others, points are individually shown. The total is 100 points. Multiple
More informationModule 1: Asymptotic Time Complexity and Intro to Abstract Data Types
Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationIntroduction to Data Structure
Introduction to Data Structure CONTENTS 1.1 Basic Terminology 1. Elementary data structure organization 2. Classification of data structure 1.2 Operations on data structures 1.3 Different Approaches to
More information