Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views2 pages

Lab5 Data Structure Scheme

The document outlines Lab 5 for CSI 2120, focusing on creating data structures in Scheme, specifically heaps. It describes the characteristics of min-heaps and max-heaps, and provides tasks for inserting and removing elements from a heap while maintaining its properties. Students are encouraged to implement their own test cases for the functions they create, as no test cases are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Lab5 Data Structure Scheme

The document outlines Lab 5 for CSI 2120, focusing on creating data structures in Scheme, specifically heaps. It describes the characteristics of min-heaps and max-heaps, and provides tasks for inserting and removing elements from a heap while maintaining its properties. Students are encouraged to implement their own test cases for the functions they create, as no test cases are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSI 2120 – Lab 5

Data Structures in Scheme

Your task in this lab is to get yourself familiarized with creating data structures in Scheme. Make
sure you have DrRacket installed, and you are familiar with the interpreter and the coding parts.
If you need help, ask your TA to help you with this.
Then, you should do the following programming tasks. Each programming task in the lab is a
design based on the subjects you learned during lectures. There are test samples that you can use
to test your program. If you have questions, ask your TAs.

Heap is a data structure that has many applications in computer science. We have min-heap and
max-heap. Min-heap is a binary tree, in which the data in every node is less than both of its
children. Note that there is no particular order between children of a node in a heap. You can use
vector or list to implement a heap.
A perfect tree is a tree that has all the possible nodes in all the levels of the tree.
A complete tree is a tree that all its missing nodes are at the right most part of the last level of the
tree.

Perfect Tree Complete Tree


A heap is a complete tree and it always stays a complete tree.
Use the following link to see a simulation of inserting and removing an element to a tree.
https://www.cs.usfca.edu/~galles/visualization/Heap.html

Task 1:
In this task, you need to write a function that takes a heap and an element and inserts that
element into the heap. Note that, we need to keep the heap a complete tree. Therefore, we always
insert the new element at the place of the first missing node in the last level of the tree. Then, we
need to make a heap again. So, the inserted node is compared with its parent and if it is less than
its parent, they will be swapped. We keep doing this until the current node is not less than its
parent or we reach the root. See the visualization for clarification.

(define (insert heap value)


)

Test cases are not provided for this task because it depends on how you implement your
data structure. You need to provide proper test cases for the method you implement the
heap.

Task 2:
Heap is not a data structure made for searching. So, we don’t have the search operation for the
heap. Also, removing from a heap does not take a value to remove because we don’t have the
search operation to search for it. Don’t get confused. Heap is a data structure for other purposes
such as buffering. We do have a remove operation, which always removes the root of the heap.
In this task, write a function that takes a heap and removes the root from the heap. For removing
from heap, we need to replace the last node in the last level of the tree with the root. This keeps
the heap a complete tree. Then, we need to bring the tree back to a heap. To do that, we compare
the root with its children and if one of the children is less than the root, we replace the root with
that child and we move in that direction, we keep doing that task until we reach the last level of
the tree. One again, check the visualization for clarification.

(define (remove heap)


)

Test cases are not provided for this task because it depends on how you implement your
data structure. You need to provide proper test cases for the way method you
implement the heap.

You might also like