Re: [algogeeks] os question

2012-12-10 Thread Navin Kumar
If virtualization is concerned, then answer would be choice d. Since its not necessary to load complete process in memory. On Sat, Dec 8, 2012 at 12:45 AM, sahil gupta wrote: > It's b. > Windows follow this Operation. > > > On Fri, Dec 7, 2012 at 4:21 AM, manish wrote: > >> Four processes of 1

Re: [algogeeks] Microsoft Interview Question

2012-10-17 Thread Navin Kumar
][3]=1 so we can't take this in put path... but actually both > are different paths.. > how you will ensure this. because we are maintaining only one visited > matrix. > > > > > > > On Wed, Oct 17, 2012 at 7:54 AM, Navin Kumar wrote: > >> @Rahul: Loop won&

Re: [algogeeks] Microsoft Interview Question

2012-10-16 Thread Navin Kumar
@Rahul: Loop won't occur because when you are visiting any matrix element then you are marking 1 in visited matrix. So second time it will be seen as a already visited element and it will choose another element (or path if exist) or will blocked. On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar Patle

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-01 Thread Navin Kumar
f(arr)-1; > do > { > if(elem==arr[n]) > print found; > n--; > > }while(n); > > > > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar wrote: > >> @atul: keep one more checking outside loop for element at 0 th index. >> Because when n = 0

Re: [algogeeks] finding element in array with minimum of comparing

