[algogeeks] Sum of weights

2013-09-11 Thread Azhar Hussain
We are given struct NodeProp { int id; int parent_id; int weight; }; Example: 100 {parent_id: -1, weight: 5} | 10 {parent_id: 100, weight: 3} | 5 {parent_id: 10, weight: 2} We have to print the sum of weights for each id For example if the id=5 parent_id- 10 and weight = 4 then id = 10

Re: [algogeeks] LEFT MOST set bit in an unsigned integer.

2012-06-14 Thread Azhar Hussain
unsigned int v; // 32-bit word to find the log base 2 of unsigned int r = 0; // r will be lg(v) while (v = 1) // unroll for more speed... { r++; } http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious - Azhar. On Thu, Jun 14, 2012 at 12:48 PM, Anika Jain

Re: [algogeeks]

2012-02-13 Thread Azhar Hussain
C, standard says which operand belongs to which operator. It does not says which one gets evaluated first. Why it is returning 8 is because of sequence point. It tells that, all the side effects of a value are resolved before an operation is performed. In your case ++i + ++i evaluates like this on

Re: [algogeeks] Re: Dynamic programming question

2011-12-22 Thread Azhar Hussain
The first problem I mentioned is a similar problem. but the second one seems to be little difficult. where additional path we could go is up. - Azhar. On Thu, Dec 15, 2011 at 10:17 PM, Dheeraj Jain dheerajj...@gmail.comwrote: http://www.geeksforgeeks.org/archives/14943 is a very similar

Re: [algogeeks] zig zag problem

2011-12-15 Thread Azhar Hussain
It is dynamic programming. Search in topcoder algo tutorials On Dec 16, 2011 10:33 AM, Sangeeta sangeeta15...@gmail.com wrote: Problem Statement A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative.

Re: [algogeeks] Re: Dynamic programming question

2011-12-14 Thread Azhar Hussain
contains a positive cycle, which doesn't apply here because once you pick up an apple, it's gone. On Dec 13, 7:17 am, vikas vikas.rastogi2...@gmail.com wrote: Graph take up, right and bottom as nodes connected to current and do find max path. On Dec 13, 3:44 pm, Azhar Hussain azhar

[algogeeks] Dynamic programming question

2011-12-13 Thread Azhar Hussain
We have apples arranged in a mxn matrix. We start from the upper left corner and have to reach bottom right corner with maximum apples. We can only move either down or right. Now if we can start any where in the matrix and have to reach anywhere on the right(reach n column). We can either up,

Re: [algogeeks] Re: Code it...

2011-10-19 Thread Azhar Hussain
I am not sure about the program to do it. But, 'strace' on linux would give the details of a program(parameters passed, retrun values, signals recieved etc). If you are looking for something similar then you can loot at strace source. mean while a.out does not not have information of stack

Re: [algogeeks] Segmentation fault with vfork

2011-09-21 Thread Azhar Hussain
Read this documentation http://pubs.opengroup.org/onlinepubs/7908799/xsh/vfork.html vfork creates read-only copy of the parent. You cannot call function or assign value to variable except pid_t. Use fork and it should succeed. PS: Please ask questions related to Algorithms, as it is algorithm

Re: [algogeeks] Re: Finding connection b/w 2 profiles

2011-09-14 Thread Azhar Hussain
Union Find Algorithm would do - Azhar. On Wed, Sep 14, 2011 at 1:42 PM, JITESH KUMAR jkhas...@gmail.com wrote: Neither depth is known nor we have to find the shortest path. We just have to find the path. -- *Regards Jitesh Kumar * -- You received this message because you are

Re: [algogeeks] OS question

2011-08-04 Thread Azhar Hussain
); /// here 'ls' will replace the child process no matter how many threads it has } else // parent wait for child } - Azhar. On Thu, Aug 4, 2011 at 9:50 PM, Azhar Hussain azhar...@gmail.com wrote: The *exec* family of functions shall replace the current process image with a new process image

Re: [algogeeks] OS question

2011-08-04 Thread Azhar Hussain
The *exec* family of functions shall replace the current process image with a new process image. It does not matter how many threads you have whole process gets replaced with new one. - Azhar. On Thu, Aug 4, 2011 at 8:27 PM, ankit sambyal ankitsamb...@gmail.comwrote: What happens when a

