{
"metadata": {
"name": "Algo HW4"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "6.1-2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "The assertion is obvious for heaps with height
\nObserve that if there are
6-3"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "b.\n
\nLet
\n
\nExtract-Min($A$, $m$, $n$):
\n min =
\n $A[1][1] = \infty$
\n
\n // Check
\n if
\n // Check
\n if
\n if
\n swap
\n Re-Youngnify(
\n else:
\n swap
\n Re-Youngnify(
\n else:
\n // Check
\n if
\n swap
\n Re-Youngnify(
\n return min
\n\n// Input data is
\nRe-Youngnify($A$, $p_1$, $r_1$, $p_2$, $r_2$):
\n // Check range
\n if
\n if
\n // Check range
\n if
\n if
\n swap
\n Re-Youngnify(
\n else:
\n swap
\n Re-Youngnify(
\n else:
\n // Check range
\n if
\n if
\n swap
\n Re-Youngnify(
"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "e.
\nAs our analysis in b. , we can extract the minimal value in
7.4-2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Observe that the recursive relation of quicksort's time consumption is
7-1"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "a.
\nWhen HOARE-PARTITION starts:
\n$x = 13$
\n$i = 0$
\n$j = 13$
\n$A = [13, 19, 9, 5, 12, 8, 7, 4, 11, 2, 6, 21]$
\n\nWhen iteration 1 terminates:
\n$x = 13$
\n$i = 1$
\n$j = 11$
\n$A = [6, 19, 9, 5, 12, 8, 7, 4, 11, 2, 13, 21]$
\n\nWhen iteration 2 terminates:
\n$x = 13$
\n$i = 2$
\n$j = 10$
\n$A = [6, 2, 9, 5, 12, 8, 7, 4, 11, 19, 13, 21]$
\n\nWhen iteration 3 terminates:
\n$x = 13$
\n$i = 10$
\n$j = 9$
\n$A = [6, 2, 9, 5, 12, 8, 7, 4, 11, 19, 13, 21]$
\nThen the comparison
\nVariable
\nAs we have discussed in b. , we already have
\nAssuming the return value
\nWe use loop invariant to prove the assertion.
\n\nLoop Invariant (loop in lines 4-13):
\nAt the start of each loop iteration,
\n\nInitialization:
\nWhen the first iteration starts, $()$ holds obviously since
\n\nMaintenance:
\nLet variable
\n\nTermination:
\nWhen the loop terminates, we have $i \geq j$.
\nIn case of $i > j$, $()$ holds for
"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
"
}
],
"metadata": {}
}
]
}
Created
March 19, 2014 00:58
-
-
Save elsdrium/9633454 to your computer and use it in GitHub Desktop.
Algo HW
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment