Re: [algogeeks] Binary Tree Amazon

2011-02-16 Thread Ashish Goel
this will not solve ..think of node->r->r->l->l Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Mon, Feb 14, 2011 at 7:50 PM, SEHAJ SINGH KALRA wrote: > HAD MISSED OUT SOPME THINGS IN PREVIOUS REPLY. > SORRY GUYS > hereby i rectify the

Re: [algogeeks] Find duplicate element in an array

2011-02-16 Thread Ashish Goel
since the question does not talk about extra space, make a BST but that will be nlgn.. or use counting sort for O(n) Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Jan 16, 2011 at 8:51 AM, nphard nphard wrote: > Given an array of intege

Re: [algogeeks] Re: String Operation

2011-02-16 Thread ashish agarwal
trie tree will be better to implement On Thu, Feb 17, 2011 at 11:07 AM, Jammy wrote: > Greedy, always choose the remaining one that is the lexicographically > smallest since choose any other way will yield a lexicographically > greater one. > > > void concante(char **strings, int n){ > qsort

Re: [algogeeks] Re: Large File & Millions of Records

2011-02-16 Thread ashish agarwal
take an array of 10 ,travese the whole rcord and apply min heap on these 10 elements. as like first 10 no will be there and we apply minheap so we will get minimun num in these 10 number..If next numbe is greater then minimun no in array ..we will replace it and apply minheap ... On Thu, Feb 17, 2

Re: [algogeeks] UVa - Gold Coins

2011-02-16 Thread nphard nphard
Question is to find the number of coins received on Nth day and not the total number of coins received after N iterations. On Wed, Feb 16, 2011 at 11:48 PM, Praveen wrote: > Hi All > >total number of coins = 1+(2+2)+(3+3+3)+(4+4+4+4)+(N+N+.N > times) >

[algogeeks] Re: Large File & Millions of Records

2011-02-16 Thread Jammy
Divide records into parts that could fit into main memory. Do rank find algorithm for certain range if necessary. On Feb 16, 7:26 pm, bittu wrote: > given a very large file (millions of record), find the 10 largest > numbers from it.in minimum time complexity > Don't think about hashing . Again I

Re: [algogeeks] Linked List & Amazon

2011-02-16 Thread nphard nphard
Node *flatten(Node *node) { if (!node) return NULL; Node *head = node; Node *next = node->next; node->next = NULL; if (node->down) node->next = flatten(node->down); while (node->next != NULL) node = node->next; node->next = flatten(next); return head; } On Wed, Feb 16, 2011 at 8:38 PM, bittu wr

[algogeeks] Re: String Operation

2011-02-16 Thread Jammy
Greedy, always choose the remaining one that is the lexicographically smallest since choose any other way will yield a lexicographically greater one. void concante(char **strings, int n){ qsort(strings,n,sizeof(char *),compareStr); } int compareStr(const void *a, const void *b){ return

[algogeeks] Re: General Sorting Header File Adobe

2011-02-16 Thread Dave
@Bittu: It is interesting that you might want to sort complex numbers, since they don't form an ordered field. See, e.g., http://en.wikipedia.org/wiki/Ordered_field for an explanation why. Dave On Feb 16, 5:57 am, bittu wrote: > write header file for sorting general element. it can sort any type

Re: [algogeeks] UVa - Gold Coins

2011-02-16 Thread Praveen
Hi All total number of coins = 1+(2+2)+(3+3+3)+(4+4+4+4)+(N+N+.N times) = 1+(2*2)+(3*3)+4*4+...+(N*N) = (N*(N+1)*(2N+1))/6 Please do correct me if i am wrong Regards Praveen On Thu, Feb 17, 2011 at 6:26

[algogeeks] Re: String Operation

2011-02-16 Thread simplyamey
Try this code. #include #include using namespace std; int main() { string sArray[5] ={"aab","abc","bba","acc","bcc"}; int n = 5; for(int i = 0;i < n; i++) { for( int j = 0; j < n - 1 ; j++) { if(sArray[j] > s

[algogeeks] Re: General Sorting Header File Adobe

2011-02-16 Thread bittu
hope it may work typedef void (*Swapfunc)(void *element_1, void *element_2); typedef int (*Cmpfunc)(void *element_1, void *element_2); void GenericSort(void *array, uint32_t nbElems, Swapfunc swapFunc, Cmpfunc cmpFunc); Thanks & Regards Shashank Mani >>"The best way to escape from a problem

[algogeeks] Linked List & Amazon

2011-02-16 Thread bittu
Given a linked list structure where every node represents a linked list and contains two pointers of its type: (i) pointer to next node in the main list. (ii) pointer to a linked list where this node is head. Write a C function to flatten the list into a single linked list. Eg. If the given link

[algogeeks] Program & System Memory checking

2011-02-16 Thread bittu
WAP or Algo That will check whether the memory allotted to the program at the initial and the memory returned to the system is same or not. Thanks & Regards Shashank Mani -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group

Re: [algogeeks] UVa - Gold Coins

2011-02-16 Thread Rel Guzman Apaza
I did it. #include #include using namespace std; int main(){ int n,ac,k,sum; while(cin>>n && n){ ac=0; k=ceil((sqrt(1+8*n)-1)/2)-1; ac+=k*(k+1)*(2*k+1)/6; sum=(k+1)*(k+2)/2; ac+=(k+1)*((k+1)-(sum-n)); cout< > Let f(n) = n(n+1)/2 > We have

[algogeeks] String Operation

2011-02-16 Thread bittu
Given a group of strings, find a string by concatenating all the strings in any order which produces the lexicographically smallest string. For e.g strings are acc bcc abb So the string formed should be abbaccbcc Thanks Shashank -- You received this message because you are subscribed to the Goog

[algogeeks] Large File & Millions of Records

2011-02-16 Thread bittu
given a very large file (millions of record), find the 10 largest numbers from it.in minimum time complexity Don't think about hashing . Again Its Flat File Not the Database Thanks & Regards Shashank Mani -- You received this message because you are subscribed to the Google Groups "Algorithm G

Re: [algogeeks] UVa - Gold Coins

2011-02-16 Thread nphard nphard
Let f(n) = n(n+1)/2 We have to find n1 and n2 such that f(n1) < N <= f(n2) and n2 = n1 + 1. Solution is n2. Can be done in O(1) as follows: Solve N = n(n+1)/2 for unknown n. Requires us to solve quadratic equation: n^2 + n - 2N = 0 Find positive root of the equation which could be a real number.

[algogeeks] UVa - Gold Coins

2011-02-16 Thread Pedro Rezende
It seems to be a very easy problem, but I'm not finding an *equation *that solves it... could someone help me with the steps? Brief: A king pays 1 gold coin to a knight on the first day. 2 gold coins for the next 2 days, 3 gold coins for the next 3 days, and so on... Given a day N, how much gold c

[algogeeks] Re: Puzzle For Puzzled Minds - Robots

2011-02-16 Thread Don
On Feb 16, 12:53 pm, bittu wrote: >  Two robots are placed at different points on a straight line of > infinite length. When they are first placed down, they each spray out > some oil to mark their starting points. > > You must program each robot to ensure that the robots will eventually > crash

[algogeeks] Re: Application Data Structure In Collision Detection

2011-02-16 Thread bittu
one idea is that quad trees are used in 2d collision detection (and OctTrees in 3d collision detection). I haven't ever written a code on it but the basic premise is that every node represents a point and say has it's x and y co-ordinates and 4 children, which actually represent 4 quadrants. So if

[algogeeks] Re: question at K10

2011-02-16 Thread Jammy
Nice solution. Similarly you could #define: void change() { #define change() i=10 } On Feb 16, 12:55 pm, ankit sablok wrote: > nice solution > > On Feb 15, 11:22 pm, jagannath prasad das wrote: > > > > > > > > > void change() > > { > >    #define i i=10,n} > > > this will do.. > > > On Tue, F

[algogeeks] Re: Application of Data Structure

2011-02-16 Thread bittu
@all well i appreciate your suggestion but all of you replied one word answer actually i forget to say "Best Data Structure & why" well hashing,trie will definitely solve this @ankit i wants to see your trie implementation for this problem , as i had not done lot stuff with trie (i read it theo

[algogeeks] Puzzle For Puzzled Minds - Robots

2011-02-16 Thread bittu
Two robots are placed at different points on a straight line of infinite length. When they are first placed down, they each spray out some oil to mark their starting points. You must program each robot to ensure that the robots will eventually crash into each other. A program can consist of the f

[algogeeks] Re: Byte or Bite...Its byte Array

2011-02-16 Thread bittu
case 1. |-|--| | 0 | remaining 7 bit| |-|--| MSB When Character is represented by 1 Byte case 2. ||-||-| | 1 | last 7 bit | dont care

[algogeeks] Re: question at K10

2011-02-16 Thread ankit sablok
nice solution On Feb 15, 11:22 pm, jagannath prasad das wrote: > void change() > { >    #define i i=10,n} > > this will do.. > > On Tue, Feb 15, 2011 at 11:33 PM, Rel Guzman Apaza wrote: > > > > > > > > > Nothing... 10 in base 5   =   5 in base 10. > > > void change(){ > >     printf(""); //...?

[algogeeks] Re: question at K10

2011-02-16 Thread ankit sablok
AX is the low order accumulator register used in the microprocessor generally the value returned is from the accumulator if u modify that value it will return the value u set it to as the Register is Divided into 2 parts AH - higher order and AX - lower order the value 10 is stored in AX and is ret

Re: [algogeeks] Application of Data Structure

2011-02-16 Thread ankit sablok
trie construction would do for this On Wed, Feb 16, 2011 at 10:15 PM, yv paramesh wrote: > build a tree > > On Wed, Feb 16, 2011 at 10:10 PM, vaibhav agrawal > wrote: > > Hash, SortedSet > > > > On Wed, Feb 16, 2011 at 9:58 PM, bittu > wrote: > >> > >> Given a set of words one after another, g

Re: [algogeeks] Application of Data Structure

2011-02-16 Thread yv paramesh
build a tree On Wed, Feb 16, 2011 at 10:10 PM, vaibhav agrawal wrote: > Hash, SortedSet > > On Wed, Feb 16, 2011 at 9:58 PM, bittu wrote: >> >> Given a set of words one after another, give a data structure so that >> you,will know whether a word has appeared already or not. >> >> Thanks >> Shash

Re: [algogeeks] Application of Data Structure

2011-02-16 Thread vaibhav agrawal
Hash, SortedSet On Wed, Feb 16, 2011 at 9:58 PM, bittu wrote: > Given a set of words one after another, give a data structure so that > you,will know whether a word has appeared already or not. > > Thanks > Shashank > > -- > You received this message because you are subscribed to the Google Grou

[algogeeks] Application of Data Structure

2011-02-16 Thread bittu
Given a set of words one after another, give a data structure so that you,will know whether a word has appeared already or not. Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@go

[algogeeks] Re: Byte or Bite...Its byte Array

2011-02-16 Thread Jammy
since it is guaranteed that l points to the start of the character. Thus I would refer to 'X‘ as the byte l points to. Each number in the following represents the MSB of the corresponding byte. E.g. 101X --> the byte preceding X has MSB 1 and the byte preceding that has MSB 0 the byte preceding tha

[algogeeks] Re: Maths

2011-02-16 Thread Akshata Sharma
he first few f(i): f(1)=0 f(2)=max(f(1)+f(1-1+1)+1) = 1 f(3)=max{f(1)+f(2)+1, f(2)+f(1)+1} = 2 f(4)=max{f(1)+f(3)+1, f(2)+f(2)+1, f(3)+f(1)+1} =3 f(5)=max{f(1)+f(4)+1, f(2)+f(3)+1, ,f(4)+f(1)+1} = 4 f(6)=max{.} =5 what I can see here is in each f(i), all comma separated expressions evalua

Re: [algogeeks] Maths

2011-02-16 Thread Vikas Kumar
f(n)=n-1. On Wed, Feb 16, 2011 at 7:39 PM, Akshata Sharma wrote: > please help.. > > if f(n+1) = max{ f(k) + f(n-k+1) + 1} for 1 <= k <= n; f(1) = 0. > Find f(n+1) in terms of n. > Eg: f(4) = ? n = 3; 1<= k <= 3; f(4) = max{f(1) + f(3) + 1, f(2) + > f(2)+1, f(3) + f(1) +1} > > -- > You received

[algogeeks] Re: General Sorting Header File Adobe

2011-02-16 Thread Don
template void sort(Iterator first, Iterator last, Compare cmp); On Feb 16, 5:57 am, bittu wrote: > write header file for sorting general element. it can sort any type of > object(int,float,complex number, objects) > > Thanks > Shashank -- You received this message because you are subscribed to

[algogeeks] Maths

2011-02-16 Thread Akshata Sharma
please help.. if f(n+1) = max{ f(k) + f(n-k+1) + 1} for 1 <= k <= n; f(1) = 0. Find f(n+1) in terms of n. Eg: f(4) = ? n = 3; 1<= k <= 3; f(4) = max{f(1) + f(3) + 1, f(2) + f(2)+1, f(3) + f(1) +1} -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" gr

[algogeeks] Application Data Structure In Collision Detection

2011-02-16 Thread bittu
many irregular shape objects are moving in random direction. provide data structure and algo to detect collision. Remember that objects are in million. Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, se

[algogeeks] General Sorting Header File Adobe

2011-02-16 Thread bittu
write header file for sorting general element. it can sort any type of object(int,float,complex number, objects) Thanks Shashank -- 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.

[algogeeks] API Question Adobe

2011-02-16 Thread bittu
one system API available setOStimer(time n, function ptr, function arg) it sets time for n sec. after expiration of timer it calls function. if another timer set with setOStimer, it will erase previously sets timer. Ex. at t = 0, setOStimer(5,fn,arg) at t = 4, setOStimer(10,fn1,arg1) now first time

Re: [algogeeks] Re: question at K10

2011-02-16 Thread Balaji S
a one line solution is needed... -- 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 algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] Re: question at K10

2011-02-16 Thread sunny agrawal
and also void change() { // Code here int x = 1; int*p= &x; while(*p != 5) p++; *p = 10; } On Wed, Feb 16, 2011 at 8:02 AM, Balaji S wrote: > > The solution is.. > >_AX = 10; > > > can anyone explain?? > > -- > You received this message because you are subscribed to the Google Groups >