Docsity

CS 473: Algorithms Lecture 12, Lecture notes of Algorithms and Programming

Partial preview of the text

Download CS 473: Algorithms Lecture 12 and more Lecture notes Algorithms and Programming in PDF only on Docsity!

CS 473: Algorithms

Ruta Mehta University of Illinois, Urbana-Champaign Spring 2021

CS 473: Algorithms, Spring 2021

Streaming Algorithms

Lecture 12 March 16, 2021

Most slides are courtesy Prof. Chekuri

Streaming Algorithms

A topic that is both very old, and very current!

Dawn of CS..

Data was stored on tapes, and amount of RAM was very small. Too much data, too little space. Store only summary or sketch of data.

Now..

Terabytes of memory, Gigabytes of RAM. Data streams: Humongous amount of data (sometimes never ending)! Can go over it at most once, and sometimes not even that! Store only summary: sub-linear space-time algorithms.

Examples

An internet router sees a stream of packets, and may want to know, which connection is using the most packets how many different connections median of the file sizes transferred since mid-night which connections are using more than 0.1% of the bandwidth. Computing aggregative information about data streams.

Data Streams

A stream of data elements, S = a 1 , a 2 ,.... Say at arrive at time t. Let us assume that at ’s are numbers for this lecture.

Data Streams

A stream of data elements, S = a 1 , a 2 ,.... Say at arrive at time t. Let us assume that at ’s are numbers for this lecture. Denote a[1..t] = 〈a 1 , a 2 ,... , at 〉. Given some function we want to compute it continually, while usinglimited space. at any timethe stream seen so far, i.e., t we should be able to query the function value on a [1..t].

Examples

S = 3, 1 , 17 , 4 , − 9 , 32 , 101 , 3 , − 722 , 3 , 900 , 4 , 32 , ...

Computing Sum

F (a[1..t]) = ∑ti =1 ai Outputs are: 3, 4, 21, 25, 16, 48, 149, 152, -570, ... Keep a counter, and keep adding to it. After T rounds, the number can be at most T 2 b. O(b + log T ) space.

Examples

S = 3, 1 , 17 , 4 , − 9 , 32 , 101 , 3 , − 722 , 3 , 900 , 4 , 32 , ...

Computing max

F (a[1..t]) = maxti =1 ai Outputs are: 3, 3, 17, 17, 17, 32, 101, 101, ... Just need to store b bits.

Examples

S = 3, 1 , 17 , 4 , − 9 , 32 , 101 , 3 , − 722 , 3 , 900 , 4 , 32 , ...

Computing max

F (a[1..t]) = maxti =1 ai Outputs are: 3, 3, 17, 17, 17, 32, 101, 101, ... Just need to store b bits. Median? A lot more tricky

Examples

S = 3, 1 , 17 , 4 , − 9 , 32 , 101 , 3 , − 722 , 3 , 900 , 4 , 32 , ...

Computing max

F (a[1..t]) = maxti =1 ai Outputs are: 3, 3, 17, 17, 17, 32, 101, 101, ... Just need to store b bits. Median? A lot more tricky

distinct elements?

Streaming Algorithms: Framework

〈Initialize summary information〉 While stream S is not done x 〈Do something with ← next element in x Sand update summary information〉 〈Output something if needed〉 Return 〈summary〉

Streaming Algorithms: Framework

〈Initialize summary information〉 While stream S is not done x 〈Do something with ← next element in x Sand update summary information〉 〈Output something if needed〉 Return 〈summary〉

Despite of restrictions, we can compute interesting functions if we can tolerate some error.

Part I

Heavy Hitters

Finding the Majority Element

Find the element that occur strictly more than half the time, if any. Note that at most one such element!