Tag Archives: interview questions

Java based interview questions from Morgan Stanley, Amazon, Yahoo

Java based interview questions from Morgan Stanley, Amazon, Yahoo,

From Career Cup at http://www.careercup.com/page?pid=java-interview-questions&n=3

Amazon Interview Question for Software Engineer / Developersabout Java
offerfromMS on October 21, 2008

What is final, finalize and finally? Where do you use ‘final’ keyword. What is the effect of making a method final?
3
[Full Interview Report]

Tags: Amazon » Java » Software Engineer / Developer
Question #63476 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
JobSeeker on October 20, 2008

Why use inner classes?
10
[Full Interview Report]

Tags: Amazon » Java » Software Engineer / Developer
Question #63087 (Report Dup) | Edit
Yahoo Interview Question for Software Engineer / Developers aboutJava
The Hercules on September 01, 2008

Difference between final & finally
3
[Full Interview Report]

Tags: Yahoo » Java » Software Engineer / Developer
Question #57962 (Report Dup) | Edit
Yahoo Interview Question for Software Engineer / Developers aboutJava
The Hercules on September 01, 2008

Different ways to pass parameters to a function (by value, by reference, by pointer). for the following cases.
6.1 Basic data type (int, char etc)
6.2 Array of integers
6.3 an object of Structure
6.4 an object of a class
Discussed about possiblities of passing constant argument values (by reference, by pointer etc) & their syntax
8
[Full Interview Report]

Tags: Yahoo » Java » Software Engineer / Developer
Question #57959 (Report Dup) | Edit
Yahoo Interview Question for Software Engineer / Developers aboutJava
The Hercules on September 01, 2008

What is the effect by keeping a constructor private? (in terms of inheritance)
10
[Full Interview Report]

Tags: Yahoo » Java » Software Engineer / Developer
Question #57958 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Terminology & Trivia
g.usask on August 25, 2008

Say you are using a map in your program, how would you count the number of times the program use put() and the get() function? How would you do that if its using multiple maps in the program? How would you do that if the map is sent as a parameter in a method? How would you do it if the multiple maps are passed into the methods (as parameters), and are use differently? (it went on forever….)
12
[Full Interview Report]

Tags: Amazon » Java Terminology & Trivia » Software Engineer / Developer
Question #58095 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Terminology & Trivia
g.usask on August 25, 2008

What is the difference between Final, Finally, and Finalize?
4
[Full Interview Report]

Tags: Amazon » Java Terminology & Trivia » Software Engineer / Developer
Question #58094 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
g.usask on August 25, 2008

What does the “Static” keyword do? Do you know any other similar keywords? What are they?
4
[Full Interview Report]

Tags: Amazon » Java » Software Engineer / Developer
Question #58093 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Jackie on August 08, 2008

What do you know about Java generics
2

Tags: Amazon » Java » Software Engineer / Developer
Question #57410 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Terminology & Trivia
Anonymous on August 04, 2008

what is object reflection in Java
3
[Full Interview Report]

Tags: Amazon » Java Terminology & Trivia » Software Engineer / Developer
Question #57338 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Terminology & Trivia
Anonymous on August 04, 2008

How does Java achieve synchronization? Given an class with Synchronized method A and B, a normal method C, there are 2 threads, one instance, can these two threads call A at the same time? call A and B at the same time? A & C at the same time?
4
[Full Interview Report]

Tags: Amazon » Java Terminology & Trivia » Software Engineer / Developer
Question #57337 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Terminology & Trivia
hipy16 on July 22, 2008

Difference between int and Integer in Java.
6
[Full Interview Report]

Tags: Amazon » Java Terminology & Trivia » Software Engineer / Developer
Question #57141 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Experience
hipy16 on July 22, 2008

What are the interfaces in Collection classes that you worked with?
(Collection, Set, Map, List, Queue)
2
[Full Interview Report]

Tags: Amazon » Java Experience » Software Engineer / Developer
Question #57116 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java Data Structures Object Oriented Design Coding
S on July 01, 2008

Had my first and second phone interview with Amazon. I was dropped. This site has been a great help towards my preparation and most questions are based on what you find here.
Posting my Questions is a small way of saying Thanks!
Interview 1:
1. What is polymorphism.
2. Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.
3. Coding: I have an integer array where every number appears even number of times and only one appears odd times. Find the number.
(I said hashtable and he asked me to write code with Hashtable)
4. What data structure would you use to look up phone numbers for customer names.
(I said Hashtable. Asked why hashtable, why not a tree. I said HT has O(1). Asked is order always 1, when more than O(1) in HT.
Second Interview:
1. Starter: Describe your college projects.
2. OO Design: Design a deck of cards. What classes, data structures will you use? How will you shuffle the cards? How will you divide (deck) among players. What class/function do you need to denote players and where will you add them? What class/function do you need to deck? What if I need to add 2 jokers to the deck of 52 cards.
3. Data Structures: How will you use a hashtable to find data in a tree. (Then he rephrased) suppose I have a hashtable, I want to store the data in a tree instead of a bucket. How will I do it. What complexity to find an element.
4. Bits & Bytes: Find if a binary representation of a number is palindrome. The function should work irrespective of number of bytes for an integer. Suppose if our machine is 4 bytes for an int, how will you use the program for 8 byte machine.
5. Unix: Suppose I have 100’s of html files in many directories. I want to find the files having phone numbers.
b) Suppose I have 2 files having phone numbers, find the repeating phone numbers. (I said sort and grep). Then he asked what if the lines cannot be sorted.
All the best guys. I think the second interview was challenging since the interviewer was prodding until he heard a leave me alone. So it means that though they are based on questions in cc, be prepared for extensions. I think this site is all you need to prepare for Amazon interview.
19

Tags: Amazon » Java Data Structures Object Oriented Design Coding » Software Engineer / Developer
Question #56632 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on June 15, 2008

What is the flaw in the design of Java.lang.Stack class of Java
7

Tags: Amazon » Java » Software Engineer / Developer
Question #2730 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on June 15, 2008

what is the difference between template in C++ and generics in java
5

Tags: Amazon » Java » Software Engineer / Developer
Question #2729 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on June 15, 2008

What is the use of volatile variable.
Explain it in Singleton class also for lazy initialization.
5

Tags: Amazon » Java » Software Engineer / Developer
Question #2726 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on June 15, 2008

How Java is plateform independent
5

Tags: Amazon » Java » Software Engineer / Developer
Question #2725 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

How to implement your own HashMap in java
1

Tags: Amazon » Java » Software Engineer / Developer
Question #2713 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

give the algorithm for checking anagram
5

Tags: Amazon » Java » Software Engineer / Developer
Question #2712 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

Why should you not make your Sinleton claas as Serializable and Clonable.
3

Tags: Amazon » Java » Software Engineer / Developer
Question #2711 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

What is the difference between sleep and yield method
3

Tags: Amazon » Java » Software Engineer / Developer
Question #2710 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

What is the limitation of singleton pattern
4

Tags: Amazon » Java » Software Engineer / Developer
Question #2789 (Report Dup) | Edit
Fair Issac Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

Tell the situation where we can use nested classes.
2

Tags: Fair Issac » Java » Software Engineer / Developer
Question #2708 (Report Dup) | Edit
Fair Issac Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

What was the problem in implementing double checked locking before java 1.5.
2

Tags: Fair Issac » Java » Software Engineer / Developer
Question #2788 (Report Dup) | Edit
Amazon Interview Question for Software Engineer / Developersabout Java
Alok Kesharwani on May 31, 2008

Why Java language designer has chosen to make all the variable inside an Interface as public ,static and final.
5

Tags: Amazon » Java » Software Engineer / Developer
Question #2706 (Report Dup) | Edit
Fair Issac Interview Question for Financial Software Developersabout Java
helper on May 09, 2008

What are the various ways in singleton pattern can be made to fail and how to avoid them ?
7

Tags: Fair Issac » Java » Financial Software Developer
Question #2673 (Report Dup) | Edit
Morgan Stanley Interview Question for Software Engineer / Developers about Java Terminology & Trivia
MJ on March 06, 2008

Do you know the big difference b/w .NET and JVM? (I answered CLR, and it’s correct) What is .NET? (A sort of JVM with gc 🙂
2
[Full Interview Report]

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Bloomberg interview questions or BOA interview questions for a C++ job? Answers included too

Bloomberg Q&A
I got phone interviewed with Bloomberg.
1)diff bet class and structure
2)syntax of copy constructor
3)why we need copy constructor?
4)why we need overloaded = operator?
5)signature of overloaded = operator for a class?
e.g. Myclass & operator =(const Myclass &)
6)why & used in return type of = operator ?
7)suppose :

