T. Andrew Yang
|
last updated: 10/21/2011 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Total points= 50 (oral
presentation) + 50 (written report) Find a topic of your interests related to ethical
issues in computer usage, development, and operations. -
Requirements: a)
Three deliverables are required of each student. See the syllabus for
the respective due dates. §
A draft of your paper – to be posted to the class discussion
board. §
An oral presentation (about 5 minutes) of your topic – to be
presented to the whole class. §
A two-page paper on the topic – to be emailed to the instructor (yang@uhcl.edu). b)
Your paper should cite three or more technical articles. Do not
use only web links; at least two of the cited articles must be
refereed journal or conference papers. c)
Proper citing should be practiced when writing the paper. Visit http://sce.uhcl.edu/yang/citing.htm
to learn how to do proper citing in a research paper. Visit http://sce.uhcl.edu/yang/research/index.htm
for sample research articles. -
Grading
criteria: 1)
40% Relevance: The chosen topic must be relevant to computer ethics. 2)
30% Technical strength: The paper should be written to demonstrate your
knowledge in the chosen topic and your technical writing ability. Coherency
is especially important. 3)
30% Cited references: See b and c above. Go to the Index Total points= 100 1.
(5 pts) Visit the class discussion board in
the UHCL BlackBoard (https://blackboard9.uhcl.edu/webapps/login/). Post
a message with your full name as the subject line. In your post, briefly
introduce yourself (including your full name) and one item you most desire to
learn in this class. Throughout this class, you shall regularly participate
at the discussion group to find recent announcements, reminders, and
discussions.
2. Algorithm Analysis
Read Chapter 5 of
the textbook. Study and understand Figure
5.3, which shows various functions in order of increasing growth rates. Assumptions: The following questions are based on a
one-dimensional array A of 275,000 integers. 2.1.1.As
stated in Sec 5.6.1 in the text, the sequential
search algorithm steps through the array sequentially until a match is
found or when all the items in the array have been examined. In the
latter case, the algorithm returns ‘not found’ as the search
result. Suppose you use sequential
search to determine the location of a given item n in the array (or to
report that n does not exist in the array).
2.1.1.1. (5 pts) What is
the fewest number of array items in A
that need to be examined in order to solve the problem (i.e., the best
scenario)? Justify your answer.
(That is, explain how your answer is correct.)
2.1.1.2. (5 pts) What is
the largest number of array items that need to be examined in order to solve
the problem (the worst scenario)?
Justify your answer.
2.1.1.3. (5 pts) What is
the average number of array items that need to be examined in order to solve
the problem (the average scenario)?
Justify your answer.
2.1.1.4. (10 pts) Explain
what it means by saying that the growth rate of the sequential search
algorithm is O(N). N represents the number of items
in the array.
2.1.2.
Sample programs from the book are
available on line at http://users.cis.fiu.edu/~weiss/dsj4/code/.
The following set of exercises are based on the
program MaxSumTest.java, which is
one of the sample applications for Chapter 5. Visit http://users.cis.fiu.edu/~weiss/dsj4/code/MaxSumTest.java
to download it directly (local
copy).
2.1.2.1. (10 pts) Run MaxSumTest.java and capture the screen snapshot
showing the complete execution of that application. Attach the
captured snapshot.
Note: The captured screen snapshot should show that the java program is
using a high percentage of the computer’s CPU. You may use Windows Task
Manager to see that. A sample snapshot showing partial execution of
the program and the cpu usage by that program is
shown below.
2.1.2.2. (10 pts) Explain why
algorithm #1 is not run when N = 100,000 and N = 1,000,000.
2.1.2.3. (10 pts) Revise the program so it will use different values
for N as shown in Table 1 (250, 2500, 25000, …).
Attach the revised source program.
2.1.2.4. (20 pts) Complete
Table 1 by filling in the
values generated by running the revised
program. Convert the printed
values into
|
Size of N
Algorithms
|
250
|
2500
|
25000
|
250000
|
2500000
|
#4
|
|
|
|
|
|
#3
|
|
|
|
|
|
#2
|
|
|
|
|
|
#1
|
|
|
|
|
|
Go to the Index
Total points= 100
Go to the Index
Total points= 100
Complete the addSorted ( ) method, which takes a
new string and adds it into the linked list while maintaining ascending order
of the items in the list.
Use the main( ) method as shown in Figure 3.1 to test the addSorted(
) method. Sample output of running the program is shown in Figure 3.2.
public static void
main(String args[]) {
ListNode2 list = new ListNode2();
System.out.println("Creating a linked list using the addSorted( )
method ...");
list = list.addSorted("Adam");
list = list.addSorted("Eve");
list =
list.addSorted("April");
list = list.addSorted("Don");
list = list.addSorted("Syd");
list = list.addSorted("Mary");
list = list.addSorted("Peter");
list = list.addSorted("April");
list.displayAllNodes();
findAndRemove (list, "April");
System.out.println("After removing \"April\"
...");
list.displayAllNodes();
} //main
Figure 3.1:
The main( ) method for testing addSorted( )
Figure 3.2:
Sample NetBeans screen output
Go to the Index
Total points= 100 + Bonus
points
Function f
(int m, int n)
{
Print (m, n); if
(m <= n) return 1; else
return f(m-2, n+3) + f(m-3, n+2); } |
Method 1: Use an array of arrays to store the
intermediate values of m and n through the iteration
The array index kind of represents the level. Each
array element itself is another array to save the values of m and n for each
level.
Ø Sample call: f(20,10,1)
Level |
First pair of (m,n) |
2nd pair of (m,n) |
3rd pair of (m,n) |
… |
… |
1 |
(20, 10) |
|
|
|
|
2 |
(18, 13) |
(17, 12) |
|
|
|
3 |
(16, 16) |
(15, 15) |
(15, 15) |
(14, 14) |
|
4 |
|
|
|
|
|
Method 2: Use an array of linked lists to store the
intermediate values of m and n through the iteration
As shown in the figure below, the array index kind of
represents the level; while the ref points to a linked list of nodes for that
level. For example, at level one, the linked list contains only one node,
with m = 20 and n = 10; while at level two, the list contains two nodes for
the values (18,13) and (17,12).
Ø Sample call: f(20,10,1)
A loop is needed to “populate” this array
of lists.
Once that’s done, have another loop to print the
appropriate level and the values of m and n in the linked list.
Total points= 100
1.
(5% each X 4 = 20%) Use mathematical
induction to prove the following identities of the Fibonacci sequence
(chapter 7).
1.1.
7.9a
1.2.
7.9b
1.3.
7.9d
1.4.
7.9g
2.
(5% each X 6 = 30%) Solve the
following sequences (chapter 7).
2.1.
7.17a
2.2.
7.17c
2.3.
7.18a
2.4.
7.18c
2.5.
7.19c
2.6.
7.19e
3.
(Based
on Lab 3, project 2) A linked list is a
recursively defined data structure. Each
node itself is the beginning of a linked list. For
instance, given a linked list called list,
if list.next is not null, list.next represents the beginning of
a linked list. This is true for each of the nodes in the rest of the linked
list.
As an illustration of converting an iterative method to a recursive
method, see Figure 5.1, where the
iterative version of displayAllNodes( ) is converted to displayAllNodesRecur(
int ).
public void displayAllNodesRecur (int nodeNumber)
{
ListNode2 tempNode = this;
/*
for (int i = 1; tempNode != null; tempNode = tempNode.next, i++)
{
System.out.println("Node " + i + ": " + tempNode.data);
}
//System.out.println("Leaving displayAllNodes\n");
*/
System.out.println("Node " + nodeNumber
+ ": " + tempNode.data);
if
(tempNode.next != null)
tempNode.next.displayAllNodesRecur(nodeNumber+1);
}
Figure 5.1 A recursive method to display all nodes in a linked
list
Write
a recursive method addSortedRecursive( ). Instead of using a loop to
determine where to add the new node, this method adds the new value into the
list by recursively calling itself. Figure 5.1 5.2 shows a sketch of the method.
public ListNode2 addSortedRecursive
(ListNode2 list, int value ) {
if the current node’s value is > value
create a new node and add value into it;
add
the new node in front of the current node;
return the new
node;
else
return
addSortedRecursive ( list.next, value ); //add the value to the linked
list after the current node
}
Figure 5.1 5.2 A sketch of the addSortedRecursive( ) method
Examples:
Case 1 – The list is null. In this
case, just add the new data into the list as a new node.
Case 2 – The list is not null. As an
example, suppose the list has got three nodes with data 2, 5 and 7, and we are
trying to add a new number 6 into the list. In this case, the call is addSortedRecursive(list, 6). Because the value of the first
node (2) is not > 6, a recursive call addSortedRecursive(list.next, 6) is made. In that call,
the value of the first node (5) is not > 6; therefore another recursive
call addSortedRecursive(list.next, 6) is made. In this case, the value of the first node
(7) is > 6, a new node is created with the value 6, and the new node is
inserted before the node with value 7.
Note 1: The sketch is not complete. For
example, you’ll
need to revise it so the returned linked list is correct.
Note 2: Use the main( ) method
shown in Figure 3.1 to test your
new method; replace all the calls of addSorted(
) to addSortedRecursive( ).
4.
(30 pts)
Attach the revised source program and screen output.
5.
(20 pts)
Give the TA a demo of your revised
application.
Go to the Index
Total points=100 + bonus points
1.
Chapter-end
exercises
1.1.
(10 pts)
18.2
1.2.
(10 pts)
Show the stack operations when an inorder traversal is applied to the tree
shown in Figure 18.25.
1.3.
(10 pts)
Show the stack operations when a preorder traversal is applied to the tree
shown in Figure 18.25.
1.4.
(5 pts) 18.5
1.5.
(10 pts) 8.21a.
Show your algorithm as pseudocodes.
1.6.
(10 pts)
8.21b. Show your algorithm as pseudocodes.
2.
This
exercise is based on the binary tree application from Chapter 18 of the
textbook. See http://users.cis.fiu.edu/~weiss/dsj4/code/
to find the source codes. You may also visit http://sce.uhcl.edu/yang/teaching/BinaryTreeDemo/BinaryTreeDemo.htm
to get the codes.
2.1.
Revise the
program BinaryTree.java by adding
three new methods that enables the duplication of a tree to another. Use the driver
program shown in Figure 6.1 to test your revised program. Sample output from
running the revised program is shown in Figure 6.2.
Note:
DO NOT change the driver method.
The three calls should remain the way they are. Part of your job is to create
three new methods with the proper method definitions to handle the three
calls as shown in Figure 6.1.
Hint:
Refer to the duplicate( ) method in the BinaryNode.java program. In the duplicate methods you define for the
BinaryTree class, consider calling the duplicate( ) method
defined in the BinaryNode class.
static public void
main(String[] args) {
BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
BinaryTree<Integer> t2 = new BinaryTree<Integer>();
BinaryTree<Integer> t4 = new BinaryTree<Integer>();
BinaryTree<Integer> t6 = new BinaryTree<Integer>();
t2.merge(2, t1, t3);
t6.merge(6, t5, t7);
BinaryTree<Integer> t8 = new BinaryTree<Integer>(); t8 = t8.duplicateFrom(t2); //an
instance method
System.out.println("t8 from t2");
t8.printInOrder(); t8 = duplicate(t6); // a static method
System.out.println("t8 from t6");
t8.printInOrder();
t4.merge(4, t2, t6); t8 = t4.duplicate(); // an instance
method
System.out.println("t8 from t4");
t8.printInOrder();
} |
Figure 6.1 Diver method to test your revised program
Figure
6.2 Sample output of calling the duplicate
methods
2.2.
(25 pts)
Attach the revised source program and screen output.
2.3.
(15 pts)
Give the TA a demo of your revised
application.
2.4.
(5 pts) What
are the differences between an instance method and a static method? Explain
the differences with respect to how the method is defined and called,
respectively.
3.
(Bonus project, 50 pts) 8.21c. Attach the source program and the captured
screen output.
Give the TA a demo during his office
hours. Be sure to give the demo before the due date.
Note: Your program must be working successfully to earn
the bonus points.
Go to the Index