Sample Solutions to Homework #2

Size: px
Start display at page:

Download "Sample Solutions to Homework #2"

Transcription

1 National aiwan University andout #1 epartment of lectrical ngineering November, 01 lgorithms, Fall 01 : Zhi-en in and Yen-hun iu ample olutions to omework # 1. (15) (a) ee Figure (a) eap built by uild-ax-eap (b) First exchange followed by ax-eapify (c) (d) (e) (f) (g) (h) (i) () (k) (l) (o) orted sequence (m) (n) Figure 1: llustration for Problem 1(a). (b) ee Figure. (c) ee Figure 3.. (0) (a) ee Figure.

2 i x = i i i i Figure : llustration for Problem 1(b) (a) he array and the auxiliary array (b) he auxiliary array after accumulation (c) he output array and auxiliary array after filling in one element (d) he output array and auxiliary array after filling in the second element (e) he output array and auxiliary array after filling in the third element (f) he sorted result Figure 3: llustration for Problem 1(c). (b) ince Y [1, 1] and Y [m, n] are the smallest and the largest elements in Y respectively, the two statements are true.

3 Figure : ample table for Problem (a). (c) e first record the smallest value and then replace it with the infinity. he infinity must be moved to proper position for maintaining property the of Young tableau. his goal is achieved by recursion. he recursion compares the current position with right and down positions. e exchange the smaller one with current position, treat the position with the smaller value as the new current position, and then do next recursion. t stops when right and down values are both infinity. fter the recursion, the recorded value is returned as the minimum value. he method is shown as follows: Framework: tep 1. ecord Y [1, 1], i.e. v Y [1, 1] tep. eplace Y [1, 1] with, then call V-(1, 1) tep 3. eturn v V-(i, ): assume Y [i, ] = if i > m or > n if Y [i + 1, ] = and Y [i, + 1] = then UN if Y [i + 1, ] < Y [i, + 1] then swap Y [i, ] with Y [i + 1, ] call V-(i + 1, ) else swap Y [i, ] with Y [i, + 1] call V-(i, + 1) ime complexity: (p) = (p 1) + Θ(1) = (p) ence, (m + n) = (m + n) (d) e first put the new element at Y [m, n]. he added element must be moved to proper position for maintaining the property of Young tableau. his goal is also achieved by recursion. he recursion compares the current position with up and left positions. f both them are larger than the current position, we exchange current position with the larger one of them; otherwise, we exchange current position with the one whose value is larger than current position. fter the exchange, we do next recursion for new position. t stops when up and left values are both smaller than current position. he method is shown as follows: Framework: tep 1. eplace Y [m, n] with the new element tep. all V-U(m, n) 3

4 V-U(i, ): assume Y [i, ] = if i < 1 or < 1 if Y [i 1, ] < Y [i, ] and Y [i, 1] < Y [i, ] then UN if Y [i 1, ] >= Y [i, ] and Y [i, 1] >= Y [i, ] then if Y [i 1, ] > Y [i, 1] then swap Y [i, ] with Y [i 1, ] call V-U(i 1, ) else swap Y [i, ] with Y [i, 1] call V-U(i, 1) else if Y [i 1, ] >= Y [i, ] then swap Y [i, ] with Y [i 1, ] call V-U(i 1, ) else swap Y [i, ] with Y [i, 1] call V-U(i, 1) ime complexity: (p) = (p 1) + Θ(1) = (p) ence, (m + n) = (m + n) (e) tep 1. nsert n values into table, needs n (n + n) = (n 3 ) tep. xtract n values from table by -N, needs n (n + n) = (n 3 ) ccording to 1 and, we have (n 3 ) sorting method. (f) Key idea: ee Figure 5 for illustration. For any position [i, ], we can see that p, q, p i, q, Y [p, q] Y [i, ]. hat is, the gray positions are not greater than Y [p, q]. o use this property, we can compare target value with Y [i, ], and then determine that the target value falls in gray or white positions.... i... Framework: tep 1. all etermine(value, m, 1) Figure 5: llustration of Problem (f). etermine(value, i, ): assume Y [i, ] = if i < 1 or < 1 or i > m or > n if Y [i, ] = then UN false if value = Y [i, ] then UN true else if value > Y [i, ] then UN etermine(value, i, + 1) else if value < Y [i, ] then UN etermine(value, i 1, )

