What is a Database Index?

What is a Database index? A database index is a data structure (most commonly B-tree) that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without having to search every row Read More →

Difference Between String , StringBuilder And StringBuffer With Example

String String is immutable ( once created can not be changed )object . The object created as a String is stored in the Constant String Pool . Every immutable object in Java is thread safe ,that implies String is also thread safe . String can not be used by two threads simultaneously. String once assigned Read More →

Difference Between Iterator And Enumeration

Difference Between Iterator And Enumeration The most common interview question in Collections is What is the difference between iterator and enumeration. Iterator Iterator is the interface and found in the java.util package. It has three methods *hasNext() *next() *remove() Enumeration Enumeration is also an interface and found in the java.util package. An enumeration is an Read More →

Difference Between HashMap And HashTable

Difference Between HashMap And HashTable 1. Synchronization or Thread Safe : This is the most important difference between two. HashMap is non synchronized and not thread safe. On the other hand, HashTable is thread safe and synchronized. 2. Null keys and null values : Hashmap allows one null key and any number of null values, Read More →

Threads , Lifecycle Explained With Example

threadstates

What is Thread ? Thread is a sequence of code executed independently with other threads of control with in a single executed program. Multi threading enables you to write in a way where multiple activities can proceed concurrently in the same program. Why Threads? If the program is break into different parts , then it Read More →

OLA Cabs Interview Questions – Set 1

Company: Ola Cabs Location: Bangalore I applied through a recruiter. The process took 1 day I applied through a recruiter. The process took 1 day. Written Coding Test (1 hour) I was asked to design a Bowling game and write code for it with proper OOPS concepts . The problem statement was not difficult . Read More →

ArrayList vs. LinkedList

arraylist-vs-linkedlist-complexity

ArrayList vs. LinkedList   ArrayList is implemented as a resizable array. As more elements are added to ArrayList, its size is increased dynamically. It’s elements can be accessed directly by using the get and set methods, since ArrayList is essentially an array. LinkedList is implemented as a double linked list. Its performance on add and Read More →

What is the Probability that a Knight Stays on Chessboard

knight_moves

Given the size of the chess board and initial position of the knight, what is the probability that after k moves the knight will be inside the chess board. Note:- 1) The knight makes its all 8 possible moves with equal probability. 2) Once the knight is outside the chess board it cannot come back Read More →

Find Largest Area Triangle from 2D Matrix

Problem: Given a table of size n * m, with each cell having a color value from the set {r, g, b}, find the area of the largest triangle that has one side parallel with the y – axis (vertical) and has no two vertices that have the same color value. Input : First line Read More →

Trie Data Structure – C Implementation

Trie Tree: A trie (from retrieval), is a multi-way tree structure useful for storing strings over an alphabet. It has been used to store large dictionaries of English (say) words in spelling-checking programs and in natural-language “understanding” programs. A trie tree uses the property that if two strings have a common prefix of length n Read More →

Implement Stack and Queue using Linked List in Java

The implementation of a linked list is pretty simple in Java. Each node has a value and a link to next node. Two popular applications of linked list are stack and queue. Stack: What is stack? Stack is a linear data structure which implements data on last in first out criteria. Here is a java Read More →

Check for Balanced Parentheses in an Expression

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[' and ']‘, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not. Algorithm: 1) Declare a character stack S. 2) Now traverse the expression string exp. Read More →