HW1

advertisement
CSE 225: Data Structures and Algorithms
Spring 2016 Due date: Sunday 24th, January, 2016 Homework 1 Text Book: “C++ Plus Data Structures”, Fifth Edition by Nell Dale.
Chapter 1
1. Explain why software might need to be modified
a. in the design phase.
b. in the coding phase.
c. in the testing phase.
d. in the maintenance phase.
2. Explain why the cost of fixing an error is higher the later in the software cycle that the
error is detected.
Chapter 2
3. Consider the abstract data type GroceryStore.
a. At the application level, describe GroceryStore.
b. At the logical level, what grocery store operations might be defined for the
customer?
c. Specify (at the logical level) the operation CheckOut.
d. Write an algorithm (at the implementation level) for the operation CheckOut.
e. Explain how parts (c) and (d) represent information hiding.
4. Indicate which predefined C++ types would most appropriately model each of the
following (more than one may be appropriate for each):
a. a chessboard
b. information about a single product in an inventory-control program
c. a list of famous quotations
d. the casualty figures (number of deaths per year) for highway accidents in Texas
from 1954 to 1974
e. the casualty figures for highway accidents in each of the states from 1954 to 1974
f. the casualty figures for highway accidents in each of the states from 1954 to 1974,
subdivided by month
g. an electronic address book (name, address, and phone information for all your
friends)
h. a collection of hourly temperatures for a 24-hour period
5. Consider the following code segmentsa.
sum2 = 0;
for (i=1; i<=n; i++)
for (j=1; j<=i; j++)
sum2++;
c.
sum = 0;
for (i=1; i<=n; i++)
sum += total(i) ;
b.
sum = 0;
for (i=1; i<=n*n; i++)
sum = sum + 1;
total = 1;
for (j=1; j<=n; j++)
total = total * j;
int total(int n)
{
sum1 = 0;
for (i = 1; i <= n; i++)
sum1 = sum1 + 1;
sum2 = 0;
for (j = 1; j <= n; i++)
for (k = j+1; k <= n; k++)
sum2++;
return sum1 + sum2;
}
Assign cost for each statement and calculate the total number of statements. At the end, figure out
the time complexity in Big-O.
Submission guideline:
 This is handwritten and individual homework.
 Use A4 size pages for homework and use both sides of the page except the cover page.
 Cover page should include the following in orderHomework no., Name, ID, Course Code, Course Name, Section, Total no. of Homework
given, Total no. of Homework completed
 All answers must be in order.
 Do not copy questions.
 Submit it at the beginning of the class at due date.
 If you do not follow the instructions then your homework will not be considered for
evaluation.
Download