Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, December 12, 2015

Study Guides for your Next Technical Interview

I get commissions for purchases made through some links in this post. The recommendations are my own, and are not sponsored (*).

Over the last couple of years, I have been creating some Interview Study Guides that have helped both improve my coding/technical skills and prepare for interviews in top tech companies. Since I believe these guides might be useful for others I have decided to publish them.

All the guides are free and released under CC-Attribution-ShareAlike License.

All the guides are a work in progress and open for improvements. You can download all the guides from here.

NEW: if you prefer video over text, then don't miss my Youtube Playlist "Before the technical interview" where I cover all the topics presented on these guides (and many others).






Below is a brief summary of each of the guides.



Computer Science Fundamentals


As the name implies, this guide provides a summary of Computer Science Fundamentals, including:
  • Data Structures
  • Algorithms
  • Complexity Analysis
  • Mathematics and Probability
  • Regular Expressions
  • Threads and Locks
The sources range from online resources like Wikipedia, GeeksForGeeks and StackOverflow to formal books including (*):

I find it useful to quickly review different algorithms and as cheatsheet for different CS courses, and most of the interviews at Google, Facebook, LinkedIn, Amazon, and other big tech companies, will make a big emphasis on these topics.

You can download this guide clicking here.

This guide will help you have the concept to solve typical problems like Finding the largest BST in a tree.

Software Development and Architecture

This guide compiles higher level topics like:
  • Object Oriented Design
  • Service Oriented Architectures (SOAP and REST)
  • Scalability and Networking
  • Front End Development
    • How do browsers work
    • How to speed up websites
    • ...and more!
  • Frameworks (specifically Spring)
  • Databases
This guide is a bit less polished than CS Fundamentals, but also includes a wide range of sources from different websites and books including (*):

You can download this guide clicking here.

Code Snippets

This guide is the shortest. It includes short descriptions and code snippets from programming languages I have had some experience with (even if only during a course in college). The code snippets are commented with syntax explanation. The languages in the guide include:
  • Ruby
  • Javascript
  • PHP
  • Prolog
  • Haskell
  • C/C++
You can download this guide clicking here.

Additional Resources

There are a lot of free resources on the Internet you can learn from:




Disclaimer

I (Christian Vielma) have personally created these guides for personal use, to be used as a reference for technical interviews, work, and study. Since I believe these documents might provide value to others, I have decided to make them public.

Most of the contents on these documents have been added from different sources, from freely available resources on the Internet, to books, with additional added content from me. I made my best effort to provide full credit to the original sources, and in no way I'm trying to take advantage of improper quotations. If you believe I have made an invalid reference to a resource, please let me know and I'll fix it.
 

I provide these guides as-is, with no additional guarantees. I'm also releasing it under CC-Atribution-ShareAlike License, so you are free to extend it and update it with proper attribution.

Enjoy!


(*) Disclaimer 2:
As an Amazon Associate I earn from qualifying purchases. Links referring to Amazon are still books that I personally recommend (not sponsored) but I might receive money based on clicks  or purchases. There might also be some ads on the sides or between posts are those are placed by Google based on their recommendations (not endorsed by me).
Big-Oh Computer Science English Interviews Java Programming Study

Friday, September 20, 2013

Find Largest Binary Search Tree in a Tree: Java Solution

The question is simple and fair common:

Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the complete Binary Tree is BST, then return the size of whole tree. (From: GeeksForGeeks)

Additionally, I'll be returning the root node for the BST. In this case the BST would have to include all its children (i.e.: it must be a BST from a specific node to the leaves).

Algorithm


To find the largest BST in a tree there are different options to traverse the tree: we could take an top-down approach or a bottom-up.

Top-Down

The top-down approach require us to check at each node from the root if the tree starting at that node is a BST. This makes us traverse multiple times the tree to find the bst. Although it stops as soon as it find a BST because it will be the largest. This solution has a time complexity of O(n^2) in worst-case (degenerated tree into list) or O(nLogn) (balanced tree)
 where n is the number of nodes in the tree.

Bottom-Up

A better approach will be bottom-up where we check from the bottom of the tree the nodes to check if the trees created are BST. This makes the evaluation of a BST in O(1) for each node, although we still have to traverse the tree completely, so this approach has a time complexity of O(n) (in fact we have to traverse the tree twice because to get to the bottom nodes we must traverse from the root and then again from the bottom to the top).

Given the implementation is recursive, this has a space complexity of O(n). 

Implementation


Below is my Java proposed solution. For a complete solution (including testing, full comments and printing) check this.

If you are preparing for a tech interview, don't forget to check the Interview Study Guides.




Big-Oh English Java Programming

Wednesday, August 28, 2013

How synchronized methods can be ignored

Here is a question:

If an object has a synchronized method A and a not synchronized method B, can both method be called by different threads?

And the answer is:

Only one thread can access synchronized method A at a time (unless there are two different objects and each thread calls method A on different objects). B can be accesed by many threads at any given time, even when A is executing.

At the beginning I was a bit confused about the second part, if that is so, then a class might not be protected against multithreading update if it has at least one non-synchronized method that modifies an instance variable used by a synchronized method. I was right!

Here's is the code to prove it:

If you run this code it will sometimes show final value as 0 and other times value as 1. So when designing a class that should be synchronized take under consideration which methods are you leaving free that can modify instance (or static) attributes.
English Java Multithreading

Sunday, July 28, 2013

How to map Postgres capital names to Hibernate

When I was developing the Simulation Model System (SimModSys), I faced this issue.

I'm from the school that believes that the database should be developed first and independently from the system, to serve the purpose of maintaining the data integrity, and the application should integrate to the existing database to apply logic on the data, but not to force how the data should be represented. So I designed the database first ignoring that there were issues between Hibernate and Postgres capital letters.

Instead of changing the database I decided to fight for it, after all it was a learning personal project. 

I received a partial answer that I completed later at StackOverflow. In short, what you have to do is the following:

  • Escape every table that has capital letters (using \"):
  • Escape every field that has capital letters (using \"):
  • Escape joins that include columns that have capital letters (strangely, using `):

It is a tedious work. This worked for me with PostgreSQL 9.1.9, Hibernate 4.1.3 and Java 7. 

For a complete example you can review the code at BitBucket of any of the classes of the SimModSys project's persistence package.
English Hibernate Java PostgreSQL Simulation Model System Troubleshooting

 

Copyright © Librethinking.
Designed by Templateism. Hosted on Blogger Platform.