Re: [algogeeks] Amazon Q

2012-08-26 Thread Mind Boggler
Q2) get to n/2 nodes Reverse link list after n/2 nodes Now check from 1st node and n/2 node for equality Can make the checking for equality function recursive Sent from my iPhone 4 On 26-Aug-2012, at 12:41 AM, Ashish Goel wrote: > Q1. Design a data structure for the following operations: > >

Re: [algogeeks] Amazon Q

2012-08-25 Thread Navin Kumar
Q1 Solution: . we can use doubly linked list with hash to implement all the operation in O(1). By keeping track of head and tail pointer we can do enqueue and dequeue in O(1) time. In hash we will keep track of each element present in linked list(queue). With node value as a hash key and address

[algogeeks] Amazon Q

2012-08-25 Thread Ashish Goel
Q1. Design a data structure for the following operations: I.Enqueue II. Dequeue III. Delete a given number(if it is present in the queue, else do nothing) IV. isNumberPresent All these operations should take O(1) time. Q2. Check if a l

Re: [algogeeks] Amazon Q: Implement an algorithm to do wild card string matching

2012-05-26 Thread atul anand
typo error above resolved :- match(*input , *pattern) if(*pat == 0) return true; if('?' == *pat) return match(input+1,pat+1) || match(input,pat+1) if('*' == *pat) return match(input+1,pat) || match(input,pat+1) if(*input == *pat)

Re: [algogeeks] Amazon Q: Implement an algorithm to do wild card string matching

2012-05-26 Thread atul anand
match(*input , *pattern) if(*pat == 0) return true; if('?' == *pat) return match(input+1,pat+1) || match(input,pat+1) if('*' == *pat) return match(input+1,pat) || match(input,pat+1) if(*text == *pat) return match(input+

[algogeeks] Amazon Q : Design a logWritter for server kind of application

2012-05-26 Thread Ashish Goel
Design a logWritter for server kind of application Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks

[algogeeks] Amazon Q: Implement an algorithm to do wild card string matching

2012-05-26 Thread Ashish Goel
Implement an algorithm to do wild card string matching Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algog

Re: [algogeeks] Amazon Q

2012-05-23 Thread Prem Krishna Chettri
This is an Age Old Amazon Question .. int main(void) { int card[52]; int n; srand(time(0)); for(int i=0;i<52;i++) card[i]=i; while(cin>>n) { for(int i=0;i<(52-i);i++) { int r=i+(rand()%(52-i)); int temp=card[i]; card

[algogeeks] Amazon Q

2012-05-23 Thread Ramindar Singh
Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect.

Re: [algogeeks] amazon q

2011-08-21 Thread Nikhil Gupta
Its both. Both can perform the operations in a maximum of O(logn) time. On Sun, Aug 21, 2011 at 7:13 PM, priya ramesh < love.for.programm...@gmail.com> wrote: > i have the same doubt :) > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group

Re: [algogeeks] amazon q

2011-08-21 Thread priya ramesh
i have the same doubt :) -- 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,

Re: [algogeeks] amazon q

2011-08-21 Thread Akash Mukherjee
heap is true but i am not getting y we can't use a balanced binary tree searching for the smallest is logn(leftmost node), then deleting it is logn so, should it be both?? thanx :) On Sun, Aug 21, 2011 at 6:54 PM, sukran dhawan wrote: > its heap > > > On Sun, Aug 21, 2011 at 6:52 PM, Puneet Ch

Re: [algogeeks] amazon q

2011-08-21 Thread priya ramesh
so which is the right option?? -- 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 op

Re: [algogeeks] amazon q

2011-08-21 Thread sukran dhawan
its heap On Sun, Aug 21, 2011 at 6:52 PM, Puneet Chawla wrote: > I think Heap DS should be used as to delete smallest element jst apply min > heap and delete it and for insertion add the element and apply max or min as > needed Max heap = Min heap both have complexities =O(logn) > > > On Sun, Aug

Re: [algogeeks] amazon q

2011-08-21 Thread Puneet Chawla
I think Heap DS should be used as to delete smallest element jst apply min heap and delete it and for insertion add the element and apply max or min as needed Max heap = Min heap both have complexities =O(logn) On Sun, Aug 21, 2011 at 6:46 PM, priya ramesh < love.for.programm...@gmail.com> wrote:

[algogeeks] amazon q

2011-08-21 Thread priya ramesh
A data structure is required for storing a set of integers such that each of the following operations can be done in (log n) time, where n is the number of elements in the set. Deletion of the smallest element Insertion of an element if it is not already present in the set Which of the following da

Re: [algogeeks] AMAZON Q

2011-07-28 Thread Anantha Krishnan
We must use BITto solve this problem with O(nlogn). Here is my implementation. Thanks & Regards Anantha Krishnan On Tue, Jul 26, 2011 at 7:18 PM, Piyush Sinha wrote: > You have an array like

Re: [algogeeks] AMAZON Q

2011-07-27 Thread Amir Aavani
Here is an algorithm which solves this problem in O(nlog^2 n): Create a set of pairs B= {: i= 1..n}. Sort B. Now use the following Divide and Conquer algorithm (Ar_Low is a global array): Fill (Start, End, Low_Array) if Start= End then Low_Array [Start]= 0 else Initialize

Re: [algogeeks] AMAZON Q

2011-07-26 Thread Anand Saha
Construct a BST using ar[], where each node contains the ar index information as well (in addition to the value). Now iterating through ar. For each element, traverse the BST by value, counting only those nodes where the value AND index# are greater then self. Once done traversal, update ar_low. -

Re: [algogeeks] AMAZON Q

2011-07-26 Thread Someshwar Chandrasekaran
On Tue, Jul 26, 2011 at 7:18 PM, Piyush Sinha wrote: > You have an array like ar[]= {1,3,2,4,5,4,2}. You need to create > another array ar_low[] such that ar_low[i] = number of elements lower > than or equal to ar[i] in ar[i+1:n-1]. > So the output of above should be {0,2,1,2,2,1,0} > > Time compl

[algogeeks] AMAZON Q

2011-07-26 Thread Piyush Sinha
You have an array like ar[]= {1,3,2,4,5,4,2}. You need to create another array ar_low[] such that ar_low[i] = number of elements lower than or equal to ar[i] in ar[i+1:n-1]. So the output of above should be {0,2,1,2,2,1,0} Time complexity : O(nlogn) use of extra space allowed. -- *Piyush Sinha*

Re: [algogeeks] AMAZON Q

2011-06-07 Thread Ashish Goel
have head and tail pointer for every hash bucket this is how linux scheduler works add at the end, remove from front each bucket represents the prioirty or unique hash value.. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Tue, Jun 7, 2011 at 1

[algogeeks] AMAZON Q

2011-06-06 Thread Piyush Sinha
Design your hash_map that allow the following Add in O(1) , delete in O(1) , iterate in O(n)? -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Gr

[algogeeks] AMAZON Q

2011-05-24 Thread Piyush Sinha
The input number is n. Find the closest Fibonacci series number i where i < n. Show the time complexity of the problem. For eg : if n = 10, the output "i" should be 8 -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -