Re: [algogeeks] How to read multiple utf-8 encoded string from stdin

2013-11-24 Thread Karthikeyan V.B
From StackOverflow, --- fgets() can decode UTF-8 encoded files if you use Visual Studio 2005 and up. Change your code like this: infile = fopen(inname, r, ccs=UTF-8); On Sat, Nov 23, 2013 at 8:25 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: Q) *C

Re: [algogeeks] amazon f2f round question ..

2013-05-13 Thread Karthikeyan V.B
should be (a) - (b) -(c) now to convert into tree as you have mentioned above you have to remove edge (b)-(c). so output will be (a)-(b) or (a)-(c) which is wrong. On 5/12/13, Karthikeyan V.B kartmu...@gmail.com wrote: @atul anand : acyclic graph can be converted to a tree using prim/kruskal

Re: [algogeeks] amazon f2f round question ..

2013-05-12 Thread Karthikeyan V.B
will work if given graph is a binary tree. problem can be solved using dfs as suggested above On 5/11/13, Karthikeyan V.B kartmu...@gmail.com wrote: Since it is an acyclic graph, find the appropriate node that can be the root of this tree. Now apply the logic to find the diameter

Re: [algogeeks] amazon f2f round question ..

2013-05-11 Thread Karthikeyan V.B
Since it is an acyclic graph, find the appropriate node that can be the root of this tree. Now apply the logic to find the diameter of the tree here, which finds the longest path in the graph as follows: int diameter(Tree * t) { if (t == 0) return 0; int lheight = height(tree-left); int rheight

Re: [algogeeks] Re: Print tree node which sum

2013-03-09 Thread Karthikeyan V.B
Assuming the BST is balanced, 1.Convert BST to Sorted Doubly-Linked list in-place 2.have two pointers start and end at head and tail of the list repeat until start-data + end-data == sum increment start if start-data + end-data sum decrement end if start-data + end-data sum 3.print the values

Re: [algogeeks] MS Question:WAP to print last n lines of a log file

2013-03-04 Thread Karthikeyan V.B
int main() { int n=10; coutEnter the value of n:; cinn; int i=0; ifstream file(C:\\Users\\kvb\\Desktop\\sample.txt); string line; string buffer[n]; if(file.is_open()) { while(file.good()) { getline(file,line);

Re: [algogeeks] help with o/p why 0 comes???

2013-02-28 Thread Karthikeyan V.B
O/p will not be 0. 1.00 is the result which when read as %d takes the decimal value of float 1.00 stored in memory - it will not be 1.00 or 0. Since float is not stored as direct binary in memory as integer is stored, instead there's a separate procedure for storing float as binary

Re: [algogeeks] Re: FInd unique element.

2013-02-22 Thread Karthikeyan V.B
@Aditya : Since km and we need the element that apears exactly k times, i think u need to find the smallest number in the array and the corresponding index is the number that is repeated most number of times. -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Number of paths

2013-02-21 Thread Karthikeyan V.B
Assuming that u can either move down or right, Using Dynamic Programming, a DP equation can be framed like this : Paths[i][j] = paths[i][j-1] + paths[i-1][j] By filling the entire matrix, result will be in Paths[m-1][n-1]. -- You received this message because you are subscribed to the Google

Re: [algogeeks] FInd unique element.

2013-02-21 Thread Karthikeyan V.B
Assuming that : all numbers of the array range from [0,n-1] n being the size of the array Copy array A to B Make all integers negative Scan the array while B[B[i]] = B[B[i]] + n Now scan the array for the smallest non-negative element : element of original array having the index of the

[algogeeks] Please take 3 minutes to help change the world

2013-02-19 Thread Karthikeyan V.B
Hello , In the next 3 minute you will Help Solve the Water Crisis LET'S GO: https://waterforward.charitywater.org/4ZT6ToxZ - the charity: water team WaterForward, 387 Tehama Street, San Francisco, CA 94103, USA. Click here to unsubscribe:

Re: [algogeeks] Threaded binary Trees

2013-02-14 Thread Karthikeyan V.B
There are a couple of advantages : 1. efficiently determine the predecessor and successor nodes starting from any node. 2. Any node can be accessible from any other node. Many problems on tree use recursion / stack to solve But if the same problem when solved using threaded binary tree gives a

Re: [algogeeks] Suggested the Data Structure to implement the solution in O(1)

2013-01-09 Thread Karthikeyan V.B
Hi, Use hashing, but with perfect hashing which does all these operations in O(1). Refer to Introduction to Algorithms by CLRS to learn about perfect hashing. --

Re: [algogeeks] Re: sortin 2D array

2013-01-09 Thread Karthikeyan V.B
Merge pairs of rows until u get a single row, while merging remove the duplicates --

Re: [algogeeks] DBMS gate 2012 query

2013-01-01 Thread Karthikeyan V.B
Hi, Result of A U B has 5 tuples and C has 2 tuples. condition is either A.Id 40 or C.Id 15 First consider C.Id 15 : 1 tuple from C satisies this condition Hence join this 1 tuple with 5 tuples of A U B = 5 new tuples A.Id 40 yields 2 tuples from A U B - join this with the remaining tuple

Re: [algogeeks] Is a point inside a polygon?

2012-12-07 Thread Karthikeyan V.B
Find the number of intersections for a ray passing from the exterior of the polygon to the point needed. If odd, the point lies inside the polygon. If even, the point lies outside the polygon. On Thu, Dec 6, 2012 at 3:54 AM, Don dondod...@gmail.com wrote: Given a simple polygon (specified by

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 Karthikeyan V.B
@navin and @atul: inorder traversal without recursion and stack can be done using Morris traversal in O(1) space. Refer the following link for Morris traversal http://www.geeksforgeeks.org/archives/6358 now the problem takes O(n) time and O(1) space. -- You received this message because you

Re: [algogeeks] Anyone Please give the Oracle Tech,Oracle Server, Oracle Finance interview process. What is the pattern of the online test?? It's coming on 9th Sept in NIT DGP. Any help will be greatl

2012-09-04 Thread Karthikeyan V.B
Hi, 4 sections time 2 hrs Basic Aptitude - Quants, Data interpretation English - comprehension,verbal,etc. Basics of computer - OS,DS,DBMS Advanced computers - Advanced Data Structures -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

[algogeeks] Duplicate file in all computers in a network

2012-08-22 Thread Karthikeyan V.B
A network of N computers is such that each computer is connected to every other.Transferring one byte of information between two computers takes one unit of time. In the beginning, a file resides on only one computer on the network. The size of the file is M bytes. Come up with a strategy to

Re: [algogeeks] google paper

2012-08-12 Thread Karthikeyan V.B
Hi, Section A - objective type 10 technical questions in OS,Algorithms,DS,C. each carries one mark. no negative marks Section B - coding 2 questions first was very simple second - spiral level order traversal of a BST -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Fixing Up The Binary Search Tree

2012-06-29 Thread Karthikeyan V.B
calculate the balance factor for all nodes and find any node with factor 1 or factor -1 and perform AVL rotation from that node -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com.

Re: [algogeeks] Programming Question

2012-06-22 Thread Karthikeyan V.B
Tries -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at

Re: [algogeeks] 4Sum

2012-06-15 Thread Karthikeyan V.B
Complexity : O(n^3) import java.util.*; public class Solution { public ArrayListArrayListInteger fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayListArrayListInteger arr=new ArrayListArrayListInteger(); Arrays.sort(num); int

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

2012-06-14 Thread Karthikeyan V.B
Hi all, Generate combinations (taken k out of n) of a given string Eg: Input : abcd Output: abc acd abd bcd -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from

Re: [algogeeks] Allocating memory of size 0

2012-06-02 Thread Karthikeyan V.B
It does not return a valid address. The result of malloc(0) is implementation defined and therefore unreliable. Some compiler implementations will cause it to return a NULL pointer, others may return some other value (but it still can't/shouldn't be used to access memory). The memory cannot be

Re: [algogeeks] Algorithm Question

2012-05-23 Thread Karthikeyan V.B
Hi, k-way merge procedure of external sorting should be applied -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] symmetric binary tree

2012-05-23 Thread Karthikeyan V.B
Hi, bool issymmetric(node* root) { return ismirror(root,root); } bool ismirror(node* root1,node* root2) { if(!root1 || !root2) return root1==NULL root2==NULL; return root1-data==root2-data ismirror(root1-left,root2-right) ismirror(root1-right,root2-left); } -- You received this

Re: [algogeeks] Re: Required O(n) Algorithm

2012-04-18 Thread Karthikeyan V.B
Hi, Hashing can be used. Perfect/Universal hashing resolves collision and makes retrievals in constant time. for n elements it gives O(n) -- 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] google

2012-04-10 Thread Karthikeyan V.B
Hi, Regd OS, 1.deadlock 2.diff between linux, windows and solaris in terms of internals design 3.diff between mutex and semaphore 4.spin lock 5.interrupts 6.steps in page fault handling 6.steps involved in booting an os 7.what is kernel 8.paging segmentation 9.process scheduling algorithms

Re: [algogeeks] Re: m*n matrix, sorted rows, sorted columns, WAP to find an element efficiently

2012-04-03 Thread Karthikeyan V.B
Hi, Start from right top corner If matrix element key move to previous column else if matrix element key move to next row int search(int** a,int key,int m,int n) { if (key a[0][0] || key a[m-1][n-1]) return 0; int min=a[0][n-1],i=0,j=n-1; while(i=m-1 j=0) {

Re: [algogeeks] hadoop anyone?

2012-04-01 Thread Karthikeyan V.B
@Arun This is the java program to execute the fsck cmd from java pgm... If any problem pls let me know //code import java.io.*; public class JavaRunCommand { public static void main(String args[]) { String s = null; try { Process p =

Re: [algogeeks] hadoop anyone?

2012-03-31 Thread Karthikeyan V.B
Hi, The NameNode splits the job into several tasks and submits to the different DataNode(i.e nodes) , the split size varies from 64KB to 128MB. The NameNode assigns the data split to a datanod. Namenode actually has a table to store the mappings of data node and block stored in it. it is

Re: [algogeeks] hadoop anyone?

2012-03-31 Thread Karthikeyan V.B
@bharat : hadoop has a* job tracker* which *resolves the dependencies* and *splits the job into blocks* and *assigns to datanodes* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com.

Re: [algogeeks] hadoop anyone?

2012-03-31 Thread Karthikeyan V.B
Hi, use the following cmd on linux environment installed with hadoop stable api fsck -blocks -files -locations this cmd displays all the blocks - data node mappings. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

[algogeeks] Kruzade

2012-02-03 Thread Karthikeyan V.B
Hi, PSG College Of Technology,Coimbatore and Dept Of CSE conducts a National level technical symposium on Feb 25,26 Visit http://www.kruzade.org/ for more details There are more brainstorming technical events too Register asap... Regards, Karthikeyan.V.B III yr CSE PSG TECH CBE -- You

[algogeeks] Disjoint Set data structure

2012-01-30 Thread Karthikeyan V.B
Hi, The disjoint set data structure has FIND and UNION operations for optimized versions of Find we use path compression and for union we use union by rank, which costs O(M log* n) , n is the input size and M the no. of makeset opns. log* n is inverse ackermann's function Can anyone tell me

[algogeeks] Reverse Engg.

2012-01-30 Thread Karthikeyan V.B
hi, can anyone tell me how i can convert exe back to c source? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] suggest algo

2012-01-19 Thread Karthikeyan V.B
Hi, sorry i mis-understood the problem ll check and submit asap.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] suggest algo

2012-01-18 Thread Karthikeyan V.B
Hi, 1.find the sum of the digits of the number [acc. to fact that number+9 has the same sum of the digits as number] 2. for i=sum_of_the_digits_of_the_number; i=number; i=i+9 3.find if number is divisible by i then print it code: #includestdio.h int sum_of_the_digits(int n) { if(n==0)

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Karthikeyan V.B
Hi, Consider, arr1={1,2,3} and arr2={-1,-2,-3} using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since square of 1 and -1 is 1) so it won work with this case 1.better take the square and negate it before adding or 2.take sum of cubes pls correct me if i'm wrong Regards,

[algogeeks] PERFECT HASHING

2012-01-03 Thread Karthikeyan V.B
Hi, I have learnt insertion using perfect hashing. Can anyone pls provide me the pseudo code for delete and search operations using perfect hashing? Since it involves randomization , i don know how retrieval and delete can take place? Pls help me asap. Thanks in advance Regards,

Re: [algogeeks] Re: All possible permutations of a given string

2011-12-27 Thread Karthikeyan V.B
Hi, Using Backtracking, void swap(char* x,char* y) { char temp; temp=*x; *x=*y; *y=temp; } void permute(char* a,int i,int n) { int j; if(i==n) printf(%s\n,a); else { for(j=i;j=n;j++) { swap((a+i),(a+j)); permute(a,i+1,n); swap((a+i),(a+j)); } } } But this takes O(n*n!) time -- You received

[algogeeks] LINKED LIST

2011-12-24 Thread Karthikeyan V.B
Segregate even and odd psoitioned nodes in a linked list Eg: 2-3-1-9-7-5 The output should be two separate lists 2-1-7 3-9-5 *My code is:* void segregate(node* head) { int i=1; node* sec=head-next; node *odd=head,*even=head-next; while(even) { if(i%2) { odd-next=even-next; even-next=NULL;

Re: [algogeeks] addition of two numbers without using logical or arithmetic operators

2011-12-22 Thread Karthikeyan V.B
Hi, *int sum(int num1,int num2) { for(int i=0;inum2;i++) num1++; return num1; }* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe

Re: [algogeeks] Re: ACM-ICPC Kanpur 2011 LCM Extreme

2011-12-19 Thread Karthikeyan V.B
Hi, Facebook is conducting a Programming challenge through which u could get placed in it Pls login to ur account and visit Careers at the bottom and click Programming Challenge tab in it It's about 1 to 2 hrs. Some practise questions are also given... Regards, Karthikeyan.V.B PSG TECH, CBE

Re: [algogeeks] suggest algo

2011-12-18 Thread Karthikeyan V.B
Trie data structure can be used... In the trie, you can record item count in each node representing frequency of word consisting of characters on the path from root to current node. The time complexity to setup the trie is O(Ln) (where L is number of characters in the longest item). To find the

Re: [algogeeks] Re: doubt in TSUM

2011-12-18 Thread Karthikeyan V.B
Hi, Actually i m sorry since i didn explain the algo fully i checked with the code the o/p is: run: 6:1 7:0 8:1 9:2 10:2 11:1 12:1 13:1 14:1 where sum 9 has two triplets so,totally (1+0+1+2+2+1+1+1+1=10) Regards, KARTHIKEYAN.V.B PSG TECH CBE -- You received this message because you are

Re: [algogeeks] Re: doubt in TSUM

2011-12-17 Thread Karthikeyan V.B
Hi, *TSUM:* This is also a brute-force approach.. Pls correct me if i m wrong Algorithm: 1.sort the array 2.find the sum of the three min elements - sum_min 3.find the sum of the three max elements - sum_max 4.for each value in [sum_min,sum_max] binary search for the triplet int

Re: [algogeeks] Re: doubt in spoj 8473 ways

2011-12-16 Thread Karthikeyan V.B
Hi! Pls some problems related to 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Thanks To aLgOgEeKs

2011-12-02 Thread Karthikeyan V.B
Congratulations:) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit

Re: [algogeeks] Link list Q

2011-12-01 Thread Karthikeyan V.B
detects the loop in the 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For

Re: [algogeeks] Removing Duplicates In array and Linked list

2011-12-01 Thread Karthikeyan V.B
Hi, Create a binary search tree with elements , while inserting check for equal elements and delete it. But for insertion of n elements in a BST takes O(nlogn) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] Anagrams

2011-11-29 Thread KARTHIKEYAN V.B.
Find the set of anagrams from a file of english words [Hint: anagrams are permutation of the word eg: ate , eat , tea are all anagrams] in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Anagrams

2011-11-29 Thread Karthikeyan V.B
Hi, Thanks a lot... Regards, Karrthikeyan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] What is the difference between portability and Platform Independence??

2011-11-27 Thread Karthikeyan V.B
Hi, Portability focuses on *adaptation of software* in various OS, by recompiling the source to make the binary compatible with the target OS and not necessarily modifying the source. If the source code strictly follows POSIX standard less likely one end up modifying it. Platform independence

[algogeeks]

2011-11-27 Thread KARTHIKEYAN V.B.
Hi, Find the highest and second highest element in an array in O(n) time Input : arr[]={1,4,0,7,8,9} Output : 9 and 8 Thanx in advance Regards, Karthikeyan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Re: puzzle

2011-10-06 Thread KARTHIKEYAN V.B.
let no of boys be x and no of girls be y. then, x=y+1 2(y-1)=x solving these we get x=4,y=3 so,x+y=7 there are 7 children. am I right -- 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] New Group For Practicing and Learning Efficient Ways of Coding

2011-10-05 Thread KARTHIKEYAN V.B.
+1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at

Re: [algogeeks]

2011-10-04 Thread KARTHIKEYAN V.B.
This is the link for the book *http://www.4shared.com/document/_Y7p3MLT/Head_First_Servlets_and_JSP.html* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from

Re: [algogeeks] Amazon - array problem

2011-09-29 Thread KARTHIKEYAN V.B.
//use dynamic programming approach //it is O(n) time and O(1) space #includestdio.h #define N 5 void main() { int a[N]={1,2,3,4,5},i; int prod1[N]; int p=1; for(i=0;iN;++i) { prod1[i]=p; p*=a[i]; } int prod2[N]; p=1; for(i=N-1;i=0;--i) { prod2[i]=p; p*=a[i]; } int products[N];

Re: [algogeeks] Amazon Ques

2011-09-28 Thread KARTHIKEYAN V.B.
reversing the linked list static void reverse(struct node** head_ref) { struct node* p=NULL; struct node* curr=*head_ref; struct node* q; while(curr!=NULL) { q=curr-next; curr-next=p; p=curr; curr=q; } *head_ref=p; } -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] C++ Query

2011-09-19 Thread KARTHIKEYAN V.B.
Hi Can anyone say me which is the best hashing tecnicque which can store duplicates and minimize time complexity? Pls reply -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com.

Re: [algogeeks] Zig Zag tree traversal

2011-08-28 Thread KARTHIKEYAN V.B.
use one queue Enqueue all the nodes in normal level order traversal in the queue as 1 2 3 4 5 6 7 Each level contains 2 to the power n nodes in the queue. have two pointers ptr1 and ptr2 point ptr1 to the start node of 2 power n nodes range and ptr2 to the last node of this range. For odd