Re: [algogeeks] Re: Given an array, find out if there exists a pair of nos. that adds up to a sum 'x'

2010-09-13 Thread Raj N
use mapint,bool S when you encounter a particular number check S[x-num] is true, if so return that pair. else S[num]=true On Sat, Sep 11, 2010 at 1:09 PM, topojoy biswas topojoy.bis...@gmail.comwrote: put all the numbers in a hash table( which demands O(n) space) and then pick each number in

[algogeeks] number of inversion pairs

2010-09-13 Thread Raj N
Given an array of n integers find all the inversion pairs in O(n) Inversion pair is one where a[i]a[j], ij -- 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

Re: [algogeeks] cyclic String

2010-09-13 Thread Raj N
Concatenate the string to itself and if the given string is a substring of the new concatenated string then it is a cyclic string On Sat, Sep 11, 2010 at 3:38 PM, Ashim Kapoor ashimkap...@gmail.com wrote: I can do it in 2 O(n)sweeps if all elements are distinct. 12345 23451 Sweep one to

[algogeeks] ternary numbers

2010-08-30 Thread Raj N
In ternary number representation, numbers are represented as 0,1,-1. (Here -1 is represented as 1 bar.) How is 352/9 represented in ternary number representation? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Will miracle ever print ?

2010-08-30 Thread Raj N
data = (int)0x8000; // Initialize data during run time if ( data == -data data!=0) printf (Miracle!!); } On 2010-8-28 1:45, Raj N wrote: int data; // Initialize data during run time if ( data == -data data!=0) printf (Miracle!!); Will miracle ever print

[algogeeks] akamai pattern

2010-08-28 Thread Raj N
Hi, Can anyone tell me the question paper pattern of akamai technologies ? What will the first written round consist of ? -- 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

[algogeeks] Will miracle ever print ?

2010-08-28 Thread Raj N
int data; // Initialize data during run time if ( data == -data data!=0) printf (Miracle!!); Will miracle ever print ? -- 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.

Re: [algogeeks] Help with Increment Operators in C!

2010-08-28 Thread Raj N
The output is undefined. Depends on the compiler. + is not a sequence point which may result in undefined behavior On Sat, Aug 28, 2010 at 5:05 PM, jagadish jagadish1...@gmail.com wrote: I ran this code.. int main() { int x=5; printf(%d,(x++ + ++x + x++)); } The output printed was 18

Re: [algogeeks] Re: linked list as tree

2010-08-25 Thread Raj N
structure and just fits computing on a tree structure. For more detailed introduction, please refer to Chapter 14.2 How to augment a data structure of the book Introduction to Algorithms, Second Edition, MIT Press. On Mon, Aug 23, 2010 at 6:50 PM, Raj N rajn...@gmail.com wrote: I came across

[algogeeks] National Instruments: points separated by a distance d

2010-08-25 Thread Raj N
Given location of huge number of points (you decide the data structure to represent them). Write a function that returns the number of points that are with distance D of a given point P. Write function, complete with what data structures, function signature etc. -- You received this message

Re: [algogeeks] Re: linked list as tree

2010-08-25 Thread Raj N
@TurksHead: No its linked list to tree On Wed, Aug 25, 2010 at 6:59 AM, TurksHead Education turksheadeducat...@gmail.com wrote: I hope you are not talking about converting a tree into a linked list http://www.rawkam.com/?p=1139 On Tue, Aug 24, 2010 at 7:20 AM, Raj N rajn...@gmail.com

Re: [algogeeks] National Instruments: linked list subtraction

2010-08-25 Thread Raj N
; } // Insert the new node result at the beginning of result list } Tell me if there're any corrections !! On Wed, Aug 25, 2010 at 3:24 PM, Raj N rajn...@gmail.com wrote: Input : Two large singly linked lists representing numbers with most significant digit as head and least significant as last node

Re: [algogeeks] Re: National Instruments: linked list subtraction

