473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Accelerated C++ exercise

Suppose we wish to find the median of a collection of values. Assume
that we have read some of the values so far, and that we have no idea
how many values remain to be read. Prove that we cannot afford to
discard any of the values that we have read. Hint: One proof strategy
is to assume that we can discard a value, and then find values for the
unread—and therefore unknown—part of our collection that would cause
the median to be the value that we discarded.

As a try;

Lets say we have read so far

5 10 34 72

and we want to read 6 more values as an example

43 32 45 56 78 89

Actually I did not understand what is meant above? Could you please
give an explanation for this problem.

Thx.

Feb 13 '06 #1
2 1870
utab wrote:
Suppose we wish to find the median of a collection of values. Assume
that we have read some of the values so far, and that we have no idea
how many values remain to be read. Prove that we cannot afford to
discard any of the values that we have read. Hint: One proof strategy
is to assume that we can discard a value, and then find values for the
unread—and therefore unknown—part of our collection that would cause
the median to be the value that we discarded.

As a try;

Lets say we have read so far

5 10 34 72

and we want to read 6 more values as an example

43 32 45 56 78 89

Actually I did not understand what is meant above? Could you please
give an explanation for this problem.

Thx.


The point is that after you've read n values, if you don't know how many
more are coming, *any* of those n values could be the median depending
upon what's read next. Here's a simple example:

Say you've read {10 20 30}

Suppose the remaining numbers are: {40 50} OR {15 25} OR {0 5}. In each
of these cases, what's the resulting median value?
Feb 13 '06 #2
no homeworks, please :(

Feb 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Martin | last post by:
I am reading through Koenig and Moo's "Accelerated C++" and attempting the exercises. Are there any sample solutions somewhere? It's all very well me doing a solution, which seems to work, but for...
3
by: Frankie Montenegro | last post by:
Hi everyone, I must say that, even though I think that Accelerated C++ by Koenig and Moo is an awesome text, the wording of exercises is very poor. I spend half the time just trying to figure...
14
by: Pete | last post by:
Is anyone familiar with this book? Exercise 6-1 of Accelerated C++ asks us to reimplement the frame() and hcat() operations using iterators. I've posted my answers below, but I'm wondering if...
1
by: utab | last post by:
Hi there, I have been reading Accelerated C++ by Andrew Koenig which is an excellent way of learning C++ from even the first pages by using the standard library. One drawback is that no...
3
by: utab | last post by:
Exercise 5.10 from Accelerated C++ by Andrew Koenig Palindromes are words that are spelled the same right to left as left to right. Write a program to find all the palindromes in a dictionary....
8
by: utab | last post by:
Dear all, in a container example, this question is asked in exercises in Accelerated C++ page 154, 8.8? why dont we use (begin+end)/2 instead of begin + (end - begin) / 2 is that someting related...
10
by: Xernoth | last post by:
Hi, This is my first post here, so please be gentle. I've been studying c+ + by mostly using the book Accelerated C++ by Andrew Koenig and Barbara E. Moo. So far, I've been picking things up...
0
by: Lambda | last post by:
I'm trying to complete all the exercises of Accelerated C++. I'm not sure what does the exercise 5-5 mean. And how about 5-9? Thanks
0
by: Lambda | last post by:
It's from the Accelerated C++ exercise 8-1 The old version is based on pointer to function: double analysis(const std::vector<Student_info>& students, double analysis_grade(const Student_info&...
8
by: utab | last post by:
Dear all, In a question in the highly recommended book Accelerated C++, it is asked to change a const function into a plain function. After on the reader is expected to find which function(s)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.