5 ime complexity: (p) = (p 1) + Θ(1) = (p) ence, (m + n) = (m + n) 3. (5) onstruct a counting array used in counting sort in (n + k) time. ince [a] denotes the number of integers which fall into the range [0, a], it is obvious to see the answer is [b] [a 1], where [ 1] is defined as 0. herefore, the query then can be answered in (1) time.. (10) (a) ee Figure. U N F U N F U N F U N F Figure : he operation of adix-ort. (b) ee Figure. 5. (0) (a) ince there are n red ugs and n blue ugs, that will take Θ(n ) comparisons to compare each red ug with each blue ug in the worst case. (b) he computation of the algorithm can be viewed in terms of a decision tree. very internal node is labelled with two ugs (red and blue), and has three outgoing edges (red ug smaller, same size, or larger than the blue ug). he leaves are labelled with a unique matching of ugs. he height of the decision tree is equal to the worst-case number of comparisons the algorithm has to make to determine the matching. o bound that size, we first compute the number of possible matchings for n red and n blue ugs. f we label the red ugs from 1 to n and we also label the blue ugs from 1 to n before starting the comparisons, every outcome of the algorithm can be represented as a set {(i, π(i)) : 1 i n and π is a permutation on {1,..., n}}, which contains the pairs of red ugs (first component) and blue ugs (second component) that are matched up. ince every permutation π corresponds to a different outcome, there must be exactly n! different results. 5

6 (a) 0 / /.13.1 /.0 /.39 /. /.53 /. /.1.9 /.9 / (b) Figure : he operation of ucket-ort. (a) he input array [1..10]. (b) he array [0..9] of sorted lists (buckets). he sorted output consists of a concatenation in order of the lists [0], [1],..., [9]. herefore, the height h of the decision tree can be bounded as follows: very tree with a branching factor of 3 (every inner node has at most three children) has at most 3 h leaves, and the decision tree must have at least n! children. his statement follows that 3 h n! (n/e) n h n log 3 n n log 3 e = Ω(n lg n). (c) o any algorithm solving the problem must use Ω(n lg n) comparisons. : red ugs with labelled numbers 1,,..., n, {1,..., n}. : blue ugs with labelled number 1,,..., n, {1,..., n}. output: n distinct pairs (i, ) indicate the red ug i and the blue ug have the same volume. Pseudocode: -JU(, ) 1 if = 0 then return 3 if = 1 then let = {r} and = {b} 5 output (r, b) return else r a randomly chosen ug in compare r to every ug of 9 < the set of ugs in that are smaller than r 10 > the set of ugs in that are larger than r 11 b the one ug in with the same size as r 1 compare b to every ug of {r} 13 < the set of ugs in that are smaller than b 1 > the set of ugs in that are larger than b 15 output (r, b) 1 -JU( <, < ) 1 -JU( >, > ) he procedure will be called only with inputs that can be matched, which means =.

