{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

mt2(4) - CS 373 U Midterm 2 Questions(April 6 2004 Spring...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 373 U Midterm 2 Questions (April 6, 2004) Spring 2004 Write your answers in the separate answer booklet. 1. A data stream is an extremely long sequence of items that you can only read only once, in order. A good example of a data stream is the sequence of packets that pass through a router. Data stream algorithms must process each item in the stream quickly, using very little memory; there is simply too much data to store, and it arrives too quickly for any complex computations. Every data stream algorithm looks roughly like this: DoSomethingInteresting (stream S ): repeat x next item in S (( do something fast with x )) until S ends return (( something )) Describe and analyze an algorithm that chooses one element uniformly at random from a data stream, without knowing the length of the stream in advance . Your algorithm should spend O (1) time per stream element and use O (1) space (not counting the stream itself). Assume you have a subroutine Random ( n ) that returns a random integer between 1 and n , each with
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern