473,320 Members | 2,000 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,320 software developers and data experts.

Array Programming Questions:

I would appreciate your help on the following programming questions:

1. Given an array of length N containing integers between 1 and N,
determine if it contains any duplicates.
HINT: [Is there an O(n) time solution that uses only O(1) extra space and
does not destroy the original array?]

The solution is:
http://domino.research.ibm.com/Comm/...nuary2004.html

but I don't understand what they meant by "Let f(x) be the location of the
array at address x."
2. Sort an array of size n containing integers between 1 and K, given a
temporary scratch integer array of size K.
HINT: Compute cumulative counts of integers in the auxiliary array. Now
scan the original array, rotating cycles!
3. An array of size k contains integers between 1 and n. You are given
an additional scratch array of size n. Compress the original array by
removing duplicates in it. What if k << n?
HINT: Can be done in O(k) time i.e. without initializing the auxiliary
array!

Any solutions, partial solutions, or algorithms to the above problems is
greatly appreciated.

William

Jul 23 '05 #1
4 4223
William wrote:
I would appreciate your help on the following programming questions:

[...]


This is a C++ language newsgroup. I recommend asking your programming
questions in a general programming newsgroup: comp.programming.

V
Jul 23 '05 #2
* William:
I would appreciate your help on the following programming questions:

1. Given an array of length N containing integers between 1 and N,
determine if it contains any duplicates.
HINT: [Is there an O(n) time solution that uses only O(1) extra space and
does not destroy the original array?]

The solution is:
http://domino.research.ibm.com/Comm/...nuary2004.html

but I don't understand what they meant by "Let f(x) be the location of the
array at address x."
What is the C++ question?

2. Sort an array of size n containing integers between 1 and K, given a
temporary scratch integer array of size K.
HINT: Compute cumulative counts of integers in the auxiliary array. Now
scan the original array, rotating cycles!
3. An array of size k contains integers between 1 and n. You are given
an additional scratch array of size n. Compress the original array by
removing duplicates in it. What if k << n?
HINT: Can be done in O(k) time i.e. without initializing the auxiliary
array!

Any solutions, partial solutions, or algorithms to the above problems is
greatly appreciated.


Try posting this in [comp.programming].

It's off-topic in [comp.lang.c++].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3
On 2005-05-26, William <wh******@student.cs.uwaterloo.ca> wrote:
I would appreciate your help on the following programming questions:


Thanks, but I've already earned my degree. Good luck with yours. If you
have any specific C++ questions, you're welcome to post them here. But
don't expect anyone to do your homework for you.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #4
William wrote:

I would appreciate your help on the following programming questions:

1. Given an array of length N containing integers between 1 and N,
determine if it contains any duplicates.
HINT: [Is there an O(n) time solution that uses only O(1) extra space and
does not destroy the original array?]

The solution is:
http://domino.research.ibm.com/Comm/...nuary2004.html

but I don't understand what they meant by "Let f(x) be the location of the
array at address x."


Array indexing.
If Numbers is the array, then f(x) would be Numbers[x] in C++ speak.
(Different programming languages have different syntax for array indexing)
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #5

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

Similar topics

12
by: Uncle | last post by:
I am an untrained hobbyist. Everything about programming I have learned from the internet. Thank you all for your gracious support. This is what I have: #define CONST_CHAR 0 void some_func(...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
17
by: newgoat | last post by:
As far as I understand, in "int arr", the name of the integer array "arr" is equivalent to the pointer to the first element of the array. But is "arr" really a pointer, identical as "int *arr;" ?...
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
18
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and...
3
by: kurrent | last post by:
i'm still new to php and programming and was hoping to get some help on a few questions i haven't had success in answering myself. I successfully created my first very simple script to accomplish a...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.