Recursion and Binary Trees: Concepts and Algorithms, Exams of Advanced Education

A comprehensive overview of key concepts and algorithms related to recursion and binary trees. It covers topics such as the differences between tail recursion and non-tail recursion, the properties and types of recursion, the various traversal methods for binary trees (preorder, inorder, postorder, and breadth-first), the characteristics of balanced and degenerate binary trees, and the implementation of a polymorphic binary search tree. The document also discusses the importance of asymptotic analysis and benchmarking in evaluating algorithm efficiency, including the use of big-o, big-omega, and big-theta notations. Additionally, it covers the concept of the critical section of an algorithm and the differences between best-case, worst-case, and average-case scenarios. This resource would be valuable for students studying data structures, algorithms, and computer science fundamentals.

Typology: Exams

2023/2024

Available from 08/27/2024

Qualityexam
Qualityexam 🇰🇪

2.5

(4)

6.4K documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 132 Exam 2 With 100% Correct
And Verified Answers
Recursion - Correct Answer-A strategy for solving problems where a method calls itself
Recursion relies on the runtime call stack
'every method invocation gets its own stack space
Tail recursion - Correct Answer--Single recursive call thats the last thing performed in
the method
'can easily be turned into a loop
Non-tail recursion - Correct Answer--The recursive call are not performed last in the
method
Recursion vs. Iteration - Correct Answer--Iterative are more efficient
'b/c it avoids the overhead recursive method calls
-Recursive algorithms
'have higher overhead
'sometimes simpler
'are natural for backtracking searches
'suited for recursive data structures
Trees - Correct Answer--Recursive data structure that have a one-to-many relationship
between elements
Root - Correct Answer-No parent
Leaf - Correct Answer-No children
Interior Nodes - Correct Answer-A node with at least one child
Siblings - Correct Answer-Have same parent
Descendants - Correct Answer-Reachable by repeated proceeding from parent to child
Subtree - Correct Answer-A tree whose root is a child
Level - Correct Answer-a measure of a node's distance from the root
Height (or Depth) - Correct Answer-the maximum level of any node in the tree
Binary Tree - Correct Answer-a tree with at most two children per node
pf3
pf4

Partial preview of the text

Download Recursion and Binary Trees: Concepts and Algorithms and more Exams Advanced Education in PDF only on Docsity!

CMSC 132 Exam 2 With 100% Correct

And Verified Answers

Recursion - Correct Answer-A strategy for solving problems where a method calls itself Recursion relies on the runtime call stack 'every method invocation gets its own stack space Tail recursion - Correct Answer--Single recursive call thats the last thing performed in the method 'can easily be turned into a loop Non-tail recursion - Correct Answer--The recursive call are not performed last in the method Recursion vs. Iteration - Correct Answer--Iterative are more efficient 'b/c it avoids the overhead recursive method calls -Recursive algorithms 'have higher overhead 'sometimes simpler 'are natural for backtracking searches 'suited for recursive data structures Trees - Correct Answer--Recursive data structure that have a one-to-many relationship between elements Root - Correct Answer-No parent Leaf - Correct Answer-No children Interior Nodes - Correct Answer-A node with at least one child Siblings - Correct Answer-Have same parent Descendants - Correct Answer-Reachable by repeated proceeding from parent to child Subtree - Correct Answer-A tree whose root is a child Level - Correct Answer-a measure of a node's distance from the root Height (or Depth) - Correct Answer-the maximum level of any node in the tree Binary Tree - Correct Answer-a tree with at most two children per node

Depth-First Traversal (DFS) - Correct Answer-visits nodes as far ahead as possible before backing up Preorder Traversal - Correct Answer-visits a parents node before its left and right children Inorder Traversal - Correct Answer-visits nodes in the order left child, parent, right child Postorder Traversal - Correct Answer-visits a parents node's left and right children before the parents node itself Breadth-Frist Traversal (BFS) - Correct Answer-visits nodes according to how far away they are from the root Balanced Binary Tree - Correct Answer-has mostly two children per node Degenerate Binary Tree - Correct Answer-has mostly one child per node Binary Search Tree (BST) - Correct Answer-a binary tree with the property that the value in every node is larger than all the values in its left subtree, and smaller than all the values in its right subtree Polymorphic Binary Search Tree - Correct Answer-a tree could be an interface, or a superclass. Implement two subclasses, EmptyTree, NoneEmptyTree EmptyTree - Correct Answer-to represent an empty tree or subtree, rather than null Singleton Pattern - Correct Answer-This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class. Benchmarking - Correct Answer-A way to measure efficiency Algorithm efficiency - Correct Answer-Amount of resources used by an algorithm Asymptotic analysis - Correct Answer-Mathematically analyze an algorithm's efficiency, and express its running time as a function of the input size (n) Big-O notation - Correct Answer-Time is on the order of some function T(n) -O( T(n) ) Upper bound on the number of steps performed by an algorithm Benchmarking vs. Asymptotic analysis - Correct Answer-Benchmarking -precise information Asymptotic analysis -Measures intrinsic efficiency

-BEST possible asymptotic solution Set data structures - Correct Answer-No relationship between the elements being stored Example of Recursion Factorial - Correct Answer-... Example of Recursion Array Search - Correct Answer-... Properties of Recursion - Correct Answer--Recursion relies on the runtime call stack -Any problem solvable with iteration can be solved with recursion, and vice versa Types of Recursion - Correct Answer--No-tail Recursion -Tail Recursion Example of Recursion Sum of Array - Correct Answer-... Auxiliary Method / Helper Method - Correct Answer-method that is actually recursive Wrapper Method - Correct Answer-the method only purpose is to call the recursive method and return its result