2025-11-05
PDF file and on CanvasLinkedBST classvocabulary (or dictionary or lexicon) consisting of words and symbols allowed in sentences in the languagex = y might mean “copy the value of y to the variable x4 + 3 − 2BNFTerminal symbols—These symbols are in the vocabulary of the language and literally appear in programs in the language—for instance, + and * in the preceding examplesNonterminal symbols—These symbols name phrases in the language, such as expression or factor in the preceding examplesMetasymbols—These symbols are used to organize the rules in the grammarMetasymbols| Metasymbol | Meaning |
|---|---|
"..." |
Enclose literal items |
= |
Means “is defined as” |
[ ... ] |
Enclose optional items |
{ ... } |
Enclose zero or more items |
( ... ) |
Group together required choices |
| |
Indicates a choice |
Recognizer – analyzes a string to determine if it is a sentence in a given languageParser – has all the features of a recognizer and returns information about the syntactic and semantic structure of a sentenceInterpreter – carries out the actions specified by a sentencescannerlexical analysis
tokens
syntax analyzer that uses the tokens and the grammar rules to determine whether the program is syntactically correctWhen the tree is completeIn an array-based implementation, the elements are stored by level

We can compute locations of items on the array-based complete binary tree:
| Item | Location |
|---|---|
| Parent | (i − 1) // 2 |
| Left sibling (if any) | i − 1 |
| Right sibling (if any) | i + 1 |
| Left child (if any) | i * 2 + 1 |
| Right child (if any) | i * 2 + 2 |
min-heap to design a priority queuesize, add, remove, peek, etcadd method – expects a comparable element as an argument and inserts the element into its proper place in the heappop method – deletes the topmost node in the heap, returns the element contained there, and maintains the heap propertypeek operation returns but does not remove the topmost element in a heap| Method | What It Does |
|---|---|
| heap.isEmpty() | Returns True if heap is empty or False otherwise. |
| heap.__len__() | Same as len(heap). Returns the number of items in heap. |
| heap.__iter__() | Same as iter(heap) or for item in heap:. Visits the items from least to greatest. |
| heap.__str__() | Same as str(heap). Returns a string that shows the shape of the heap. |
| heap.__contains__(item) | Same as item in heap. Returns True if item is in the heap or False otherwise. |
| heap.__add__(otherHeap) | Same as heap + otherHeap. Returns a new heap with the contents of heap and otherHeap. |
| heap.__eq__(anyObject) | Same as heap == anyObject. Returns True if heap equals anyObject or False otherwise. |
| heap.peek() | Returns the topmost item in heap. Precondition: heap is not empty. |
| heap.add(item) | Inserts item in its proper place in heap. |
| heap.pop() | Removes and returns the topmost item in heap. Precondition: heap is not empty. |
Notemin-heap to design a priority queuei:
2*i + 12*i + 2(i - 1) // 2min-heap.
Add Methoddef add(self, item):
self.size += 1
self.heap.append(item)
curPos = len(self.heap) - 1
while curPos > 0:
parent = (curPos - 1) // 2 # Integer quotient!
parentItem = self.heap[parent]
if parentItem <= item: # Found the spot
break
else: # Continue walking up
self.heap[curPos] = self.heap[parent]
self.heap[parent] = item
curPos = parentPop MethodPop Methoddef pop(self):
if self.isEmpty():
raise AttributeError("Heap is empty")
self.size -= 1
topItem = self.heap[0]
bottomItem = self.heap.pop(len(self.heap) - 1)
if self.isEmpty():
return bottomItem
self.heap[0] = bottomItem
lastIndex = len(self.heap) - 1
curPos = 0
while True:
leftChild = 2 * curPos + 1
rightChild = 2 * curPos + 2
if leftChild > lastIndex:
break
if rightChild > lastIndex:
maxChild = leftChild
else:
leftItem = self.heap[leftChild]
rightItem = self.heap[rightChild]
if leftItem < rightItem:
maxChild = leftChild
else:
maxChild = rightChild
maxItem = self.heap[maxChild]
if bottomItem <= maxItem:
break
else:
self.heap[curPos] = self.heap[maxChild]
self.heap[maxChild] = bottomItem
curPos = maxChild
return topItemPS5: submission on CanvasLinkedBST class implementation as discussed in the class and ensure that the codes are working as expected.PDF to Canvas page created for this homeworkheight and isBalanced to the LinkedBST class. The height method returns the height of the tree, as defined in this chapter. The isBalanced method returns True if the height of the tree is less than twice the \(log_2\) of its number of nodes, or False otherwise.PS5Analyze your binary tree program output by completing the following:
Take a screenshot after completing Task 1 and running your program in the terminal. The screenshot should show the output starting from ========Wonder Tree:============.
Using the tree shown in your screenshot, draw its hierarchical (top-to-bottom, pyramid-like) structure.
Describe the shape of your binary tree (e.g., perfectly balanced, unbalanced, complete, or full).
List all the leaf nodes in your tree.
List all nodes at level 2.
For your tree, provide the node visitation order for each of the following traversal algorithms: