Re: [algogeeks] How to read multiple utf-8 encoded string from stdin
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 program* that reads multiple UTF-8 encoded strings from STDIN (1 > string per line), count all *non-ascii* characters (ascii characters are > with ordinal decimal 0 to 127) and print the total non-ascii character > count to STDOUT (1 number per line). > > Contraint : > > >- You cannot use any *wchar.h* service in your program. >- The UTF-8 strings supplied to you can have *1 or more whitespaces* in >them. >- No input string will have a character length greater than*200 *(including >spaces) >- You will be given multiple lines of input (1 string per line). >- Input will be limited to UTF-8 encoded strings and will not contain >any garbage values. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to algogeeks+unsubscr...@googlegroups.com. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] amazon f2f round question ..
@atul anand : got it thanks for pointing it out On Mon, May 13, 2013 at 12:19 AM, atul anand wrote: > @Karthikeyan : Given graph is directed and does not carry edge > weight.So you cannot use pris/kruskal algo to convert them to > tree.Even if you tweak prism/krukal algo to form a tree , you can > never guarantee that each node will have only 2 child , it can have > more than 2 children.So your terminology of using t-.left and t->right > wont work here.nevertheless it will fail for simple cases mentioned > below :- > > given graph :- > > (a)->(b) > (a)->(c) > (b)->(c) > > output 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 wrote: > > @atul anand : acyclic graph can be converted to a tree using prim/kruskal > > or by finding an appropriate node that can act like the root of a tree > > > > > > On Sun, May 12, 2013 at 5:55 PM, atul anand > > wrote: > > > >> @karthikeyan : It is an acyclic graph not a binary tree. your solution > >> 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 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 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 = height(tree->right); int ldiameter = > >> > diameter(tree->left); int rdiameter = diameter(tree->right); return > >> > max(lheight + rheight + 1, max(ldiameter,rdiameter)); } > >> > int height(Tree * t) > >> > { > >> > if (t == 0) > >> > { return 0; } else { return 1 + max(height(t->left),height(t->right)); > >> > } > >> } > >> > > >> > > >> > On Sat, May 11, 2013 at 10:59 PM, Aman Jain > >> wrote: > >> > > >> >> In a connected and acyclic graph,that is a tree, we can apply this > >> >> approach > >> >> 1. apply *dfs *on any random node and find the longest distant node > >> >> from > >> >> this node.Let us say this node i*s u*. > >> >> 2. from this no*de u*, again apply* dfs* to find longest distant node > >> >> from this node.Let us say that node is v. > >> >> (u,v) is the required pair of nodes. > >> >> > >> >> > >> >> > >> >> On Sat, May 11, 2013 at 7:16 PM, MAC wrote: > >> >> > >> >>> Given an acyclic graph. Give an algorithm to find the pair of nodes > >> >>> which > >> >>> has the maximum distance between them, i.e. the maximum number of > >> >>> edges > >> >>> in > >> >>> between them > >> >>> > >> >>> > >> >>> any suggestion ? > >> >>> > >> >>> > >> >>> thanks > >> >>> --mac > >> >>> > >> >>> -- > >> >>> You received this message because you are subscribed to the Google > >> >>> Groups > >> >>> "Algorithm Geeks" group. > >> >>> To unsubscribe from this group and stop receiving emails from it, > >> >>> send > >> >>> an > >> >>> email to algogeeks+unsubscr...@googlegroups.com. > >> >>> > >> >>> > >> >>> > >> >> > >> >> -- > >> >> You received this message because you are subscribed to the Google > >> Groups > >> >> "Algorithm Geeks" group. > >> >> To unsubscribe from this group and stop receiving emails from it, > send > >> an > >> >> email to algogeeks+unsubscr...@googlegroups.com. > >> >> > >> >> > >> >> > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "Algorithm Geeks" group. > >> > To unsubscribe from this group and stop receiving emails from it, send > >> > an > >> > email to algogeeks+unsubscr...@googlegroups.com. > >> > > >> > > >> > > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Algorithm Geeks" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to algogeeks+unsubscr...@googlegroups.com. > >> > >> > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to algogeeks+unsubscr...@googlegroups.com. > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to algogeeks+unsubscr...@googlegroups.com. > > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] amazon f2f round question ..
@atul anand : acyclic graph can be converted to a tree using prim/kruskal or by finding an appropriate node that can act like the root of a tree On Sun, May 12, 2013 at 5:55 PM, atul anand wrote: > @karthikeyan : It is an acyclic graph not a binary tree. your solution > 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 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 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 = height(tree->right); int ldiameter = > > diameter(tree->left); int rdiameter = diameter(tree->right); return > > max(lheight + rheight + 1, max(ldiameter,rdiameter)); } > > int height(Tree * t) > > { > > if (t == 0) > > { return 0; } else { return 1 + max(height(t->left),height(t->right)); } > } > > > > > > On Sat, May 11, 2013 at 10:59 PM, Aman Jain > wrote: > > > >> In a connected and acyclic graph,that is a tree, we can apply this > >> approach > >> 1. apply *dfs *on any random node and find the longest distant node from > >> this node.Let us say this node i*s u*. > >> 2. from this no*de u*, again apply* dfs* to find longest distant node > >> from this node.Let us say that node is v. > >> (u,v) is the required pair of nodes. > >> > >> > >> > >> On Sat, May 11, 2013 at 7:16 PM, MAC wrote: > >> > >>> Given an acyclic graph. Give an algorithm to find the pair of nodes > >>> which > >>> has the maximum distance between them, i.e. the maximum number of edges > >>> in > >>> between them > >>> > >>> > >>> any suggestion ? > >>> > >>> > >>> thanks > >>> --mac > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > >>> Groups > >>> "Algorithm Geeks" group. > >>> To unsubscribe from this group and stop receiving emails from it, send > >>> an > >>> email to algogeeks+unsubscr...@googlegroups.com. > >>> > >>> > >>> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Algorithm Geeks" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to algogeeks+unsubscr...@googlegroups.com. > >> > >> > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to algogeeks+unsubscr...@googlegroups.com. > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to algogeeks+unsubscr...@googlegroups.com. > > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] amazon f2f round question ..
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 = height(tree->right); int ldiameter = diameter(tree->left); int rdiameter = diameter(tree->right); return max(lheight + rheight + 1, max(ldiameter,rdiameter)); } int height(Tree * t) { if (t == 0) { return 0; } else { return 1 + max(height(t->left),height(t->right)); } } On Sat, May 11, 2013 at 10:59 PM, Aman Jain wrote: > In a connected and acyclic graph,that is a tree, we can apply this approach > 1. apply *dfs *on any random node and find the longest distant node from > this node.Let us say this node i*s u*. > 2. from this no*de u*, again apply* dfs* to find longest distant node > from this node.Let us say that node is v. > (u,v) is the required pair of nodes. > > > > On Sat, May 11, 2013 at 7:16 PM, MAC wrote: > >> Given an acyclic graph. Give an algorithm to find the pair of nodes which >> has the maximum distance between them, i.e. the maximum number of edges in >> between them >> >> >> any suggestion ? >> >> >> thanks >> --mac >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to algogeeks+unsubscr...@googlegroups.com. >> >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to algogeeks+unsubscr...@googlegroups.com. > > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] Re: Print tree node which sum
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 of (start->data , end->data) Regards, Karthikeyan -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] MS Question:WAP to print last n lines of a log file
int main() { int n=10; cout<<"Enter the value of n:"; cin>>n; 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); buffer[i++%n]=line; } file.close(); } for(int j=i%n;jhttps://groups.google.com/groups/opt_out.
Re: [algogeeks] help with o/p why 0 comes???
O/p will not be 0. 1.00 is the result which when read as %d takes the decimal value of 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 in memory -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] Re: FInd unique element.
@Aditya : Since khttps://groups.google.com/groups/opt_out.
Re: [algogeeks] FInd unique element.
Assuming that : all numbers of the array range from [0,n-1] 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 smallest element is the element that exactly appears k times in the array Eg: Assume k=3 and m=5 1 2 3 1 2 3 1 2 3 1 3 1 3 Step 1: -1 -2 -3 -1 -2 -3 -1 -2 -2 -1 -3 -1 -3 Step 2: 64 37 62 -1 -2 -3 -1 -2 -2 -1 -3 -1 -3 Step 3: Smallest non-negative element is : 37 Element corresponding to the index of 37 in the original array is 2 So element 2 appears exactly k times in the array -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] Number of paths
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 Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[algogeeks] Please take 3 minutes to help change the world
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: https://waterforward.charitywater.org/opt_out?token=4ZT6ToxZ&email=algogeeks%40googlegroups.com -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] Threaded binary Trees
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 solution in O(n) and space O(1) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] Re: sortin 2D array
Merge pairs of rows until u get a single row, while merging remove the duplicates --
Re: [algogeeks] Suggested the Data Structure to implement the solution in O(1)
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] DBMS gate 2012 query
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 of C = 2 new tuples Hence 7 new tuples. --
Re: [algogeeks] Is a point inside a polygon?
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 wrote: > Given a simple polygon (specified by a list of the vertices) and a > point, how do you determine if the point is inside the polygon? > > -- > > > --
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
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 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 http://groups.google.com/group/algogeeks?hl=en.
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.
@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 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 http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Duplicate file in all computers in a network
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 duplicate this file across all N machines {that is each machine should have a local copy of the file} in minimum amount of time. -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] google paper
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 "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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Fixing Up The Binary Search Tree
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. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Programming Question
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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] 4Sum
Complexity : O(n^3) import java.util.*; public class Solution { public ArrayList> fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayList> arr=new ArrayList>(); Arrays.sort(num); int n=num.length; int sum=0; for(int i=0;i target) l--; else { ArrayList al=new ArrayList(); al.add(a); al.add(b); al.add(c); al.add(d); if(!arr.contains(al)) arr.add(al); k++; } } } } return arr; } } -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure
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 this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Allocating memory of size 0
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 used, (however it may require free()ing). -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] symmetric binary tree
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 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Algorithm Question
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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Required O(n) Algorithm
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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] google
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 10.RTOS & Buffer overflow attack Regards, Karthikeyan -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: m*n matrix, sorted rows, sorted columns, WAP to find an element efficiently
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) { if(a[i][j] > key) j--; else if(a[i][j] < key) i++; else return 1; } return 0; } Regards, Karthikeyan.V.B -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
@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 = Runtime.getRuntime().exec("fsck -files -blocks -loactions"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.r,.eadLine()) != null) { System.out.println(s); } System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } System.exit(0); } catch (IOException e) { System.out.println("exception happened - here's what I know: "); e.printStackTrace(); System.exit(-1); } } } Regards, Karthikeyan.V.B -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
@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. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
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, 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
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 possible to query the namenode and get data from it. Regards, Karthikeyan -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Suggest some Data Structure appropriate to the problem
Hi, Perfect Hashing can be used Insertion - O(1) Deletion - O(1) Search any element - O(1) for getMin() - have a pointer to hold the content of min element which gets updated during every insertion/deletion Regards, Karthikeyan.V.B -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] merge two sorted list
Hi, this logic generates 10 10 20 25 .. and so on it doesn delete the duplicates in the result 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Kruzade
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 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 http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Disjoint Set data structure
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 how inverse ackermann's function is related to this method . pls suggest me any idea or article Thanx in advance -- 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 http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Reverse Engg.
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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] suggest algo
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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] suggest algo
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: #include int sum_of_the_digits(int n) { if(n==0) return 0; return (n%10 + sum_of_the_digits(n/10)); } int main() { int a; printf("Enter the number:"); scanf("%d",&a); int i; for(i=sum_of_the_digits(a);i<=a;i+=9) if(a%i==0) { printf("%d",i); break; } return 0; } Regards, Karthikeyan.V.B PSGTECH CBE -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: check Similar array
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, Karthikeyan PSG TECH -- 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 http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] PERFECT HASHING
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, Karthikeyan.V.B -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: All possible permutations of a given string
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 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 http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] LINKED LIST
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; odd=odd->next; if(!odd->next) break; } else { even->next=odd->next; odd->next=NULL; even=even->next; if(!even->next) break; } i++; } } Pls correct me if i'm wrong or suggest me a better approach Regards, KARTHIKEYAN.V.B PSGTECH CBE -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] addition of two numbers without using logical or arithmetic operators
Hi, *int sum(int num1,int num2) { for(int i=0;ihttp://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: ACM-ICPC Kanpur 2011 LCM Extreme
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 -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] suggest algo
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 top k items, we can traversal the trie, which also costs O(n). So it takes O(n) to solve this problem. Regards, KARTHIKEYAN.V.B PSGTECH CBE -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: doubt in TSUM
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 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: doubt in TSUM
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 count=0; Arrays.sort(a); int sum_min=a[0]+a[1]+a[2]; int sum_max=a[a.length-1]+a[a.length-2]+a[a.length-3]; for(int sum=sum_min;sum<=sum_max;sum++) { for(int i=0;i j) { count++; } } } System.out.println(sum+":"+count); count=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@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: doubt in spoj 8473 ways
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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Thanks To aLgOgEeKs
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 this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Removing Duplicates In array and Linked list
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 to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Link list Q
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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Anagrams
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. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Anagrams
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 email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks]
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 email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] What is the difference between portability and Platform Independence??
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 focuses on *ability of software* to run on VIRTUAL hardware that inturn interfaces with the PHYSICAL hardware. Examples of cross-platform or platform independent languages are Java etc. * * Regards, KARTHIKEYAN.V.B PSG TECH COIMBATORE. -- 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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: puzzle
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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] New Group For Practicing and Learning Efficient Ways of Coding
+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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
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 this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon -> array problem
//use dynamic programming approach //it is O(n) time and O(1) space #include #define N 5 void main() { int a[N]={1,2,3,4,5},i; int prod1[N]; int p=1; for(i=0;i=0;--i) { prod2[i]=p; p*=a[i]; } int products[N]; for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Ques
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 "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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] C++ Query
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. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Zig Zag tree traversal
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 levels print nodes from ptr1 to ptr2 For even levels print nodes from ptr2 to ptr1 Keep count for odd and even levels so that it may be easy This was my question in Microsoft Interview for Internship in the 2nd round. But I too gave the solution using two stacks but the interviewer told me this approach. Regards, Karthik. -- 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 http://groups.google.com/group/algogeeks?hl=en.