Friday, 17 July 2009

C++ Interview Questions - Finance

Finance is a bitch of an environment to work in, especially if you are coding in C++! You can end up spending endless hours staring at tiny bits of strings and numbers, wondering what the hell is happening. It can get to be quite a bit of a pain, as the problem is compounded with real time data, and if you are working with something like NASDAQ, you can be looking at 27 GB of data a day! That's pretty much alot of trades, but NASDAQ is pretty much as big as the whole of Europe combined in the number of trades that go on during the day (So whomever said the USA is declining as a superpower, please get a clue - far from it).

Anyway, I've always had issues finding any conclusive interview preparation when it came to programming and finance, because what I think that there is a critical gap between the developers and the bankers, a sort of digital divide, that the bankers are pretty much idiots when it comes to technology, and all us developers have taken jobs with NO FINANCE EXPERIENCE REQUIRED at the bottom of the job description........ I don't know what can be done to fix that, and i dont really care because I've done my own homework when it comes to finance. So maybe some time when am not stressed about that damn feed handler, I'll propose a new recruitment philosophy and arrogantly blog about it.

So to the meat. Here are some questions (and answers mind you) I have encountered, whether through being interviewed or interviewing, or just plain day-to-day issues I came across.

In no particular order:

1) How many vtables do you have in any particular program?

A: C++ maintains a virtual table for each class within your program.

2) What is the difference between allocating memory using new and malloc ? What are the disadvantages of malloc?

A: New allocated memory on the heap, while malloc allocates memory on the stack. Memory allocated using the heap will live throughout the lifetime of the program, while malloc goes out of scope as soon as the method/class it is contained in returns. Malloc is also bad as it can lead to memory leaks, and running out of memory if we do not free the memory we allocate. In addition, malloc will allocate a fixed chunk of memory that is static and must be set by the user, while that is left up to the system when you use new. New also invokes the destructor automatically

4) What is the difference between free and realloc ?

5) What are the four methods that are provided for you with by default when a class is invoked?

A: Constructor, destructor, copy constructor and assignment

6) How many bits in a byte? Give an example of where you would want to use bit manipulation in a financial context.

A: 8 bits in a byte. If you are receiving messages from a trade, you may want to move pointers around the bits and bytes to read through them.

7) So you are receiving messages from an exchange - in a tag->value format. What would be a suitable data structure to use ?

A: A map.

8) So you are using a map, what is the disadvantage of using erase()

A: when u erase an element from a map, the map reshuffles, and ur pointer may either be pointing to null, or to a different location in the map.

9) What is the size of a pointer?

10) What is the difference between a shared pointer, an auto pointer and a regular pointer.

share and auto pointers are smart pointers. Smart pointers own the object they point to, and thus are responsible for deleting it (calls delete on itself). An auto pointer is a regular pointer wrapped by an object that owns this pointer, and deletes it when that object goes out of scope. Shared pointers compliment auto pointers, and you don't need to know who owns it. When the last shared pointer for an object in memory is destructed, the wrapped pointer will also be deleted.

11) What is a pure virtual function? What would be a scenario when u would need to declare a virtual function as pure?

A: A pure virtual function has no implementation and it usually belongs to a parent in a parent-child class hierarchy. Rather the implementation is left to the inherited class- yet pure virtual functions force inherited classes to implement that function, yet when that method is not pure, the child class does not need to implement it. (Although it can).

12) What is the difference between overloading and overriding?

A: Overriding is usually in inheritance, that u override a function in the base class by re-implementing it in the child class, usually by having the same function with a different implementation, while you overload operators or functions that have the same name but different signatures are thus overloaded. Another flavor of overloading would be operator overloading, where u can use the + operator to add an integer to a pointer for example.

12) What is the recommended maximum level of inheritance in any number of classes?

A: Try to restrict your parent child relationship to 3 levels : parent-child-grandchild. Deeper levels can lead to circular references and confusion.

13) Assume you have a child class, and you declare an object of type of the base class in the child class. That object is pointing to a method in the child class. What happens when you delete the pointer? (An asshole in New York asked me this during an interview)

A: (This one still escapes me, if anyone has an answer or better explanation, give me a shout).

14) What is the difference between private and protected?

A: Private functions are private to the class itself, and its children, but none else. Methods declared as protected are accessible by friend classes.

15) What are forward declarations?

A: Forward declarations allow us to declare objects before providing definitions for them. That's probably why you would need to declare ur methods in ur header files first. You can use them in ur program and it would compile even before u implement them (or just have an empty { } implementation).

16) What is an abstract class?

A: An abstract class is a class containing at least one abstract method - an abstract method is a method declaration without any implementation.

17) What is the difference between a copy constructor and constructor ?

A: A copy constructor is a constructor that takes an object of itself as an argument:

class MyObject (MyObject A);

18) What is the lookup time of a hash table? How about sorting it? What can be the worst case scenario?

A: O(1) for lookup, O(logn) for sorting. The worst case scenario for hash table sorting is O(n) if heavy chaining occurs - i.e. lots of collisions with all elements having the same hash value.

19) What is the lookup time for a Binary Search Tree? How about sorting it?

A: O(logn) for lookup, O(nlogn) for sorting.

20) What is the reference of a null pointer?

A: Null pointers always point to reference 0 (zero).

21) What is a vector?

A vector is a dynamic array of any data type. The associated methods are pop(), push_back(element), size()

22) What is the difference between string messages and packets?

A: That depends on what your packet looks like, but the general idea is that packets have a header and a trailer, with checksums and CRCs that could allow you to reconstruct lost or partially received messages.

23) What are the advantages and disadvantages of using a TCP-based connection? How about UDP?

24) Can you implement a queue with two stacks? How about a stack with two queues?

25) Which of these tuples are alike? Why?

AABBCCDEE - 11233445566 - EEFFGGHII ,


11375500 - 09455901


Answer: In fact, all the above are alike except AAABBBDDD- AAABBBCCC - CCCDDDEEE because there is not enough information to make an assumption.

a - AABBCCDEE - 11233445566 - EEFFGGHII are alike because if there is only one byte that is alternating its position. For alphabetics based strings, the 3rd bit from the right-most side is a single digit and its alternating position to become the 3rd byte from the left most position for numeric based strings.

b-113755900 - 094559001 , this is a time indication. 11:37:55:900 (hours, minutes, seconds, milliseconds

c-ABCAABC - XXXYZZZ : these are palindroms from the look of it.

27) Give an example where u would need to use bit shifting.

28) In Finance, time and timezones are of essence.

29) What is multiple inheritance? What are its advantages and disadvantages?

Multiple inheritance is mainly a C++ charachteristic, that allows classes to inherit from more than one class (disallowed in Java). The disadvantage is that it may lead to ambiguity.

29) In binary trees, describe preorder, postorder and inorder traversal.

More questions to come.

1 comment:

Ribery said...


I read this post two times.

I like it so much, please try to keep posting.

Let me introduce other material that may be good for our community.

Source: Financial interview questions

Best regards