Solve the Rat In A Maze problem using backtracking.

This is one of the classical problems of computer science. There is a rat trapped in a maze. There are multiple paths in the maze from the starting point to the ending point. There is some cheese at the exit. The rat starts from the entrance of the maze and wants to get to the cheese. This problem can be attacked as follows. Have a m*m matrix which represents the maze. [Read More]

Sorting binary array - Array containing only 0 and 1 in one pass OR two color sort

in your Pseudocode, the if condition should be if …

RM - May 3, 2014

in your Pseudocode, the if condition should be if (low < high).

Thanks Rish. I have made the change a[low] > a[high] rather than low < low. :). Thanks for correcting me.

Sorting binary array - Array containing only 0 and 1 in one pass OR two color sort

Problem Sort a binary array - array containing 0s and 1s in 1 pass. This is also called two color sort. Example Input - Binary unsorted array A = {0,1,1,0,0,1}; Output - binary sorted array B = {0,0,0,1,1,1} Solution This is similar to quicksort partition algorithm. Though normal sorting takes O(n log n) time, but we have to just partition 0 from 1, and hence it should only take time of partitioning - O(n). [Read More]

Data Structures Interview Questions (Theoritical)

1) What is the difference between Storage structure and file structure? The representation of a particular data structure in the memory of a computer is called a storage structure whereas a storage structure representation in auxiliary memory is often called a file structure. 2) Define data structure in terms of relation? The possible ways in which the data items or atoms are logically related define different data structures. 3) State procedure in accordance with function? [Read More]

To reverse the bits in an integer

Method1 ` unsigned int num; // Reverse the bits in this number. unsigned int temp = num; // temp will have the reversed bits of num. int i; for (i = (sizeof(num)*8-1); i; i–) { temp = temp | (num & 1); temp «= 1; num »= 1; } temp = temp | (num & 1); ` Method2 In this method, we use a lookup table. ` const unsigned char ReverseLookupTable[] = [Read More]

Check if the 20th bit of a 32 bit integer is on or off?

AND it with x00001000 and check if its equal to x00001000

if((num & x00001000)==x00001000)

Note that the digits represented here are in hex.

`
     0      0      0      0      1      0      0      0
                                 ^                   
                                 |

 x0000   0000   0000   0000   0001   0000   0000   0000 = 32 bits

  ^                              ^                    ^
  |                              |                    |

  0th bit                        20th bit             32nd bit
`

CTS Aptitude Question paper(Yellow)

1. If all the 6 are replaced by 9, then the algebraic sum of all the numbers from 1 to 100(both inclusive) varies by Ans: 330 2. The total no. of numbers that are divisible by 2 or 3 between 100 and 200(both inclusive) are Ans:67 3. From a pack of cards Jack, Queen, King & ace are removed. Then the algebraic sum of rest of the cards is Ans:216 [Read More]

CTS Aptitude Question paper(Yellow)

Question 1: If all the 6 are replaced by 9, then the algebraic sum of all the numbers from 1 to 100(both inclusive) varies by Answer: 330 Question 2: The total no. of numbers that are divisible by 2 or 3 between 100 and 200(both inclusive) are? Answer: 67 Question 3: From a pack of cards Jack, Queen, King & ace are removed. Then the algebraic sum of rest of the cards is? [Read More]

Questions on various topics

Some questions to start with: c  cpp Data structure java advanced java Operating System Micro processor Electronics questions C questions What does static variable mean? What is a pointer? What is a structure? What are the differences between structures and arrays? In header files whether functions are declared or defined?  What are the differences between malloc() and calloc()? What are macros? what are its advantages and disadvantages? [Read More]