chandan.jc
BAN USER- 5of 5 votes
AnswersWrite a program to print all the permutations of the given input string.
- chandan.jc in United States for Software| Report Duplicate | Flag | PURGE
NetApp Intern Algorithm - 0of 0 votes
AnswersIn a multi-threaded process,If one thread is busy on I/O will the entire process be blocked?
- chandan.jc in United States for System Software| Report Duplicate | Flag | PURGE
NVIDIA Intern Operating System - 1of 1 vote
AnswersAssuming there's no Array data structure in C, how would you implement it.
- chandan.jc in United States for System Software| Report Duplicate | Flag | PURGE
NVIDIA Intern C
I have given a rough idea here. Not very clear about specific interrupts at each step. Hope this helps.
1) CPU first fetches the instruction x = 7 from the Instruction cache (when it reads this address in the PC/IR)
2) After decoding and executing the instruction, it sees that, it needs to access the memory location of variable x (which will be a virtual address)
3) Hence it issues a request to the TLB to return the physical address/tag.
Assuming the cache is Virtually indexed, it will parallely calculate the index for this virtual address.
4) Since it's a TLB miss, it accesses the Page table which resides mostly in Memory.
//Not sure what the interrupt here is?
5) But since, the translation is not found, meaning the page for this address is not in RAM, it issues a DMA request to transfer the page from Secondary storage to the RAM. It knows the address of the page on Secondary storage through the vm_area struct for this process, which maintains the location of all the pages.
// This is done in page fault handler. Page fault is raised when this even occurs.
6) Once DMA is complete, the processor is interrupted with this event. It then updates the page table with this entry and also the TLB.
//This would be an I/O interrupt to the processor
7) Once it gets the tag, it checks if that tag matches in the cache.
8) It won't, since cache does not have this entry.
9) Hence it fetches this block (cache block) from memory and places into the cache and restarts the execution.
10) In the MEM phase of the execution pipeline, it writes the value 7 to this location in the cache.
It'd be
log(2){((2^N) - 1)((2^N) - 1) + ((2^N) - 1)}
= log(2) {2^2N - 2^N}
Leaving away -2^N, since we are looking for the highest number of bits,
we get
= log(2) {2^2N}
= 2N
Algorithm:
1) Initialize all the output array values to -1.
2) Find even_count and odd_count
2) If (odd_count > even_count)
First fill up even numbers in even places by traversing input array
Then traverse the input array from behind, and fill up the output array from behind, wherever you see a -1, for all odd nos in the input array.
Else if(odd_count < even_count)
Similar to the above step.
Else //If the counts are same
Traverse from front and fill up the output array //Trivial case
The solution given by @pradegup works fine with a little modification. We don't add all the keys initially. Instead,
1)we read an item x.
2)check if sum-x is present in Hash.
3)If yes, then we print x and key (which is sum-x)
Else, we add x to the Hash table.
int main()
{
char str[] = "abcd1234defgh8965";
char *out;
int i;
int n = strlen(str);
int int_c = 1;
int char_c = 0;
out = malloc(sizeof(char) * (n+1));
for(i = 0; i < n; i++)
{
if((str[i]-'0') >= 0 && (str[i] - '0') <= 9)
{
*(out + int_c) = str[i];
int_c += 2;
}
else if((str[i] - 0) >= 65 && (str[i] - 0) <= 122)
{
*(out + char_c) = str[i];
char_c += 2;
}
}
*(out+n) = '\0';
printf("out:..%s\n",out);
}
Thanks for the first reply to this comment, that mostly answers the question as well.
- chandan.jc September 26, 2012The one by M@X above, "depends on which model of threads is used" is the right answer, as far as I know.
- chandan.jc September 26, 2012"If, for example, a thread which processes the user input is busy on I/O then it would appear to the user that the process is blocked" -- The question is not about how the user "sees" it, but about what happens to the workload assigned to the rest of the threads, do they wait (by virtue of OS or something else) for this thread to finish, or do they carry on with their own business (assuming programmer has allowed them to do so).
- chandan.jc September 26, 2012Spin locks are the simplest means of achieving mut-ex in multicores. But they are expensive since they incur a lot of cache coherence bus traffic, making them non-scalable. Alternatives are Queued locks and Ticket spin locks (used in Linux kernel).
- chandan.jc September 26, 2012char y = ((x << 8 - m) >> (8 - m + n));
- chandan.jc March 08, 2012
RepEllaWilliams, Analyst at A9
I am a perceptive systems analyst adept at designing innovative IT solutions and enhancing existing systems with new features. I ...
RepStanPhillips, Animator at AMD
StanPhillips, a Landscape architect . I have been working at Pro Property Maintenance it's almost 10 years . I also help ...
RepRitterNicole, DIGITAL MARKETING at Arista Networks
I am Ritter, Experimental psychologist refers to work done who apply experimental methods to psychological study and the processes that ...
Repleroykrtz, Backend Developer at Achieve Internet
I am a Homeowner association manager and am typically involved in drafting and enforcing community rules and regulations. These rules ...
RepHenryLee, Accountant at AMD
I am a creative and 5 years experienced beautician. I have experience with most cosmetology tools, including razors, nail clippers ...
Repmirezwanda, Android test engineer at Arista Networks
Computer database administrator with 3+ years of experience working in Gamma Realty . I often plan security measures, making sure that ...
RepJuanitaRiegel, Analyst at ABC TECH SUPPORT
Juanita a dedicated Assistant Event Coordinator adept at managing various corporate events, developing budgets, and recruiting and training new personnel ...
RepNevaLucas, Analyst at Apache Design
I was the Training manager in Checker Auto Parts Center. My current research projects are about astrology, vashikaran health outcomes ...
RepAriasBitner, Systems developer at 247quickbookshelp
I am a Systems developer . My duties primarily revolve around building software by writing code, as well as modifying software ...
RepDeanSims, Associate at ASU
DeanSims a hardworking Tire builder . expert in this work working at Magna Architectural Design . I am also a part of ...
RepAnnetteFlynn, Android test engineer at ABC TECH SUPPORT
Hello I am a skill trainer. Master's Degree in Industrial and Organisational Psychology and 10 years of experience working ...
- chandan.jc November 06, 2012