Re: [algogeeks] Novell - Technical Interview

2011-07-29 Thread Azhar Hussain
symbolic link /boot/vmlinuz will point to the actual kernel executable(or image). /lib/modules are modules that can be loaded if required. google for vmlinuz or lib modules for more info. - Azhar. On Fri, Jul 29, 2011 at 11:54 AM, Vishal Thanki vishaltha...@gmail.comwrote: For 2nd, Are you

Re: [algogeeks] Unique substring

2011-07-05 Thread Azhar Hussain
This link can be useful. http://geeksforgeeks.org/?p=12998 - Azhar. On Tue, Jul 5, 2011 at 11:31 AM, Akshata Sharma akshatasharm...@gmail.comwrote: someone please suggest me an efficient way to find the longest unique substring in a given string.. -- You received this message because you

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread Azhar Hussain
Q8 is a DP problem, here is the solution #include stdio.h #define MAX 125 #define VAL 6 int Min[MAX]; int N[VAL] = {5, 10, 20, 25, 50, 100}; int main(void) { int i, j; for (i = 1; i MAX; i++) Min[i] = 100; for (i = 5; i MAX; i += 5) for (j = 0; j VAL; j++)

Re: [algogeeks] Some adobe interview questions.

2011-07-05 Thread Azhar Hussain
Well that sounds interesting. You can read more info here http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=dynProg If you don't understand please explain which parts you don't understand. We can discuss it then. Its a bit of lengthy explanation about DP. Lots of websites have notes on it. -

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread Azhar Hussain
For Q4: I think this is the optimal code int recurPalin(char *start, char *end) { if (end start) return true; if (*start != *end) return false; return recurPalin(start+1, end-1); } - Azhar. On Tue, Jul 5, 2011 at 12:21 PM, vikas mehta...@gmail.com wrote: My

Re: [algogeeks] MS interview question

2011-06-02 Thread Azhar Hussain
struct node *reverse(struct node *head, int k ) { struct node *prev = NULL; struct node *current = head; struct node *next = NULL; int count = 0; while(current count k) { next = current-next; current-next = prev; prev = current; current = next; count++; } /*** reverse remaining nodes

Re: [algogeeks] please explain the output

2011-04-05 Thread Azhar Hussain
Few Important things about macros, before I explain the output 1. Macros are replaced in passes. 2. Macros are not recursive. regarding the output remember the rule for expansion A parameter in the replacement list, *UNLESS* preceded by a # or ## preprocessing token or followed by a ##

Re: [algogeeks] Synopsis Help ???

2011-01-16 Thread Azhar Hussain
Polish your Mathematical aptitude, basic data structures, matrices and linear programming(added advantage) might help - Azhar. On Sat, Jan 15, 2011 at 7:07 PM, Decipher ankurseth...@gmail.com wrote: Can anyone help me find some questions or post some questions on Synopsys(EDA tool-based

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread Azhar Hussain
represents the diagonal elements hope this gives some usefull info (i havent gone through any book nor do i guarantee optimal or best memory usage) On Wed, Jan 12, 2011 at 9:50 AM, Azhar Hussain azhar...@gmail.com wrote: I have a symmetric matrix. I am wondering what would be the best data

Re: [algogeeks] Symmetric matrix

2011-01-13 Thread Azhar Hussain
Thanks for the help. It may not be symmetric on a diagonal. I have to consider both situations - Azhar. On Thu, Jan 13, 2011 at 3:37 PM, juver++ avpostni...@gmail.com wrote: One-dimensional array. 1 2 4 2 3 5 4 5 6 = [1, 2, 3, 4, 5, 6] Is your matrix summetric on a diagonal? -- You

[algogeeks] Symmetric matrix

2011-01-11 Thread Azhar Hussain
I have a symmetric matrix. I am wondering what would be the best data structure to store such a matrix? How many elements do I need to store for a nxn matrix? Thanks in advance for the help. - Azhar. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] palindrome

2010-12-22 Thread Azhar Hussain
Hi, Here is the simple solution unsigned int r = v; // r will be reversed bits of v; first get LSB of v int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end for (v = 1; v; v = 1) { r = 1; r |= v 1;