Cs 141 Solution

Q.1. Explain the difference between

A) a set and a map

B) a binary tree and a balanced binary tree

Q.2. Write a loop that prints all elements that are in both set<strings and set<stringt.

Q.3. What is Big-O notation? Give some examples?

Q.4. A) If a min-heap has 1024 nodes, calculate its height?

B) If we insert into an empty binary search tree the following sequence of nodes with the specified keys, what will be root key?

Keys: 12, 7, 25, 6, 9, 13, 44

Q.5. Consider the following tree and write

Q.6. Write a program to demonstrates a heap as a priority queue by using a class which can encapsulates a work order with a priority.

Q.7. What does this code print? Why is it polymorphic?

Q8 : Can you convert a superclass reference into a subclass reference? A subclass reference into a superclass reference? If so, give examples. If not, explain why not.

Q.9 : Implement a superclass Person. Make two classes, Student and Instructor that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Write the class declarations, the constructors, and the methods toString for all classes. Supply a test program that tests these classes and methods

Q.10. Implement the compare method of the following class RectangleComparator. The method compares two rectangles. The method should return:

A positive integer if the area of the first rectangle is larger than the area of the second rectangle

A negative integer if the area of the first rectangle is smaller than the area of the second rectangle

0 if the two rectangles have the same area.
Powered by