CMSC 132 Exam 2 Study Guide: Recursion, Trees, and Algorithm Efficiency, Exams of Advanced Education

A comprehensive overview of key concepts related to recursion, trees, and algorithm efficiency, designed to help students prepare for the cmsc 132 exam 2. It covers topics such as recursion strategies, tail and non-tail recursion, and the differences between recursion and iteration. The document also delves into tree data structures, including binary trees, depth-first and breadth-first traversals, and binary search trees. Furthermore, it explains algorithm efficiency, asymptotic analysis, big-o notation, and benchmarking, offering a solid foundation for understanding algorithm performance and optimization. This study guide is useful for students to understand the core concepts of data structures and algorithms, providing clear definitions and explanations that facilitate exam preparation and deeper understanding of computer science principles. It is a valuable resource for mastering essential topics in computer science.

Typology: Exams

2024/2025

Available from 06/17/2025

Gab-kaylan
Gab-kaylan 🇰🇪

8.5K 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 2025
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 CMSC 132 Exam 2 Study Guide: Recursion, Trees, and Algorithm Efficiency and more Exams Advanced Education in PDF only on Docsity!

CMSC 132 Exam 2 With 100% Correct

And Verified Answers 2025

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