2012-09-30 Thread Navin Kumar
@atul: keep one more checking outside loop for element at 0 th index. Because when n = 0 the your loop come out from the loop without comparing it. On Mon, Oct 1, 2012 at 8:55 AM, atul anand wrote: > n=sizeof(arr); > n--; > > while(n) > { > if(elem=arr[n]) > print found; > > n--;

Re: [algogeeks] longest palindrome in a string size 2*10^4

2012-09-23 Thread Navin Kumar
it&redlink=1>in 1995" source: wikipedia On Sun, Sep 23, 2012 at 5:08 PM, Navin Kumar wrote: > Build a common suffix tree for the given string and for its reverse. Then > take out the string ending at maximum depth at a common node. Time > complexity would be linear. > >

Re: [algogeeks] longest palindrome in a string size 2*10^4

2012-09-23 Thread Navin Kumar
Build a common suffix tree for the given string and for its reverse. Then take out the string ending at maximum depth at a common node. Time complexity would be linear. On Sat, Sep 22, 2012 at 5:33 PM, Aditya Raman wrote: > Hello everybody, > I need to find a way of finding the longest palindrome

Re: [algogeeks] Adobe Written Test - 25 SEPT 2010

2012-09-21 Thread Navin Kumar
PM, Dave wrote: > @Navin: It means that given a positive integer n whose decimal > representation ends in 3, find a multiple, m*n, which is written solely > with the digit 1. E.g., 3: 37 * 3 = 111; 13: 8547 * 13 = 111,111. > > Dave > > On Thursday, September 20, 2012 11:56:08

Re: [algogeeks] Adobe Written Test - 25 SEPT 2010

2012-09-20 Thread Navin Kumar
@all: Please explain question number 8. I am not getting the question exactly what it says ? On Fri, Sep 21, 2012 at 9:30 AM, Dave wrote: > @Bharat: Simulate long division, dividing a number ...1 by the number. > You can do this one digit at a time, printing the quotient digit by digit > unt

Re: [algogeeks] Data Structure

2012-09-18 Thread Navin Kumar
d to the this new queue and add it > to hastable. > clear all previous "monday" to "sunday" queues. > and start creating queue for new week. > > > > On Tue, Sep 18, 2012 at 1:20 PM, Navin Kumar wrote: > >> >> Which data structure is used to mai

[algogeeks] Data Structure

2012-09-18 Thread Navin Kumar
Which data structure is used to maintain browser history? -- 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/-/MCj-0bFwvV0J. To post to this group, send email t

Re: [algogeeks] Finding top 10 most frequent repeated word

2012-09-11 Thread Navin Kumar
te: > >> hashmap for word to count mapping and a heap will have count and >> corresponding words (will get updated at run time) >> Best Regards >> >> Ashish Goel >> "Think positive and find fuel in failure" >> +919985813081 >> +919966006652

Re: [algogeeks] Finding top 10 most frequent repeated word

2012-09-11 Thread Navin Kumar
rnal sorting >>coming to second point it dynamically changing leads lot of >> other questions before going give algo . >> >> >> On Sat, Sep 8, 2012 at 7:43 PM, Navin Kumar wrote: >> >>> Given a file which has billions of words and file can be

[algogeeks] Finding top 10 most frequent repeated word

2012-09-08 Thread Navin Kumar
Given a file which has billions of words and file can be loaded in memory. Now find 10 most frequent words in file. What if file is dynamically changing means words are continuously added to it. What if file cant be loaded in memory. -- You received this message because you are subscribed to

Re: [algogeeks] Number of arrangements

2012-09-06 Thread Navin Kumar
@tendua: Answer will be 6C3 x 3! . For example: If 5 letters are given then you can get only 10 combination of different letter = 5C3 ABC ABD ABE BCD BCE CDE ACD ACE ADE BDE now each of these can be arranged in 3! ways. So final answer will be : 120 On Fri, Sep 7, 2012 at 1:11 AM, tendua wrote

Re: [algogeeks] Number of arrangements

2012-09-06 Thread Navin Kumar
@tendua: answer would be 6C3. Read about combination definition. On Thu, Sep 6, 2012 at 5:05 PM, atul anand wrote: > question says *3 alphabets with no data repeated* ...you no need of doing > 3! permutation. > eg 123 and 321 are same > > > On Thu, Sep 6, 2012 at 4:35 PM, tendua wrote: > >> fro

Re: [algogeeks] MICROSOFT:Given a BST and a number. Find two node in a BST whose sum is equal to given number in O(n) time and O(1) space.

2012-09-04 Thread Navin Kumar
@all: Now the problem is for getting O(n) time and O(1) space we have to run two inorder traversal simultaneously. How can we do it?? On Mon, Sep 3, 2012 at 9:31 PM, Karthikeyan V.B wrote: > @navin and @atul: > > inorder traversal without recursion and stack can be done using Morris > traversal

Re: [algogeeks] MICROSOFT:Given a BST and a number. Find two node in a BST whose sum is equal to given number in O(n) time and O(1) space.

2012-09-03 Thread Navin Kumar
success when the >>>> sum equals the given number or with failure when the two traversals have >>>> reached the same node. >>>> Dave >>>> >>>> On Sunday, September 2, 2012 11:00:42 PM UTC-5, atul007 wrote: >>>> &

[algogeeks] MICROSOFT:Given a BST and a number. Find two node in a BST whose sum is equal to given number in O(n) time and O(1) space.

2012-09-02 Thread Navin Kumar
-- 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/-/aLuPUOKxmaoJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this gro

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
hich will be O(n). > > > On 9/2/12, Navin Kumar wrote: > > @atul : suppose if all element of input array is zero then i think > hashing > > will also produce n^2 output. so worst case time complexity would be > > O(n^2). > > > > On Sun, Sep 2, 2012 at 9:18 PM

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
inding problem. But if I recall correctly that only works in >> >> linear time if the input is entirely positive integers? >> >> Maybe I'm being stupid but wont checking that array be quadratic? >> >> >> >> On 2 September 2012 20:02, Navin Kumar &g

Re: [algogeeks] Microsoft written test question

2012-09-02 Thread Navin Kumar
void correctBST(struct node *root) { int flag =0; static struct node *temp1, *temp2, *temp3, *prev; static int found; if(found) return; if(root) { correctBST(root->left); if(!temp1 && prev && root->data < prev->data) { temp1 = prev; temp2 = root;

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
@pradip: Finding same element in temp array is little bit tricky. For displaying item from i+1 to j , you have to make sure that there is equal element at i and j index in temp array. How will you ensure it in O(n) time? On Sun, Sep 2, 2012 at 3:16 PM, Pradeep Mishra wrote: > This algorithm is *O

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
gt; between the sum of 2 prefixes. > 3. for each entry search for the corresponding difference such the index > found is greater than original index. > > Works for any sum, not just 0. Takes O(n log n) > > > On 2 September 2012 14:22, Navin Kumar wrote: > >> Given an un

[algogeeks] Contiguous Sub sequence

2012-09-01 Thread Navin Kumar
Given an unsorted integer array. Find the contiguous sub sequences whose sum is 0. -- 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/-/pFvfWQjVrnkJ. To post t

Re: [algogeeks] TRIE problem

2012-09-01 Thread Navin Kumar
on why a trie or a tree node couldn't be used to > 'represent' > > more than one word. Although you'd take a penalty in the complexity for > > searching etc. > > > > On 31 August 2012 15:33, Navin Kumar wrote: > > > >> Can we store m

[algogeeks] TRIE problem

2012-08-31 Thread Navin Kumar
Can we store multiple words in single TRIE node by using linked list or some other data structure. Based on the some property a node in TRIE will hold all the word with same property. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view

Re: [algogeeks] Re: give the algo or program to find second largest element in a list using tournament method

2012-08-30 Thread Navin Kumar
@sangeeta: n-1 comparison required to choose winner. By tournament approach winner has played match with logn team and winner must have beaten second largest element. So among logn number we can select maximum in logn - 1 comparison. So total comparison required is: n + logn -2 On Thu, Aug 30, 20

Re: [algogeeks] Amazon Q

2012-08-25 Thread Navin Kumar
Q1 Solution: . we can use doubly linked list with hash to implement all the operation in O(1). By keeping track of head and tail pointer we can do enqueue and dequeue in O(1) time. In hash we will keep track of each element present in linked list(queue). With node value as a hash key and address

Re: [algogeeks] MS interview

2012-08-24 Thread Navin Kumar
Anagram problem solution using TRIE.. For each word in dictionary we will put it in TRIE as.. 1. First sort the word 2. Search in trie using sorted word. If search found then we will add the original word in that TRIE node. 3. If node node not found then using simple TRIE insertion insert sorte

Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Few more Test cases : Check for 10 node. Check for 1 million node Check for even number of nodes Check for odd number of nodes... etc etc... On Fri, Aug 24, 2012 at 6:25 PM, Navin Kumar wrote: > Reversing a linked list if loop exists: > > 1. Find the node from which loop start by

Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Reversing a linked list if loop exists: 1. Find the node from which loop start by any loop finding algorithm in linked list and keep the position of that node. 2. Unroll the loop i.e. set the last node's(last unrepeating node) next pointer to NULL. 3. Reverse this singly linked list. 4. Change

Re: [algogeeks] MS interview

2012-08-22 Thread Navin Kumar
@Ashish: According to your algo making multimap itself takes O(mn) time complexity (preprocessing). After then getting anagram of a string takes O(n) time. Am i right? On Thu, Aug 23, 2012 at 6:51 AM, Ashish Goel wrote: > O(n) > convert each string into format a1b2and then insert into multim

Re: [algogeeks] Invert bits

2012-08-22 Thread Navin Kumar
x ^= 15; (^ = bit wise xor) On Wed, Aug 22, 2012 at 4:16 PM, Abhi wrote: > Write a one line code to invert the last four bits of an integer ? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web visit

Re: [algogeeks] Re: Printing random word from file

2012-08-19 Thread Navin Kumar
with probability 1/i. > When EOF is reached, every word in the file will have probability 1/n of > being the saved word. Print it. > > Dave > > On Saturday, August 18, 2012 1:28:56 AM UTC-5, Navin Kumar wrote: > >> Print a *Random word* from a file. Input is "path to a fi

[algogeeks] Printing random word from file

2012-08-17 Thread Navin Kumar
Print a *Random word* from a file. Input is "path to a file", constraints- No extra memory like hashing etc. All the words in the file should have equal probability. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion o

Re: [algogeeks] Re: MICROSOFT QUESTION

2012-08-16 Thread Navin Kumar
We have to consider cases when an element is zero. On Thu, Aug 16, 2012 at 7:07 PM, shady wrote: > well we can do with just one array. Overwrite the answer directly on > left[] array. > > > On Thu, Aug 16, 2012 at 6:47 PM, mohit wrote: > >> >> here are the steps : >> 1) Construct a temporary ar

Re: [algogeeks] Finding Minimum of the maximum values

2012-08-12 Thread Navin Kumar
on again and join us for solving the main problem > > > On Sun, Aug 12, 2012 at 4:19 PM, Navin Kumar wrote: > >> We can solve using Dynamic programming.. >> Take n*2 matrix for storing sum. Let A be original matrix and matrix M >> hold sum. Let M[i, j] cont

Re: [algogeeks] Finding Minimum of the maximum values

2012-08-12 Thread Navin Kumar
We can solve using Dynamic programming.. Take n*2 matrix for storing sum. Let A be original matrix and matrix M hold sum. Let M[i, j] contains max sum upto i th row and j th column. recursion will be as follows: M[i, j] = max(M[i - 1, j], M[i, j-1]) + A[i, j] By above formula fill whole M matrix

Re: [algogeeks] Data Cache implementation problem

2012-08-11 Thread Navin Kumar
I think best data structure would be "Optimal BST" On Fri, Aug 10, 2012 at 11:47 PM, Kumar Vishal wrote: > Huffman tree ??? > > > On Fri, Aug 10, 2012 at 11:38 PM, Varma Selvaraj wrote: > >> A data cache needs to be implemented for the top 100 data items selected >> based on their frequency

Re: [algogeeks] converting binary tree to BST

2012-08-08 Thread Navin Kumar
@vaibhav : yes it will be a balanced BST. On Wed, Aug 8, 2012 at 11:29 AM, vaibhav shukla wrote: > @Navin > > By your algo of starting with the middle node,I guess a balanced BST would > be created. Is it ? > > > On Wed, Aug 8, 2012 at 1:24 AM, Navin Kumar wrote: > >&g

Re: [algogeeks] Re: [Amazon] : constructing fully binary tree

2012-08-07 Thread Navin Kumar
vague . > > On Sunday, 15 July 2012 01:41:15 UTC+5:30, Navin Kumar wrote: > >> Given Preorder and postorder traversals of a tree. Device an algorithm to >> constuct a fully binary tree from these traversals. > > -- > You received this message because you are subscrib

Re: [algogeeks] converting binary tree to BST

2012-08-07 Thread Navin Kumar
1. Convert your Binary tree into doubly linked list. 2. Sort the linked list using merge sort 3. Build BST using doubly linked list by each time selecting middle node and recursively calling left part of linked list and right part of linked list. On Tue, Aug 7, 2012 at 10:23 PM, vaibhav shukla wro

Re: [algogeeks] merging

2012-08-05 Thread Navin Kumar
++]=arr[i]; > a[l++]=arr[j++]; > a[l++]=arr[k++]; > } > for(int i=0;i arr[i]=a[i]; > free(a); > } > cud be dun be dun recursively also to minimize d space complexity... > > > > > > On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar wrote: > >> In given

[algogeeks] Re: DE Shaw written test

2012-08-05 Thread Navin Kumar
This is a linear time constant space algorithm. Assume the stocks prices are given in an array where index represents the day no . For ex a[365] represents stock price on 365th day of year. Find the min and max element in the array. If the min comes before max, then return the dates- min to buy

[algogeeks] Amazon CodeSprint

2012-08-04 Thread Navin Kumar
Given the array of digits, you have to calculate the least positive integer value of the expression that could *NOT *have been received by you. The binary operators possible are *, +, -, / and brackets possible are ( and ). Note that / is an integer division i.e. 9/5 = 1. For ex- 6 6 4 4 the a

[algogeeks] merging

2012-08-03 Thread Navin Kumar
In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn]. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web

Re: [algogeeks] Microsoft first round interview question.

2012-08-02 Thread Navin Kumar
@sahil: Please elaborate your question. I didn't understand your question. what is straight doubly linked list?? How many pointers each node have?? On Thu, Aug 2, 2012 at 4:26 PM, Amit Basak wrote: > Does each node in the list have three pointers? > What do you mean by straight doubly link lis

Re: [algogeeks] Microsoft online questions

2012-08-01 Thread Navin Kumar
> using the DLL/array given ..? > > > On Tue, Jul 31, 2012 at 10:57 PM, manish untwal > wrote: > >> hey friends, >> just wanted to ask like what they ask in quants and DI >> >> >> On Tue, Jul 31, 2012 at 10:45 PM, Navin Kumar >> wrote

Re: [algogeeks] Re: coin problem

2012-07-31 Thread Navin Kumar
; I think we are blindfolded.. > how can we know afetr dividing 10 coins that 7 r heads.. or 'x' are heads > and we need to flip it over.. ? > > On Tuesday, 31 July 2012 12:33:09 UTC+5:30, Navin Kumar wrote: >> >> You are blindfolded and 20 coins are placed on the table i

Re: [algogeeks] Microsoft online questions

2012-07-31 Thread Navin Kumar
@Daksh: total number of BST possible with n nodes will be : catalan number we can build balanced BST by each time selecting middle element as a root node and its left pointer will point to left linked list and right pointer will point to right linked list. Do it recursively for left list and right