class Myclass{
public:
Myclass(int a){m=a;};

private :
int m;
};

a)how will u create an array of objects of Myclass on stack?
b)how will u crete an array of objects on heap?

8)what precautions should be taken to write a class’s destructure?
9)what will u do to prevent others from creating more than one instances of ur class?
10)how will u make singleton thread safe?
10.1) what problem may occure with singleton at run time?
11)what is diff between “operator new” and “new” ?
12)what happens if new fails to allocate memory?

1. By default class has private access specifier and structure has public in C++.
2. MyClass(const MyClass &)
{
}
3. To create a copy of existing object.
4. By default = does a shallow copy so if your class has pointers to some other data type except inbuilt one then a shallow copy would be done and it may result in dangling pointers.
5. const MyClass& operator = (const MyClass &)
{
}
6. So that chaining can be possible like below
x = y = z = 10;
8. The class destructor should never throw an exception. A destructor can be called in 2 ways.One when an object goes out of scope and 2nd when stack unwinding happens.So if a destructor is called due to stack unwinding and it throws an exception then C++ unexpected is called which calles terminate which terminates the whole application.Nothing is destroyed not even local objects.
9. Make class Singleton.
10. Use Mutex to warp the code where instantiation happens.
11. Operator new allocates raw memory only.It is similar to malloc() in C.
new first allocates raw memory using operator new and then calls constructor for the class.
12. bad_alloc exception is thrown.

7a.
Myclass myclass[10]; will not work.This statement would give a compile time error as the class lacks a default constructor.

To construct the array on stack it would be done like below

int i[] = {1,2,3,4,5,6,7,8,9,10};

MyClass myClass[10] = {1,2,3,4,5,6,7,8,9,10};

—> ” Myclass *myclass = new MyClass[10]; ” here new will allocate memory and creates object as well, by calling its default constructor. During compilation, You will encounter ‘No appropriate default constructor available’ error.
Rest of the code is also error.

The correct answer to 7b is:

MyClass* mc[10];
for (int i=0; i < 10; i++) mc[i] = new MyClass(i); <--- it will call user-defined constructor here. To point#8, it is necessary declare it as "virtual" also if the destructor is called by a base pointer: class A {...}; class B: public A {...}; ... A* pA = new B(); ... delete pA; If A destructor is not virtual only A destructor is called. BOA questions 1) Type of stl containers 2) difference in composition, agregation,association. 3) Predicates 4) Deadlock and Starvation 5) Raised condition 6) Diff in Conversion ctr and explicit ctr 7) diff in has_map and map 8) explain hash_map and bucketing 9) virtaul inheritance, diamond problem 10) function adaptors 11) fucntors 12) function objects 13) in how many ways two classes A and B be related to each other. 14) diff between vector and dqueue 15) Repopulation of dqueue and its complexity. 16) types of iterators 17) how would you implement a map. 18) concept of immutability.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Simplest builder pattern code sample in C++ for job interview questions using an abstract base class with derived concrete classes

Simplest builder pattern code sample in C++ for job interview questions using an abstract base class with derived concrete classes.

This example builds ‘distributed work packages’
This seems to the best build pattern code on the net. This basically builds an object step by step. In a nutshell, this example, distributed work packages are abstracted to be persistant and platform independent. This includes files, queues, pathway, etc. A reader or parser retrieves the archives specs through DistrWorkPackage. It will then delegate each build step to the builder object that was registered by the client. At the end, the client will retrieve the end result from the builder

//from http://sourcemaking.com/design_patterns/builder/cpp/1#

#include
#include
#include

enum PersistenceType
{
File, Queue, Pathway
};

struct PersistenceAttribute
{
PersistenceType type;
char value[30];
};

class DistrWorkPackage
{
public:
DistrWorkPackage(char *type)
{
sprintf(_desc, “Distributed Work Package for: %s”, type);
}
void setFile(char *f, char *v)
{
sprintf(_temp, “\n File(%s): %s”, f, v);
strcat(_desc, _temp);
}
void setQueue(char *q, char *v)
{
sprintf(_temp, “\n Queue(%s): %s”, q, v);
strcat(_desc, _temp);
}
void setPathway(char *p, char *v)
{
sprintf(_temp, “\n Pathway(%s): %s”, p, v);
strcat(_desc, _temp);
}
const char *getState()
{
return _desc;
}
private:
char _desc[200], _temp[80];
};

class Builder
{
public:
virtual void configureFile(char*) = 0;
virtual void configureQueue(char*) = 0;
virtual void configurePathway(char*) = 0;
DistrWorkPackage *getResult()
{
return _result;
}
protected:
DistrWorkPackage *_result;
};

class UnixBuilder: public Builder
{
public:
UnixBuilder()
{
_result = new DistrWorkPackage(“Unix”);
}
void configureFile(char *name)
{
_result->setFile(“flatFile”, name);
}
void configureQueue(char *queue)
{
_result->setQueue(“FIFO”, queue);
}
void configurePathway(char *type)
{
_result->setPathway(“thread”, type);
}
};

class VmsBuilder: public Builder
{
public:
VmsBuilder()
{
_result = new DistrWorkPackage(“Vms”);
}
void configureFile(char *name)
{
_result->setFile(“ISAM”, name);
}
void configureQueue(char *queue)
{
_result->setQueue(“priority”, queue);
}
void configurePathway(char *type)
{
_result->setPathway(“LWP”, type);
}
};

class Reader
{
public:
void setBuilder(Builder *b)
{
_builder = b;
}
void construct(PersistenceAttribute[], int);
private:
Builder *_builder;
};

void Reader::construct(PersistenceAttribute list[], int num)
{
for (int i = 0; i < num; i++) if (list[i].type == File) _builder->configureFile(list[i].value);
else if (list[i].type == Queue)
_builder->configureQueue(list[i].value);
else if (list[i].type == Pathway)
_builder->configurePathway(list[i].value);
}

const int NUM_ENTRIES = 6;
PersistenceAttribute input[NUM_ENTRIES] =
{
{
File, “state.dat”
}
,
{
File, “config.sys”
}
,
{
Queue, “compute”
}
,
{
Queue, “log”
}
,
{
Pathway, “authentication”
}
,
{
Pathway, “error processing”
}
};

int main()
{
UnixBuilder unixBuilder;
VmsBuilder vmsBuilder;
Reader reader;

reader.setBuilder(&unixBuilder);
reader.construct(input, NUM_ENTRIES);
cout << unixBuilder.getResult()->getState() << endl; reader.setBuilder(&vmsBuilder); reader.construct(input, NUM_ENTRIES); cout << vmsBuilder.getResult()->getState() << endl; } This will output: Distributed Work Package for: Unix File(flatFile): state.dat File(flatFile): config.sys Queue(FIFO): compute Queue(FIFO): log Pathway(thread): authentication Pathway(thread): error processing Distributed Work Package for: Vms File(ISAM): state.dat File(ISAM): config.sys Queue(priority): compute Queue(priority): log Pathway(LWP): authentication Pathway(LWP): error processing

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Everything you need to know about binary trees and circular linked lists for C++ job interview questions

Everything you need to know about binary trees and circular linked lists for C++ job interview questions

In order to properly build a binary tree, you need to do the following steps:

1) Inorder traversal of a Binary search Tree prints the data in the increasing order.
2) While doing in order traversal, at each step, build the linked list adding the each element at the end of linked list.
3) At each step, also make the end of the linked list to point to the first element of the linked list. This will make the linked list circular.

Here is a code sample of a binary sorted tree that can be converted to a linked list (this also ensures the list is circular):

#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#define MAX 1000
#define max(a,b) (a)>=(b)?(a):(b)
#define REP(i,n) for(i=0;i
/*** structure of the tree node ****/
struct node
{
int data;
node *small;
node *large;
};
/* fun to insert element in the binary search tree */
void insert(node **root,int val)
{
node *tmp;
if(*root==NULL)
{
tmp=(node*)malloc(sizeof(node));
tmp->data=val;
tmp->small=NULL;
tmp->large=NULL;
*root=tmp;
}
else
{
if(val<(*root)->data)
insert(&((*root)->small),val);
else
insert(&((*root)->large),val);
}
}
/* this function joins two given nodes */
void join(node **a,node **b)
{
(*a)->large=(*b);
(*b)->small=(*a);
}

/* this function appends second list behind first list */
node *append(node *head1,node *head2)
{
if(head1==NULL)
return head2;
if(head2==NULL)
return head1;

node *alast,*blast;
alast=head1->small;
blast=head2->small;

join(&alast,&head2);
join(&blast,&head1);
return head1;
}

