How can we create different functionality to objects of a same class?
What is the difference in searching and sorting ?
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
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...
Describe an algorithm to compute the average of two scores obtained by each of the 100 students
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;
}
}
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...
Design an algorithm to show the different operations on degree
Can you be a little more explicit on what kind of degree?
Is that related to exponentiation?
Bring out the advantages of circular queue over linear queue
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...
What is the importance of algorithms in the field of computer science?
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...
What is meant by algorithm profiling?
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!
Suggest two different methods of knowing if a given integer is prime and analyse them.
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
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
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
Give an algorithm that calculates the distance between two text strings (only operations you can have are: delete, add, and change, one by one).
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...
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.
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
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
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...
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...
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...
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.
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.
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...
How to find time complexity?
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...
Demonstrate the quicksort algorithm to sort a list of data elements
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
Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in inorder.
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
operator+ is not a bitwise operation ....
Conventional iterative algorithm
Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in postorder.
We define int visit[SIZEOFTREE] such that visit[i]=1 if i th node is visited=0 otherwise visit[NULL]=1 alwaysvoid posttrav_ite...
How many values can be held by an array with dimensions a(0:n), b(-1:n,1:m), c(-n:0,2)?
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
Design a conventional iterative algorithm to traverse a binary tree represented in linked lists in preorder.
preorder(node root)
if root=NULL;
return
else
do
print "root->data"
preorder(root->left)
preorder(root->right)
end else
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.