Midterm Exam Revision (See handout on web page for full details)

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

David Luebke 1 4/22/2015 CS 332: Algorithms Quicksort.
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
Quicksort CSE 331 Section 2 James Daly. Review: Merge Sort Basic idea: split the list into two parts, sort both parts, then merge the two lists
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Linear Time Selection These lecture slides are adapted from CLRS 10.3.
1 Algorithmic analysis Introduction. This handout tells you what you are responsible for concerning the analysis of algorithms You are responsible for:
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
Sorting. Pseudocode of Insertion Sort Insertion Sort To sort array A[0..n-1], sort A[0..n-2] recursively and then insert A[n-1] in its proper place among.
David Luebke 1 6/3/2016 CS 332: Algorithms Analyzing Quicksort: Average Case.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Sorting Fundamental Data Structures and Algorithms Aleks Nanevski February 17, 2004.
David Luebke 1 2/19/2016 Priority Queues Quicksort.
Lecture 6 Sorting II Divide-and-Conquer Algorithms.
Prof. U V THETE Dept. of Computer Science YMA
Sorting.
Fundamental Data Structures and Algorithms
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Order Statistics.
Order Statistics Comp 122, Spring 2004.
Searching – Linear and Binary Searches
Towers of Hanoi Move n (4) disks from pole A to pole C
CS 162 Intro to Programming II
Warmup What is an abstract class?
Randomized Algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide and Conquer divide and conquer algorithms typically recursively divide a problem into several smaller sub-problems until the sub-problems are.
Divide and Conquer.
CS 583 Fall 2006 Analysis of Algorithms
Lab 10 - Quicksort.
CSC 413/513: Intro to Algorithms
Data Structures and Analysis (COMP 410)
Richard Anderson Lecture 14 Divide and Conquer
Wednesday, April 11, 2018 Announcements… For Today…
Draw pictures to indicate the subproblems middleMax solves at each level and the resulting maxPtr and PrevPtr for each on this linked list:
CSC212 Data Structure - Section RS
Unit-2 Divide and Conquer
Randomized Algorithms
Sorting Algorithms Ellysa N. Kosinaya.
Data Structures Review Session
Lecture 3 / 4 Algorithm Analysis
CS200: Algorithm Analysis
Richard Anderson Lecture 13 Divide and Conquer
Order Statistics Comp 550, Spring 2015.
Chapter 4.
CSE 326: Data Structures Sorting
Divide-and-Conquer The most-well known algorithm design strategy:
CS 3343: Analysis of Algorithms
CS 332: Algorithms Quicksort David Luebke /9/2019.
CSE 373 Data Structures and Algorithms
Algorithms: Design and Analysis
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Topic: Divide and Conquer
Heaps.
Order Statistics Comp 122, Spring 2004.
Lecture 15, Winter 2019 Closest Pair, Multiplication
Richard Anderson Lecture 14 Divide and Conquer
The Selection Problem.
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Design and Analysis of Algorithms
Richard Anderson Lecture 14 Divide and Conquer
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
Lecture 15 Closest Pair, Multiplication
Analysis of Algorithms CS 477/677
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

Midterm Exam Revision (See handout on web page for full details) COMP 3711H – Fall 2016 Midterm Exam Revision (See handout on web page for full details)

Heaps [8 pts] A new node was added to hold the 7 and it was then bubbled up to its proper place. 7 and the items that were moved are in bold.

2 was removed, 25 was moved to the top and bubbled down. The node originally holding 25 was removed. That items that were moved are in bold.

Design an O(n log k) worst-case time algorithm for k-sorting an array. You must describe (either in plain english or pseudocode) how your algorithm works, justify its correctness and prove that it runs in O(n log k) worst-case time. For simplicity, you may assume that both n and k are powers of 2 and that all elements in the array are distinct.

Intuition was to do something like quicksort but at each step choosing the median item as the partition. The median can be found in O(n) time using deterministic selection and partitioning takes O(n) time. After one step, the array is split into halves with everything in the first half less than everything in the second one. Now recurse in the two halves and repeat recursing until the subarray sizes are n/k : This doesn’t quite work because it doesn’t include the partitioning elements in the two sides of the recursion but we can fix this (see next slide)

The algorithm recursively k-sorts the sub- array A[i; j] for 𝑘≥2: We assume that the top level call will be to KSort(1; n; k)

The worst case running time of this algorithm to k-sort n items is T(n; k), which from the description on previous page satisfies the below which can be solved using the expansion method Plugging l= log k into this expansion gives the final result

4. Interval Selection [12 pt] This is exactly what was taught in class (see class slides)

This is exactly what was taught in class

(b) You could either have shown the proof in class which gave 𝑐= 2 or showed that the minimum number of nodes in an AVL of height h grows like the Fibonacci numbers and gives 𝑐=𝜙.

The solution to this problem was to describe the algorithm given by following the blue arrows. Common errors were to say that A,B were evaluated at n points and not 2n ones, or to forget to say that multiplying the polynomial values pointwise gives the same values as the FFT on C.