/**** most important function ,uses recursion to convert bst to circular ll ***/

node* treetolist(node *root)
{
if(root==NULL)
return NULL;

node *alist,*blist;
alist=treetolist(root->small);
blist=treetolist(root->large);

root->small=root;
root->large=root;

alist=append(alist,root);
alist=append(alist,blist);

return alist;
}

/* funtion to display bst */
void display(node *root)
{
if(root!=NULL)
{
display(root->small);
cout<data<<"\t"; display(root->large);

}
}

/* function to display ll */
void displayl(node *head)
{
for(int i=1;i<=5;i++) { cout<data<<"\t"; head=head->large;
}
}
int main()
{
node *root=NULL;
node *head;

/* test values */
insert(&root,10);insert(&root,4);insert(&root,8);insert(&root,15);insert(&root,9);
display(root);
cout<

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Pointer job interview questions involving C++ pointers and raw pointers

Pointer job interviews involving C++ pointers and raw pointers
The general difference between a reference and a pointer is that pointers can be null while references cannot be. Also, references needed to be initialized when created, cannot reseat one reference to an object, and cannot take a reference of a reference, but a pointer of pointer is possible. References should be used to define ‘attractive’ interfaces while pointers should be used to implement data structures and implement algorithms.
Shallow copy versus deep copy
Shallow copy means copy each bit of one member block to another. Also, if pointers are involved so new memory location will be created and data is copy into that location.
A deep copy (also known as a hard copy) involves recursively copying variables in a nested structure or in a nested object. This also involves copying from one structure to another if there are pointers in the structure, then the second pointer will point the same as the first one. This will copy all fields and also makes copies of dynamically allocated memory pointed by the fields. In order to deep copy, you must create a copy constructor which will overload the assignment operator otherwise it will copy and point to the original with disastrous results.
The difference between calloc and malloc are:
There are 2 arguments needed for calloc while malloc only needs one. The initializing of memory in calloc is zero.
Malloc reduces the need to request more memory from the operating system since it is done on a user by user basis. It recycles the freed memory space. When pointers are created and free ( pointer) is called, the header and foot are looked at by the memory allocator. The header contains information on necessary items including the size of space taken up, status if the memoery block is freed or allocated, and know if it can be removed or not.
When pointers are allocated, two bytes are used with the size of the memory block. The memory block can be assigned based on best fit or worst fit. This free memory list cannot a single linked list. This linked ist could be a balanced tree.
Sizes of memory could be:
Char a[] = “ “; could be two bytes while
Char b[10] would be 10.
a will contain two bytes where one is null and the other is ‘\0’. The trick is to remember that it will allocated to characters to this array. In short, a would be whatever is in the quotes plus a null characters as well.
Also, if you do char *c, size would be 4 in 32 bit systems but will be 8 in 64 bit systems so if you do:
b=c; size would become 4 as well.
Also, note char a[]=”hello” will be six bytes while char *P=”Hello” will result in four bytes.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

c++ interview questions on functors, namespace, and using

c++ interview questions on functors, namespace, and using

Namespace:

What problem does the namespace feature solve?
Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library’s external declarations with a unique namespace that eliminates the potential for those collisions.
namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.
What is the use of ‘using’ declaration?
A using declaration makes it possible to use a name from a namespace without the scope operator.
What is an Iterator class?
A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. Something like a pointer.

Functor:
What is a functor?
Functor means function pointers. The pointer variable that holds the address of some function.
Syntax for declaring a functor is:

return_type (* nameofFunctor)(parameter_type1, 2, 3, ……);

It means nameofFunctor is a functor that can point to functions taking parameter_type1, 2, 3, ….. and returning return_type

Functors are functions with a state. In C++ you can realize them as a class with one or more private members to store the state and with an overloaded operator () to execute the function.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ interview questions on database, debugging, gdb, arrays

Database:
Suppose your software requires the client to enter information into a database. What do you do if data insertion takes too long?
I said, improve the hardware. Not what he was looking for, but the answer worke
Debugging
in unix one task/process is stuck. How will debug it ?
Attach it to GDB via gdb -p PID and see where its stuck. Now examine various parameter values, to see what they are at the moment (this is convenient the process and libraries were compiled with -g i.e. with debugging information. Otherwise disassemble current (or previous frames) via gdb, and get ready for long session of reading assembly).

Simple function to add two numbers – try to think of all possible ways to debug it –
int range overflow (how to detect) , incorrect inputs, error codes and return values etc.
Arrays:
what all errors is possible if u write past the array bounds?
memory corruption, call stack corruption. In unix, scope is limited to these 2 inside a process. In RTOS, the corruption can span across multiple tasks/processes
you inadvertently overwrite some portion of memory that some pointer or a variable is pointing to when you write past array bounds

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

c++ interview questions on garbage collection, java, cast,

Garbage Collection:
If you were to implement a garbage collector in C++ how will you do it?

the easiest way is to use ref count list
check out

http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Implementation_strategies
create a daemon thread

“What is multiGenerations Garbage Collection?”
Variable scope:
scope of variables – that has goto and multiple blocks in a program

casting
size_t
(Programming Language Test) When casting an object of a polymorphic class from a base class, which kind of cast executes only if it’s is valid?
choices were a number of different kinds of casts – dynamic, static, reinterpret, etc.
You should use dynamic cast. It returns a null pointer if it’s not valid. Reinterpret will give you a bad pointer since the cast will be pointing to the wrong part of the polymorphic object.

Also, it’s important to note the difference between using pointers vs references in the case of casts. In C++, if you use a pointer in a dynamic_cast<>() and it fails, the result is a null pointer. However, since you cannot have a null reference, dynamic casts need to be wrapped in try/catch blocks.
Datsa structure
Data Structures for handling high volume data

time complexities
java:
What are the trade-offs in C++ vs Java?

http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B

does java.io have for preventing malicious code from altering Serialized Objects?
What support does java.io have for preventing malicious code from altering Serialized Objects?
When using an ArrayList as the implementation for a list collection, what happens if adding an element exceeds the ArrayList’s capacity?

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

c++ interview questions on XML, quant, and multithreading

XML
You have to manually parse HTTP call whereas SOAP library parses the XML for you and provides methods to get the header and body information.
Quant based:
Describe a CDS to a layman.

What is Z spread?

Difference between a forward and a future?”
Find the error code sample:
Find the error and fill in the blanks, what is the output?
i=0;
i++ || ++i || i–;
printf(“%d\n”,i);
by Scofield:
i++ and I — negate each other, so ++i
i =1
i == 2

i++ is post-increment, when the first operator || gets the value it will still be zero.
++i is pre-increment, so the second operator || will get 2
The || operator will shortcut with:
0 || 2

so the final ++i will not be executed.
Multithreading:
How can you lock a portion of a file and how to use it ?
man -S 2 fcntl

The lockf() function shall lock sections of a file with advisory-mode locks. Calls to lockf() from other threads which attempt to lock the locked file section shall either return an error value or block until the section becomes unlocked.

Say you have a multithreaded network I/O bound server that is single-threaded, under a load of tens of thousands of connections. What is the most expensive operation encountered in processing data, and how would you minimize the impact of the operation?
The most expensive operation is the read from the network socket. You would minimize its impact by using non-blocking sockets and reading as much as you could in one go; this would allow a minimal number of read operations to obtain the contents of the stream.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ interview questions on binary trees with in order traversal, linked list, recursive traverse

C++ interview questions on binary trees with in order traversal, linked list, recursive traverse

Binary tree:
Convert a binary search tree to a circular sorted linked list. The highest valued node should point to the lowest valued node at each step.
I think it should be implemted by using Breadth-first traversal.

We can Insert elements in link list by traversing tree in INORDER. At last we can point last elemtents node to the head.

You are right.
Inorder traversal would give a sorted list which can be pused inside a circular link list.

Guys,

1) Inorder traversal of a Binary search Tree prints the data in the increasing order.
2) While doing inorder traversal, at each step, build the linked list adding the each element at the end of linked list.
3) At each step, also make the end of the linked list to point to the first element of the linked list.