2010-08-25 Thread Raj N
@Hari: But I've not reversed the lists and I think my logic works. On Wed, Aug 25, 2010 at 6:47 PM, hari harihari1...@gmail.com wrote: I dont think it can be done without reversing the linked list!! On Aug 25, 2:54 pm, Raj N rajn...@gmail.com wrote: Input : Two large singly linked lists

Re: [algogeeks] Subsequence

2010-08-25 Thread Raj N
@Jaswanth: Your code nowhere checks the non-decreasing sequence On Tue, Aug 24, 2010 at 7:16 PM, Jashwant Raj jashuu...@gmail.com wrote: hope i got d logic right On Tue, Aug 24, 2010 at 9:55 AM, Rahul rv.wi...@gmail.com wrote: How to find out Non-Decreasing subsequence of length k with

Re: [algogeeks] National Instruments: linked list subtraction

2010-08-25 Thread Raj N
, Then take the difference numC = abs(numA - numB), Then convert numC to linked list with the digits any comments ?, overflow condition is the problem here. Thanks regards, Sathaiah Dontula On Wed, Aug 25, 2010 at 3:24 PM, Raj N rajn...@gmail.com wrote: Input : Two large singly linked lists

Re: [algogeeks] National Instruments: linked list subtraction

2010-08-25 Thread Raj N
@Terence: It is subtraction of 2 lists and not addition. N for your logic of addition for x9 you add px+1 and after that if it becomes 9 how do you know the previous of it as you've moved the previous pointer? Can someone comment on my logic ? On Wed, Aug 25, 2010 at 9:10 PM, Raj N rajn

Re: [algogeeks] Subsequence

2010-08-25 Thread Raj N
@Rahul: Input: 5 4 6 7 3 2 9 8 and if k=3 should the output be 4+6+7=11 ? Is that what you mean by non-decreasing ? On Wed, Aug 25, 2010 at 9:27 PM, Raj N rajn...@gmail.com wrote: @Jaswanth: Your code nowhere checks the non-decreasing sequence On Tue, Aug 24, 2010 at 7:16 PM, Jashwant Raj

Re: [algogeeks] National Instruments: linked list subtraction

2010-08-25 Thread Raj N
, 2010 at 8:18 PM, Raj N rajn...@gmail.com wrote: My approach: Use divide and conquer approach. i.e divide(a) divide(b) i.e first list and divide(c) divide(d) of second list recursively (like mergesort). Then apply subtract(a,c) and subtract(b,d) It goes this way: Make both lists of equal length

Re: [algogeeks] Re: Subsequence

2010-08-25 Thread Raj N
@Vikas: I want to know the same. On Wed, Aug 25, 2010 at 10:02 PM, Vikas Kumar dev.vika...@gmail.com wrote: can you define what here subsequence means? On Wed, Aug 25, 2010 at 9:32 PM, Rahul rv.wi...@gmail.com wrote: @Jaswanth It will be really kind if you will state the algorithm rather

Re: [algogeeks] Re: linked list as tree

2010-08-24 Thread Raj N
/child node. On Aug 23, 10:50 am, Raj N rajn...@gmail.com wrote: What will be the representation. How do you define left and right pointers of the tree for a linked list. On Mon, Aug 23, 2010 at 10:35 PM, Yan Wang wangyanadam1...@gmail.com wrote: Actually, a linear data structure like

Re: [algogeeks] Re: BST Problem

2010-08-23 Thread Raj N
Perform inorder traversal and store in an array. low = 0, high = size-1 while(low=high) { if ( a[low] + a[high] sum) low++; else if (a[low] + a[high] sum) high--; else return a[high] and [low] } On Mon, Aug 23, 2010 at 9:29 AM, R.ARAVINDH aravindhr...@gmail.com wrote: @giri: can

Re: [algogeeks] Re: To sort an array of 0,1,2

2010-08-23 Thread Raj N
Refer Dutch National Flag Algorithm On Mon, Aug 23, 2010 at 12:10 PM, Manjunath Manohar manjunath.n...@gmail.com wrote: is it possible to do without any extra space... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] linked list as tree

2010-08-23 Thread Raj N
Hi, Could anyone help me representing linked list in the form a binary tree ? Thanks !! -- 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

Re: [algogeeks] Sorting algorithm

2010-08-23 Thread Raj N
@Tanveer: Count sort is not in place. uses extra memory On Mon, Aug 23, 2010 at 4:32 PM, varun bhatia varunbhatia@gmail.comwrote: Who said count sort does not uses extra space??? As faras I know, it does need extra space to need thr frequency of each and every element within a given

Re: [algogeeks] linked list as tree

2010-08-23 Thread Raj N
What will be the representation. How do you define left and right pointers of the tree for a linked list. On Mon, Aug 23, 2010 at 10:35 PM, Yan Wang wangyanadam1...@gmail.comwrote: Actually, a linear data structure like a linked list is also a specific kind of tree structure. 2010/8/23 Raj N

Re: [algogeeks] Re: Adobe Questions

2010-08-22 Thread Raj N
2. Google dutch national flag problem. This has already been discussed. 3. *printLevelorder(tree)* bool ltr = 0; for d = 1 to height(tree) printGivenLevel(tree, d, ltr); ltr ~= ltr /*flip ltr*/ Function to print all nodes at a given level *printGivenLevel(tree, level)* if tree is

Re: [algogeeks] Algorithm to find all subsets of size K

2010-08-22 Thread Raj N
Generate all binary strings of length k. For eg: S={1,2,3,4,5} generate all binary strings of length 5. 0 represents that particular number is absent and 1 for the presence of the number. On Fri, Aug 13, 2010 at 11:35 PM, asdf gyanendra1...@gmail.com wrote: Most efficient algorithm to find all

Re: [algogeeks] Re: Permutation of Array.

2010-08-22 Thread Raj N
hence 12 should appear first. On Sun, Aug 22, 2010 at 12:39 PM, Raj N rajn...@gmail.com wrote: Take the input from the user of the min length number he would input i.e min_length. Then accept the the numbers in the form of strings and calculate the length of every number. Construct a binary

Re: [algogeeks] Re:

2010-08-22 Thread Raj N
Could anyone of you elaborate on how to implement the algo ? On Sun, Aug 22, 2010 at 11:56 AM, Ukil ukil.sou...@gmail.com wrote: use suffix trie. On Aug 16, 9:36 pm, ashita dadlani ash@gmail.com wrote: You have a string say foobarfoo in which fo and oo aree repeated twice.You have to

Re: [algogeeks] Re: Permutation of Array.

2010-08-22 Thread Raj N
Take the input from the user of the min length number he would input i.e min_length. Then accept the the numbers in the form of strings and calculate the length of every number. Construct a binary search tree with fields as follows: struct node { int number;// atoi(input) int remainder;

[algogeeks] Generate all bit strings of length n

2010-08-13 Thread Raj N
Hi, Can someone gimme the code to generate all possible bit strings of length n recursively ? -- 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

Re: [algogeeks] Copy Constructor

2010-08-13 Thread Raj N
This has already been discussed a lot many times. Please check older posts !! On Thu, Aug 12, 2010 at 3:44 AM, amit amitjaspal...@gmail.com wrote: why copy constructor must pass by reference? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Re: Median of two arrays..

2010-08-13 Thread Raj N
Can someone tell me what do you mean by median of 2 arrays ? Is it that the sorted arrays are merged and finding the median of resulting one? On Fri, Aug 13, 2010 at 1:32 AM, sachin sachin_mi...@yahoo.co.in wrote: If the ranges of the arrays are 1..n 1..m, then we can solve it this way

[algogeeks] closest pair problem

2010-08-11 Thread Raj N
Hi, Can someone give me the code for finding closest pair of points using divide and conquer strategy? Thanks !! -- 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

Re: [algogeeks] Copy Constructor and reference

2010-08-04 Thread Raj N
If it isn't passed by reference it goes to an infinite recursion. On Wed, Jul 21, 2010 at 12:08 AM, mallesh mallesh...@gmail.com wrote: In C++ Why is it that copy constructor uses only reference as parameter and not the actual class? I was given a hint that it has got something to do with

[algogeeks] interesting c++ questions

2010-08-04 Thread Raj N
1) Can a constructor call another constructor to initialize the same object? 2) Can a struct variable be assigned to another if the structure contains an array as a field? 3) Can we pass a private member by reference to a non member function? 4) Can the destructor be called explicitly? 5) Can copy

Re: [algogeeks] Associativity...............

2010-08-04 Thread Raj N
Both are unary operators and hence the associativity is from right to left. On Wed, Aug 4, 2010 at 8:31 AM, UMESH KUMAR kumar.umesh...@gmail.comwrote: How to decide associativity of the operation on operand so a simple Ex:- *ptr++ and ++*ptr how to work both ? --

[algogeeks] Initialization list

2010-08-04 Thread Raj N
Can someone tell me why the order of initialization in the initialization list of constructor, the order of declaration of data members in C++ ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Default arguments

2010-08-03 Thread Raj N
I wanted to know if the default arguments are pushed on the stack in c+ +? -- 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

[algogeeks] All about references

2010-08-03 Thread Raj N
1) Can we return a reference to an internal static variable in a function ? 2) Can we return a reference to a dynamic variable variable in a function ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] pointer and array

2010-08-03 Thread Raj N
array is passed a pointer in the function, hence sizeof(arr)==sizeof(*arr) On Fri, Jul 23, 2010 at 9:10 PM, tarak mehta tarakmeht...@gmail.com wrote: int arr[]={1,2,3,4}; k=sizeof(arr)/sizeof(*arr); value of k=4; however void hell(int arr[]); main() { int arr[]={1,2,3,4};

Re: [algogeeks] Boxes!!!

2010-07-21 Thread Raj N
This question has already been discussed. My solution goes like this Constructing trees... Box 1 dim: 7,8,9 Make it as root1. The root also has a counter associated with it. Now count1=1. Then Box 2 dim: 5,6,8 7,8,9. Make it as a left child of root1 and count1=2. Box 3 dim: 5,8,7 doesn't fit in

Re: [algogeeks] Re: isbst

2010-07-04 Thread Raj N
@Dheeraj: It would return false. Initially temp=12, next temp=14, then it'll compare 13temp and flag becomes 0 and hence not bst. Am I wrong ?? On Sun, Jul 4, 2010 at 10:01 AM, Dheeraj Jain dheerajj...@gmail.com wrote: @Raj N It won't work for the tree like. your method would return true

Re: [algogeeks] oops

2010-07-04 Thread Raj N
For the first question answer is 2 copy constructors are called. One when you call foo(*a) and the other when you are assigning object b to *a On Sun, Jul 4, 2010 at 8:49 PM, sharad sharad20073...@gmail.com wrote: 1)void foo(A a){} A* a =new A(); foo(*a); A b=*a; b=*a; How many copy ctors

Re: [algogeeks] Re: isbst

