1) A Ramanujam number can be written two different ways as the sum of two
cubes—i.e. , there exist distinct a, b, c, and d such that a3 +b3 = c3 +d3. Generate
all Ramanujam numbers where a, b, c, d < n.
3-18. What method would you use to look up a word in a dictionary?
3-19. Imagine you have a closet full of shirts. What can you do to organize your shirts
for easy retrieval?
3-20. Write a function to find the middle node of a singly-linked list.
3-24. What is the best data structure for maintaining URLs that have been visited by
a Web crawler? Give an algorithm to test whether a given URL has already been visited, optimizing both space and time.
3-18) Hash tables would be used to look up a word in dictionary. It is the best structure of key,value pairs to store corresponding values of a particular key in dictionary.
3-19) arrange the used ones behind the unused ones. That will represent a queue mechanism, so the unused ones will be in the front, as and when a new shirt is removed and used, it'll be put at the end. this will help in organizing the shirts better and redundancy will also be reduced.
3-20)let's find the count of nodes in the list. iterating over the list again from beginning to count/2 element that is the middle element. display it.
code is below
void printMiddle()
{
Node temp = head;
int count =0,value;
//Node last = head;
while(temp != null)
{
count +=1;
temp = temp.next;
}
temp = head;
while (temp != null && value<=count/2)
{
temp = temp.next;
}
System.out.println("The middle element is " +
temp.data );
}
}
3-24) best data structure for web crawler tracing is stack. it follows last in first out mechanism. so best data structure is stack
1) A Ramanujam number can be written two different ways as the sum of two cubes—i.e....