7 . (10) he correctness of the algorithm can be proved as follows. nce the ug r is randomly picked from, there will be a matching among the ugs in volume smaller than r which are in the sets < and <, and likewise between the ugs larger than r which are in the sets > and >. ince < + > < in every recursive step, the size of the first parameter reduces with every recursive call, and the recursion will be terminated when the parameter reaches 0 or 1. he analysis of the expected number of comparisons is similar to that of the quicksort algorithm. o analyze the expect number of comparisons, we first order the red and blue ugs as r 1,..., r n and b 1,..., b n where r i < r i+1 and b 1 < b i+1 for i = 1,..., n, and r i = b i. hen, the indicator random variable can be defined as follows. i = {red ug r i is compared to blue ug b }. s in quicksort, a given pair r i and b i is compared at most once. hen comparing r i to every ug in, ug r i will not be put in either < or <. hen comparing b i to every ug in {r i }, ug b i is not put into either < or <. he total number of comparisons is = n 1 n i=1 =i+1 i. hen, the expected value of can be calculated as follows. [] = n 1 n i=1 =i+1 P r{r i is compared to b } nce we choose a ug r k such that r i < r k < b, we will put r i in < and b in >, and so r i and b will never be compared again. Jugs r i and b will be compared if and only if the first ug in i = {r i,..., r } to be chosen is either r i or r. ny ug in i is equally likely to be first one chosen. ince i = i + 1, the probability of any given ug being the first one chosen in i is 1/( i + 1). imilar to the analysis of quicksort, we can prove that the expected number of comparisons is (n lg n). he worst-case number of comparisons is Θ(n ). n the worst-case we always choose the largest or smallest ugs to partition the sets, which reduces the set sizes only by 1. he worst-case running time obeys the recurrence (n) = (n 1) + Θ(n), and the worst-case number of comparisons is (n) = Θ(n ). e can optimize by splitting the input in pairs and comparing each pair. fter n/ comparisons, we have reduced the potential minimums and potential maximums to n/ each. Furthermore, those two sets are disoint so now we have two problems, one minimum and one maximum, each of size n/. he total number of comparisons is n/ + (n/ 1) = n/ + n = 3n/ his assumes that n is even. f n is odd we need one additional comparison in order to determine whether the last element is a potential minimum or maximum. ence the ceiling.. (10) his problem can be solved by a binary-search approach. et p be the median of [1..n], and q be the median of Y [1..n]. f p > q, then the median of the two arrays is in [1.. n ] or Y [ n..n]. f p q, then the median of the two arrays is in [ n..n] or Y [1.. n ]. herefore, we can use recursion to solve this problem. For any instance with two sorted arrays [1..n] and Y [1..n], we first compare the median of them, and then follow the mentioned rules to divide the two arrays into half of the original size. fter dividing, we can let the new smaller arrays as the new instance and apply the same strategy recursively. bviously, this binary-search approach divides the problem size into half size every recursion. hus we have the time complexity, (n) = (n/) + θ(1) = (lg n)

8 . (10) he optimal y-coordinate for Professor lay s east-west oil pipeline is as follows: f n is even, then on either the oil well whose y-coordinate is the lower median or the one whose y-coordinate is the upper median, or anywhere between them. f n is odd, then on the oil well whose y-coordinate is the median. Proof: e examine various cases. n each case, we will start out with the pipeline at a particular y-coordinate and see what happens when we move it. e ll denote by s the sum of the north-south spurs with the pipeline at the starting location, and s will denote the sum after moving the pipeline. e start with the case in which n is even. et us start with the pipeline somewhere on or between the two oil wells whose y-coordinates are the lower and upper medians. f we move the pipeline by a vertical distance d without crossing either of the median wells, then n/ of the wells become d farther from the pipeline and n/ become d closer, and s = s + dn/ dn/ = s; thus, all locations on or between the two medians are equally good. Now suppose that the pipeline goes through the oil well whose y-coordinate is the upper median. hat happens when we increase the y-coordinate of the pipeline by d > 0 units, so that it moves above the oil well that achieves the upper median? ll oil wells whose y-coordinates are at or below the upper median become d units farther from the pipeline, and there are at least n/ + 1 such oil wells (the upper median, and every well at or below the lower median). here are at most n/ 1 oil wells whose y-coordinates are above the upper median, and each of these oil wells becomes at most d units closer to the pipeline when it moves up. hus, we have a lower bound on s of s s + d(n/ + 1) d(n/ 1) = s + d > s. e conclude that moving the pipeline up from the oil well at the upper median increases the total spur length. symmetric argument shows that if we start with the pipeline going through the oil well whose y-coordinate is the lower median and move it down, then the total spur length increases. e see, therefore, that when n is even, an optimal placement of the pipeline is anywhere on or between the two medians. Now we consider the case when n is odd. e start with the pipeline going through the oil well whose y-coordinate is the median, and we consider what happens when we move it up by d > 0 units. ll oil wells at or below the median become d units farther from the pipeline, and there are at least (n + 1)/ such wells (the one at the median and the (n 1)/ at or below the median.) here are at most (n 1)/ oil wells above the median, and each of these becomes at most d units closer to the pipeline. e get a lower bound on s of s s + d(n + 1)/ d(n 1)/ = s + d > s, and we conclude that moving the pipeline up from the oil well at the median increases the total spur length. symmetric argument shows that moving the pipeline down from the median also increases the total spur length, and so the optimal placement of the pipeline is on the median. ince we know we are looking for the median, we can use the linear-time median-finding algorithm. hus, the optimal location can be determined in linear time. 9. (10) (b) (d) 10. (10) ne possible algorithm works in the following steps. (a) nsert the sequences one by one into the radix tree. (b) raverse the radix tree with pre-order tree walk, and write down sequences visited. he correctness of the algorithm can be ustified by proving that the pre-order tree walk visits sequences in monotonically increasing order. ccording to the structure of radix trees and the definition of lexicographically less than, for any node i in a radix tree, we have (he sequence on i) < (any sequence in the left subtree of i) < (any sequence in the right subtree of i.)

