Comm Data Structures

Abdullah-sunul
DataStructursHW2.pdf

HONOR CODE

COMP-3040-02

Data Structures

Assignment-2

Due on 09/12/2018

I pledge my honor that I have neither given nor received aid on this work.

Do not sign until after you have completed your assignment.

Name: Signature:

COMP3040-02 Data Structures Assignment 2

Due 9/12/2018

1. What are the fundamental operations of an unsorted array?

2. Why is the insertion not supported for unsorted array?

3. What is the time complexity of deleting an element from a sorted array? Does it have better time

complexity than deleting a node from an unsorted array? Why?

4. Programming:

4.1 Download and study program P1-1.

 Add a testing class that can test all the operations defined in the unsortedArrayAccess class.

 Make your testing menu-driven.

4.2 Download and study program P1-2.

 Add a testing class that can test all the operations defined in the sortedArrayAccess class.

 Make your testing menu-driven.

4.3 Modify program P1-2 so that the array is of Employee type. The sorting key is the employee’s id. The class Employee is given blow:

 import java.util.Scanner;

 public class employee

 {

 public int id;  public String name;

 public double salary;

 public void Input()

 {  System.out.println("Enter name: ");

 name = new Scanner(System.in).nextLine();

 System.out.println("Enter ID: ");

 id = Integer.parseInt(new Scanner(System.in).nextLine());

 System.out.println("Enter Salary: ");

 salary = Double.parseDouble(new Scanner(System.in).nextLine());  }

 public void Output()

 {

 System.out.printf("Name: %1$s, ID: %2$s, Grade: %3$s ", name, id, salary);

  }

 public String toString()

 {

 return String.format("[Name: {0}, ID: {1}, Grade: {2}]", name, id, salary);

 }

 } 

 Add a testing class that can test all the operations defined in the sortedArrayAccess class.

 Modify the sortedArrayAccess class by adding a method that find the employee who has the highest salary.

 Modify the sortedArrayAccess class by adding a method that find the average salary of all employees.

 Make your testing menu-driven.

Requirement for assignment reports

1. The cover page must be attached.

2. You must type your answer using a computer. Handwriting is not accepted.

3. For programming question, the submission must contain the running page (screen shot)

which shows that the program works for all cases.

4. Each program should have proper comments lines for non-trivial so that the instructors

can read and understand the program.

5. Hand in your hardcopy in class and submit the softcopy to e-learn Dropbox.

6. The contents of hardcopy must be the same as you softcopy.