Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 1: Implement a city database using unordered lists Each database record

ID: 3874555 • Letter: P

Question

Project 1: Implement a city database using unordered lists Each database record contains the name of the city (a string of arbit coordinates of the city expressed as x and y coordinates. Your database should allow records to be inserted, deleted by name or coordinate, and by name or coordinate. Implement the database using an array-based list implementation, and then a linked list implementation Collect running time statistics for each operation in both implementations. And think . What are your conclusions about the relative advantages and disadvantages of the two implementations? Would storing records on the list in alphabetical order by city name speed any of the operations? would keeping the list in alphabetical order slow any of the operations?

Explanation / Answer

For both array based and linked list implementation it requires constant time. The space comparisons issues are same for the stack implementation. But not the array based stack implementation. There is basically no fixed way to store two queues in same array, until and unless items will be directly transferred from one to another.

The basic operation for a database is finding a record that matches a provided key. This raise to extract the key from a record. This is typical in database application.

The city database record implementation:

/* entry with coordinates and name fields */

class City {

            private integer x_coordinates;

            private integer y_coordinates;

            private string name;

City (int x_c, int y_c ,string cname ) {

            x_coordinates = x_c;

            y_coordinates = y_c;

            name = cname;

}

Public integer getx_coordinates () {return x_coordinates;}

Public integer gety_coordinates () {return y_coordinates;}

Public string getname () {return name;}

}

/* City record implementation */

/* City records are implemented with an unsorted array based list */

Dictionary<integer , City> x_coordinatesdict = new UALdictionary <integer, City>();

Dictionary<integer , City> y_coordinatesdict = new UALdictionary <integer, City>();

Dictionary<string , City> namedict = new UALdictionary <string, City>();

City foo1 = new City(10,15,”ABC”);

City foo2 = new City(20,15,”XYZ”);

x_coordinatesdict.insert(foo1.getx_cordinates(), foo1);

x_coordinatesdict.insert(foo2.getx_cordinates(), foo2);

y_coordinatesdict.insert(foo1.gety_cordinates(), foo1);

y_coordinatesdict.insert(foo2.gety_cordinates(), foo2);

namedict.insert(foo1.getname(), foo1);

namedict.insert(foo2.getname(), foo2);

City findfoo1 = x_coordinatesdict.find(10);

City findfoo2 = namedict.find(“XYZ”);

The below operations will be available to the user:

1) Insertion of new cities. The array based list will be organized by the city’s name.

2) Finding cities by name.

3) Finding cities by coordinate.

4) Search and display all information for a city by its name.

5) Search and display all information for a city by its coordinates.

6) Print all cities in alphabetical order.