CSE 589 Applied Algorithms Spring 1999

Slides:



Advertisements
Similar presentations
Sorting in Linear Time Introduction to Algorithms Sorting in Linear Time CSE 680 Prof. Roger Crawfis.
Advertisements

NP-Completeness.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
8.1 Advanced Operating Systems Defeating The Thrashing The RAM is limited. Sometimes, too many processes need large memory allocations and the sum of these.
1 Chapter 4 Analysis Tools. 2 Which is faster – selection sort or insertion sort? Potential method for evaluation: Implement each as a method and then.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
CSE 373 Data Structures Lecture 19
Sorting (Part II: Divide and Conquer) CSE 373 Data Structures Lecture 14.
CSE 373 Data Structures Lecture 15
CSE 589 Applied Algorithms Spring Colorability Branch and Bound.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
2IL50 Data Structures Spring 2015 Lecture 3: Heaps.
Jessie Zhao Course page: 1.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
Cliff Shaffer Computer Science Computational Complexity.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
Divide and Conquer Sorting
Sorting.
The Subset-sum Problem
Hard Problems Some problems are hard to solve.
Priority Queues An abstract data type (ADT) Similar to a queue
Divide-and-Conquer 6/30/2018 9:16 AM
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015.
CS 3343: Analysis of Algorithms
Hard Problems Introduction to NP
Introduction to Algorithms
David Kauchak CS52 – Spring 2015
Divide-And-Conquer-And-Combine
Chapter 7 Sorting Spring 14
CS 213: Data Structures and Algorithms
CS 583 Fall 2006 Analysis of Algorithms
Evaluation of Relational Operations
Data Structures (CS212D) Overview & Review.
Design and Analysis of Computer Algorithm (CS575-01)
Algorithm Analysis (not included in any exams!)
Lower Bound Theory.
The Complexity of Algorithms and the Lower Bounds of Problems
Analysis and design of algorithm
Objective of This Course
CS 3343: Analysis of Algorithms
Algorithms Analysis Section 3.3 of Rosen Spring 2017
Data Structures Review Session
Lecture 6 Overview.
Divide-and-Conquer 7 2  9 4   2   4   7
Chapter 11 Limitations of Algorithm Power
Data Structures (CS212D) Overview & Review.
NP-Complete Problems.
CSE 2010: Algorithms and Data Structures
Linear-Time Sorting Algorithms
Priority Queues An abstract data type (ADT) Similar to a queue
Analysis of Algorithms
Implementation of Relational Operations
Algorithms: the big picture
Topic 5: Heap data structure heap sort Priority queue
Divide-and-Conquer 7 2  9 4   2   4   7
CSE 373 Data Structures and Algorithms
Lecture 30 CSE 331 Nov 12, 2012.
Analysis of Algorithms
Introduction To Algorithms
David Kauchak cs161 Summer 2009
CSE 332: Parallel Algorithms
CSE 373: Data Structures and Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Algorithms Analysis Section 3.3 of Rosen Spring 2013
Algorithms Analysis Section 3.3 of Rosen Spring 2018
Divide and Conquer Merge sort and quick sort Binary search
Analysis of Algorithms
CMPT 225 Lecture 10 – Merge Sort.
Presentation transcript:

CSE 589 Applied Algorithms Spring 1999 Subset Sum Algorithm Evaluation Mergesort

An Easy NP-Complete Problem Subset Sum Input: Integers Output: Determine if there is subset with the property Algorithm: Let A[0..b] be a Boolean array of size b + 1 initialized as follows A[0] = 1 and A[i] = 0 for 1 < i < b. After scanning the input a1, a2, … , ak maintaining the invariant that A[i] = 1 if and only if some subset of a1, a2, … , ak adds up to i. CSE 589 - Lecture 7 - Spring 1999

Subset Sum Algorithm for k = 1 to n do for i = b to 0 if A[i] = 1 and ak + i < b then A[ak + i] := 1 if A[b] = 1 then some subset adds up to b Time Complexity is O((b+1)n) Polynomial time? CSE 589 - Lecture 7 - Spring 1999

Example of the Algorithm 3, 5, 2, 7, 4, 2, b = 11 0 1 2 3 4 5 6 7 8 9 10 11 1 3 1 1 5 1 1 1 1 2 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 CSE 589 - Lecture 7 - Spring 1999

Polynomial or Exponential? O((b+1)n) b is represented in binary a1,a2, … , an, b < 2k where problem size s < (n+1)k array A[0..b] has size at most 2k + 1 = 2s/(n+1) + 1. b is represented in unary a1,a2, … , an < 2k where problem size s < kn + b array A[0..b] has size b+1 < s. CSE 589 - Lecture 7 - Spring 1999

