Advanced Data Structures

Slides:



Advertisements
Similar presentations
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
Advertisements

Gerth Stølting Brodal University of Aarhus Monday June 9, 2008, IT University of Copenhagen, Denmark International PhD School in Algorithms for Advanced.
Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Lower bound for sorting, radix sort COMP171 Fall 2005.
Median Finding, Order Statistics & Quick Sort
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Analysis of Quicksort. Quicksort Algorithm Given an array of n elements (e.g., integers): If array only contains one element, return Else –pick one element.
1 Sorting Problem: Given a sequence of elements, find a permutation such that the resulting sequence is sorted in some order. We have already seen: –Insertion.
Lower bound for sorting, radix sort COMP171 Fall 2006.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 19: Heap Sort.
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
CPSC 411, Fall 2008: Set 2 1 CPSC 411 Design and Analysis of Algorithms Set 2: Sorting Lower Bound Prof. Jennifer Welch Fall 2008.
© 2004 Goodrich, Tamassia Selection1. © 2004 Goodrich, Tamassia Selection2 The Selection Problem Given an integer k and n elements x 1, x 2, …, x n, taken.
CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009.
TTIT33 Algorithms and Optimization – Dalg Lecture 2 HT TTIT33 Algorithms and optimization Lecture 2 Algorithms Sorting [GT] 3.1.2, 11 [LD] ,
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Linear Time Selection These lecture slides are adapted from CLRS 10.3.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 CSC401 – Analysis of Algorithms Lecture Notes 9 Radix Sort and Selection Objectives  Introduce no-comparison-based sorting algorithms: Bucket-sort and.
CHAPTER 11 Searching. 2 Introduction Searching is the process of finding a target element among a group of items (the search pool), or determining that.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Analysis of Algorithms CS 477/677
Selection1. 2 The Selection Problem Given an integer k and n elements x 1, x 2, …, x n, taken from a total order, find the k-th smallest element in this.
The Complexity of Algorithms and the Lower Bounds of Problems
Lower Bounds for Comparison-Based Sorting Algorithms (Ch. 8)
Data Structure & Algorithm Lecture 7 – Linear Sort JJCAO Most materials are stolen from Prof. Yoram Moses’s course.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Better way for sorting – heap sort , , Department of Computer Science and Information Engineering, Chung Cheng University, Chayi, Taiwan.
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
B-trees and kd-trees Piotr Indyk (slides partially by Lars Arge from Duke U)
Lecture 1: Introduction and Overview CSCI 700 – Algorithms 1.
Search Algorithms Prepared by John Reif, Ph.D. Analysis of Algorithms.
Analysis of Algorithms CS 477/677
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
1 Medians and Order Statistics CLRS Chapter 9. upper median lower median The lower median is the -th order statistic The upper median.
COSC 3101A - Design and Analysis of Algorithms 6 Lower Bounds for Sorting Counting / Radix / Bucket Sort Many of these slides are taken from Monica Nicolescu,
LIMITATIONS OF ALGORITHM POWER
Data Structures Haim Kaplan & Uri Zwick December 2013 Sorting 1.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
1 Sorting an almost sorted input Suppose we know that the input is “almost” sorted Let I be the number of “inversions” in the input: The number of pairs.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
1 Merge Sort 7 2  9 4   2  2 79  4   72  29  94  4.
Lecture 3 Sorting and Selection. Comparison Sort.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting So Far Insertion sort: –Easy to code –Fast on small inputs (less than ~50 elements) –Fast on nearly-sorted.
Selection in Column Monotone Matrices, X + Y and Heaps [G.N. Frederickson, D.B. Johnson, The Complexity of Selection and Ranking in X+Y and Matrices with.
Quick-Sort 2/18/2018 3:56 AM Selection Selection.
List Order Maintenance
Decision trees Polynomial-Time
Sorting We have actually seen already two efficient ways to sort:
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
The Complexity of Algorithms and the Lower Bounds of Problems
Dr. Yingwu Zhu Chapter 9, p Linear Time Selection Dr. Yingwu Zhu Chapter 9, p
MSIS 655 Advanced Business Applications Programming
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Selection in Column Monotone Matrices, X + Y and Heaps
Data Structures Sorting Haim Kaplan & Uri Zwick December 2014.
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
CSC 143 Binary Search Trees.
Algorithms CSCI 235, Spring 2019 Lecture 20 Order Statistics II
Quick-Sort 5/7/2019 6:43 PM Selection Selection.
Quick-Sort 5/25/2019 6:16 PM Selection Selection.
Presentation transcript:

Advanced Data Structures (Random topics Gerth finds interesting...) Gerth Stølting Brodal

Formalities Versions of course: ”normal”, 3 implementation projects, groups 2-3 people ”honours”, 4 theoretical projects, individual Exam: Individual discussion about projects (Jan.) Literature: Research papers Lectures: High level discription of ideas

Problem Input: Unordered list (x1,x2,...xn) and y1<y2<∙∙∙<yk Output: For each yi determine if yi is in the list *Comparison model

Selection [T.H. Cormen, C.E. Leiserson, R.L. Rivest, C. Stein, Introduction to Algorithms, 2001, Chapter 9.3] Original [M. Blum, R.W. Floyd, V. Pratt, R. Rivest and R. Tarjan, Time bounds for selection, J. Comp. Syst. Sci. 7 (1973) 448-461] Problem: Given an array A of n elements and an integer k, find the k’th smallest element in A Component used as a subrutine used in many algorithms Question: How would you construct such an algorithm? Sorting, construct priority queue + k deletions (need to recall binary heaps?) A 3 7 8 2 9 15 28 6 5 13 3’rd smallest (k=3)

Randomized Selection Algorithm [C. A. R. Hoare: Algorithm 65: find. Commun. ACM 4(7): 321-322 (1961)] Algorithm QuickSelect(A,k) p = random element from A A< = { e | e  A and e < p } A> = { e | e  A and e > p } if |A<|= k-1 then return p if |A<|> k-1 then return QuickSelect(A<,k) return QuickSelect(A>, k-|A<|-1) Assumption All elements are distinct Question How can we assume this? (eg consider pairs) Recall expected analysis (good partitionings and bad partitionings; expected O(1) partitionings until factor ¾ reduction; sum is geometric decreasing) Thm QuickSelect runs in expected O(n) time Proof □

Deterministic Selection Algorithm [M. Blum, R.W. Floyd, V. Pratt, R. Rivest and R. Tarjan, Time bounds for selection, J. Comp. Syst. Sci. 7 (1973) 448-461] Algorithm Select(A,k) if |A|= 1 then A[1] A A’ p = Select(A’,|A’|/2) A< = { e | e  A and e < p } A> = { e | e  A and e > p } if |A<|= k-1 then return p if |A<|> k-1 then return Select(A<,k) return Select(A>, k-|A<|-1) n/5 groups 2 4 1 3 7 8 6 4 2 10 9 11 3 2 12 ... 5 5 5 n/5 medians, one for each group 3 6 9 ...

Deterministic Selection Algorithm Thm Select runs in worst-case O(n) time Proof = O(n) □ 1 2 3 n/10+1 n/5 Problems Rounding, n not power of 5, etc... Analysis: Question – how do you solve this recurence? Proof: Unfold recursion tree. Depth i has total size n*(1/5+7/10)^i, which is also the time spend at the level. 1 2 ... 4 3 6 9 p 8 11 7 10 12 <p A’ >p consider each group as a sorted column

Application: Lazy Construction of Search Trees [Y.-T. Ching, K. Mehlhorn, M.H.M. Smid: Dynamic Deferred Data Structuring. Inf. Process. Lett. (IPL) 35(1):37-40 (1990)] 1 10 3 6 2 15 12 7 14 13 8 4 5 11 9 4 8 2 1 3 5 7 9 11 13 15 6 10 14 12 Construction T= sorting = O(n∙log n) Searching O(log n) Construction + k searches O((n+k)∙log n)

Application: Lazy Construction of Search Trees 1 10 3 6 2 15 12 7 14 13 8 4 5 11 9 Find root using selection/median and recurse 4 8 2 1 3 5 7 9 11 13 15 6 10 14 12 Construction O(n∙log n)

Application: Lazy Construction of Search Trees 1 10 3 6 2 15 12 7 14 13 8 4 5 11 9 4 8 2 1 3 5 7 9 11 13 15 6 10 14 12 % % Search(7) Lazy construct nodes on 1 search path: 1+2+4+∙∙∙+n/2+n=O(n)

Application: Lazy Construction of Search Trees Thm Lazy construction + k searches worst-case O(n∙log k) time Proof □ log k levels completely build O(n) time per level worst-case Question why? k leaf paths O(n/k) time per leaf

unsuccesfull searches Thm Lazy construction + k searches requires worst-case Ω(n∙log k) time Proof Consider the elements of the input array in sorted order, and consider k unsuccessful search keys y1<∙∙∙<yk. The algorithm must determine the color (inteval between two search keys) of each element in the input array, otherwise an element could have been equal to a search key. There are (k+1)n colorings. A dicision tree must determine the coloring. Decision tree depth is ≥ log2(k+1)n = n∙log2 (k+1) □ worst-case Question why? y1 y2 yk unsuccesfull searches