What are the two properties of heap?

  • Implmeented by binary tree
  • the relation between the upper level and lower level node (e.g. upper level node is always greater than lower level for max heap)

What is a balanced tree?

  • The tree is balanced only if:
    • The left and right subtrees' heights differ by at most one.
    • AND the left subtree is balanced.
    • AND the right subtree is balanced

What’s the difference between a stack and a heap?

  • difference between stack and heap
  • Each thread has its own private stack where it stores its variables whereas each thread shares the heap. So there has to be some coordination between the threads so that they don’t try to access and manipulate the same piece(s) of memory in the heap at the same time.
  • stack is used to store local variables and function calls whereas heap is used to store the objects.
  • Exceeding heap memory causes JVM to throw OutOfMemoryError. Exceeding stack memory causes JVM to throw StackOverFlowError. Recursive calls are generally stack intensive, they use up stack pretty soon

Can an object be stored on the stack instead of the heap?
Yes, an object can be stored on the stack. If you create an object inside a function without using the “new” operator then this will create and store the object on the stack, and not on the heap.

void somefunction( )
{
/* create an object "m" of class Member
    this will be put on the stack since the 
    "new" keyword is not used, and we are 
   creating the object inside a function
*/

  Member m;

} //the object "m" is destroyed once the function ends

What is big O Notation? What is the difference between Big O and Big Omega notations?

  • It measures the efficiency of an algorithm based on the time it takes for the algorithm to run as a function of the input size.
  • Big O is used to describe the worst case running time for an algorithm. But, Big Omega notation, on the other hand, is used to describe the best case running time for a given algorithm. Big Omega is for lower bound, Big O is for upper bound.