wolverine
BAN USER- 0of 0 votes
AnswersDesign a efficient cache, supporting retrieval of maximum element in cache along with other normal cache operations.
- wolverine
Suggest data structures to be used,also tell the complexities for each of the operations.| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Algorithm
- 0 Answers How to apply for various companies offline ?
Hi, I am a final year B.Tech(C.S.E) student from India.We have our placement session going on , but some of the big shots like Amazon,Yahoo,Adobe etc .. will not be visiting our campus this year.
- wolverine October 16, 2009
I would like to know how can i apply offcampus for these companies.Do i need to know a person who can refer me or is there some other way also to apply ?
Also,I am really interested in Apple,but i guess Apple doesn't have a development wing in India.So is there any way to apply for an internship at Apple.I mean do they accept applications from interested foreigner candidates.
Previously I have done internship at Google India.| Flag | PURGE
//finds the sum of digits of a number
#include<cstdio>
int addDigits(int no) {
int negFlag=0;
int sum=0;
if(no<0) {
negFlag=1;
no=-no;
}
while(no>0) {
sum+=no%10;
no/=10;
}
return sum;
}
int main() {
printf("%d : %d ",567,addDigits(567));
printf("%d : %d ",5,addDigits(5));
printf("%d : %d ",0,addDigits(0));
printf("%d : %d ",-567,addDigits(-567));
}
#include<stdio.h>
int revDigits(int no) {
int negFlag=0;
int rev=0;
if(no<0) {
negFlag=1;
no=-no;
}
while(no>0) {
rev*=10;
rev+=(no%10);
no=no/10;
}
if(negFlag) {
rev=-rev;
}
return rev;
}
int main() {
printf("%d : %d\n",764,revDigits(764));
printf("%d : %d\n",-764,revDigits(-764));
printf("%d : %d\n",0,revDigits(0));
printf("%d : %d",4,revDigits(4));
}
#include<stdio.h>
#include<stdlib.h>
void reverse(char *str,int len) {
int i=0;
char ch;
for(i=0;i<=(len-1)/2;i++) {
ch=str[i];
str[i]=str[len-1-i];
str[len-1-i]=ch;
}
}
char* itoa(int number) {
char *str=malloc(sizeof(char)*20);
int negFlag=0,pos=0;
if(number<0) {
negFlag=1;
number=-number;
}
while(number>0) {
str[pos++]='0'+number%10;
number=number/10;
}
if(negFlag) {
str[pos++]='-';
}
str[pos]='\0';
reverse(str,pos);
return str;
}
int main() {
printf("reverse %d : %s ",-543,itoa(-543));
printf("reverse %d : %s ",54,itoa(54));
printf("reverse %d : %s ",5,itoa(5));
}
This can be done in O(n+m) time without using any space .
here is the pseudo code :-
for i->1 to m+n {
a[a[i]%n]+=n
}
for i->1 to n {
print "number i occurs " a[i]/n "times
}
for example :-
take n=4
input :-
2,1,3,3,4,1,2
when i=1
2,5,3,3,4,1,2
i=2
6,5,3,3,4,1,2
so on final array :-
10,9,11,7,4,1,2
hence 1 occurs 10/4 = 2 times
'' 2 occurs 9/2=2 times
'' 3 occurs 11/4=2 times
4 occurs 7/4 = 1 times
Expected value of boys in one family=1
Expected value of girls in one family=1*.5*.5+2*.5*.5*.5+3*.5*.5*.5*.5+...
which is a AGP,
on solving this you will get E(girls in one family)=1
Ratio of boys to girls in village=expected value of boys divided by expected value of girls=1/1=1
Bigger cache increases hit time,which will make the access slow for the already present element in cache,but it reduces miss rate as more of data can be put into the cache.
- wolverine October 20, 2009Smaller cache have a less hit time hence,hence can operate fast.but it increases miss rate as less data can be accompanied in cache.
To utilize the benefits of both caches systems have 2 level cache L1(smaller) and L2(bigger)