2010-07-03 Thread Raj N
According to me perform inorder traversal and at every point store the current element in a temporary variable and check if the next element obtained is greater than temp otherwise return false int temp=-; int flag=1; void isBst(NODE *tree) { if (tree!=NULL) {

[algogeeks] Insertion in a balanced BST

2010-07-03 Thread Raj N
Hi, Can someone provide me the code to perform insertion in balanced BST with proper explanation. Thanks !! -- 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

Re: [algogeeks] Binary trees with 3 nodes

2010-07-03 Thread Raj N
@sharad: Can you give a detailed explaination. Also it is required to print the possible trees On Sat, Jul 3, 2010 at 7:08 AM, sharad kumar aryansmit3...@gmail.comwrote: catalan numbers.(2n)Cn/(n+1) On Sat, Jul 3, 2010 at 1:06 AM, Raj N rajn...@gmail.com wrote: How to find all

Re: [algogeeks] microsoft interview(numbers)

2010-07-03 Thread Raj N
Every node can also have an index field. Keep a global variable index=0 After insertion of every new node do node-index=++index, and during the output compare the index values, the one which has a smaller value will come first. Modify the BST based on the count value obtained i.e insert the first

[algogeeks] Binary trees with 3 nodes

2010-07-02 Thread Raj N
How to find all the possible trees with 3 nodes from a given tree -- 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

Re: [algogeeks] complete binary tree

2010-06-30 Thread Raj N
Find the height of the tree. And start the traversal from root, if at any level height, its left or right child is NULL then it is not complete binary On Tue, Jun 29, 2010 at 11:34 PM, sharad kumar sharad20073...@gmail.comwrote: A *complete binary tree* is a binary tree in which every level,

[algogeeks] Difference between assignment operator and copy constructor

2010-06-29 Thread Raj N
Hi, Can anyone tell me the difference between using an assignment operator and copy constructor ? sample s1; sample s2; s2=s1; sample s3(s2); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] a bst

2010-06-29 Thread Raj N
, will the right pointer be NULL ? If yes, we need to chk for that also in the code. On Sun, Jun 27, 2010 at 6:47 PM, Raj N rajn...@gmail.com wrote: @Anand: Agreed. But according to this problem only the leaves form the doubly linked list On Sun, Jun 27, 2010 at 10:41 AM, Anand

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
-left... at this point u ll get height.. rite? On 26 June 2010 11:49, Raj N rajn...@gmail.com wrote: @Divya: What will happen when say node-right when you reach the leaves ? Is it equivalent to node-next and node-left = = node-previous in the doubly linked list ? On Tue, Jun 22, 2010 at 4

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
the solution traverse till node-right!=node-right-left... at this point u ll get height.. rite? On 26 June 2010 11:49, Raj N rajn...@gmail.com wrote: @Divya: What will happen when say node-right when you reach the leaves ? Is it equivalent to node-next and node-left = = node-previous in the doubly

Re: [algogeeks] a bst

2010-06-26 Thread Raj N
be used and hence the condition becomes node==node-right-left which is nothing but node==node-next-previous in doubly linked list terminology. I hope this is clear. On Sun, Jun 27, 2010 at 12:48 AM, Raj N rajn...@gmail.com wrote: @Algoose: Thanks for correcting it. Even I have made the same

Re: [algogeeks] Next higher element

2010-06-24 Thread Raj N
should be what (7 or 6 ) because 6 is more closer to 7 but 7 comes first in arr On Wed, Jun 23, 2010 at 11:18 AM, Raj N rajn...@gmail.com wrote: Design a data structure to find the next higher element for each element in an array. For e.g. if array is 1 2 3 4 5 8 6 o/p should be (element

Re: [algogeeks] linked list

2010-06-24 Thread Raj N
Keep a pointer list1 at the beginning of one of the lists, and call the function below on the other list. int reverseCheck(NODE *p) { list2=p; if(list2-next==NULL) return; reverseCheck(list2-next); if(list2-next-data==list1-data) list1=list1-next; else flag=0; return

[algogeeks] Trie

2010-06-24 Thread Raj N
Hi, Can anyone explain me the implementation of trie. I would be grateful if one could provide me the link to a good learning resource. Thanks!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Maximum size binary search tree

2010-06-23 Thread Raj N
Find the maximum size Binary search tree in a binary tree?? -- 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

[algogeeks] Maximum number of collinear points

2010-06-23 Thread Raj N
In a plane given n points (x1,y1) (x2,y2)(xn,yn), find the the maximum number of collinear points. -- 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

[algogeeks] Next higher element

2010-06-23 Thread Raj N
Design a data structure to find the next higher element for each element in an array. For e.g. if array is 1 2 3 4 5 8 6 o/p should be (element) (next higher element) 1 2 2 3 3 4 4 5 5 8 8 nothing 6 nothing The array need not be sorted. Constraints-O(n) time complexity -- You received this

[algogeeks] triplets summing to zero

2010-06-23 Thread Raj N
Given a list of n integers?(negative and positive), not sorted and duplicates allowed, you have to output the triplets which sum upto 0. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Maximum subset of cuboid boxes

2010-06-23 Thread Raj N
Given a lot of cuboid boxes with different length, breadth and height. We need to find the maximum subset which can fit into each other. For example: If Box 1 has LBH as 7 8 9 If Box 2 has LBH as 5 6 8 If Box 3 has LBH as 5 8 7 If Box 4 has LBH as 4 4 4 then answer is 1,2,4 A box can fit into

Re: [algogeeks] stack

2010-06-12 Thread Raj N
this behaviour of stack1 by using some tag. On Fri, Jun 11, 2010 at 10:19 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: @raj n for 2 stacks its fine can you please tell for 3 stacks ...i'll generalize it On Fri, Jun 11, 2010 at 9:32 PM, Anurag Sharma anuragvic...@gmail.comwrote: Is it without

Re: [algogeeks] Re: infix

2010-06-11 Thread Raj N
As you encounter the opening parentheses (,[,{ push them onto the stack. When you encounter closing parentheses pop the top element if it is not a matching parentheses then the expr is not valid. Finally after the input string is scanned, the stack has to be empty else expr is invalid. On Fri,

Re: [algogeeks] c output

2010-06-11 Thread Raj N
It will be c 1 6 2 6 and 2 because of newline On Fri, Jun 11, 2010 at 9:26 AM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: c 1 6,2 u might be expecting 5,1 if u are forgetting the newline character :) -- Rohit Saraf Second Year

[algogeeks] Print large Fibonacci numbers

2010-06-11 Thread Raj N
How to print very large Fibonacci numbers eg fib(1000). My approach: When any one of fib(i-1) or fib(i-2) has more than 12 or 13 digits, partition them into groups of 4 digits and put them in a linked list. fib(i-1) is put in list1, fib(i-2) in list2. Perform the addition of these long numbers and

[algogeeks] Common elements in 2 circular linked lists

2010-06-11 Thread Raj N
Given a circular linked list, what is the most efficient way of constructing a new list which contains the common elements between the 2 given lists. Is it sorting and then comparing ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

[algogeeks] concatenation of 2 circular linked lists

2010-06-11 Thread Raj N
Hi, I came across this statement that using circular lists, concatenation can be done without traversing either list. The same case with freeing the entire list. Can someone elaborate on this ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Derivation

2010-06-11 Thread Raj N
) and distance left to cover for Y= du/(u+v) time X will take to cover this distance= dv/(u*(u+v)) = a time Y will take to cover this distance= du/(v*(u+v)) = b = a : b = v^2 : u^2 = u : v = b^1/2 : a^1/2 hope its clear Anurag Sharma On Thu, Jun 10, 2010 at 11:05 PM, Raj N rajn

Re: [algogeeks] Re: c output

2010-06-11 Thread Raj N
@kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for '\n' so its 6 and for the next one 1+1=2 On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote: Output will be 1,1 bcoz printf returns number of characters or integers printed On Jun 11, 12:26

Re: [algogeeks] stack

2010-06-11 Thread Raj N
@jalaj: This question has already been discussed for n=2,3 On Fri, Jun 11, 2010 at 4:11 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Give an algorithm to implement n stacks in an array... take care of the empty space too i.e no overflow shld occur if there is eny empty space left .

Re: [algogeeks] sum to x

2010-06-11 Thread Raj N
@sharad: Does it have to return the first pair or all possible pairs ? On Fri, Jun 11, 2010 at 6:56 PM, sharad sharad20073...@gmail.com wrote: Given a large file, having N (N is very large) positive integers, how will you find a pair of numbers that add up to x (eg. 100). What data structure

Re: [algogeeks] Re: concatenation of 2 circular linked lists

2010-06-11 Thread Raj N
item and ending with the first item (if it is correct to say that you end traversing a circular list). Dave On Jun 11, 2:53 am, Raj N rajn...@gmail.com wrote: Hi, I came across this statement that using circular lists, concatenation can be done without traversing either list. The same case

Re: [algogeeks] Common elements in 2 circular linked lists

2010-06-11 Thread Raj N
@Anurag: Any other efficient way you can think of ? On Fri, Jun 11, 2010 at 9:30 PM, Anurag Sharma anuragvic...@gmail.comwrote: Ya that will do.. Anurag Sharma On Fri, Jun 11, 2010 at 7:08 PM, Raj N rajn...@gmail.com wrote: Given a circular linked list, what is the most efficient way

Re: [algogeeks] Print large Fibonacci numbers

2010-06-11 Thread Raj N
:) -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Fri, Jun 11, 2010 at 8:12 PM, Raj N rajn...@gmail.com wrote: How to print very large

[algogeeks] Derivation

2010-06-10 Thread Raj N
Can someone help me deriving this ? If 2 trains start at the same time from points A and B towards each other and after crossing they take a and b sec in reaching B and A respectively, then A's speed:B's speed=b^1/2:a^1/2 -- You received this message because you are subscribed to the Google

Re: [algogeeks] Single ordered list

2010-06-09 Thread Raj N
. On 8 June 2010 19:59, Raj N rajn...@gmail.com wrote: What is the most efficient way of combining 2 separate ordered list into a single ordered list ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] Single ordered list

2010-06-08 Thread Raj N
What is the most efficient way of combining 2 separate ordered list into a single ordered list ? -- 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,

[algogeeks] Variable number of integers

2010-06-08 Thread Raj N
What do you mean by a stack or a queue in which each item is a variable number number of integers? Is it a queue of a queue, queue of a stack etc -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: binary nos

2010-06-08 Thread Raj N
@Divya: That was the question i previously asked. If n=3 000,001,010,100,101 are valid. So the solution for this is fib(n+2). If n=4 no. of sequences will be fib(6) i.e 8 On Tue, Jun 8, 2010 at 9:31 AM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: getting fibonacci nos is trivial using matrix

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread Raj N
T(n) = fib(n+2) where fib = Fibonacci series which is interesting. On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote: @sharad: What about 101 even it doesn't have two 1's in a row On Sat, Jun 5, 2010 at 8:59 AM, sharad kumar aryansmit3...@gmail.comwrote: @rajn.can

[algogeeks] Time complexity

2010-06-08 Thread Raj N
What is the time complexity of insertion and deletion in 1. Linked list 2. Queue 3. Queue implemented using a linked list -- 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

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread Raj N
shoonya.mo...@gmail.comwrote: @Raj, no they are not same case 1: i is const case 2: ptr is const and whatever is const cann't be modified Mohit Ranjan On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5

Re: [algogeeks] Pointer to a constant

2010-06-08 Thread Raj N
Mohit Ranjan On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5; 2) int i=5; int *ptr=i; const int *ptr=i; In the first case i can be modified via ptr

Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-08 Thread Raj N
wrote: it might be referring to no of sequences (say T(n) ) with no consecutive 1's for n = 3, ans would be 5 viz. 000, 001, 010, 100, 101 T(n) = fib(n+2) where fib = Fibonacci series which is interesting. On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote: @sharad: What

[algogeeks] Pointer to a constant

2010-06-07 Thread Raj N
Can someone tell me the difference between 1) const int i=5; 2) int i=5; int *ptr=i; const int *ptr=i; In the first case i can be modified via ptr i.e *ptr++ is valid. In the second case *ptr++ is illegal. Why is that so? Aren't

Re: [algogeeks] ds

2010-06-07 Thread Raj N
@sain: But the question demands O(n) time On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote: Here is my approach is o(n). http://codepad.org/YAFfZpxO http://codepad.org/YAFfZpxO On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote: this is ques by

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
Ok this is just counting now how to do the same to print all possibilities? On Mon, Jun 7, 2010 at 1:14 PM, Raj N rajn...@gmail.com wrote: @Dave: Hey i'm finding little difficulty in understanding the 3rd condition - p(*k*,*n*) = 0 if *k* *n* - p(*k*,*n*) = 1 if *k* = *n* - p

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
of partitions of n is given by the partition function p(n). You can compute p(n) recursively. See http://en.wikipedia.org/wiki/Partition_(number_theory)http://en.wikipedia.org/wiki/Partition_%28number_theory%29 . Dave On Jun 6, 2:05 pm, Raj N rajn...@gmail.com wrote: How do you count

Re: [algogeeks] Re: Can you count?

2010-06-07 Thread Raj N
. Dave On Jun 6, 2:05 pm, Raj N rajn...@gmail.com wrote: How do you count the number of ways a number can be expressed as a sum of 2 or more numbers? For eg. if the number is 5 , count=3 i.e 1+1+1+1+1, 4+1, 3+2 note 2+3 is same as 3+2 -- You received this message because you are subscribed