[algogeeks] coin problem

2012-07-31 Thread Navin Kumar
You are blindfolded and 20 coins are placed on the table in front of you. Out of them 10 coins have heads facing up and other tails. You are allowed to flip and move the coins. You should divide those coins into two sets such that one set contains 10 heads and other tails. You are allowed to on

[algogeeks] absolute minimum difference

2012-07-27 Thread Navin Kumar
Given array of integers (0 or +ve or -ve value) find two elements having minimum difference in their absolute values. e.g. Input {10 , -2, 4, 9,-20,17,-8,14,12) output {9,-8} I have solved it in O(nlogn). can it be solved in O(n). -- You received this message because you are subscribed to the G

Re: [algogeeks]

2012-07-25 Thread Navin Kumar
logic is very simple ...just trace the program you will understand. On Wed, Jul 25, 2012 at 7:28 PM, Navin Kumar wrote: > #include > #include > #include > > char *decrypt(char *s) > { > int n; > char *digit = (char *)malloc(sizeof(char) * 5); > char *p1 =

Re: [algogeeks]

2012-07-25 Thread Navin Kumar
#include #include #include char *decrypt(char *s) { int n; char *digit = (char *)malloc(sizeof(char) * 5); char *p1 = (char *)malloc(sizeof(char) * 1024); char *p = p1; char *digit2; char prev; prev = *s; *p++ = *s++; while(s != '\0') { if(isdigit(*s)) { d

[algogeeks] [amazon]: calculating resistance

2012-07-21 Thread Navin Kumar
Given a Circuit (with resistors), we need to calculate the total resistance. Input will be like AB-5ohm, BC-6ohm, BC-10ohm, BC-20 ohm, CD-5 ohm. BC has been repeated twice implying they are in parallel. "Write a program by implementing efficient data structure for storing and calculating the to

Re: [algogeeks] Anagram problem

2012-07-18 Thread Navin Kumar
he word(use quick sort(nlogn time))- and den >>>>> search using binary search(logn time) >>>>> or we can evn do by hashing-hash the word,den for every word keep >>>>> decreasing the counter,if the hash array is zero ,anagram,else reset the >>>

[algogeeks] Anagram problem

2012-07-17 Thread Navin Kumar
Assuming a preexisting list of 100 words, how would you efficiently see if a word received from input is an anagram of any of the 100 words? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://gr

Re: [algogeeks] Re: Appropriate data structure

2012-07-17 Thread Navin Kumar
; > On Saturday, July 14, 2012 2:55:48 PM UTC-5, Navin Kumar wrote: > >> A set of integer values are being received (1 per day). Store these >> values and at any given time, retrieve the min and max value over the last >> k days. What data structures would you use for stor

Re: [algogeeks] Appropriate data structure

2012-07-15 Thread Navin Kumar
rote: >> >> Min or max heap accordingly. This will do the job in O(log n) time. >> >> On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar wrote: >> >>> A set of integer values are being received (1 per day). Store these >>> values and at any given time, ret

[algogeeks] Remove duplicates from min-heap.

2012-07-14 Thread Navin Kumar
-- 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/-/lZRdyZn85fcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this gro

[algogeeks] [Amazon] : constructing fully binary tree

2012-07-14 Thread Navin Kumar
Given Preorder and postorder traversals of a tree. Device an algorithm to constuct a fully binary tree from these traversals. -- 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

[algogeeks] Appropriate data structure

2012-07-14 Thread Navin Kumar
A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups "A

Re: [algogeeks] Re: [Google] Finds all the elements that appear more than n/3 times

2012-07-11 Thread Navin Kumar
/3 times or more - O(n) *{mark >> for output if yes}* >> >> its 7*O(N) => O(N) solution. Constant space. >> >> we need not check further down or recursively. {why? reason it.. its >> simple} >> >> >> On Wednesday, 27 June 2012 18:35:12

Re: [algogeeks] Re: [Google] Finds all the elements that appear more than n/3 times

2012-07-11 Thread Navin Kumar
eck if median element is repeared n/3 times or more - O(n) *{mark >> for output if yes}* >> >> its 7*O(N) => O(N) solution. Constant space. >> >> we need not check further down or recursively. {why? reason it.. its >> simple} >> >> >> On

Re: [algogeeks] Re: seperate diff types of coins

2012-07-10 Thread Navin Kumar
@payal: In this case too i think minimum number of weighing required is 3. Slightly change in my previous solution. x1+x2+x3 = 3x and y1+y2+y3 = 3y. On Wed, Jul 11, 2012 at 8:00 AM, payal gupta wrote: > @ Dave sir > the balance considered here is simple balance scale incapable of > giving any

[algogeeks] Google : Print in interleaved fashion

2012-07-10 Thread Navin Kumar
Given two strings .Print all the interleavings of the two strings. Interleaving means that the if B comes after A .It should also come after A in the interleaved string. ex- AB and CD ABCD ACBD ACDB CABD CADB CDAB -- You received this message because you are subscribed to the Google Groups "Alg

Re: [algogeeks] seperate diff types of coins

2012-07-10 Thread Navin Kumar
ght will be either a or b. Depending upon outcome we will categorize them a and b. So 3 weighing is required. On Tue, Jul 10, 2012 at 7:05 PM, payal gupta wrote: > @navin...Sorry didnt get you how come u were able to segregate all the > coins by the proposed method?? > > > On 7/10/

Re: [algogeeks] seperate diff types of coins

2012-07-10 Thread Navin Kumar
Minimum no. weighings: Divide 8 coins in group of 3, 3 and 2. For minimum weighsing group1 's total weight is x units(say) -->FIrst weighing Groups 2nd total weights is y units > Second weighing. Lastly one more weighing among a unit and b unit coins.--->3 rd weighing So minimum

Re: [algogeeks] Re: Inversion problem

2012-07-08 Thread Navin Kumar
Thanx Deepika :) On Sun, Jul 8, 2012 at 11:48 AM, deepikaanand wrote: > http://www.geeksforgeeks.org/archives/3968 > > > On Jul 8, 11:01 am, Navin Kumar wrote: > > Let A[n] be an array of n distinct number. If i A[j] then > the > > pair (i , j) is called inve

[algogeeks] Inversion problem

2012-07-07 Thread Navin Kumar
Let A[n] be an array of n distinct number. If i A[j] then the pair (i , j) is called inversion of A. Give an algorithm that determines the total number of inversions in O(nlogn) time. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view

[algogeeks] simple FILE reading problem.