Basically, we need to maintain always two pointers, one to head and another to the last element of the linked list

its the great tree list recursion problem… find it on
http://www.google.com/search?hl=en&q=stanford+cs+lib&btnG=Search

Question doesn’t restrict space usage and thus this is not that ‘great’ problem. Moreover, this is a question asked for Program Manager.

void main_class::iterate(Node *new_node)
{
char flag;
Node *temp_parent = NULL;
if (root == NULL)
{
//This is the root node
root = new_node;
cout<<"Root value: "<value<<"\n\n"; } else { //This is not a root node and hence, now we iterate Node *current = root; while(current != NULL) { if(current->value < new_node->value) // Go right
{
temp_parent = current;
current = current->child_right;
flag = ‘r’;

}
else
{
temp_parent = current;
current = current->child_left;
flag = ‘l’;

}
}

new_node->parent = temp_parent;
if(flag == ‘l’)
{
temp_parent->child_left = new_node;
}
else
{
temp_parent->child_right = new_node;
}
cout<<"Value: "<value<<" Parent value: "<<(new_node->parent)->value<<"\n\n"; } } /* This is a recursive function to traverse the binary tree INORDER */ void main_class::recursive_traverse(Node *current) { if(current->child_left != NULL)
{
current = current->child_left;
//cout<<"Going left to: "<value;
recursive_traverse(current);
current = current->parent;
}

cout<value<<" "; /* This section is for making of the Circular Linked list*/ if(previous_node == NULL) { /* This is the head*/ previous_node = current; root = current; //root->child_left = NULL;
//previous_node->child_left = NULL;
}
else
{
//previous_node->child_right = current; // Logical error here. The tree structure is being changed
//before the tree can be traversed!
current->child_left = previous_node;
previous_node = current;
}
/* Section for making of the Linked List ends here */

if(current->child_right !=NULL)
{
current = current->child_right;
//cout<<"Going right to: "<value;
recursive_traverse(current);
}

return;
}

