what is the time complexity for the code ?
#includeiostream
using namespace std;
main()
{
int arr[] = { 2,3,4,9,2,7};
int *ptr1 = arr[0];
int *ptr2 = arr[1];
const int SIZE = sizeof arr / sizeof arr[0];
while(1)
{
if(*ptr1 ==
This will help u
http://www.geeksforgeeks.org/archives/570
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@Arun: The referenced algorithm solves the wrong problem. The problem given
has n-2 unique elements and 1 element repeated twice. The referenced
algorithm has n-1 elements that occur in pairs and one that is unique;
xoring will solve this problem, but it won't help solve the given one.
Dave
http://ideone.com/vuAse
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/rbiZjy8dcgEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To
@deepikaanand
(checksum 1 100) will it work ?
as i know int has only 32 bits !!
Thanks Regards
Saurabh Yadav
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To
Could u please tell me the way to find number repeated odd number of time
using X-oR..??
On Sunday, 27 November 2011 00:49:59 UTC+5:30, Gene wrote:
Isn't this overkill? If you're already using a set, just check the set
before you insert each new element, and you'll discover the
duplicates:
Atul: The original poster asked for an algorithm that is O(n) in time
and O(1) space. So please tell us how you are going to sort the array
with those limitations.
Dave
On Dec 6, 1:35 am, atul anand atul.87fri...@gmail.com wrote:
Given : 4 2 8 9 5 1 9
sort the array.
sorting: 1 2 4 5 8 9
@Dave : sorry , i considered sorting a prerequisite for the given problem .
should have read it properly before posting.
On Tue, Dec 6, 2011 at 8:56 PM, Dave dave_and_da...@juno.com wrote:
Atul: The original poster asked for an algorithm that is O(n) in time
and O(1) space. So please tell us
Given : 4 2 8 9 5 1 9
sort the array.
sorting: 1 2 4 5 8 9 9
for ( i = 0 ; i len ; i++)
{
if( i != len-1 )
{
if (arr[i]==arr[i+1])
{
printf(\nfound repeated element\n);
break;
}
}
}
On Mon, Nov 28, 2011 at 1:24
Isn't this overkill? If you're already using a set, just check the set
before you insert each new element, and you'll discover the
duplicates:
S = empty
while i = input item existss
if i in S output i has a duplicate;
insert i in S
end
XOR is generally useful only for detecting a single item
@kunzmilan : i did not get u, once explain with example...
On 23 November 2011 23:47, kunzmilan kunzmi...@atlas.cz wrote:
On 24 lis, 07:02, kumar raja rajkumar.cs...@gmail.com wrote:
In the given array all the elements occur single time except one element
which occurs 2 times find it
I have an O(n) space and time solution by using hashing . Firstly,
make a hash table by using a hash function for each of the number in
the array. After that, go through the hash table to see whether there
are any repetitions for the same entry.
--
You received this message because you are
hashing is not that simple, can you tell your hash function ?
On Thu, Nov 24, 2011 at 6:26 PM, ravu sairam ravu...@gmail.com wrote:
I have an O(n) space and time solution by using hashing . Firstly,
make a hash table by using a hash function for each of the number in
the array. After that, go
@ravu sairam:
Suppose the hashing is banned ,now what is ur solution???
Hashing is quite theoretical concept with time complexity O(1).
But it will not be the case every time.so suggest some other better
solution
I used to thought of using count array ,but again its size is not O(n), its
size
find it in O(n) time and O(1) space,
are you sure that it is possible to do it in O(n) time ?
On Thu, Nov 24, 2011 at 6:59 PM, kumar raja rajkumar.cs...@gmail.comwrote:
@ravu sairam:
Suppose the hashing is banned ,now what is ur solution???
Hashing is quite theoretical concept with time
@shady : i am not sure , if u can do it with O(n) space as well it is fine
for me . but once try whether it is possible in O(1) space.
On 24 November 2011 05:42, shady sinv...@gmail.com wrote:
find it in O(n) time and O(1) space,
are you sure that it is possible to do it in O(n) time ?
On
i also doubt about the time and space complexity of the problem, i has been
asked a number of times with these constraints but never been answered the
required, as far as i remember the best solution to this problem that has
been discussed so far is using hashing and that too theoretically having
i don't think there is an O(n) time solution for this... bcoz there are no
constraints on the values, and on the number of values in the array.
On Thu, Nov 24, 2011 at 7:15 PM, kumar raja rajkumar.cs...@gmail.comwrote:
@shady : i am not sure , if u can do it with O(n) space as well it is fine
Finding duplicates in a multiset is a pretty standard problem. I've
only ever heard of two solutions, and it's unlikely there are others.
One is to sort, which will place duplicates adjacent to each other, so
you can find them by comparing a[i] with a[i+i] for all I. This
algorithm is O(sorting
On 24 lis, 09:09, kumar raja rajkumar.cs...@gmail.com wrote:
@kunzmilan : i did not get u, once explain with example...
On 23 November 2011 23:47, kunzmilan kunzmi...@atlas.cz wrote:
Matrix M
0 1 0
0 1 0
1 0 0
multiplied with M(T)
0 0 1
1 1 0
0 0 0
gives
1 0 0
0 2 0
0 0 0.
On its diagonal
@kunzmilan :
Can u please maintain the clarity ??
How did u find the M
if the list is 4 2 8 9 5 1 9 how M looks like ?? please elaborate it...
On 24 November 2011 06:15, kunzmilan kunzmi...@atlas.cz wrote:
On 24 lis, 09:09, kumar raja rajkumar.cs...@gmail.com wrote:
@kunzmilan : i did not
@kunzmilan
Nice idea, how do you decide the row-size or column-size of the matrix?
On Thu, Nov 24, 2011 at 8:00 PM, kumar raja rajkumar.cs...@gmail.comwrote:
@kunzmilan :
Can u please maintain the clarity ??
How did u find the M
if the list is 4 2 8 9 5 1 9 how M looks like ?? please
@Anup:
Atleast u tell me how the M has formed???
On 24 November 2011 11:21, Anup Ghatage ghat...@gmail.com wrote:
@kunzmilan
Nice idea, how do you decide the row-size or column-size of the matrix?
On Thu, Nov 24, 2011 at 8:00 PM, kumar raja rajkumar.cs...@gmail.comwrote:
@kunzmilan :
Can
^^+1..how matrix formed ??
But as Gene said we can use a set to store all the unique elements
Now we xor all the set elements and then xor them with the elements of the
array . This wud give us the repeating element as all the elements coming
once will be 0(xored twice) and repeating element wud
On 24 lis, 07:02, kumar raja rajkumar.cs...@gmail.com wrote:
In the given array all the elements occur single time except one element
which occurs 2 times find it in O(n) time and O(1) space.
e.g. 2 3 4 9 3 7
output :3
If such a solution exist can we extend the logic to find All the
25 matches
Mail list logo