Tuesday, 2 August 2016

Exceptions handling in python with Examples

Exceptions handling in python with Examples:
What is an exception?
In this post I am trying to explain how the exceptions got
Here I am giving definition to the exception. An event which is got occurred during the execution of a program which disturbs the normal flow of our application is known as exception. When an exception occurs, it causes the current process to stop and passes it to the calling process until it is handled. If we cannot handled it properly, our application will crash. To avoid these types of problems we need to catch them and handle them properly, then our application will not crash and cannot got interrupted in middle.
Catching Exceptions in Python:
As of we know that the exceptions can be handled using a try statement. A code segment which can raise exception is placed inside the try and the code that handles exception is written in except.

Tuesday, 26 July 2016

Bit flags, Bit masks and why they are useful?

Bit flags, Bit masks and why they are useful? Explanation with examples.


First of all we want to know what bit flag is and what is bit mask, in this post I would like to give brief knowledge on bit flags and bit masks

Bit Flags: As of we know that we cannot access bits directly, So we have to use the bit-wise operators to set, unset, or query them.

Bit flags are the individual bits that are used to improve the efficiency of the storage.

In storage-intensive cases where we have lots of related Boolean options, it can be useful to “pack” 8 individual Boolean's into a single byte for storage efficiency purposes.

Why are bit flags useful?

Bit flags are used in two cases:

1) It is very much useful when you have many sets of identical bit flags.

Sunday, 24 July 2016

Diff in Conversion ctr and explicit ctr

Diff in Conversion ctr and explicit ctr, explain with examples:


Before going to know about the difference between the implicit and explicit convertions we need to have a little bit knowledge on casting

Casting


Casting means converting form one data type to another. We have two types of castings
·        Implicit casting
·        Explicit casting


Implicit casting


The Implicit casting doesn't require any casting operator. This casting is normally used when converting data from smaller integral types to larger or derived types to the base type.

Thursday, 21 July 2016

Explain hash_map and bucketing with examples


A small introduction to the hash map:

The template class describes an object that controls a varying-length sequence of elements that has bidirectional access. You use the container hash_map to manage a sequence of elements as a hash table, each table entry storing a bidirectional linked list of nodes, and each node storing one element.

Syntax of the hash map is:
Microsoft::VisualC::StlClr::GenericPair

Here the parameters are explained as shown below. Key - The type of the key component of an element in the controlled sequence.Mapped- The type of the additional component of an element in the controlled sequence.

In the above syntax an element consists of a key, for ordering the sequence, and a mapped value, which goes along for the ride.

Tuesday, 19 July 2016

Bit Count In Product

Bit Count In Product. Explain with examples:

Write a function:
int solution(int A, int B);
that, given two non-negative integers A and B, returns the number of bits set to 1 in the binary representation of the number A * B.
For example, given A = 3 and B = 7 the function should return 3, because the binary representation of A * B = 3 * 7 = 21 is 10101 and it contains three bits set to 1.
Assume that:
·   A and B are integers within the range [0..100,000,000].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Finding the length of the Arrays

How to find the length of the Array, explain with examples:

A non-empty zero-indexed array A consisting of N integers is given.
Array A represents a linked list. A list is constructed from this array as follows:

• the first node (the head) is located at index 0;
• the value of a node located at index K is A[K];
• the successor of a node located at index K is located at index A[K];
• if the value of a node is −1 then it is the last node of the list. For example, for array A such that: A[0] = 1
A[1] = 4
A[2] = -1
A[3] = 3
A[4] = 2
the following list is constructed:
• the first node (the head) is located at index 0 and has a value of 1;
• the second node is located at index 1 and has a value of 4;
• the third node is located at index 4 and has a value of 2;
• the fourth node is located at index 2 and has a value of −1.

Monday, 25 April 2016

Difference between the Composition, aggregation, association Relationships.

Difference between the Composition, aggregation, association Relationships.

Now first look into the composition:


To understand the design first of all we must know the relationships. The most important relationships are

 Association
 Aggregation
 Composition

Now see the below about each one elaborately.

Association:

Association is a relationship where all objects have their own life cycle and there is no owner.
Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own life cycle. Both can create and delete independently. This represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.