Vamsi Pavan’s Place

When curiousity outbursts …..

Entries Tagged as 'Algorithms'

Selection Sort

April 15th, 2007 · No Comments · Algorithms, C/C++, Source Code

The code for the selection sort in C lang is provided below.

#include
#define NUM 6

void swap(int arr[], int i, int j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}

main() {

int arr[NUM],i,j;

// start reading nums
for(i=0;i arr[j])
swap(arr,i,j);

// print sorted arr
for(i=0;i
Please point your web link to this page if you are using this code for any purposes.

Bookmark it!
These icons […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Fast Bit Counting Routines

October 17th, 2006 · No Comments · Algorithms, C/C++, Placements

A common problem asked in job interviews is to count the number of bits that are on in an unsigned integer. Here are seven solutions to this problem. Source code in C is available.

Iterated Count

int bitcount (unsigned int n)
{
int count=0;
while (n)
{
count += n & […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

A program to draw a circle

October 6th, 2006 · No Comments · Algorithms, Placements

I recently came across a book called Programming Interviews Exposed. I’ve never actually read one of these books which purports to tell how to answer interview questions at tech companies. If you’re thinking about buying this book to help you land a job at a place like M$ or Google, don’t.
The first thing I checked […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Polynomial evaluation

October 6th, 2006 · No Comments · Algorithms

Paranthesization of polynomial evaluation
A polynomial of degree N-1 will have N terms (including the constant). And a product of two polynomials each of degree N-1 will have a degree of 2N-2 with 2N-1 terms.
Evaluation of a polynomial function without using any extra storage and extra multiplications can be done using Homer’s rule: by alternatinv addition […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Sum two numbers using bits

October 6th, 2006 · No Comments · Algorithms, C/C++

int main(int argc,char *argv[]){
int a=atoi(argv[1]),b=atoi(argv[2]),sum,carry;
sum = a^b;
carry = a&b;
while(carry){
carry = carry

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Fibonacci numbers

October 6th, 2006 · No Comments · Algorithms

f(n) = (1/sqrt(5)) * (((1+sqrt(5))/2) ^ n - ((1-sqrt(5))/2) ^ n)
a Number N is fibacci number iff 5*N*N+4

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.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Heterogenious linked list

October 6th, 2006 · No Comments · Algorithms

If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer […]

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Sort linked list

October 6th, 2006 · No Comments · Algorithms

Node *MoveMinToStart(Node *aHead)
{
if(aHead == NULL or aHead->next == NULL)
return aHead;
Node *PrevMin = NULL,*Cur=aHead,*Prev=NULL,*Min=NULL;
while(Cur){
if(Min == NULL or Min->Value > Cur->Value){
Min = Cur;
PrevMin = Prev;
}
Prev = Cur;
Cur = Cur->next;
}
if(PrevMin == NULL)

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.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Repeating characters

October 6th, 2006 · No Comments · Algorithms

Write a funtion that finds repeating characters in a string.
Sort the string

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.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags:

Draw circle, using integer operations

October 6th, 2006 · No Comments · Algorithms

Q: Write a routine to draw a circle given a center coordiante (x,y) and a radius (r) without making use of any floating point computations.
Refer to graphics algorithms

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.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

[Read more →]

Tags: