6.1-4
Where in a max-heap might the smallest element reside, assuming that all
elements are distinct?
The smallest element in a max-heap is in any of the leaves.
According to the definition of a max-heap property:
In a max-heap, the max-heap property is t

CSCI 651
Lecture 3: The List ADT
Instructor: Dr. Wenjia Li
10/27/16
1
List ADT
A list is a dynamic ordered tuple of homogeneous
elements
Ao, A1, A2, , AN-1
where Ai is the i-th element of the list
The position of element Ai is i; positions range from 0

7.4-1
Show that in the recurrence
= ! +
+ (),
= .
Proof:
We assume n = c2*n and we guess T(n) c*n2 2n:
T(n)=max c q! 2q + c n q 1 ! 2 + 2 + 2 + (n)
= cmax q! + (n q 1)! 2 + 2 + (n)
We have proved that in Exercise 7.4.3 that q2 + (n-q-1)2

7.4-2
Show that quicksort's best-case running time is (nlgn).
Let T (n) be the best-case time for the procedure QUICKSORT on an input of size n.
We have the recurrence:
T(n)= min(T(q)+T(nq1)+ (n)
(1qn1)
We guess T (n) cn lg, Thus:
T(n) min (c

7.2-3
Show that the running time of QUICKSORT is (n2)when the array A contains
distinct elements and is sorted in decreasing order.
In the textbook, since we choose the last element as the pivot, all other elements are
greater than the pivot in the proces

7.2-2
What is the running time of QUICKSORT when all elements of array A have the
same value?
Answer: It is (n2)
Since one of the partitions is always empty.
So T(n) = T(n 1) + ()
We have proved that T(n) = (! ) in earlier exercise.
Thus, the running time

7.4-3
Show that the expression q2 + (n-q-1)2 achieves a maximum over q= 0,1, n-1 when
q=0 or q=n-1.
f(q)= q2 + (n-q-1)2
f(q) = 2q2(nq1)=4q2n+2
f(q) =4
! !
f(q)=0 when q=!n!. f(q) is also continious.
q:f(q)>0, which means that f(q)=0 is a local m

6-2 Analysis of d-ary heaps
A d-ary heap is like a binary heap, but (with one possible exception) non-leaf nodes have d
children instead of 2 children.
a. How would you represent a d-ary heap in an array?
A d-ary heap can be represented in a 1-dimensional

6.1-6
Is the array with values cfw_23, 17, 14, 6, 13, 10, 1, 5, 7, 12 a max-heap?
Answer: No.
After we represent this array to a heap. As we can see in the graph above, this array is not a maxheap because there is one violation between 6 and 7.

CSCI 651
Lecture 4: Linked Lists,
Stacks and Queues
Instructor: Dr. Wenjia Li
10/27/16
1
Implementing A Linked List
To create a doubly linked list as seen below
10/27/16
MyLinkedList class
Node class
LinkedListIterator class
Sentinel nodes at head and tai