subject

For this question, we will use the heap-supporting functions as seen in the lecture slides as building blocks for this assignment to build a new heap implementation. The heap implementation shown in the lecture slides is an example of a min-heap, in which the smallest element is at the root and all elements in child trees are larger than the value at the root. We can also construct max-heap data structures in which the largest element in the heap is at the root and all elements in child trees are smaller than the root.

The objective is to define SCHEME functions to manipulate a heap which:

1. maintain a binary tree as a heap,

2. use a generic (first order) order relation,

3. provides functions which can determine if a heap is empty? as well as heap-insert, heap-remove, and combine-heaps

(a) Define a SCHEME procedure, named (heap-insert f x H), which adds element x to heap H using the first-order relation f to determine which element belongs at the root of each (sub)tree.
For instance, if we wanted the same behavior as the heaps in the lecture slides (min-heap), we would use the "less than" function as our first-order relation:

(heap-insert < 100 (heap-insert < 10 (list))) (10 () (100 () ()))

If, instead, we wanted a max-heap implementation, where the largest element is at the root of the heap, we would use the "greater than" function as our first-order relation.

(heap-insert > 100 (heap-insert > 10 (list))) (100 () (10 () ()))

Note, you must use the same first-order relation for all of the heap procedures applied to a particular heap structure

HELPER FUNCTIONS

(define (create-heap value left right)
(list value left right))
(define (heap-root H) (car H))
(define (left T) (cadr T))
(define (right T) (caddr T))

(define (heap-insert f x H)
...)

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, Tcareyoliver
The salespeople at hyperactive media sales all use laptop computers so they can take data with them on the road. you are a salesperson for superduper lightspeed computers talking to hyperactive media sales about upgrading the laptops to windows 10. explain how network location awareness in windows 10 would make the laptops more secure.
Answers: 3
image
Computers and Technology, 23.06.2019 13:30, mads000
Drag the tiles to the correct boxes to complete the pairs. match the errors with their definitions. #name #value #ref when a formula produces output that is too lengthy to fit in the spreadsheet cell arrowright when you enter an invalid cell reference in a formula arrowright when you type text in cells that accept numeric data arrowright when you type in a cell reference that doesn’t exist arrowright reset next
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, janny48
How often does colleges update the cost of attendance on their website? . a)every two years b) every four years c) every year d) every semester
Answers: 1
image
Computers and Technology, 23.06.2019 23:00, minosmora01
How do you know if the website is secure if you make a purchase
Answers: 2
You know the right answer?
For this question, we will use the heap-supporting functions as seen in the lecture slides as buildi...

Questions in other subjects: