If virtualization is concerned, then answer would be choice d. Since its
not necessary to load complete process in memory.
On Sat, Dec 8, 2012 at 12:45 AM, sahil gupta wrote:
> It's b.
> Windows follow this Operation.
>
>
> On Fri, Dec 7, 2012 at 4:21 AM, manish wrote:
>
>> Four processes of 1
][3]=1 so we can't take this in put path... but actually both
> are different paths..
> how you will ensure this. because we are maintaining only one visited
> matrix.
>
>
>
>
>
>
> On Wed, Oct 17, 2012 at 7:54 AM, Navin Kumar wrote:
>
>> @Rahul: Loop won&
@Rahul: Loop won't occur because when you are visiting any matrix element
then you are marking 1 in visited matrix. So second time it will be seen as
a already visited element and it will choose another element (or path if
exist) or will blocked.
On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar Patle
f(arr)-1;
> do
> {
> if(elem==arr[n])
> print found;
> n--;
>
> }while(n);
>
>
>
> On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar wrote:
>
>> @atul: keep one more checking outside loop for element at 0 th index.
>> Because when n = 0
@atul: keep one more checking outside loop for element at 0 th index.
Because when n = 0 the your loop come out from the loop without comparing
it.
On Mon, Oct 1, 2012 at 8:55 AM, atul anand wrote:
> n=sizeof(arr);
> n--;
>
> while(n)
> {
> if(elem=arr[n])
> print found;
>
> n--;
it&redlink=1>in
1995"
source: wikipedia
On Sun, Sep 23, 2012 at 5:08 PM, Navin Kumar wrote:
> Build a common suffix tree for the given string and for its reverse. Then
> take out the string ending at maximum depth at a common node. Time
> complexity would be linear.
>
>
Build a common suffix tree for the given string and for its reverse. Then
take out the string ending at maximum depth at a common node. Time
complexity would be linear.
On Sat, Sep 22, 2012 at 5:33 PM, Aditya Raman wrote:
> Hello everybody,
> I need to find a way of finding the longest palindrome
PM, Dave wrote:
> @Navin: It means that given a positive integer n whose decimal
> representation ends in 3, find a multiple, m*n, which is written solely
> with the digit 1. E.g., 3: 37 * 3 = 111; 13: 8547 * 13 = 111,111.
>
> Dave
>
> On Thursday, September 20, 2012 11:56:08
@all: Please explain question number 8. I am not getting the question
exactly what it says ?
On Fri, Sep 21, 2012 at 9:30 AM, Dave wrote:
> @Bharat: Simulate long division, dividing a number ...1 by the number.
> You can do this one digit at a time, printing the quotient digit by digit
> unt
d to the this new queue and add it
> to hastable.
> clear all previous "monday" to "sunday" queues.
> and start creating queue for new week.
>
>
>
> On Tue, Sep 18, 2012 at 1:20 PM, Navin Kumar wrote:
>
>>
>> Which data structure is used to mai
Which data structure is used to maintain browser history?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/MCj-0bFwvV0J.
To post to this group, send email t
te:
>
>> hashmap for word to count mapping and a heap will have count and
>> corresponding words (will get updated at run time)
>> Best Regards
>>
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
rnal sorting
>>coming to second point it dynamically changing leads lot of
>> other questions before going give algo .
>>
>>
>> On Sat, Sep 8, 2012 at 7:43 PM, Navin Kumar wrote:
>>
>>> Given a file which has billions of words and file can be
Given a file which has billions of words and file can be loaded in memory.
Now find 10 most frequent words in file. What if file is dynamically
changing means words are continuously added to it.
What if file cant be loaded in memory.
--
You received this message because you are subscribed to
@tendua: Answer will be 6C3 x 3! .
For example: If 5 letters are given then you can get only 10 combination of
different letter = 5C3
ABC
ABD
ABE
BCD
BCE
CDE
ACD
ACE
ADE
BDE
now each of these can be arranged in 3! ways. So final answer will be : 120
On Fri, Sep 7, 2012 at 1:11 AM, tendua wrote
@tendua: answer would be 6C3. Read about combination definition.
On Thu, Sep 6, 2012 at 5:05 PM, atul anand wrote:
> question says *3 alphabets with no data repeated* ...you no need of doing
> 3! permutation.
> eg 123 and 321 are same
>
>
> On Thu, Sep 6, 2012 at 4:35 PM, tendua wrote:
>
>> fro
@all: Now the problem is for getting O(n) time and O(1) space we have to
run two inorder traversal simultaneously. How can we do it??
On Mon, Sep 3, 2012 at 9:31 PM, Karthikeyan V.B wrote:
> @navin and @atul:
>
> inorder traversal without recursion and stack can be done using Morris
> traversal
success when the
>>>> sum equals the given number or with failure when the two traversals have
>>>> reached the same node.
>>>> Dave
>>>>
>>>> On Sunday, September 2, 2012 11:00:42 PM UTC-5, atul007 wrote:
>>>>
&
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/aLuPUOKxmaoJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this gro
hich will be O(n).
>
>
> On 9/2/12, Navin Kumar wrote:
> > @atul : suppose if all element of input array is zero then i think
> hashing
> > will also produce n^2 output. so worst case time complexity would be
> > O(n^2).
> >
> > On Sun, Sep 2, 2012 at 9:18 PM
inding problem. But if I recall correctly that only works in
>> >> linear time if the input is entirely positive integers?
>> >> Maybe I'm being stupid but wont checking that array be quadratic?
>> >>
>> >> On 2 September 2012 20:02, Navin Kumar
&g
void correctBST(struct node *root)
{
int flag =0;
static struct node *temp1, *temp2, *temp3, *prev;
static int found;
if(found) return;
if(root) {
correctBST(root->left);
if(!temp1 && prev && root->data < prev->data) {
temp1 = prev;
temp2 = root;
@pradip: Finding same element in temp array is little bit tricky. For
displaying item from i+1 to j , you have to make sure that there is equal
element at i and j index in temp array. How will you ensure it in O(n) time?
On Sun, Sep 2, 2012 at 3:16 PM, Pradeep Mishra wrote:
> This algorithm is *O
gt; between the sum of 2 prefixes.
> 3. for each entry search for the corresponding difference such the index
> found is greater than original index.
>
> Works for any sum, not just 0. Takes O(n log n)
>
>
> On 2 September 2012 14:22, Navin Kumar wrote:
>
>> Given an un
Given an unsorted integer array. Find the contiguous sub sequences whose
sum is 0.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/pFvfWQjVrnkJ.
To post t
on why a trie or a tree node couldn't be used to
> 'represent'
> > more than one word. Although you'd take a penalty in the complexity for
> > searching etc.
> >
> > On 31 August 2012 15:33, Navin Kumar wrote:
> >
> >> Can we store m
Can we store multiple words in single TRIE node by using linked list or
some other data structure. Based on the some property a node in TRIE will
hold all the word with same property.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view
@sangeeta: n-1 comparison required to choose winner. By tournament approach
winner has played match with logn team and winner must have beaten second
largest element. So among logn number we can select maximum in logn - 1
comparison.
So total comparison required is: n + logn -2
On Thu, Aug 30, 20
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
Anagram problem solution using TRIE..
For each word in dictionary we will put it in TRIE as..
1. First sort the word
2. Search in trie using sorted word. If search found then we will add the
original word in that TRIE node.
3. If node node not found then using simple TRIE insertion insert sorte
Few more Test cases :
Check for 10 node.
Check for 1 million node
Check for even number of nodes
Check for odd number of nodes...
etc etc...
On Fri, Aug 24, 2012 at 6:25 PM, Navin Kumar wrote:
> Reversing a linked list if loop exists:
>
> 1. Find the node from which loop start by
Reversing a linked list if loop exists:
1. Find the node from which loop start by any loop finding algorithm in
linked list and keep the position of that node.
2. Unroll the loop i.e. set the last node's(last unrepeating node) next
pointer to NULL.
3. Reverse this singly linked list.
4. Change
@Ashish: According to your algo making multimap itself takes O(mn) time
complexity (preprocessing). After then getting anagram of a string takes
O(n) time. Am i right?
On Thu, Aug 23, 2012 at 6:51 AM, Ashish Goel wrote:
> O(n)
> convert each string into format a1b2and then insert into multim
x ^= 15;
(^ = bit wise xor)
On Wed, Aug 22, 2012 at 4:16 PM, Abhi wrote:
> Write a one line code to invert the last four bits of an integer ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
with probability 1/i.
> When EOF is reached, every word in the file will have probability 1/n of
> being the saved word. Print it.
>
> Dave
>
> On Saturday, August 18, 2012 1:28:56 AM UTC-5, Navin Kumar wrote:
>
>> Print a *Random word* from a file. Input is "path to a fi
Print a *Random word* from a file. Input is "path to a file",
constraints- No extra memory like hashing etc. All the words in the file
should have equal probability.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion o
We have to consider cases when an element is zero.
On Thu, Aug 16, 2012 at 7:07 PM, shady wrote:
> well we can do with just one array. Overwrite the answer directly on
> left[] array.
>
>
> On Thu, Aug 16, 2012 at 6:47 PM, mohit wrote:
>
>>
>> here are the steps :
>> 1) Construct a temporary ar
on again and join us for solving the main problem
>
>
> On Sun, Aug 12, 2012 at 4:19 PM, Navin Kumar wrote:
>
>> We can solve using Dynamic programming..
>> Take n*2 matrix for storing sum. Let A be original matrix and matrix M
>> hold sum. Let M[i, j] cont
We can solve using Dynamic programming..
Take n*2 matrix for storing sum. Let A be original matrix and matrix M hold
sum. Let M[i, j] contains max sum upto i th row and j th column.
recursion will be as follows:
M[i, j] = max(M[i - 1, j], M[i, j-1]) + A[i, j]
By above formula fill whole M matrix
I think best data structure would be "Optimal BST"
On Fri, Aug 10, 2012 at 11:47 PM, Kumar Vishal wrote:
> Huffman tree ???
>
>
> On Fri, Aug 10, 2012 at 11:38 PM, Varma Selvaraj wrote:
>
>> A data cache needs to be implemented for the top 100 data items selected
>> based on their frequency
@vaibhav : yes it will be a balanced BST.
On Wed, Aug 8, 2012 at 11:29 AM, vaibhav shukla wrote:
> @Navin
>
> By your algo of starting with the middle node,I guess a balanced BST would
> be created. Is it ?
>
>
> On Wed, Aug 8, 2012 at 1:24 AM, Navin Kumar wrote:
>
>&g
vague .
>
> On Sunday, 15 July 2012 01:41:15 UTC+5:30, Navin Kumar wrote:
>
>> Given Preorder and postorder traversals of a tree. Device an algorithm to
>> constuct a fully binary tree from these traversals.
>
> --
> You received this message because you are subscrib
1. Convert your Binary tree into doubly linked list.
2. Sort the linked list using merge sort
3. Build BST using doubly linked list by each time selecting middle node
and recursively calling left part of linked list and right part of linked
list.
On Tue, Aug 7, 2012 at 10:23 PM, vaibhav shukla wro
++]=arr[i];
> a[l++]=arr[j++];
> a[l++]=arr[k++];
> }
> for(int i=0;i arr[i]=a[i];
> free(a);
> }
> cud be dun be dun recursively also to minimize d space complexity...
>
>
>
>
>
> On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar wrote:
>
>> In given
This is a linear time constant space algorithm.
Assume the stocks prices are given in an array where index represents the
day no . For ex a[365] represents stock price on 365th day of year.
Find the min and max element in the array.
If the min comes before max, then return the dates- min to buy
Given the array of digits, you have to calculate the least positive
integer value of the expression that could *NOT *have been received by you.
The binary operators possible are *, +, -, / and brackets possible are (
and ). Note that / is an integer division i.e. 9/5 = 1.
For ex- 6 6 4 4 the a
In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c1,c2,c3,...cn]
.Write an efficient program to merge them like
[a1,b1,c1,a2,b2,c2,...an,bn,cn].
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web
@sahil: Please elaborate your question. I didn't understand your question.
what is straight doubly linked list?? How many pointers each node have??
On Thu, Aug 2, 2012 at 4:26 PM, Amit Basak wrote:
> Does each node in the list have three pointers?
> What do you mean by straight doubly link lis
> using the DLL/array given ..?
>
>
> On Tue, Jul 31, 2012 at 10:57 PM, manish untwal
> wrote:
>
>> hey friends,
>> just wanted to ask like what they ask in quants and DI
>>
>>
>> On Tue, Jul 31, 2012 at 10:45 PM, Navin Kumar
>> wrote
; I think we are blindfolded..
> how can we know afetr dividing 10 coins that 7 r heads.. or 'x' are heads
> and we need to flip it over.. ?
>
> On Tuesday, 31 July 2012 12:33:09 UTC+5:30, Navin Kumar wrote:
>>
>> You are blindfolded and 20 coins are placed on the table i
@Daksh: total number of BST possible with n nodes will be : catalan number
we can build balanced BST by each time selecting middle element as a root
node and its left pointer will point to left linked list and right pointer
will point to right linked list. Do it recursively for left list and right
You are blindfolded and 20 coins are placed on the table in front of you.
Out of them 10 coins have heads facing up and other tails. You are allowed
to flip and move the coins. You should divide those coins into two sets
such that one set contains 10 heads and other tails. You are allowed to
on
Given array of integers (0 or +ve or -ve value) find two elements having
minimum difference in their absolute values.
e.g. Input {10 , -2, 4, 9,-20,17,-8,14,12)
output {9,-8}
I have solved it in O(nlogn). can it be solved in O(n).
--
You received this message because you are subscribed to the G
logic is very simple ...just trace the program you will understand.
On Wed, Jul 25, 2012 at 7:28 PM, Navin Kumar wrote:
> #include
> #include
> #include
>
> char *decrypt(char *s)
> {
> int n;
> char *digit = (char *)malloc(sizeof(char) * 5);
> char *p1 =
#include
#include
#include
char *decrypt(char *s)
{
int n;
char *digit = (char *)malloc(sizeof(char) * 5);
char *p1 = (char *)malloc(sizeof(char) * 1024);
char *p = p1;
char *digit2;
char prev;
prev = *s;
*p++ = *s++;
while(s != '\0') {
if(isdigit(*s)) {
d
Given a Circuit (with resistors), we need to calculate the total
resistance. Input will be like AB-5ohm, BC-6ohm, BC-10ohm, BC-20 ohm, CD-5
ohm. BC has been repeated twice implying they are in parallel. "Write a
program by implementing efficient data structure for storing and
calculating the to
he word(use quick sort(nlogn time))- and den
>>>>> search using binary search(logn time)
>>>>> or we can evn do by hashing-hash the word,den for every word keep
>>>>> decreasing the counter,if the hash array is zero ,anagram,else reset the
>>>
Assuming a preexisting list of 100 words, how would you efficiently see if
a word received from input is an anagram of any of the 100 words?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://gr
;
> On Saturday, July 14, 2012 2:55:48 PM UTC-5, Navin Kumar wrote:
>
>> A set of integer values are being received (1 per day). Store these
>> values and at any given time, retrieve the min and max value over the last
>> k days. What data structures would you use for stor
rote:
>>
>> Min or max heap accordingly. This will do the job in O(log n) time.
>>
>> On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar wrote:
>>
>>> A set of integer values are being received (1 per day). Store these
>>> values and at any given time, ret
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/lZRdyZn85fcJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this gro
Given Preorder and postorder traversals of a tree. Device an algorithm to
constuct a fully binary tree from these traversals.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com
A set of integer values are being received (1 per day). Store these values
and at any given time, retrieve the min and max value over the last k days.
What data structures would you use for storing and retrieving ?
--
You received this message because you are subscribed to the Google Groups
"A
/3 times or more - O(n) *{mark
>> for output if yes}*
>>
>> its 7*O(N) => O(N) solution. Constant space.
>>
>> we need not check further down or recursively. {why? reason it.. its
>> simple}
>>
>>
>> On Wednesday, 27 June 2012 18:35:12
eck if median element is repeared n/3 times or more - O(n) *{mark
>> for output if yes}*
>>
>> its 7*O(N) => O(N) solution. Constant space.
>>
>> we need not check further down or recursively. {why? reason it.. its
>> simple}
>>
>>
>> On
@payal:
In this case too i think minimum number of weighing required is 3.
Slightly change in my previous solution. x1+x2+x3 = 3x and y1+y2+y3 = 3y.
On Wed, Jul 11, 2012 at 8:00 AM, payal gupta wrote:
> @ Dave sir
> the balance considered here is simple balance scale incapable of
> giving any
Given two strings .Print all the interleavings of the two strings.
Interleaving means that the if B comes after A .It should also come after A
in the interleaved string.
ex-
AB and CD
ABCD
ACBD
ACDB
CABD
CADB
CDAB
--
You received this message because you are subscribed to the Google Groups
"Alg
ght will be either a or b. Depending upon outcome we will
categorize them a and b.
So 3 weighing is required.
On Tue, Jul 10, 2012 at 7:05 PM, payal gupta wrote:
> @navin...Sorry didnt get you how come u were able to segregate all the
> coins by the proposed method??
>
>
> On 7/10/
Minimum no. weighings:
Divide 8 coins in group of 3, 3 and 2.
For minimum weighsing group1 's total weight is x units(say) -->FIrst
weighing
Groups 2nd total weights is y units > Second weighing.
Lastly one more weighing among a unit and b unit coins.--->3 rd weighing
So minimum
Thanx Deepika :)
On Sun, Jul 8, 2012 at 11:48 AM, deepikaanand wrote:
> http://www.geeksforgeeks.org/archives/3968
>
>
> On Jul 8, 11:01 am, Navin Kumar wrote:
> > Let A[n] be an array of n distinct number. If i A[j] then
> the
> > pair (i , j) is called inve
Let A[n] be an array of n distinct number. If i A[j] then the
pair (i , j) is called inversion of A.
Give an algorithm that determines the total number of inversions in
O(nlogn) time.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view
Suppose a file.txt contains : 50 40 30 # # 5 # 10 # #
i want to fetch only integers. How should i fetch it. I tried with fgetc
and fscanf but it was too complicated.
My approach: fetched one word at a time and put it into separate string and
then i converted that string to integer(if each chara
we can serialize the binary tree using preorder traversal and marking NULL
pointer as '#'.
source:
http://www.leetcode.com/2010/09/serializationdeserialization-of-binary.html
On Wed, Jul 4, 2012 at 4:21 PM, Ashish Goel wrote:
> my understanding is to either write the level order traversal notin
@Vindhya: BST can be reconstructed only by preorder traversal. In case of
binary tree we need two traversal inorder and pre/post order
On Wed, Jul 4, 2012 at 1:07 PM, vindhya chhabra wrote:
> u need inoder traversal as well
>
>
> On Wed, Jul 4, 2012 at 11:22 AM, Navin
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/xmZH9KY72_IJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this gro
Design an algorithm that, given a list of n elements in an array, finds all
the elements that appear more than n/3 times in the list. The algorithm
should run in linear time
( n >=0 ).
You are expected to use comparisons and achieve linear time. No
hashing/excessive space/ and don't use stan
whether it is in character array or integer array??
On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel wrote:
>
> 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
>
please provide some good data structure to solve this problem:
http://www.careercup.com/question?id=14062676
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algog
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/xM3mGdcfvi4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this gro
Is longest path between two node in a tree is equal two logest path between
two leaves??
On Sat, Jun 23, 2012 at 5:35 PM, Navin Kumar wrote:
> Is this similar to finding the diameter of a tree(longest disteance
> between two leaves) ?? If yes than visit this link
>
> http://www
Is this similar to finding the diameter of a tree(longest disteance between
two leaves) ?? If yes than visit this link
http://www.cs.duke.edu/courses/spring00/cps100/assign/trees/diameter.html
On Sat, Jun 23, 2012 at 2:44 PM, Avinash wrote:
> Some how I found that we need to run bfs twice to ge
Extract words from file and make a BST. Then do inorder traversal and print
them.
On Fri, Jun 22, 2012 at 3:52 PM, Sourabh Singh wrote:
> u can use stl::map(,vector)
> idea is same bucket sort :-)
>
> On Fri, Jun 22, 2012 at 3:02 AM, Eshwar wrote:
> > Bucket sort algortihm Linkedlist based
> >
>
@Rishabh: i know using stack or recursion it can be done easily with O(n)
space. I want to know whether there exist more space efficient algo for
this problem or not?
On Wed, Jun 20, 2012 at 9:20 PM, Rishabh Agarwal wrote:
> @Navin: as you say "you have to take stack or some other data structure"
:
> How ??
> I am asking to manipulate the same queue.
> Dequeue n-1 elements and enqueue them in order to you take out to the same
> queue..Where is extra space involved ?
>
>
> On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar wrote:
>
>> @saurabh : i want solution with s
@saurabh : i want solution with space complexity of O(1) . your solution is
right but it takes O(n) space.
On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh wrote:
> Why will my proposed solution not work for you ???
>
>
> On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar wrote:
>
ueue el
> return nQ
> end
> return q
> end
>
>
>
> On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote:
>>
>> Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue
>> etc
>>
>> On Wed, Jun 20, 2012 at 6:50 PM, a
gt; On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar wrote:
>
>> @Saurabh: queue will be remain unchanged according to your algorithm.
>> Because if you will delete an element from front and add at rear no change
>> will be there. After n iteration front will be pointing to same ele
, 2012 at 6:46 PM, Navin Kumar wrote:
> @Saurabh: queue will be remain unchanged according to your algorithm.
> Because if you will delete an element from front and add at rear no change
> will be there. After n iteration front will be pointing to same element and
> rear will also p
, Jun 20, 2012 at 6:39 PM, saurabh singh wrote:
> count the size of queue : O(n)
> loop for n and do remove and add in queue : O(n)
>
> Total : O(n)
>
>
> On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar wrote:
>
>> How to reverse a Queue .
>>
>> Constraints: T
How to reverse a Queue .
Constraints: Time complexity O(n). space complexity: O(1)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ.
To post to
@Umer:
rand(5) + (rand(5)%2): => it will never give 6 because for rand(7) range
will be 0-6.
So better try this: rand(5) + (rand(5)%3).
On Tue, Jun 19, 2012 at 2:45 PM, Umer Farooq wrote:
> rand(5) + (rand(5)%2);
>
>
> On Tue, Jun 19, 2012 at 12:30 PM, Sourabh Singh
> wrote:
>
>> @ sry
>> cond
I corrected in function InsertAtBottom :"In my code isntead of
(!IsEmptyStack) use IsEmptyStack"
On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar wrote:
> @all:
>
> In my code isntead of (!IsEmptyStack) use IsEmptyStack
>
> Logic :
>
> First pop the all element an
@all:
In my code isntead of (!IsEmptyStack) use IsEmptyStack
Logic :
First pop the all element and then start putting element at bottom in
reverse order i.e. the element which is fetched last is put at the bottom
and so on.
ex: let our stack is: 1 2 3 4 (1 is at bottom).
function Call is will
void Reverse(struct Stack *S) {
int data;
if(IsEmptyStack(S)) return;
data=pop(s);
ReverseStack(S);
InsertAtBottom(S, data);
}
void InsertAtBottom(struct stack *S, int data)
{
int temp;
if(!IsEmptyStack(S)){
push(S,data);
return;
}
temp=pop(S);
Ins
@Ashot: You can traverse array one time. In your case you are traversing
twice. First for counting occurrence of R , G and B then again traversing
for assigning values. But constraints is that you have to traverse only
once.
On Sun, Jun 10, 2012 at 5:13 PM, Akshat Sapra wrote:
> int low,mid,hig
Given a character array as input. Array contains only three types of
characters 'R', 'G' and 'B'. Sort the array such that all 'R's comes before
'G's and all 'G's comes before 'B's.
Constraint :- No extra space allowed(except O(1) space like variables) and
minimize the time complexity.
You ca
Write an efficient program that prints the distinct words in its input
sorted into decreasing order of frequency of occurrence. Precede each word
by its count.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the
ing 8 32 96...and dats the correction required which i made
>
>
> On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar wrote:
>
>> @Mahendra: for ur above code with t=(a<<2)+a o/p will be 5,10, 15 as i
>> explained above. without bracket answer will be 8 , 32 and 96 because +
>
@Mahendra: for ur above code with t=(a<<2)+a o/p will be 5,10, 15 as i
explained above. without bracket answer will be 8 , 32 and 96 because +
precedence is higher than <<.
On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar wrote:
> Cracked it...i guess precedence of + is more than <<
> so
> use t=(
one left shift is equivalent to multiplying with 2.Two left is equivalent
to multiplying with 2^2. and so on. so i left shift means multiplying with
2^i.
In your program you did left shift with 2.so it is equivalent to
multiplying with 4. so when input is 1 function will return 4*1+1=5. when
input
1 - 100 of 110 matches
Mail list logo