cobra
BAN USERNothing
- 0of 0 votes
AnswersI have Created Dynamic Web Application...
- cobra in India
there is user table with column "enabled" to check if the user is already logged in
enabled = true --> logged in otherwise not
if i logged in , i cannot loggin at the same time in anothe r browser ..
but if i logged in and close the browser, how can i handle further loggin ??| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswerAfter creating Huffman tree, how to print the huffman code for each character which are the leaf nodes?
- cobra in India
leaf nodes contain: character (ex:'a') and its frequency
other nodes contain: character '*' and sum of the frequency of the child nodes.| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
Answerswhat is the difference between IN , ANY and ALL in oracle?
- cobra in India
can anyone explain with an example?| Report Duplicate | Flag | PURGE
Database
in can be done in O(n)..
keep a counter.. increment the counter while traversing the increasing array elements..
when a small element is encountered...
max_count = count;
count = 0;
and then resume traversing keep on incrementing the count till next small element is encountered..
if(count>max_count)
max_count = count;
and also keep track of the start index and end index of the subsequence to print the elements
- cobra July 20, 2012It is still nearer to O(n) than O(n^2) where n is the number of types of denomination
Example: for denomination:{1,2,4,5,6} output:2 {denomination: 5,4}
package com.programs;
import java.util.Scanner;
public class CoinProblem {
/**
* Minimum Coin Problem
*/
static int[] coin = {1,2,4,5,6};
static int getMinCoins(int total_amount)
{
int min_coin = 0,temp =0,opti_min_coin=9999999,temp_amount;
for(int i = coin.length-1;i>=0;i--)
{
min_coin=0;
temp_amount = total_amount;
for(int j= i;j>=0;j--)
{
temp = temp_amount/coin[j];
temp_amount = temp_amount - temp*coin[j];
min_coin+=temp;
if(total_amount==0 || min_coin > opti_min_coin)
break;
}
opti_min_coin=(min_coin < opti_min_coin)?min_coin:opti_min_coin;
}
return opti_min_coin;
}
public static void main(String[] args) {
int total_amount, min_num_coins;
//getting the value of the amount
System.out.println("Enter the amount:");
Scanner scanner = new Scanner(System.in);
total_amount = scanner.nextInt();
min_num_coins = getMinCoins(total_amount);
System.out.println(min_num_coins);
}
}
1. Take XOR of all elements and store in a variable 'temp'
2. Now with two pointer in the list... with first one(say 'first') points to head and other(say 'second') moves through the list, when two pointer have same values , delete both the nodes.(by this time first = first->next and second = first -> next). Repeat this step until moving pointer reach the end.
3. now the list contain only element that are repeated odd number of times
4. now xor this list and then xor with temp.
5. you will get the element which is repeated even number of times
Number of comparisons = No of comparisons in insertion sort
while comparing two elements
1. create an array of size 10 and intialize to zero ..
2. take the first element and traverse its digits (using modulo) and set the array[digit] to 1
3. when you traverse the second element's digits and if you found array[digit] to 1 then these two elements are friends..
is my solution right?
By using adjacency list in directed graph, we can solve it
take a vertex say from 10 vertices and see the adjacent vertex(let it be 3 vertices)
now take only these 3 adjacent vertex and look for the vertex which doesnt have the adjacent vertex
this vertex is the celebrity
...
is there any other solution?
Complexity: O(n)
package com.programs;
/*
* Print list ['a','b','c','d',...'j'] in 3 columns
* output:
* a e i
* b f j
* c g
* d h
*
*/
public class printPattern {
public static void main(String args[])
{
char[] elements = {'a','b','c','d','e','f','g','h','i','j','k','l','m'};
int num_of_elements = elements.length;
int remainder = num_of_elements%3;
int rows = (remainder > 0) ? ((num_of_elements/3) +1) : (num_of_elements/3);
int modulo = rows * 3;
int index = 0;
for(int j=0;j<modulo;j++)
{
if(index<num_of_elements)
System.out.print(elements[index]+" ");
index+=rows;
if((index)<modulo)
continue;
else
{
index = ((index+1)%modulo);
System.out.println("");
}
}
}
}
its a dynamic problem..
1. Let the source be grid[0][0] if it is not Zero. then keep on adding max(left,right,up,down) and change the visited grid[i] [j] to zero..so that it cannot be visited again..
2. if you cant move further store the temporary sum say 'temp_sum' in a separate variable say 'max_sum' and start check the other non-zero grid..
3. if the temp_sum becomes greater than max_sum, then max_sum = temp_sum
is my idea right?
for the case given by ninja, i am giving an overview:
- cobra July 21, 2012create an adjacency matrix.
here where BC is repeated
means you have to update graph['B']['C'] using ohm's law(1/r = 1/r1 + 1/r2)
now graph[B][C] = 3.15
now add graph[B][C] and graph[C][D] , and store in graph[B][D] which is 8.15
now add graph[A][B] and graph[B][D] and store in graph [A][D] which is 13.15..