Oops… u guys will need one more function…lol… on May 09, 2009 |Edit | Edit

{
new Node(7); new Node(4); new Node(3); new Node(5);
new Node(15); new Node(12); new Node(10);

recursive_traverse(root);

Node *an_iterator = previous_node;

/*The following part connects the root node
to the last node making the queue circular
*/
root->child_left = previous_node;
previous_node->child_right = root;

/* The following prints the Linked list
to check if it is indeed the list that
was intended. It also makes it a double
linked list form a single linked list while doing so.
It was not possible to make a double linked list
to begin with because it was creating a logical
error as indicated a few lines of code below.
Hence, iterating from right to left.
*/

cout<<"\n\nThe Linked list: "; while (an_iterator != root) { cout<value<<" "; an_iterator->child_left->child_right = an_iterator;
an_iterator = an_iterator->child_left;
}

/*
This extra print statement has to be put
outside to print the root node’s valuel
*/
cout<value<<" "; cout<<"\n\n"; } Isnt the problem statement to convert the existing bst to a ll and not creating a new one!!! This is the well working code for this problem..:) #include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#define MAX 1000
#define max(a,b) (a)>=(b)?(a):(b)
#define REP(i,n) for(i=0;i
/*** structure of the tree node ****/
struct node
{
int data;
node *small;
node *large;
};
/* fun to insert element in the binary search tree */
void insert(node **root,int val)
{
node *tmp;
if(*root==NULL)
{
tmp=(node*)malloc(sizeof(node));
tmp->data=val;
tmp->small=NULL;
tmp->large=NULL;
*root=tmp;
}
else
{
if(val<(*root)->data)
insert(&((*root)->small),val);
else
insert(&((*root)->large),val);
}
}
/* this function joins two given nodes */
void join(node **a,node **b)
{
(*a)->large=(*b);
(*b)->small=(*a);
}

/* this function appends second list behind first list */
node *append(node *head1,node *head2)
{
if(head1==NULL)
return head2;
if(head2==NULL)
return head1;
node *alast,*blast;
alast=head1->small;
blast=head2->small;

join(&alast,&head2);
join(&blast,&head1);
return head1;
}

/**** most important function ,uses recursion to convert bst to circular ll ***/