9 (a) (b) Figure : llustration for Problem 11(a) and (b). (a) inary search tree. (b) ed-black tree (a) (b) Figure 9: llustration for Problem 11(c). (a) inary search tree. (b) ed-black tree. herefore, the pre-order tree walk does visit sequences in monotonically increasing order. he timing bound can be derived as follows. nserting the sequences takes Θ(n) time and the pre-order tree walk takes Θ(n) time. n conclusion, the timing of the algorithm is Θ(n). 11. (0) 1. (0) (a) ee Figure (a). (b) ee Figure (b). (c) ee Figure 9(a) for the binary search tree. Yes, see Figure 9(b) for the red-black tree. (d) ee Figure 10(a) for the inserted red-black tree. ee Figure 10(b) for the legal red-black tree. (e) ee Figure 11(a) for the deleted red-black tree. ee Figure 11(b) for the legal red-black tree. (a) f we know N h 1 and N h, we can determine N h. ince this N h noded tree must have a height h, the root must have a child that has height h 1. o minimize the total number of nodes in this 9

10 (a) (b) Figure 10: llustration for Problem 11(d). (a) nserting key 3 to the original red-black tree. (b) egal red-black tree (a) (b) Figure 11: llustration for Problem 11(e). (a) eleting key to the original red-black tree. (b) egal red-black tree. tree, we would have this sub-tree contain N h 1 nodes. y the property of an V tree, if one child has height h1, the minimum height of the other child is h. y creating a tree with a root whose left sub-tree has N h 1 nodes and whose right sub-tree has N h nodes, we have constructed the V tree of height h with the least nodes possible. his V tree has a total of N h 1 + N h + 1 nodes. he base cases are N 0 = 1 and N 1 =. From here, we can iteratively construct N h by using the fact that N h = N h1 + N h + 1 that we figured out above. N h = N h 1 + N h + 1 N h 1 = N h + N h N h = (N h + N h 3 + 1) + N h + 1 N h > N h N h > h lg N h > lg h lg N h > h 10

11 ase 1 ase ight rotate eft rotate ase 3 ase eft rotate ight rotate Figure 1: llustration for Problem 1(b). h = (lg N h ) herefore, an V tree witn n nodes has height (lg n). (b) ee Figure 1 for four cases for N(x). (c) Pseudocode: V-N(x, z) 1 -N(x, z) N(x) (d) V-insertions are binary search tree insertions plus at most two rotations. ince binary search tree insertions take (h) time, rotations are (1) time, and V trees have h = (lgn), V insertions take (lgn) time. 13. (0) ynamic Programming. Please finish this on (0) ynamic Programming. Please finish this on (0) Y. 11

II (Sorting and) Order Statistics

II (Sorting and) Order Statistics II (Sorting and) Order Statistics Heapsort Quicksort Sorting in Linear Time Medians and Order Statistics 8 Sorting in Linear Time The sorting algorithms introduced thus far are comparison sorts Any comparison

More information

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

How 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 information

Lower bound for comparison-based sorting

Lower bound for comparison-based sorting COMP3600/6466 Algorithms 2018 Lecture 8 1 Lower bound for comparison-based sorting Reading: Cormen et al, Section 8.1 and 8.2 Different sorting algorithms may have different running-time complexities.

More information

CS2223: 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 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 information

Jana 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 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 information

Multiple-choice (35 pt.)

Multiple-choice (35 pt.) CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

More information

Sorting and Selection

Sorting and Selection Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element

More information

The complexity of Sorting and sorting in linear-time. Median and Order Statistics. Chapter 8 and Chapter 9

The complexity of Sorting and sorting in linear-time. Median and Order Statistics. Chapter 8 and Chapter 9 Subject 6 Spring 2017 The complexity of Sorting and sorting in linear-time Median and Order Statistics Chapter 8 and Chapter 9 Disclaimer: These abbreviated notes DO NOT substitute the textbook for this

More information

We assume uniform hashing (UH):

We assume uniform hashing (UH): We assume uniform hashing (UH): the probe sequence of each key is equally likely to be any of the! permutations of 0,1,, 1 UH generalizes the notion of SUH that produces not just a single number, but a

More information

Design and Analysis of Algorithms

Design 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 information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

Lecture 5: Sorting Part A

Lecture 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 information

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;

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; 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 information

QuickSort

QuickSort QuickSort 7 4 9 6 2 2 4 6 7 9 4 2 2 4 7 9 7 9 2 2 9 9 1 QuickSort QuickSort on an input sequence S with n elements consists of three steps: n n n Divide: partition S into two sequences S 1 and S 2 of about

More information

EECS 2011M: Fundamentals of Data Structures

EECS 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 information

Data Structures and Algorithms Chapter 4

Data Structures and Algorithms Chapter 4 Data Structures and Algorithms Chapter. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Chapter Divide and conquer

More information

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

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms Comparison Based Sorting Algorithms Algorithms and Data Structures: Lower Bounds for Sorting Definition 1 A sorting algorithm is comparison based if comparisons A[i] < A[j], A[i] A[j], A[i] = A[j], A[i]

More information

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola CS 3343 Fall 2007 Sorting Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 3343 Analysis of Algorithms 1 How fast can we sort? All the sorting algorithms we have seen

More information

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

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1 Algorithms and Data Structures: Lower Bounds for Sorting ADS: lect 7 slide 1 ADS: lect 7 slide 2 Comparison Based Sorting Algorithms Definition 1 A sorting algorithm is comparison based if comparisons

More information

Question 7.11 Show how heapsort processes the input:

Question 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 information

The divide-and-conquer paradigm involves three steps at each level of the recursion: Divide the problem into a number of subproblems.

The 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 information

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs Algorithms in Systems Engineering ISE 172 Lecture 16 Dr. Ted Ralphs ISE 172 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms

More information

Priority Queues, Binary Heaps, and Heapsort

Priority Queues, Binary Heaps, and Heapsort Priority Queues, Binary eaps, and eapsort Learning Goals: Provide examples of appropriate applications for priority queues and heaps. Implement and manipulate a heap using an array as the underlying data

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 Amarda Shehu Lecture: Analysis of Algorithms (CS583-002) Sorting in O(n lg n) Time: Heapsort 1 Outline of Today s Class Sorting in O(n

More information

1 (15 points) LexicoSort

1 (15 points) LexicoSort CS161 Homework 2 Due: 22 April 2016, 12 noon Submit on Gradescope Handed out: 15 April 2016 Instructions: Please answer the following questions to the best of your ability. If you are asked to show your

More information

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014 CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want

More information

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs Computational Optimization ISE 407 Lecture 16 Dr. Ted Ralphs ISE 407 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms in

More information

CS 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 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 information

CS S-11 Sorting in Θ(nlgn) 1. Base Case: A list of length 1 or length 0 is already sorted. Recursive Case:

CS 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 information

Data Structures and Algorithms Week 4

Data Structures and Algorithms Week 4 Data Structures and Algorithms Week. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Week Divide and conquer Merge

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Merge Sort

Merge Sort Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Divide-and-Conuer Divide-and conuer is a general algorithm design paradigm: n Divide: divide the input data S in two disjoint subsets S 1 and

More information

Algorithms for Memory Hierarchies Lecture 2

Algorithms for Memory Hierarchies Lecture 2 Algorithms for emory Hierarchies Lecture Lecturer: odari Sitchianva Scribes: Robin Rehrmann, ichael Kirsten Last Time External memory (E) model Scan(): O( ) I/Os Stacks / queues: O( 1 ) I/Os / elt ergesort:

More information

CS 5321: Advanced Algorithms Sorting. Acknowledgement. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms Sorting. Acknowledgement. Ali Ebnenasir Department of Computer Science Michigan Technological University CS 5321: Advanced Algorithms Sorting Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Nishit Chapter 22 Bill 23 Martin

More information

Selection (deterministic & randomized): finding the median in linear time

Selection (deterministic & randomized): finding the median in linear time Lecture 4 Selection (deterministic & randomized): finding the median in linear time 4.1 Overview Given an unsorted array, how quickly can one find the median element? Can one do it more quickly than bysorting?

More information

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

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9) CPSC 311 Lecture Notes Sorting and Order Statistics (Chapters 6-9) Acknowledgement: These notes are compiled by Nancy Amato at Texas A&M University. Parts of these course notes are based on notes from

More information

CPSC W2 Midterm #2 Sample Solutions

CPSC W2 Midterm #2 Sample Solutions CPSC 320 2014W2 Midterm #2 Sample Solutions March 13, 2015 1 Canopticon [8 marks] Classify each of the following recurrences (assumed to have base cases of T (1) = T (0) = 1) into one of the three cases

More information

8 SortinginLinearTime

8 SortinginLinearTime 8 SortinginLinearTime We have now introduced several algorithms that can sort n numbers in O(n lg n) time. Merge sort and heapsort achieve this upper bound in the worst case; quicksort achieves it on average.

More information

CSE 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. 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 information

Sorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements.

Sorting. 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 information

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions Dr. Amotz Bar-Noy s Compendium of Algorithms Problems Problems, Hints, and Solutions Chapter 1 Searching and Sorting Problems 1 1.1 Array with One Missing 1.1.1 Problem Let A = A[1],..., A[n] be an array

More information

COMP 352 FALL Tutorial 10

COMP 352 FALL Tutorial 10 1 COMP 352 FALL 2016 Tutorial 10 SESSION OUTLINE Divide-and-Conquer Method Sort Algorithm Properties Quick Overview on Sorting Algorithms Merge Sort Quick Sort Bucket Sort Radix Sort Problem Solving 2

More information

Other techniques for sorting exist, such as Linear Sorting which is not based on comparisons. Linear Sorting techniques include:

Other techniques for sorting exist, such as Linear Sorting which is not based on comparisons. Linear Sorting techniques include: Sorting in Linear Time Comparison Sorts O(nlgn), Ω(nlgn) for some input The best we can do for comparison sorts is Ω(nlgn). Other techniques for sorting exist, such as Linear Sorting which is not based

More information

9/24/ Hash functions

9/24/ Hash functions 11.3 Hash functions A good hash function satis es (approximately) the assumption of SUH: each key is equally likely to hash to any of the slots, independently of the other keys We typically have no way

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of s Lecture 01 Medians and s (Chapter 9) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 24 Spring 2010 Given an array A of n distinct

More information

Lower Bound on Comparison-based Sorting

Lower Bound on Comparison-based Sorting Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting

More information

Principles of Algorithm Design

Principles of Algorithm Design Principles of Algorithm Design When you are trying to design an algorithm or a data structure, it s often hard to see how to accomplish the task. The following techniques can often be useful: 1. Experiment

More information

Lecture 8: Mergesort / Quicksort Steven Skiena

Lecture 8: Mergesort / Quicksort Steven Skiena Lecture 8: Mergesort / Quicksort Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Give an efficient

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

CS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example

CS61B 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 information

Sorting. There exist sorting algorithms which have shown to be more efficient in practice.

Sorting. There exist sorting algorithms which have shown to be more efficient in practice. Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics

More information

PART IV. Given 2 sorted arrays, What is the time complexity of merging them together?

PART IV. Given 2 sorted arrays, What is the time complexity of merging them together? General Questions: PART IV Given 2 sorted arrays, What is the time complexity of merging them together? Array 1: Array 2: Sorted Array: Pointer to 1 st element of the 2 sorted arrays Pointer to the 1 st

More information

CS240 Fall Mike Lam, Professor. Quick Sort

CS240 Fall Mike Lam, Professor. Quick Sort ??!!!!! CS240 Fall 2015 Mike Lam, Professor Quick Sort Merge Sort Merge sort Sort sublists (divide & conquer) Merge sorted sublists (combine) All the "hard work" is done after recursing Hard to do "in-place"

More information

CS 561, Lecture 1. Jared Saia University of New Mexico

CS 561, Lecture 1. Jared Saia University of New Mexico CS 561, Lecture 1 Jared Saia University of New Mexico Quicksort Based on divide and conquer strategy Worst case is Θ(n 2 ) Expected running time is Θ(n log n) An In-place sorting algorithm Almost always

More information

CS S-06 Binary Search Trees 1

CS S-06 Binary Search Trees 1 CS245-2008S-06 inary Search Trees 1 06-0: Ordered List T Operations: Insert an element in the list Check if an element is in the list Remove an element from the list Print out the contents of the list,

More information

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

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

Lecture 2: Getting Started