Re: [algogeeks] Re: array question

2010-06-07 Thread Raj N
@Anand :Your approach will turn out very crude if elements are something like 1000, 2000 keeping an array i.e count[1000] is not feasible. I think souravsain's approach is better. On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote: Here is my approch which runs in O(n).

Re: [algogeeks] Pointer to a constant

2010-06-07 Thread Raj N
1) const int i=5;2) int i=5; int *ptr=i; const int*ptr=i; On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5

[algogeeks] Modified Tower of Hanoi

2010-06-06 Thread Raj N
Here is a modified version tower of hanoi. Along with usual tower of hanoi conditions there ia also a condition that a disk cannot rest over another disk that is more than one size larger. For eg disk 2 may rest on disk 3 but not on disk 4. How to make changes to the existing algo to incorporate

[algogeeks] Can you count?

2010-06-06 Thread Raj N
How do you count the number of ways a number can be expressed as a sum of 2 or more numbers? For eg. if the number is 5 , count=3 i.e 1+1+1+1+1, 4+1, 3+2 note 2+3 is same as 3+2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Product Array

2010-06-05 Thread Raj N
Given an array arr[] of n integers, construct a Product Array prod[] (of same size) such that prod[i] is equal to the product of all the elements of arr[] except arr[i]. Solve it without division operator and in O(n). Can someone explain me the logic. Thanks!! -- You received this message

[algogeeks] Recursion help!

2010-06-04 Thread Raj N
int Max(int a[],int n) { int max; if(n==1) return a[0]; else max=Max(a,n-1); if(maxa[n-1]) return max; else return a[n-1]; } Hi, the above is a code to find the max in an array recursively. I

[algogeeks] Print the string in reverse order (not revstr

2010-06-04 Thread Raj N
If I've a string like It is a fine morning, the algorithm has to print morning fine a is It and not gninrom enif a si tI The algo has to do this in linear time. Can someone help me out in this -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Print the string in reverse order (not revstr)

2010-06-04 Thread Raj N
If I've a string like It is a fine morning, the algorithm has to print morning fine a is It and not gninrom enif a si tI The algo has to do this in linear time. Can someone help me out in this -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row

2010-06-04 Thread Raj N
Hi, I came across this question to find the number of sequences of n binary digits that don't contain 2 1's in a row. I wanted to know what exactly this means. Is it like if n=3 then compute all binary numbers having 3 digits which don't have consecutive 1's 110, 011, 111 ?? If not help me

  1   2   >