node* treetolist(node *root)
{
if(root==NULL)
return NULL;
node *alist,*blist;
alist=treetolist(root->small);
blist=treetolist(root->large);

root->small=root;
root->large=root;

alist=append(alist,root);
alist=append(alist,blist);

return alist;
}
/* funtion to display bst */
void display(node *root)
{
if(root!=NULL)
{
display(root->small);
cout<data<<"\t"; display(root->large);

}
}
/* function to display ll */
void displayl(node *head)
{
for(int i=1;i<=5;i++) { cout<data<<"\t"; head=head->large;
}
}
int main()
{
node *root=NULL;
node *head;
/* test values */
insert(&root,10);insert(&root,4);insert(&root,8);insert(&root,15);insert(&root,9);
display(root);
cout<
struct ListNode
{
T value;
ListNode* next;
explicit ListNode(T v) : value(v), next(NULL) { }
};
template
struct TreeNode
{
T value;
TreeNode* left;
TreeNode* right;
};

template
ListNode* to_list(TreeNode* tree, ListNode*& tail)
{
ListNode* list = NULL;
if (tree)
{
list = to_list(tree->right, tail);
ListNode* node = new ListNode(tree->value);
if (!list)
{
list = node;
}
if (tail)
{
tail->next = node;
}
tail = node;
node->next = to_list(tree->left, tail);
}
return list;
}

cristi.vlasceanu on July 17, 2009 |Edit | Edit

oh, and to make the list circular we need to call the function like this:

ListNode* tail = NULL;
ListNode* list = to_list(tree, tail);
if (tail)
tail->next = list; // make it circular

what nagendra.kumar suggested is right.
this way list would be sorted in increasing order and each element would be pointing
to the smallest as per the question.And there is no need to traverse right subtree first.

i m using double linked list….

node *p=NULL;
node* Cirq(node *t)//we have call with root node….
{

if(t->left !=NULL)
{
p=tree(t->left);
p->right=t;
t->left=p;
}
else if(t->right !=NULL)
{
p=tree(t->right);
t->right=p;
return p;
}
else
{
return t;
}
}

Inorder traversal would print the numbers in icreasing order for Binary search tree.

inorder(Node *root)
{
if(root)
{
inorder(root->left);
//printf(“%d”, root->value); Instead of print to just assign the next poiter to end //of the list. I guess that shoudn;t be hard to figure how to assign the next link 😉
inorder(root->right);
}
}

one more statement after the end of the traversal to point the last node to the head of the list
Reply to Comment
nirmalr on November 09, 2009 |Edit | Edit

// Routine to convert tree into doubly list
// after conversion “right” points to “next” node and “left” points to “prev” node

node_t * toList(node_t *curr, node_t *next) {
if (curr == 0) return next;

curr->right = toList(curr->right, next);
if (curr->right)
curr->right->left = curr;

return toList(curr->left, curr);
}

invoke like this,

head = toList(root, 0);

this routine returns head of the list. head and tail is not linked that can be done easily.

abhimanipal on May 09, 2010 |Edit | Edit

Very nice and effective solution

typedef node * NodePtr;

node *CreateListFromTree(node *root)
{
NodePtr start = NULL, tail = NULL;
CreateListFromTreeCore(root,&start,&tail);
return start;
}

/* Assume right for tree will act as next for Linked List */
void CreateListFromTreeCore(node *root, NodePtr *start, NodePtr *tail)
{
CreateListFromTreeCore(root->left,start,tail);
node *temp = root->right;
root->left = NULL;
if (*start == NULL)
*start = *tail = root;
else
{
(*tail)->right = root;
*tail = root;
}
*tail->right = *start;
CreateListFromTreeCore(temp,start,tail);
}

Question is convert BST to LL but not create another list and copy values.
here is working solution.

btnode* formListFromBT(btnode* root, btnode* cur, btnode** head) {
if(!root) return cur;

cur = formListFromBT(root->left, cur, head);
if(*head == NULL) {
*head = cur = root;
}
cur->left = root; cur = cur->left;

cur = formListFromBT(root->right, cur, head);
}

// call the above function using…
btnode *listhead = NULL;
tail = formListFromBT(head, NULL, &listhead);
tail->left = listhead;
Reply to Comment
Anonymous on January 14, 2010 |Edit | Edit

//call will be
// Element *start = null;
// Element *tail = BuildCircularLL(root, &start);
// tail->left = start;

Element *BuildCircularLL(Element *head, Element **start)
{
Element *begin = *start;
Element *node = head;
Element *prev = null;
Element *after = null;
if(node == null)
{
return null;
}
prev = BuildCircularLL(&node->left, &begin);
if(prev != null)
{
if(begin == null)
{
begin = prev;
}
prev->left = node;
}
after = BuildCircularLL(&node->right, &begin);
if(after != null)
{
node->left = after;
node->right = null;
return after;
}
else
{
return node;
}

}

binary search to speed up

balancing binary trees, find the depth of a tree.
They asked about balancing binary trees and
Print nodes in a binary tree in level order
Tree traversal

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!