Lecture 2: Getting Started Lecture 2: Getting Started Insertion Sort Our first algorithm is Insertion Sort Solves the sorting problem Input: A sequence of n numbers a 1, a 2,..., a n. Output: A permutation (reordering) a 1, a 2,...,

More information

Sorting Pearson Education, Inc. All rights reserved.

Sorting Pearson Education, Inc. All rights reserved. 1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

The divide and conquer strategy has three basic parts. For a given problem of size n,

The 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 information

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331 CSE2331/5331 Topic 6: Binary Search Tree Data structure Operations Set Operations Maximum Extract-Max Insert Increase-key We can use priority queue (implemented by heap) Search Delete Successor Predecessor

More information

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

Quiz 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 information

ECE608 - Chapter 8 answers

ECE608 - Chapter 8 answers ¼ À ÈÌ Ê ÈÊÇ Ä ÅË ½µ º½¹ ¾µ º¾¹ µ º ¹½ µ º ¹ µ º ¹ µ º ¹¾ µ ¹ µ ¹ ½ ECE608 - Chapter 8 answers (1) CLR 8.1-3 If the sort runs in linear time for m input permutations, then the height h of those paths of

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss another important ADT: PriorityQueue. Like stacks and queues, priority queues store arbitrary collections

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

Binary Search Trees, etc.

Binary Search Trees, etc. Chapter 12 Binary Search Trees, etc. Binary Search trees are data structures that support a variety of dynamic set operations, e.g., Search, Minimum, Maximum, Predecessors, Successors, Insert, and Delete.

More information

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black. Outline 1 Definition Computer Science 331 Red-Black rees Mike Jacobson Department of Computer Science University of Calgary Lectures #20-22 2 Height-Balance 3 Searches 4 Rotations 5 s: Main Case 6 Partial

More information

( ) n 3. n 2 ( ) D. Ο

( ) n 3. n 2 ( ) D. Ο CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black

More information

Lecture 3: Sorting 1

Lecture 3: Sorting 1 Lecture 3: Sorting 1 Sorting Arranging an unordered collection of elements into monotonically increasing (or decreasing) order. S = a sequence of n elements in arbitrary order After sorting:

More information

Problem Set 5 Solutions

Problem Set 5 Solutions Introduction to Algorithms November 4, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 21 Problem Set 5 Solutions Problem 5-1. Skip

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]: CSE 101 Homework 1 Background (Order and Recurrence Relations), correctness proofs, time analysis, and speeding up algorithms with restructuring, preprocessing and data structures. Due Thursday, April

More information

Search Trees. Undirected graph Directed graph Tree Binary search tree

Search Trees. Undirected graph Directed graph Tree Binary search tree Search Trees Undirected graph Directed graph Tree Binary search tree 1 Binary Search Tree Binary search key property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then

More information

Worst-case running time for RANDOMIZED-SELECT

Worst-case running time for RANDOMIZED-SELECT Worst-case running time for RANDOMIZED-SELECT is ), even to nd the minimum The algorithm has a linear expected running time, though, and because it is randomized, no particular input elicits the worst-case

More information

Algorithms Chapter 8 Sorting in Linear Time

Algorithms Chapter 8 Sorting in Linear Time Algorithms Chapter 8 Sorting in Linear Time Assistant Professor: Ching Chi Lin 林清池助理教授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University Outline Lower

More information

Introduction to Algorithms I

Introduction to Algorithms I Summer School on Algorithms and Optimization Organized by: ACM Unit, ISI and IEEE CEDA. Tutorial II Date: 05.07.017 Introduction to Algorithms I (Q1) A binary tree is a rooted tree in which each node has

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

15.4 Longest common subsequence

15.4 Longest common subsequence 15.4 Longest common subsequence Biological applications often need to compare the DNA of two (or more) different organisms A strand of DNA consists of a string of molecules called bases, where the possible

More information

Can we do faster? What is the theoretical best we can do?

Can we do faster? What is the theoretical best we can do? Non-Comparison Based Sorting How fast can we sort? 2 Insertion-Sort O( n ) Merge-Sort, Quicksort (expected), Heapsort : ( n lg n ) Can we do faster? What is the theoretical best we can do? So far we have

More information

Tirgul 4. Order statistics. Minimum & Maximum. Order Statistics. Heaps. minimum/maximum Selection. Overview Heapify Build-Heap

