GeekInterview.com
Series: Subject: Topic:

Algorithm Questions

Showing Questions 21 - 40 of 51 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

How can we create different functionality to objects of a same class?

Asked By: ykirankumarmca | Asked On: Apr 2nd, 2006

Answered by: yzesong on: Aug 8th, 2009

We may forget, the question is really talking about objects of same class. So I think all the answer on virtual functions are wrong. tehoclub may get close to the point of the question in my opinion.

Answered by: tehoclub on: Oct 31st, 2008

You can use a callback function as below,

typedef void (*DoFunc)();

void Draw();
void Paint();

class MyClass { 
void DoSomething(DoFunc fa) { fa(); } 
}

MyClass a, b;
a.DoSomething(Draw);
b.DoSomething(Paint);



What is the difference in searching and sorting ?

Asked By: Varsha | Asked On: Oct 3rd, 2007

Answered by: nsudheer on: Jun 4th, 2011

Searching means Searching
Sorting means Sorting

Nothing special in its meaning, even in computer science. But, the algorithms to achieve this task are going to be special

Answered by: kbjarnason on: Jul 2nd, 2010

Searching is finding things, sorting is arranging them.Suppose you have the characters 'Z', 'A' and 'M' in an array.  Your code needs to know if 'M' is in the arra...

Compute average of two scores

Asked By: lakumi | Asked On: Aug 2nd, 2010

Describe an algorithm to compute the average of two scores obtained by each of the 100 students

Answered by: yogishsanjeeva on: Jan 18th, 2011

struct student
{
int scoreone;
int scoretwo;
};

student st[10];

void average()
{
int result,sum;
 for(int count=0; count < 10; count++)
 {
   sum = st[i].scoreone + st[i].scoretwo;
   result = sum/2;
 }
}

Answered by: travisdavies on: Aug 24th, 2010

Lets assume an array called Array, of type Student.Each student contains 3 data members. they are: String name;int scoreOne;int scoreTwo;for(int i = 0; i < Array.length; i++){    int...

Degree operations

Asked By: a1v2i3k4 | Asked On: Nov 8th, 2010

Design an algorithm to show the different operations on degree

Answered by: Prince Mishra on: Jan 4th, 2011

Can you be a little more explicit on what kind of degree?
Is that related to exponentiation?

Advantages of circular queue

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Bring out the advantages of circular queue over linear queue

Answered by: dharmraj on: Sep 5th, 2010

In CQ we utilize memory efficiently. because in queue when we delete any element only front increment by 1, but that position is not used later. so when we perform more add and delete operation, m...

Importance of algorithms

Asked By: Debprasad | Asked On: Feb 14th, 2010

What is the importance of algorithms in the field of computer science?

Answered by: kbjarnason on: Jul 2nd, 2010

An algorithm is nothing more than a defined series of steps to achieve a goal.  For example adding a value to the value in a memory location works something like this:  load existing value f...

Algorithm profiling

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

What is meant by algorithm profiling?

Answered by: anks1987 on: Jun 25th, 2010

Profiling is the process of executing a correct program on different data sets to measure the time and space that is takes to compute the results.

Thanks!

Prime integer

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Suggest two different methods of knowing if a given integer is prime and analyse them.

Answered by: rrc_83 on: Jun 21st, 2010

Prime Integer can be calculated as follows - if n < 2:  return Falseif n == 2 :   return True  // Only even number thats Primeif (n % 10) in [0, 2, 4, 5, 6, 8]:  return False&nb...

Algorithm to input the price of a textbook

Asked By: jovan | Asked On: Mar 31st, 2010

Write an algorithm to input the price of a textbook. Calculate the price and print the total cost of the book after 15% VAT is added

Answered by: rrc_83 on: Jun 22nd, 2010

In python -

input_price = float(input('Enter price of book'))
output_price = round((input_price * 1.15) , 2) // price+ price *0.15
print 'Cost of book after VAT is %s'% output_price

To calculate distance between two text strings

Asked By: koolck619 | Asked On: Jun 26th, 2008

Give an algorithm that calculates the distance between two text strings (only operations you can have are: delete, add, and change, one by one).

Answered by: rrc_83 on: Jun 20th, 2010

In python - # Input is string s1 and string s2# Check which string is bigger (compares ascii value)if s1 > s2:  b, s = s1, s2else :  b, s  = s2, s1# Covert string to listl1, l2 = lis...

Answered by: yzesong on: Aug 9th, 2009

The distance of two strings, like "car" and "cat", is 1. So all we need to do is, compare two strings one character by one character and get the distance value. The complexity is O(max(m,n)), m, n are the length of each string.

Write an algorithm to read the date borrowed and present date.

Asked By: jovan | Asked On: Mar 31st, 2010

A video club rents video for three days. Write an algorithm to read the date borrowed and the present date; calculate the number of days borrowed. If the number of days exceeds three days, compute the number of days overdue and overdue charge. Use a rate of $1.50 for everyday overdue or part overdue

Answered by: Chrisostomo Quitana on: May 18th, 2010

Set dateBarrowed as DateSet todayDate as Current DateSet duration as integerSet overDueFee as DoublePrint "Enter barrowed Date:"read dateBarrowedset duration as the difference of dateBarrowe...

Finding a 'circle' in a linked list

Asked By: wcmaggot | Asked On: Jun 8th, 2009

You have n numbrer node objects - could be 1,000,000 for all you know. Each node has a getnext() method that returns the next node (a linked list).But the chain of n number of node objects linked together by the getnext() method, somewhere in the chain, points back to a node earlier in the chain so...

Answered by: kaushurtz on: Mar 2nd, 2010

There are many ways to find loops in linked list but the best one is known as tortoise and hare algorithm.In this we take 2 nodes say slow and fast node. Then we move the slow node by one shift ie sta...

Answered by: doddaiah on: Jun 21st, 2009

Take two pointers P1 and P2.Initially let P1 and P2 point to starting node (S) and set counter to zero.increment the counterthen check while(1) {if p1 == p2 ->next{   print the count...

Strings as input

Asked By: rakeshchandra | Asked On: Jun 3rd, 2008

Implement an algorithm that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. Speed it up and test it.

Answered by: kaushurtz on: Mar 2nd, 2010

Using HashSet as in case of jave will be better than HashMap. We can just iterate over the characters of both the strings and put them in set.

Answered by: yzesong on: Aug 8th, 2009

I think of an idea to do this by using a hash table. First, loop through first string, creat map<char, int>, we can use ascii value of the char as the value. Only insert the char/int pair when a...

Time complexity

Asked By: javasoftware | Asked On: Nov 16th, 2008

How to find time complexity?

Answered by: adnan15110 on: Jan 3rd, 2010

Time complexity usually expressed by asymptotic notation.To find out time complexity we need to see the growth of function of that algorithm. Which means to identify how the loops or comparisons behav...

Quicksort algorithm

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Demonstrate the quicksort algorithm to sort a list of data elements

Answered by: adnan15110 on: Jan 3rd, 2010

Pick an element, called a pivot from the list. Reorder the list so that all elements which are less than the pivot come before the pivot and so that all elements greater than the pivo...

Traverse binary tree in inorder

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in inorder.

Answered by: ChrisL216 on: Dec 13th, 2009

void display(){
    System.out.print(lnr(root));
}

void lnr(Node p){      // left node right
    if(p == null) return;
    lnr(p.left);
    System.out.print(p.key);
    lnr(p.right);
}

How can we multiply an integer by 7 by using bitwise operators

Asked By: vinay jindal | Asked On: Sep 3rd, 2007

Answered by: vivgrn on: Oct 6th, 2009

7 =111

thus

x*7 = (x <<2) + (x<<1) + x

Answered by: Casul on: May 22nd, 2008

operator+ is not a bitwise operation ....

Conventional iterative algorithm

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in postorder.

Answered by: trivial on: Aug 19th, 2009

We define int visit[SIZEOFTREE] such that visit[i]=1 if i th node is visited=0 otherwise visit[NULL]=1 alwaysvoid posttrav_ite...

Array values algorithms

Asked By: francislawrance | Asked On: Jan 4th, 2009

How many values can be held by an array with dimensions a(0:n), b(-1:n,1:m), c(-n:0,2)?

Answered by: imithya on: Aug 16th, 2009

A(0:n) = n+1 elements-1 specifies that the array indexing starts at '-1' uptill 'n'. Therefore, there can be "n-(-1)+1 = n+2" rows in the array. Each of this row may hold upt...

Algorithm to traverse binary tree

Asked By: Dheerendra_juli | Asked On: Jul 22nd, 2009

Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in preorder.

Answered by: ratanlal on: Aug 14th, 2009

preorder(node root)
if root=NULL;
return
else
do
print "root->data" 
preorder(root->left)
preorder(root->right)
end else

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.