Strong NP-Completeness A decision problem is strong NP-complete if it remains NP-complete even if the numerical inputs are presented in unary. Subset Sum and similar problems are polynomial time solvable if the problem is presented in unary. 3-Partition and Bin Packing are strong NP-complete. CSE 589 - Lecture 7 - Spring 1999

Some “Hard” Problems are Easy Example: Given a set of fields of a structure of length f1, f2, … ,fn in bytes. Can they be fit into two cache lines of length b bytes each. Critical observation: b is small, often 32 or 64. Algorithm: Use the subset sum algorithm to find the largest c < b such that some subset of the fields fits exactly into c bytes. You will need the method of reporting a solution from the decision problem to report a subset that adds up to c. The remaining field lengths must sum to be < b. CSE 589 - Lecture 7 - Spring 1999

Evaluating Algorithms - Correctness Correctness or quality of the answer Does it give the right answer. Does it give an answer that is close to the right answer (for an approximate algorithm). This can be extremely difficult to determine. Does it give a good answer on real data or on what I foresee as real data. Must implement and test on real data. Use of benchmarks Good because common to all. Bad because algorithms can be tuned to a benchmark. CSE 589 - Lecture 7 - Spring 1999

Examples of Quality Criteria Lossless Data Compression compression ratio VLSI Layout area used Compiler Optimization percentage reduction in execution time Encryption Security of the method from attacks Traveling Salesman’s Tour closeness to optimal CSE 589 - Lecture 7 - Spring 1999

Theoretical Analysis Time complexity Storage complexity worst case average case amortized time complexity Storage complexity Important operation counts Memory performance cache misses or page faults CSE 589 - Lecture 7 - Spring 1999

Empirical Evaluation Must implement to test Data Profiling real data set synthetic - generated by a program Profiling wall clock execution time performance monitoring using processor counters instrument program with internal counters binary instrumentation tools - Atom, Etch, ... CSE 589 - Lecture 7 - Spring 1999

Atom Alan Eustace and Amitabh Srivastava (1994) Examples of use Simulate a cache with specific parameters (size, block size, associativity). Output total memory accesses and cache misses. Generate a histogram of heap data sizes allocated Simulate a branch prediction scheme. Output successes. How done Atom inserts code into a binary to do specific tasks. CSE 589 - Lecture 7 - Spring 1999

Atom Flow Instrumentation code Instrumented Executable executable binary Instrumented executable Atom Analysis data Analysis code CSE 589 - Lecture 7 - Spring 1999

Sorting Input: Array A[1..n] of keys. Output: A[1..n] in sorted order, that is for 1 < i < n, A[i] < A[i+1]. 27 5 14 20 1 25 29 17 10 4 15 9 30 31 26 8 1 4 5 8 9 10 14 15 17 20 25 26 27 29 30 31 CSE 589 - Lecture 7 - Spring 1999

Classic Mergesort Two sorted arrays can be merged into one sorted array very quickly in time O(n + m) where n and m are the sizes of the arrays. 1 5 10 14 20 25 27 29 4 8 9 15 17 26 30 31 1 4 5 8 9 10 CSE 589 - Lecture 7 - Spring 1999

Merging (1) 1 5 10 14 20 25 27 29 4 8 9 15 17 26 30 31 1 4 5 8 9 10 14 CSE 589 - Lecture 7 - Spring 1999

Merging (2) 1 5 10 14 20 25 27 29 4 8 9 15 17 26 30 31 1 4 5 8 9 10 14 15 CSE 589 - Lecture 7 - Spring 1999

Merging (3) 1 5 10 14 20 25 27 29 4 8 9 15 17 26 30 31 1 4 5 8 9 10 14 15 17 CSE 589 - Lecture 7 - Spring 1999

Recursive Mergesort A[1..n] is to be sorted; B[1..n] is an auxiliary array; Mergesort(i,j) {sorts the subarray A[i,j] } if i < j then k := (i+j)/2; Mergesort(i,k); Mergesort(k+1,j); Merge A[i..k] with A[k+1..j] into B[i..j]; Copy B[i..j] into A[i..j]; CSE 589 - Lecture 7 - Spring 1999

Mergesort Analysis Storage complexity is 2n plus O(log n) for the call stack. This is not an “in-place” sorting algorithm. Time complexity is O(n log n). Recurrence describes the running time Time to merge and copy. 2 recursive calls CSE 589 - Lecture 7 - Spring 1999

Solving the Recurrence substitution algebra generalization CSE 589 - Lecture 7 - Spring 1999

Merging Pattern of Recursive Mergesort CSE 589 - Lecture 7 - Spring 1999