Anyone has the solution to the question "Given an array a[N] with value
1...N, find a repeted value" in C code?
Thanks a lot 5 1694
<ca********@hot mail.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. . Anyone has the solution to the question "Given an array a[N] with value 1...N, find a repeted value" in C code?
Thanks a lot
My solution is to ask your class teacher. ca********@hotm ail.com wrote: Anyone has the solution to the question "Given an array a[N] with value 1...N, find a repeted value" in C code?
Since an array a[N] has offsets 0 through N - 1, I presume that by
"value 1...N" you are referring to the values stored in the array
elements.
The best way to get a solution to a simple problem like this is
to write it yourself.
Start like this:
#include <stdio.h>
int find_repeated_v alue(int *a, size_t n, int *repval)
{
int found = 0;
/* insert your code here */
if(found)
{
/* write the repeated value to *repval */
}
return found;
}
int main(void)
{
/* change this test array to include/not include repeated
* values, putting them in various places in the array
* on successive tests.
*/
int array[] = { 31, 41, 59, 26, 53, 58, 97, 93, 23, 84 };
int repeated = 0;
if(find_repeate d_value(array,
sizeof array / sizeof array[0],
&repeated))
{
printf("At least one value was repeated: %d\n", repeated);
}
else
{
puts("All Values Unique!");
}
return 0;
}
I will give you a clue for an efficient solution. It's easy to write
O(n^2) solution and O(n) solution as well with O(n) extra space. But
solution can also be O(n) with O(1) extra space which uses the fact
that <b> possible values in an array of size N are 1..N </b>
Groovy hepcat ca********@hotm ail.com was jivin' on 25 Dec 2004
08:29:55 -0800 in comp.lang.c.
Given an array a[N] with value 1...N, find a repeted value's a cool
scene! Dig it! Anyone has the solution to the question "Given an array a[N] with value 1...N, find a repeted value" in C code?
Your instructor misspelled "repeated". The specification isn't even
clear. And he apparently failed to teach you how to do your own
homework. So, if I were you, I'd find a better school.
--
Dig the even newer still, yet more improved, sig! http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 = {0,1,2,4,9};
|
by: mike |
last post by:
I have ListArray with number in Eg:
1, 1.456, 2.43, 4, 6.78
next i have a decimal variable containing one number EG:
1.786
Could someone please tell me how i find the "closest match" number below the
decimal variable from the arraylist.
Thanks ever so much in advance
|
by: Arjen |
last post by:
Hi,
I need to add this inside an array:
1 3
2 4
3 2
4 5
5 1
I think of using this:
|
by: yawnmoth |
last post by:
Given an element ID, is there a way to figure out what index one would
need to use in the parentNode's childNodes array to get at that
element?
For example...
<body>
<div id="parent">
<div id="a">a</div>
<div id="b">b</div>
|
by: Ros |
last post by:
Peeps,
I need help with trying to find a value in array of arrays.
Public Module myModule
Private Site_Access() As Array
Property Set_SA()
Get
Return Site_Access
End Get
| |
by: Manish |
last post by:
This is the print_r() for a variable $categories.
$categories ::
Array
(
=Array
(
=Array
(
|
by: begum |
last post by:
in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don't want
to find the sum!!!!. please can anyone help me?
|
by: msggeca |
last post by:
I want the source code in c++ of a program which finds factorial of any no between 1yo 365
and also displays how many times each digit is repeted in it
eg 4
24
0=0
1=0
2=1
3=0
4=1
5=0
|
by: raylopez99 |
last post by:
I would like to know if there's a quick "Linq" way to find the index
of an array having a particular value. I can do this the long way by
sequential iteration, but would like to know if there's a shortcut.
Specifically, you have an Array, say an array of Ints. You have a
maximum value, i.e. int someValue = Array.Max(); and you would like to
know which ith cell of the Array holds this value.
How to do this without iterating the entire...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |