Our site saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing our website without changing the browser settings you grant us permission to store that information on your device.

# Week 11 homework

Week 11 homework

## Resources

### Definitions File

```theory Defs
imports "~~/src/HOL/Library/Tree" "HOL-Library.Multiset"
begin

fun heap::"'a::linorder tree \<Rightarrow> bool" where
"heap Leaf = True"
| "heap (Node l x r) = ((\<forall>y\<in>set_tree l. x \<le> y) \<and> (\<forall>y\<in>set_tree r. x \<le> y) \<and> heap l \<and> heap r)"

end```

### Template File

```theory Submission
imports Defs
begin

fun siftdown::"'a::linorder tree  \<Rightarrow> 'a::linorder tree" where
"siftdown _ = undefined"

fun heapify:: "'a::linorder tree  \<Rightarrow> 'a::linorder tree" where
"heapify _ = undefined"

lemma heapify_is_heap: "heap (heapify t)"
sorry

lemma heapify_preserve: "mset (inorder (heapify t)) = mset (inorder t)"
sorry

end```

### Check File

```theory Check
imports Submission
begin

lemma heapify_is_heap: "heap (heapify t)"
by(rule heapify_is_heap)

lemma heapify_preserve: "mset (inorder (heapify t)) = mset (inorder t)"
by(rule heapify_preserve)

end```

Terms and Conditions