Sat Dec 29 10:02:40 PST 2018


If you have just started learning Java and came from C background then you might have noticed some difference between Java and C programming language e.g.
String is an object in Java and not a NULL terminated character array. Similarly, there is is no
sizeof() operator in Java. All primitive values have predefined size e.g. int is 4 bytes, char is 2 byte, short is 2 byte, long and float is 8 byte and so on. But if you are missing
sizeOf operator then why not let's make it a coding task? If you are Ok, then your next task is to write a method in Java, which can behave like
sizeOf() operator/function of C and returns size in bytes for each numeric primitive types i.e. all primitive types except boolean.







This week?s task is to implement
binary search in Java, you need to write both iterative and
recursive binary search algorithm. In computer science, a binary search or half-interval search is a divide and conquer algorithm which locates the position of an item in a sorted array. Binary search works by comparing an input value to the middle element of the array. The comparison determines whether the element equals the input, less than the input or greater. When the element being compared to equals the input the search stops and typically returns the position of the element. If the element is not equal to the input then a comparison is made to determine whether the input is less than or greater than the element. Depending on which it is the algorithm then starts over but only searching the top or a bottom subset of the array's elements. If the input is not located within the array the algorithm will usually output a unique value indicating this.







It's been a long time since I have discussed any 
coding or 
algorithm interview questions, so I thought to revisit one of the most popular array based coding problem of finding missing numbers in given
array. You might have heard or seen this problem before on your programming job interview but there are a lot of different versions of increasing difficulty levels which interviewer normally use to confuse candidate and further test their ability to adapt to frequent changes. In the past I have demonstrated 
how to find the missing number in a sorted array as well on the unsorted integer array in Java using BitSet (see
here), but, with just one missing number and without any duplicates.







Comments

Popular posts from this blog

termux vnc viewer setup

../Settings.jpg

me.html