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 sahilgupta...@gmail.comwrote: It's b. Windows follow this Operation. On Fri, Dec 7, 2012 at 4:21 AM, manish

Re: [algogeeks] Microsoft Interview Question

2012-10-18 Thread Navin Kumar
this. because we are maintaining only one visited matrix. On Wed, Oct 17, 2012 at 7:54 AM, Navin Kumar algorithm.i...@gmail.comwrote: @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

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
=sizeof(arr)-1; do { if(elem==arr[n]) print found; n--; }while(n); On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar algorithm.i...@gmail.comwrote: @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

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 atul.87fri...@gmail.com wrote: n=sizeof(arr); n--; while(n) { if(elem=arr[n])

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

2012-09-23 Thread Navin Kumar
On Sun, Sep 23, 2012 at 5:08 PM, Navin Kumar algorithm.i...@gmail.comwrote: 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

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

2012-09-21 Thread Navin Kumar
-5, Navin Kumar wrote: @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 dave_an...@juno.com wrote: @Bharat: Simulate long division, dividing a number ...1 by the number. You can do this one digit at a time

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 dave_and_da...@juno.com wrote: @Bharat: Simulate long division, dividing a number ...1 by the number. You can do this one digit at a time, printing the

[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 to

Re: [algogeeks] Data Structure

2012-09-18 Thread Navin Kumar
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 algorithm.i...@gmail.comwrote: Which data structure is used to maintain browser history? -- You received this message because you

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

2012-09-11 Thread Navin Kumar
it dynamically changing leads lot of other questions before going give algo . On Sat, Sep 8, 2012 at 7:43 PM, Navin Kumar algorithm.i...@gmail.comwrote: 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

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

2012-09-11 Thread Navin Kumar
...@gmail.com wrote: 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 On Tue, Sep 11, 2012 at 2:07 PM, Navin Kumar algorithm.i

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 atul.87fri...@gmail.com 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,

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

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 kartmu...@gmail.com wrote: @navin and @atul: inorder traversal without recursion and stack can be done using

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
to sorted DLL.. now it is a double linked list , so we can find 2 number in O(n) time by keeping 2 pointers(one at start and one at end) from sorted DLL. now convert DLL to BST. On Mon, Sep 3, 2012 at 1:32 AM, Navin Kumar algorit...@gmail.comwrote: MICROSOFT:Given a BST and a number. Find two node

[algogeeks] Contiguous Sub sequence

2012-09-02 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 to

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
as the difference 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 algorithm.i...@gmail.com wrote: Given an unsorted

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

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
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 algorithm.i...@gmail.com wrote: @pradip: Finding same element in temp array is little bit tricky. For displaying

Re: [algogeeks] Contiguous Sub sequence

2012-09-02 Thread Navin Kumar
or notwhich will be O(n). On 9/2/12, Navin Kumar algorithm.i...@gmail.com 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, Carl Barton odysseus.ulys

[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

Re: [algogeeks] TRIE problem

2012-09-01 Thread Navin Kumar
no reason 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 algorithm.i...@gmail.com wrote: Can we store multiple words in single TRIE node by using linked list

[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,

Re: [algogeeks] Amazon Q

2012-08-26 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 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 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 algorithm.i...@gmail.comwrote: Reversing a linked list if loop exists: 1. Find the node from which loop

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

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 abhi120@gmail.com 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

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 ashg...@gmail.com wrote: O(n) convert each string into format a1b2and then

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 file, constraints- No extra memory like

[algogeeks] Printing random word from file

2012-08-18 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 on

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 sinv...@gmail.com 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 mohitsingh1...@gmail.com wrote: here are the steps

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

Re: [algogeeks] Finding Minimum of the maximum values

2012-08-12 Thread Navin Kumar
the question again and join us for solving the main problem On Sun, Aug 12, 2012 at 4:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: 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

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 kumar...@gmail.com wrote: Huffman tree ??? On Fri, Aug 10, 2012 at 11:38 PM, Varma Selvaraj varm...@gmail.comwrote: A data cache needs to be implemented for the top 100 data items selected

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 vaibhav200...@gmail.comwrote: @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 algorithm.i

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

[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

Re: [algogeeks] merging

2012-08-05 Thread Navin Kumar
++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;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 algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1

[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

[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 abas...@gmail.com wrote: Does each node in the list have three pointers? What do you mean by straight

Re: [algogeeks] Microsoft online questions

2012-08-01 Thread Navin Kumar
can get using the DLL/array given ..? On Tue, Jul 31, 2012 at 10:57 PM, manish untwal manishuntw...@gmail.comwrote: 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 algorithm.i...@gmail.comwrote: @Daksh: total number

[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

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

Re: [algogeeks] Re: coin problem

2012-07-31 Thread Navin Kumar
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 in front of you. Out of them 10 coins

[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

Re: [algogeeks]

2012-07-25 Thread Navin Kumar
#include stdio.h #include stdlib.h #include ctype.h 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') {

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 algorithm.i...@gmail.comwrote: #include stdio.h #include stdlib.h #include ctype.h char *decrypt(char *s) { int n; char *digit = (char *)malloc(sizeof(char) * 5); char

[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

Re: [algogeeks] Anagram problem

2012-07-18 Thread Navin Kumar
18, 2012 at 2:07 AM, Navin Kumar algorithm.i...@gmail.com wrote: 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

Re: [algogeeks] Re: Appropriate data structure

2012-07-17 Thread Navin Kumar
, 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 storing and retrieving ? -- You received this message

[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

Re: [algogeeks] Appropriate data structure

2012-07-15 Thread Navin Kumar
wrote: 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 algorithm.i...@gmail.comwrote: 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

[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

[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

[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

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

2012-07-11 Thread Navin Kumar
need not check further down or recursively. {why? reason it.. its simple} On Wednesday, 27 June 2012 18:35:12 UTC-4, Navin Kumar wrote: 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

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

2012-07-11 Thread Navin Kumar
or recursively. {why? reason it.. its simple} On Wednesday, 27 June 2012 18:35:12 UTC-4, Navin Kumar wrote: 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

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 3

Re: [algogeeks] seperate diff types of coins

2012-07-10 Thread Navin Kumar
. 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 gpt.pa...@gmail.com wrote: @navin...Sorry didnt get you how come u were able to segregate all the coins by the proposed method?? On 7/10/12, Navin Kumar

[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

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 gpt.pa...@gmail.com wrote: @ Dave sir the balance considered here is simple balance scale

[algogeeks] Inversion problem

2012-07-08 Thread Navin Kumar
Let A[n] be an array of n distinct number. If ij and A[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

Re: [algogeeks] Re: Inversion problem

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

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 vindhyachha...@gmail.comwrote: u need inoder traversal as well On Wed, Jul 4, 2012 at 11:22 AM, Navin Kumar

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 ashg...@gmail.com wrote: my understanding is to either write the level

[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

[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

[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

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 ashg...@gmail.com 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

[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

[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

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 jain.av...@gmail.com wrote: Some how I found that we need to

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 algorithm.i...@gmail.comwrote: Is this similar to finding the diameter of a tree(longest disteance between two leaves) ?? If yes than visit this link http

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 singhsourab...@gmail.comwrote: u can use stl::map(string,vectorstring) idea is same bucket sort :-) On Fri, Jun 22, 2012 at 3:02 AM, Eshwar eshwaronl...@gmail.com

[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] Reverse Queue

2012-06-20 Thread Navin Kumar
, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: 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 algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
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, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we

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 saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
saurabh.n...@gmail.comwrote: 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 algorithm.i...@gmail.comwrote: @saurabh : i want solution

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 rishabh...@gmail.comwrote: @Navin: as you say you have to take stack or some

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 the.um...@gmail.com wrote: rand(5) + (rand(5)%2); On Tue, Jun 19, 2012 at 12:30 PM, Sourabh Singh

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);

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
I corrected in function InsertAtBottom :In my code isntead of (!IsEmptyStack) use IsEmptyStack On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar algorithm.i...@gmail.comwrote: @all: In my code isntead of (!IsEmptyStack) use IsEmptyStack Logic : First pop the all element and then start putting

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 sapraaks...@gmail.com

[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

[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

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

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

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

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

2012-06-07 Thread Navin Kumar
@Mahendra: for ur above code with t=(a2)+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 sengar.m...@gmail.comwrote: Cracked it...i guess precedence of + is more than

Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
#include stdio.h #include stdlib.h #include sys/types.h #include dirent.h #include unistd.h #include ctype.h #include string.h void dirfun(char *); int main() { char *home=/home/navin/temp/; dirfun(home); return 0; } void dirfun(char *path) { struct dirent

Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
you can set your directory path in this line char *home=/home/navin/temp/; On Sun, Jun 3, 2012 at 11:26 AM, Navin Kumar algorithm.i...@gmail.comwrote: #include stdio.h #include stdlib.h #include sys/types.h #include dirent.h #include unistd.h #include ctype.h #include string.h void

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Navin Kumar
I think the easiest method to do this problem is this: http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html On Thu, May 31, 2012 at 5:58 PM, Ashish Goel ashg...@gmail.com wrote: that is what i have done by using recursion=stack. my code has problem, after

  1   2   >