Common differences asked in coding interviews

SAX Parser v/s DOM Parser


SAX Parser DOM Parser
It is event based. Fires an event when it encounters opening tag, or element attribute. Document Object Model. Creates in-memory tree representation of XML files and then parses them.
Good for large files because it reads large files in small parts. Good for small files since entire XML is loaded in the memory.
Need to implement more methods for parsing. It has good implementation of different parsing.




Stack V/s Heap


Stack
Heap
Allocation of memory is static in stack. Allocation of memory is dynamic. If more memory is needed more space is allocated and vice-versa.
Each thread gets its own stack. An application gets a heap of memory.
Scope of stack is till the thread execution. Once thread exits, stack is reclaimed. Heap is reclaimed once the application exits.
It is faster since allocation and deallocation of memory is faster. The allocation and deallocation of memory is slow in case of heap.
Once a function returns, stack is discarded. Destructed manually or is Garbage collected.
Primitives are stored on stack, pass by values are also stored on stack. Objects are stored on heap.


Trie v/s BST

Trie
Binary search tree
Lookup is O(m) Lookup is O(logn)
Storage space is less because node share the content. Nodes doesn’t share the content.
Number of internal nodes equals key length. It doesn’t depend on key length, instead it depends upon what order the keys appear.


Primary Key v/s Unique Key

Primary Key
Unique key
Primary keys are indexed by clusters. Their index is not clustered.
Primary constraint is applicable. Unique constraint on a column of the table.
Only one per table. A table can have more than 1 unique keys.
Could be combination of unique keys. Cannot be a combination of different keys.

You might also like:

2 comments:

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...