Entries Tagged as 'Algorithms'
Represent 7 in binary format. Now shifting and adding by appropriate times will give the solution
or Multiply it by 8 (shift by 3 bits) and subtract the original number.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
Q. Give one line C expression to check whether a given number is an exponential power of 2
Ans:
if ( x & (x-1) == 0){
printf(”Yes”)
}else{
printf(”No”)
}
What about zero ??
Set the LSB to zero
x = x&x(-1);
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
Repeated Number = Sigma(n) - Sigma(n-1)
Q. The integers from 1 to n are stored in an array in a random fashion. but one integer is missing. Write a program to find the missing integer.
Follow the same technique
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
[The solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn’t too […]
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
BFS(G)
Breadth First search, will give the shortest path from the root, assuming all the edges are of same weight. You need additional datastructure like queue to implement it.
DFS(G)
Depth First Search, calculates the discovery and finished time of each node. These will help in classifying the edges into forward or tree, backward, cross edge.
The finishing time […]
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
assume x[i] represents the position of queen i
canPlace(k,i)
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
In one parse, count the number Normal nodes and NULL nodes. If there is no cycle then the
number of NULL nodes = No. Normal nodes + 1
If this is not followed, which means there is a cycle in the tree.
But since there is a cycle, you will never finish counting the number of nodes.
Bookmark it!
These […]
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
If the desired length of each line is n, then a line can be divided into three possible ways:
1. The line has exactly n characters, and hence doesn’t need any processing
2.. If the line has more than n characters, then we can always choose maximum number of words that can fit into a length of […]
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
A monotone increasing subsequence is a subset of numbers which are strictly increasing from left to rght. This definition does not require that the numbers be adjacent in the original set or that the longest sequence is unique. Ex.
1 2 9 4 7 3 11 8 14 6
The sequence 1 2 4 7 11 14 […]
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags:
Follow Quick sort paradigm
What if k
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
[Read more →]
Tags: