Hi,
My solution is :
int Find_repeat(int *array, int n)
{
int index=0, index1 =0;
while(array[index]0) // assume number are in between 1 to n and size of
array is n also atleast one is repeated.
{
array[index] = -array[index];
indeax = abs(array[index])-1;
}
awesome :)
On Wed, Jul 7, 2010 at 9:07 AM, Dave dave_and_da...@juno.com wrote:
There are 6 cases to consider (we can list them but we don't know
which one applies):
1. Initially, all 4 coins are tails.
2. Initially, all 4 coins are heads.
3. Initially, 3 of the coins are heads, 1 is tails.
* find height of BINARY tree ITERATIVELY??*
//**
* Algorithm:-*
First create a STACK of Apropriate Size of Bnode pointer type
and perform a PUSH operation
i like the idea whereby when you xor again with all xored, essentially, we
are removing one xor and the result would be the left number(which were
repeated odd number of times)
however, this will simply not work when
a] there are multiple single numbers like
1,2,1,3,1,4,5
b] this would need two
@all: First of all apologize for posting the wrong solution.
The whole idea behind it was first find the xor of all array elements and
this will have xor of only those value which got repeated once and thrice
b'cos element which got repeated twice gets nullified. Now intention behind
xoring it
Both the algorithms are explained in great detail at the below link:
http://www.rawkam.com/?p=870
-
On Wed, Jul 7, 2010 at 8:39 AM, Dave dave_and_da...@juno.com wrote:
Of course O(n) is the average complexity. The worst-case complexity is
O(n^2). There is a divide and conquer algorithm with
Given a list of numbers, A = {a0, a1, ..., an-1}, its pairwise sums P
are defined to be all numbers of the form ai + aj for 0 = i j n.
For example, if A = {1,2,3,4}, then
P = {1+2, 1+3, 1+4, 2+3, 2+4, 3+4} = {3, 4, 5, 5, 6, 7}.
Now give you P, design an algorithm to find all possible A.
--
You
Hi can anybody tell me how to construct a suffix tree in O(n)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
http://www.spoj.pl/problems/LIS2/
i used nlogn code for this problem i gets wrong answer.
here is my code. pls tell me where i went wrong pls.
pls correct my code.
Thanks in advance.
int main()
{
int n;
scanf(%d,n);
vector pairlong int,long int v( n );
FOR(i,0,n)
I made a mistake here.I traversed only the leftmost and the rightmost
branches.We need to use stack here.
On Fri, Jul 9, 2010 at 11:15 AM, Ashish kumar Jain
akjlucky4...@gmail.comwrote:
Here is the Iterative function:
//Function to compute height of a binary tree iteratively
int
You are given a String number containing the digits of a phone number
(the number of digits, n, can be any positive integer) . To help you
memorize the number, you want to divide it into groups of contiguous
digits. Each group must contain exactly 2 or 3 digits. There are three
kinds of groups:
•
Here is one other way:
Planning to do a level order traversal using a Queue and a small marker
field whose storage in the queue is proportional to the height of the tree.
Here is a psuedo code for it..
// Returns the height of the binary tree as int.
int find_bintree_height(root) {
unsigned
for loop will terminate at root only
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Fri, Jul 9, 2010 at 10:42 PM, Balaji balaji.subraman...@gmail.comwrote:
Here is one other way:
Planning to do a level order traversal using a Queue and a
http://www.daniweb.com/code/snippet216621.html
decent code
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Fri, Jul 9, 2010 at 3:35 PM, UMESH KUMAR kumar.umesh...@gmail.comwrote:
* find height of BINARY tree ITERATIVELY??*
a minor correction
nC2 possibilities
so n can be found using nC2=say6 then n=4
a+b=p0
a+c=p1
a+d=p2
b+c=p3
b+d=p4
c+d=p5
3a+b+c+d=po+p1+p2
b+c+d=(p3+p4+p5)/2
so a= (2(p0+p1+p2)-p3-p4-p5)/6
take case of 5 numbers {1,2,3,4,5}
P={3,4,5,6,5,6,7,7,8,9}
5C2=10 so n=5
Back edges are the key to finding a cycle in an undirected graph.
Condition for Back edge is vertex(u,v):v that we are trying to explore from
(u) should not be the parent of u.
http://codepad.org/t7Y5wshb
On Tue, Jun 15, 2010 at 5:25 AM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote:
@vivek :
nice approach Ashishthkz
On Fri, Jul 9, 2010 at 11:14 AM, Ashish Goel ashg...@gmail.com wrote:
a minor correction
nC2 possibilities
so n can be found using nC2=say6 then n=4
a+b=p0
a+c=p1
a+d=p2
b+c=p3
b+d=p4
c+d=p5
3a+b+c+d=po+p1+p2
b+c+d=(p3+p4+p5)/2
so a=
plz write a code to
Sort n integer in the range 1 to n^2 in O(n)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
int count=0;
for every vertex v{
if visited[v]==0
dfs(v)
count++;
}
count is the number of components in graph or m i missing something
?
On Fri, Jul 9, 2010 at 9:23 PM, amit amitjaspal...@gmail.com wrote:
How to check if a directed graph is connected.
--
Dis can help u
http://www.allisons.org/ll/AlgDS/Tree/Suffix/
On Fri, Jul 9, 2010 at 9:36 PM, amit amitjaspal...@gmail.com wrote:
Hi can anybody tell me how to construct a suffix tree in O(n)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
Hi , I was reading TST from this
http://www.ahhf45.com/info/Data_Structures_and_Algorithms/resources/technical_artile/ternary_search_tree/terstree.htm
But I could not understand its two applications i.e the nearest
neighbourhood search and Pattern Matching Search...
If anyone of you know about it
i think dijikshtra can be useful here too
On Wed, Jul 7, 2010 at 1:28 PM, sharad kumar aryansmit3...@gmail.comwrote:
this the same hamming distance problem...this can be done thorugh
trie.pls check archives this has been discussed before..
On Wed, Jul 7, 2010 at 10:12 AM, Ashish
@Jalaj
how using dijikshtra??
can u explain lilbit ... ???
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
23 matches
Mail list logo