Heapsort
1. Constructs an array satisfying the max-heap property.
2. Sorts the array in ascending order.
Note: A.length is the length of array A, which does not change.
A.heap-size is the size of the
Binary tree - recursively defined on a finite set of nodes that either
contains no nodes
is composed of three disjoint sets of nodes:
root node
binary tree called the left subtree
binary tree called t
Build-Max-Heap
"Max" refers to the fact that this algorithm calls Max-Heapify, which guarantees that the
object the with the largest value is at the top of the heap.
Build-Max-Heap (A)
- alters A
- po
Uses:
Use recursion tree to determine a good asymptotic bound on the recurrence T(n) =
o
Sum the costs within each level of the tree to obtain a set of per-level costs.
o
Sum all the per-level costs
Definition
Asymptotic
a line that continually approaches a given curve but does not meet it at any finite
distance.
Example
x is asymptotic with x + 1
limit -
f(x) = k
Roughly translated might read as
Max heaps maintain the maximum heap value at array location 1.
A priority queue requires that the priority value be accessible at the head of the queue, location 1.
Example - The highest priority (max
Max-heap property
The max-heap property:
for every node i other than the root
A[ Parent( i ) ] A[ i ]
Note that the root is excluded as it has no parents.
The max-heap property means that the parent v
4.3 OVERVIEW - Don't confuse with forward or backward substitution
Substitution as used here, refers to substituting a guess for a closed-end recurrence solution into
an induction proof.
To prove asym
Sorting_Machine can be implemented by the sorting algorithms listed in the table below.
The actual work done to get the items sorted will be performed in one of the three
different sorting machine op
How fast can we sort?
We will prove a lower bound.
Why ( n ) as a lower bound?
Comparison sorting
The only operation that may be used to gain order information about a
sequence is comparison of pairs
Definition
A heap can be defined as a binary tree with one key (value) assigned to each node provided the
following two requirements are met:
Tree shape - the binary tree is essentially complete; all
Note that tree here means binary tree.
A complete tree is a full tree.
1. There are at most 2h leaves in a binary tree of height h.
That is the nodes at the bottom level.
Base
h=1, no more than 21 = 2
Computing the limit of the ratio of two functions is another way to classify the growth of a
function.
What f(n) is in terms of O, , , o, and
f(n)/g(n
)
o
0
O
f(n)
O(g(n)
f(n)
(g(n)
f(n)
(g(n)
f(n
Assignment
1. Write down for each statement the number of times the statement is executed in the worst
case.
2. Compute T(n), i.e., the running time of Find_Largest, and simplify (if possible) by
comb
Assignment
1. Write down for each statement the number of times the statement is executed in the worst
case.
2. Compute T(n), i.e., the running time of Find_Largest, and simplify (if possible) by
comb
Homework 7
Document last modified: 03/07/2014 04:44:57
Overview
The text presents algorithms and analysis of an Insertion and Quick sort. The assignment seeks to
verify empirically the accuracy of tho
Homework 8
Document last modified: 01/06/2012 10:09:12
1. (3) Explain under what circumstances, if any, redundant DISK-WRITE or DISK-READ
operations are performed during the course of executing a call
Homework 1
Document last modified: 01/16/2013 06:27:00
1. Text 2.1-3.
From text:
Consider the searching problem:
Input: A sequence of n numbers A=<a1,a2,.,an> and a value v.
Output: An index i such th
Homework 3
Document last modified: 01/06/2012 10:08:45
1. Exercise 3.1-1 - The following is half the proof.
Prove max(f(n), g(n) is (f(n) + g(n)
That means determine two constants c1 and c2 such that:
Homework 9
Document last modified: 01/06/2012 10:08:11
1. (6) Show the data structure p that results and the answers returned by the following
program.
i
1 2 3 4 5 6 7 8
Line 1 p[i]
Line 2 p[i]
Line 3
Homework 10
Document last modified: 04/09/2014 00:24:07
The following homework performs empirical analysis of an algorithm to determine the worst
case run time performance.
The general idea is to:
Det
C455 Test 1 Sample and Study Guide
You'll be given any necessary reference material such as algorithms from the
text or notes, definitions of and summation formulas.
You can bring one page of notes on
Homework 6
Document last modified: 01/06/2012 10:08:15
1. (3) Exercise 11.1-3 Hint: Assume that a successful search can choose to return the
address of any node having the matching, duplicate key.
2.
Homework 5
Document last modified: 01/06/2012 10:08:54
1. (4) Exercise 6.5-7 - A Java Heap can be downloaded for testing.
2. (2) Determine the cost for deleting the key at index i in Question 1.
3. (5
Homework 4
Document last modified: 01/31/2013 20:23:43
1. Draw the recursion tree and verify a good asymptotic upper bound (i.e. O) is correct
using substitution for the following recurrence. Substitu