2012-07-04 Thread Navin Kumar
Suppose a file.txt contains : 50 40 30 # # 5 # 10 # # i want to fetch only integers. How should i fetch it. I tried with fgetc and fscanf but it was too complicated. My approach: fetched one word at a time and put it into separate string and then i converted that string to integer(if each chara

Re: [algogeeks] serialize a binary tree

2012-07-04 Thread Navin Kumar
we can serialize the binary tree using preorder traversal and marking NULL pointer as '#'. source: http://www.leetcode.com/2010/09/serializationdeserialization-of-binary.html On Wed, Jul 4, 2012 at 4:21 PM, Ashish Goel wrote: > my understanding is to either write the level order traversal notin

Re: [algogeeks] Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-04 Thread Navin Kumar
@Vindhya: BST can be reconstructed only by preorder traversal. In case of binary tree we need two traversal inorder and pre/post order On Wed, Jul 4, 2012 at 1:07 PM, vindhya chhabra wrote: > u need inoder traversal as well > > > On Wed, Jul 4, 2012 at 11:22 AM, Navin

[algogeeks] Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-03 Thread Navin Kumar
-- 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/-/xmZH9KY72_IJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this gro

[algogeeks] [Google] Finds all the elements that appear more than n/3 times

2012-06-27 Thread Navin Kumar
Design an algorithm that, given a list of n elements in an array, finds all the elements that appear more than n/3 times in the list. The algorithm should run in linear time ( n >=0 ). You are expected to use comparisons and achieve linear time. No hashing/excessive space/ and don't use stan

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Navin Kumar
whether it is in character array or integer array?? On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel wrote: > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > -- > You received this message because you are subscribed to the Google Groups >

[algogeeks] [amazon ] Finding Sub segment

2012-06-25 Thread Navin Kumar
please provide some good data structure to solve this problem: http://www.careercup.com/question?id=14062676 -- 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/algog

[algogeeks] Is max distance between two leaves(diameter) in a tree is equal to max distance between any two node in that tree??

2012-06-24 Thread Navin Kumar
-- 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/-/xM3mGdcfvi4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this gro

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Navin Kumar
Is longest path between two node in a tree is equal two logest path between two leaves?? On Sat, Jun 23, 2012 at 5:35 PM, Navin Kumar wrote: > Is this similar to finding the diameter of a tree(longest disteance > between two leaves) ?? If yes than visit this link > > http://www

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Navin Kumar
Is this similar to finding the diameter of a tree(longest disteance between two leaves) ?? If yes than visit this link http://www.cs.duke.edu/courses/spring00/cps100/assign/trees/diameter.html On Sat, Jun 23, 2012 at 2:44 PM, Avinash wrote: > Some how I found that we need to run bfs twice to ge

Re: [algogeeks] Programming Question

2012-06-22 Thread Navin Kumar
Extract words from file and make a BST. Then do inorder traversal and print them. On Fri, Jun 22, 2012 at 3:52 PM, Sourabh Singh wrote: > u can use stl::map(,vector) > idea is same bucket sort :-) > > On Fri, Jun 22, 2012 at 3:02 AM, Eshwar wrote: > > Bucket sort algortihm Linkedlist based > > >

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@Rishabh: i know using stack or recursion it can be done easily with O(n) space. I want to know whether there exist more space efficient algo for this problem or not? On Wed, Jun 20, 2012 at 9:20 PM, Rishabh Agarwal wrote: > @Navin: as you say "you have to take stack or some other data structure"

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
: > How ?? > I am asking to manipulate the same queue. > Dequeue n-1 elements and enqueue them in order to you take out to the same > queue..Where is extra space involved ? > > > On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar wrote: > >> @saurabh : i want solution with s

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh wrote: > Why will my proposed solution not work for you ??? > > > On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar wrote: >

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
ueue el > return nQ > end > return q > end > > > > On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: >> >> Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue >> etc >> >> On Wed, Jun 20, 2012 at 6:50 PM, a

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
gt; On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar wrote: > >> @Saurabh: queue will be remain unchanged according to your algorithm. >> Because if you will delete an element from front and add at rear no change >> will be there. After n iteration front will be pointing to same ele

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
, 2012 at 6:46 PM, Navin Kumar wrote: > @Saurabh: queue will be remain unchanged according to your algorithm. > Because if you will delete an element from front and add at rear no change > will be there. After n iteration front will be pointing to same element and > rear will also p

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
, Jun 20, 2012 at 6:39 PM, saurabh singh wrote: > count the size of queue : O(n) > loop for n and do remove and add in queue : O(n) > > Total : O(n) > > > On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar wrote: > >> How to reverse a Queue . >> >> Constraints: T

[algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to

Re: [algogeeks]

2012-06-19 Thread Navin Kumar
@Umer: rand(5) + (rand(5)%2): => it will never give 6 because for rand(7) range will be 0-6. So better try this: rand(5) + (rand(5)%3). On Tue, Jun 19, 2012 at 2:45 PM, Umer Farooq wrote: > rand(5) + (rand(5)%2); > > > On Tue, Jun 19, 2012 at 12:30 PM, Sourabh Singh > wrote: > >> @ sry >> cond

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
I corrected in function InsertAtBottom :"In my code isntead of (!IsEmptyStack) use IsEmptyStack" On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar wrote: > @all: > > In my code isntead of (!IsEmptyStack) use IsEmptyStack > > Logic : > > First pop the all element an

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
@all: In my code isntead of (!IsEmptyStack) use IsEmptyStack Logic : First pop the all element and then start putting element at bottom in reverse order i.e. the element which is fetched last is put at the bottom and so on. ex: let our stack is: 1 2 3 4 (1 is at bottom). function Call is will

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
void Reverse(struct Stack *S) { int data; if(IsEmptyStack(S)) return; data=pop(s); ReverseStack(S); InsertAtBottom(S, data); } void InsertAtBottom(struct stack *S, int data) { int temp; if(!IsEmptyStack(S)){ push(S,data); return; } temp=pop(S); Ins

Re: [algogeeks] [amazon]: dutch national flag algorithm

2012-06-10 Thread Navin Kumar
@Ashot: You can traverse array one time. In your case you are traversing twice. First for counting occurrence of R , G and B then again traversing for assigning values. But constraints is that you have to traverse only once. On Sun, Jun 10, 2012 at 5:13 PM, Akshat Sapra wrote: > int low,mid,hig

[algogeeks] [amazon]: dutch national flag algorithm

2012-06-09 Thread Navin Kumar
Given a character array as input. Array contains only three types of characters 'R', 'G' and 'B'. Sort the array such that all 'R's comes before 'G's and all 'G's comes before 'B's. Constraint :- No extra space allowed(except O(1) space like variables) and minimize the time complexity. You ca

[algogeeks] Word printing Program

2012-06-09 Thread Navin Kumar
Write an efficient program that prints the distinct words in its input sorted into decreasing order of frequency of occurrence. Precede each word by its count. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the

Re: [algogeeks] Re: wrong output of C program

2012-06-08 Thread Navin Kumar
ing 8 32 96...and dats the correction required which i made > > > On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar wrote: > >> @Mahendra: for ur above code with t=(a<<2)+a o/p will be 5,10, 15 as i >> explained above. without bracket answer will be 8 , 32 and 96 because + >

Re: [algogeeks] Re: wrong output of C program

2012-06-07 Thread Navin Kumar
@Mahendra: for ur above code with t=(a<<2)+a o/p will be 5,10, 15 as i explained above. without bracket answer will be 8 , 32 and 96 because + precedence is higher than <<. On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar wrote: > Cracked it...i guess precedence of + is more than << > so > use t=(

Re: [algogeeks] wrong output of C program

2012-06-07 Thread Navin Kumar
one left shift is equivalent to multiplying with 2.Two left is equivalent to multiplying with 2^2. and so on. so i left shift means multiplying with 2^i. In your program you did left shift with 2.so it is equivalent to multiplying with 4. so when input is 1 function will return 4*1+1=5. when input

  1   2   >