All permutations of a string
Posted on September 7, 2011
(Last modified on August 7, 2020)
| 1 minutes
| Kinshuk Chandra
small trick ,but a very nice solution for duplicat…
nikhil - Feb 4, 2014
small trick ,but a very nice solution for duplicates!!!!
Thanks Nikhil. :)
can u please write the main function for duplicate program. I ran the duplicate program and it is not giving me the desired output
All permutations of a string
Posted on September 7, 2011
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Problem
Write a method to compute all permutations of a string.
Example
For a string of length n, there are n! permutations.
INPUT: “abc”
OUTPUT: “abc” “acb” “bac” “bca” “cab” “cba” So, we have 3! = 6 items for string abc.
Solution
There are several ways to do this. Common methods use recursion, memoization, or dynamic programming.
The basic idea is that you produce a list of all strings of length 1, then in each iteration, for all strings produced in the last iteration, add that string concatenated with each character in the string individually.
[Read More]Program to check if two rectangle overlap or itntersect
Posted on May 14, 2011
(Last modified on August 7, 2020)
| 1 minutes
| Kinshuk Chandra
Rectangles can be tilted also, what about that cas…
Anonymous - Dec 3, 2013
Rectangles can be tilted also, what about that case?
Program to check if two rectangle overlap or itntersect
Posted on May 14, 2011
(Last modified on August 7, 2020)
| 4 minutes
| Kinshuk Chandra
Input - 2 Rectangles with x and y coordinates.
Output - boolean value which states if they overlap or not This is a one of the classic problems in graphics programming and game development. So, let’s see how we can solve it.
Most computer (now cellphone) screens have an invisible coordinate system that is used to identify where graphical objects are on the screen. For example, the iPhone coordinate system has the origin at the top-left corner of the screen.
[Read More]Array implementation of stack
Posted on October 20, 2010
(Last modified on August 12, 2020)
| 3 minutes
| Kinshuk Chandra
Here will discuss the array implementation of stack.
Problems with array implementation
Underflow - Array may be empty but people may try to pop the element
Overflow - Array is full. To over come we have to use re-szing of array. We can see how we can solve this problem here - http://k2code.blogspot.com/2013/09/resizing-array-implementation-of-stack.html
Null items - Can nulls be added - Yes in this case, nulls can be added in stack
[Read More]Array implementation of stack
Posted on October 20, 2010
(Last modified on August 12, 2020)
| 3 minutes
| Kinshuk Chandra
Here will discuss the array implementation of stack.
Problems with array implementation
Underflow - Array may be empty but people may try to pop the element
Overflow - Array is full. To over come we have to use re-szing of array. We can see how we can solve this problem here - http://k2code.blogspot.com/2013/09/resizing-array-implementation-of-stack.html
Null items - Can nulls be added - Yes in this case, nulls can be added in stack
[Read More]Enums in java
Posted on September 21, 2010
(Last modified on August 7, 2020)
| 4 minutes
| Kinshuk Chandra
In prior releases, the standard way to represent an enumerated type was the int Enum pattern:
**// int Enum Pattern - has severe problems!** public static final int SEASON\_WINTER = 0; public static final int SEASON\_SPRING = 1; public static final int SEASON\_SUMMER = 2; public static final int SEASON\_FALL = 3; But these are not type safe, and clearly naming them is bit of a problem. So in Java 5, they introduced Enums.
[Read More]Modifying Java Variables (w.r.t c and c++)
Posted on September 18, 2010
(Last modified on August 7, 2020)
| 1 minutes
| Kinshuk Chandra
Modifying Simple Variable
The only mechanism for changing the value of a simple Java variable is an assignment statement. Java assignment syntax is identical to C assignment syntax. As in C, an assignment replaces the value of a variable named on the left- hand side of the equals sign by the value of the expression on the right- hand side of the equals sign.
Modifying Object Variable Java object variables can be changed in two ways.
[Read More]Constructor in java 1
Posted on September 17, 2010
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Constructors When you create a new instance (a new object) of a class using the new keyword, a constructor for that class is called. Constructors are used to initialize the instance variables (fields) of an object. Constructors are similar to methods, but with some important differences.
Constructor name is class name. A constructors must have the same name as the class its in.
Default constructor. If you don’t define a constructor for a class, a default parameterless constructor is automatically created by the compiler.
[Read More]Common naming convention : Coding Style
Posted on September 17, 2010
(Last modified on August 7, 2020)
| 9 minutes
| Kinshuk Chandra
**Variable names must be in mixed case starting with lower case. **
Common practice in the Java development community and also the naming convention for variables used by Sun for the Java core packages. Makes variables easy to distinguish from types, and effectively resolves potential naming collision as in the declaration
eg.
int state;
Names representing constants (final variables) must be all uppercase using underscore to separate words.
MAX_ITERATIONS, COLOR_RED
[Read More]