Questions Collected From Web - Amazon
Questions Collected From Web - Amazon
A class defines the characteristics of a certain type of object. An object is instance of 3 Why would you use an array vs linked-list Multi Dimension and Fixed size -> Array Single Dimension and Variable Size -> Linked List Search and Access -> Array Insert and Delete -> Linked List 4 5 How much experience do you have with unix What sort of commenting standards do you use -File headers -Class headers -Function headers -Inline comments - Revising Code comments 6 Describe the classes and data structures you would use for a file system File metadata (Bacon) or File Control Block: file size, permissions, owner, group, dates, ... Information about where data on disk can be found. Active file table in memory: each entry contains Metadata for a file currently in use & number of readers/writers. index to the table is the UFID (Unix: file descriptor, Windows NT: file handle) open file creates entry in the file table close file writes metadata to disk (assumes file is not used by anyone in the system)
Implementations vary: a per process table may exist too! 7 What's the point of inheritance
Subclasses provide specialized behaviors from the basis of common elements prov Through the use of inheritance, programmers can reuse the code in the superclass m 8
Algorithm: You have 50,000 html files, some of which contain phone n you create a list of all the files which contain phone numbers? -Linked List What's the max insertion time for a hash table O(1) but if no chaining and probing What's the max look up time for a binary tree?
10
11 12 13
O(log n) Explain the classes and objects for a generic deck of cards that would be used i Algorithm: Explain algorithm to shuffle cards. Coding: Write code to tokenize a string. #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { int x = 1; char str[]="this:is:a:test:of:string:tokenizing"; char *str1; /* print what we have so far */ printf("String: %s\n", str); /* extract first string from string sequence */ str1 = strtok(str, ":"); /* print first string after tokenized */ printf("%i: %s\n", x, str1);
/* loop until finishied */ while (1) { /* extract string from string sequence */ str1 = strtok(NULL, ":"); /* check if there is nothing else to extract */ if (str1 == NULL) { printf("Tokenizing complete\n"); exit(0); } /* print string after tokenized */ printf("%i: %s\n", x, str1); x++; } return 0 } 14 15 If you had the entire text to 65 million books in a database, what would you do
How would you implement a map (not a map of like a city... just a set of k values") Give two data structures you - What is average and worst case insert time, delete time - What are pros/cons of each
Ans: -Array -Linked List 16. Remove characters from a string. What is the running time of your algorithm? 17. Describe a binary tree, its properties, and name all of its traversal algorithms.
18. Puzzle: You've got an 88 checkerboard and a bunch of dominoes that ea squares of the checkboard. You can easily tile the entire checkerboard with th say that you remove two squares, one at one corner and the other at the opp left with 62 squares. Can you tile this with the dominoes? If so, show how. If no 19
Reverse this string: "This is a sentence" using pointer. Answer should be "sent Reverse the full string first; Then reverse each word. char* StrReverse(char* str) { char int len, i; temp=str; for(len=0; ptr=malloc(sizeof(char)*(len+1)); for(i=len-1; i>=0; i--) ptr[len-i-1]=str[i]; ptr[len]='\0'; return ptr;
*temp,
*temp
} 20. Suppose you are in the 1800, posed with a 'race condition' problem. Race con where 2 or more threads/processes exibit critical unexpected dependence on t events. You are the first person to encounter this problem f race condition. I by which you can deal with this problem (like design a mutex, semaphore righ might now use any library functions, If you do you might be asked to implem although use Interrupts, both hardware and software to solve this question. 21. Implement a Garbage Collector for C++ http://www.codeproject.com/cpp/gc.asp 24. Why is Virtual Memory important?
http://en.wikipedia.org/wiki/Virtual_memory 25. How does the compiler know which virtual table to point to when the base cla its derided class object?
26. What will this do? int main(){ return main; } How much memory will it use ea compiler optimization or not)
27. What did you use to connect Perl to database? Dbmopen and Dbmclose Tie and untie 28. What is deep copy in C++? When would you use it? You will use deep copy when you have dynamically allocated members in a class 29. What is deep copy in C++? When would you use it?
In a deep copy (also called "memberwise copy"), the copy operation respects object semant copy when you have dynamically allocated members in a class 30. What's the difference between malloc and calloc? What is a static method in C?
First, is in the number of arguments. malloc() takes a single argument(memory required needs 2 arguments(number of variables to allocate memory, size in bytes of a single variabl Secondly, malloc() doesnt initialize the memory allocated, while calloc() initializes th ZERO. 31. What's the difference between Linked List and Array List
The main difference between the linked list and the array is that while the array is a static number of elements), the linked list - dynamic data structure. In terms of complexity, t more efficient as to the space it uses, however, algorithms for linked lists are usually more of the array. 32. What is difference between Java and C++? http://www.experts-exchange.com/Programming/Q_20687267.html 33. What is C++? C++ is an object-oriented language 34. What is Polymorphism?
Polymorphism in C++ is exhibited by the ability of a pointer or reference to a base class typ ways when it is used to manipulate objects of different subtypes of that base class. 35. What is virtual function?
Any base class method intended to be overridden in any subclass should be declared as virtual is optional, but recommended in subclasses Polymorphism in C++ works only with pointers and references and only with methods decl If a class declares any virtual methods, the destructor of the class should be declared ensures that regardless of the actual subclass of an object accessed via a base class pointer destructor will clean it up. 36. What are the main features of C++?
-oops (encapsulation, polymorphism, inheritance) -pass by reference -Template class and Template library -Exception handling -Defining variable wherever you want -Automatic pointer dereferencing. -Enforces data typing conventions. 37. What is a pointer? Do you use it a lot? Pointers are variables that hold addresses in C and C++. Yes 38. What is encapsulation?
In object-oriented programming, encapsulation is the inclusion within a program object o for the object to function - basically, the methods and the data. It is data abstraction with handling information. 39. What is a map in STL?
It is an associative container in STL of C++. Key-value pairs are stored. Duplicates are not a 40. Tell me some categories in STL?
-containers, iterators, generic algorithms, function objects, adapters. 41 7 servers running in parallel. What happens when you need to expand to 20 l What could you do to fix this issue in the future? - Threading 42 Coding: How would you find the nth to last element in a linked list?
To find nth element from the end u should advance fptr n number of time the beginning.After that fptr = fptr->next; sptr = sptr->next; when fptr is NULL then sptr will be at the nth element from end as we have already movedfp Please correct and explain if I am wrong
43 Coding: Jig saw puzzle. What are the data structures? Assume you have some m you if two pieces fit together. How would you solve the puzzle, minimizing the have to call that function?
44 You have a basket ball hoop and someone says that you can play 1 of 2 games. Y shot to get the hoop. Or, you get three shots and you have to make 2 of 3 sho choose? If p is the probability of making a particular shot, what value of p make
45 Coding: You have an array of ints. How would you find the two elements tha
value?
Sort the numbers in ascending order. Add first and last. If that equals then you get it. If value, shift the first by next one. If its more than the required value, shift the last one to prev 46 Coding: Implement a binary search in a sorted array int binarySearch(int y[], int lim, int key){ int low, mid, high = lim -1; low = 0; while (low <= high){ mid = (low+high)/2; if (key == y[mid] return (mid); else if (key < y[mid]) high = mid -1; else low = mid + 1; } return (-1) }
47 Coding: How would you reverse the words in a string? (ie, "the quick brown quick the"
First reverse the string And then reverse each word. 48. Computer Architecture: Virtual Memory, Interrupts, Cache, Hazards, CISC vsR
Virtual (or logical) memory is a concept that, when implemented by a computer and its programmers to use a very large range of memory or storage addresses for stored data. The the programmer's virtual addresses to real hardware storage addresses. Usually, the pr having to be concerned about the availability of data storage
A request-for-attention signal sent by either hardware or software to the CPU that causes t operations and transfer control to an interrupt handler
Cache memory is random access memory (RAM) that a computer microprocessor can acc can access regular RAM. As the microprocessor processes data, it looks first in the cache m data there (from a previous reading of data), it does not have to do the more time-consumin
CISC Variable length instruction Single word instruction Variable format Fixed-field decoding Memory operands Load/store architecture Complex operations Simple operations 49. When do you use a double pointer?
Double pointer (**) parameters are common in linked list or other pointer manipulating interest to share and change is itself a pointer, such as a linked list head pointer. 50. Draw all the components of a computer! 51. What's XD bit ? How does buffer overflow work ?
NX stands for No eXecute. Generically, it is a technology used in CPUs to segregate areas of storage of processor instructions (aka code) or for storage of data. Any section of mem attribute means it's only for use by data, therefore processor instructions cannot and shoul popular technique used to prevent certain types of malicious software from taking over com code into another program's data storage area and running their own code from within this a buffer overflow attack, and NX can prevent it in many cases. 52. Coding: function generate nth fibonnaci number - what's the largest n could be? int fibo (int int i, current, one_back, two_back; if return else one_back = two_back = for (i= current one_back = two_back; two_back = } /* } /* return } 53. Coding: Reverse linked list
(n
<=
2; i <=
n; i++)
end end
for else
lo bl
Static void* Reverse(struct node** headRef){ Struct node* result = NULL; Struct node* current = *headRef; Struct node* next; While(current != NULL){ Next = current->next; Current->next = result; result = current; current = next; } *headRef = result; } 54. Write code to compute the intersection of 2 rectangles. Rect A and Rect B. Upper Left(ul) and Lower Right(lr) co-ords are given. The following function will return true if they intersect.
int areIntersecting(Rect A, Rect B) { return ( ! ( (A.ul.x > B.lr.x) || (B.ul.x > A.lr.x) || (A.ul.y < B.lr.y) || (B.ul.y < A.lr.y)) } 55. What's the difference between c++ and java? 1>Platform Independent : Java code is said to be a multiplatform code and can run on any p compilation of the source code byte code(s) are created rather than a binary code so it can ru supports JVM concept but on the contrast at time(s) it slows down the application tremendo 2> Garbage Collection : Java handles freeing up of the memory but this is not guranteedsin lowest priority 3>Operator Overloading : is not provided in Java,but what are the advantages of Operator question what are its advantages, well it makes a more readable and a modular code. In c++ also be overloaded which again leads to a better readability and flexibility 4> Multiple Inheritance : Java does provide multiple inheritance in form of Interfaces, In Ja from more than one class but it definitely can implement any number of interfaces 5> Templates: in c++ give such a lot of flexibility and avoids redundant coding which again i 56. Coding: Many overlapping rectangles - want to return which (doesn't matter w several) rectangle the mouse is over.
57. I have a HxW picture, 32 bit picture --> represented by int array. How do you 90 degrees into a new array? Write the code
I guess transposing the 2 dimensional array will do the job. 58. Coding: binary search tree: - find element with given key and return, - node del Recursive implementation of search ========= Node* search ( Node* nodePtr, itemtype key ) if (nodePtr == NULL) return NULL else if ( nodePtr->item == key ) return nodePtr else if ( nodePtr->item > key ) return search(nodePtr->left, key) else return search(nodePtr->right, key) Deletion ====== Traverse tree and search for node to remove ! Five possible situations " Item not found " Removing a leaf " Removing a node with one child - right only " Removing a node with one child - left only " Removing a node with two children
59. Algorithm: You have a video card with memory. You can read and write to it. H write to it through a byte mask (if bit of byte mask ==1, then you can write to th stays unchanged). Also, you can not read the byte mask (you can only cha determine what the value of the byte mask is (you can write to the video card as to the same condition as you left it).
60. You have 2 arrays, a and b, both are sorted in ascending order. You know the know the size of a but you know a can at a minimum hold the size of the curren valid values are at beginning of array) plus the size of b. How do you combine while keeping a sorted when returned (no extra array to use) 61. : You struct { int struct have a linked
node
struct node } initially all childs are null and it is just a linked list. given a list with some m make a linked list such that: there is a linked list of just the not selected, then th list is an element without any data but its child is pointing to a linked list tha nodes (the last element of which points back to the one with - how would you traverse this new structure (even if there was a child th - what if that circular connection was cut, then how would - what if you can add a Boolean value to the structure (that you can only set a how would you do it
62. You know how web addresses convert spaces and such into i.e., space == - given a string, convert the string to a string where all what are the different ways to - what if unlimited memeory, what if you cant have any memory and the string end that isnt used - what if you want to say if the string will cutoff and only convert if cut off
63. Reverse C-Style String. void strrev { char *t = char ch = '\0'; while (s ch *s *t s++; t--; } } 64. : print a linked list in reverse order
- Can you do this in O(n) time, O(1) memory? [O(1) memory = no recursion]
-Reverse the linked list -Reverse the linked list again but this time print the values before reversing. 65. You have an array of integers (both positive and negative). Find the continuo largest sum. (i.e., if the array was {6,-8, 3, -2, 4} then you'd want to return {3,-2 This can be solved by Divided and conquer Approach.
Lets say A is the array. P and Q are indices of the two ends. If there are n numbe
So
the
pseudo
will
be
MAXSUM(A,P,Q) if return end r max1 max2 maxPartition for i = L <M <if maxPartition end end return = <<1 summation summation ((L+M)
P+Q =
max(max1,
max2,
Complexity: O(nlogn) 66. Game of battleship. Implement shoot(x, y). What are the data structure you wo
67. Find the first occurrence of a string in a multi-string. (Multi-string means t string like "cat\0dog\0monkey\0\0". The true end of the series of strings occ null chars in a row). 68. Copy a Linked List, and delete all even data from the Linked List. 69. Write a function to merge two sorted linked list in a sorted order. 70. Add numbers in base n. 71. Given a chunk of memory. 1. Implement malloc. 2. Implement free.
72. A disk is partitioned into two hemispheres colored in black and w is rotating.By appropriate positioning of sensors (A sensor can read the dis white) we need to find the direction of the motion of the disk.
73. The bigger the ratio between the size of the hash table and the number of da chance there is for collision. What is a drawback to making the hash table big of collision is ignorable? -probing will be a problem
74. How could a linked list and a hash table be combined to allow someone to run item to item while still maintaining the ability to access an individual element i
75. Given two log files, each with a billion usernames (each username appended to usernames existing in both documents in the most efficient manner? Use pse your code calls pre-existing library functions, create each library function from