Tirgul 4. Order statistics. Minimum & Maximum. Order Statistics. Heaps. minimum/maximum Selection. Overview Heapify Build-Heap Tirgul 4 Order Statistics minimum/maximum Selection Heaps Overview Heapify Build-Heap Order statistics The i th order statistics of a set of n elements is the i th smallest element. For example the minimum

More information

Shell s sort. CS61B Lecture #25. Sorting by Selection: Heapsort. Example of Shell s Sort

Shell s sort. CS61B Lecture #25. Sorting by Selection: Heapsort. Example of Shell s Sort CS6B Lecture #5 Today: Sorting, t. Standard methods Properties of standard methods Selection Readings for Today: DS(IJ), Chapter 8; Readings for Next Topic: Balanced searches, DS(IJ), Chapter ; Shell s

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss priority queues, another important ADT. As stacks and queues, priority queues store arbitrary collections

More information

Range searching. with Range Trees

Range searching. with Range Trees Range searching Computational Geometry [csci 3250] Range searching with Range Trees Given a set of points, preprocess them into a data structure to support fast range queries. 2D Laura Toma Bowdoin College

More information

CPS 231 Exam 2 SOLUTIONS

CPS 231 Exam 2 SOLUTIONS CPS 231 Exam 2 SOLUTIONS Fall 2003 1:00-2:25, Tuesday November 20th Closed book exam NAME: Problem Max Obtained 1 10 2 25 3 (a) 15 3 (b) 15 3 (c) 10 4 (a) 10 4 (b) 15 4 (c) 10 Total 110 1 [10 points ]

More information

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

& ( D.  mnp ' ( ) n 3. n 2. ( ) C.  n CSE Name Test Summer Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n " n matrices is: A. " n C. "% n B. " max( m,n, p). The

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

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

1. [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 information

Lower and Upper Bound Theory. Prof:Dr. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY

Lower and Upper Bound Theory. Prof:Dr. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY Lower and Upper Bound Theory Prof:Dr. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1 Lower and Upper Bound Theory How fast can we sort? Lower-Bound Theory can

More information

Introduction. e.g., the item could be an entire block of information about a student, while the search key might be only the student's name

Introduction. e.g., the item could be an entire block of information about a student, while the search key might be only the student's name Chapter 7 Sorting 2 Introduction sorting fundamental task in data management well-studied problem in computer science basic problem given an of items where each item contains a key, rearrange the items

More information

( D. Θ n. ( ) f n ( ) D. Ο%

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING ASSORTED MINUTIAE HW6 Out Due next Wednesday ASSORTED MINUTIAE HW6 Out Due next Wednesday Only two late days allowed ASSORTED MINUTIAE HW6 Out Due

More information

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph. Trees 1 Introduction Trees are very special kind of (undirected) graphs. Formally speaking, a tree is a connected graph that is acyclic. 1 This definition has some drawbacks: given a graph it is not trivial

More information

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced 13 Red-Black Trees A red-black tree (RBT) is a BST with one extra bit of storage per node: color, either RED or BLACK Constraining the node colors on any path from the root to a leaf Ensures that no such

More information

Solutions to Problem Set 1

Solutions to Problem Set 1 CSCI-GA.3520-001 Honors Analysis of Algorithms Solutions to Problem Set 1 Problem 1 An O(n) algorithm that finds the kth integer in an array a = (a 1,..., a n ) of n distinct integers. Basic Idea Using

More information

1 Minimum Cut Problem

1 Minimum Cut Problem CS 6 Lecture 6 Min Cut and Karger s Algorithm Scribes: Peng Hui How, Virginia Williams (05) Date: November 7, 07 Anthony Kim (06), Mary Wootters (07) Adapted from Virginia Williams lecture notes Minimum

More information

Elementary maths for GMT. Algorithm analysis Part II

Elementary maths for GMT. Algorithm analysis Part II Elementary maths for GMT Algorithm analysis Part II Algorithms, Big-Oh and Big-Omega An algorithm has a O( ) and Ω( ) running time By default, we mean the worst case running time A worst case O running

More information

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist. Sorting Popular algorithms: Selection sort* Insertion sort* Bubble sort* Quick sort* Comb-sort Shell-sort Heap sort* Merge sort* Counting-sort Radix-sort Bucket-sort Tim-sort Many algorithms for sorting

More information