iterators recursion trees Flashcards

1
Q

What is the purpose of the Iterator interface?

A

To access data items in a collection one at a time, where each element is delivered exactly once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three main operations provided by an Iterator?

A

hasNext(), next(), and remove() (optional)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is recursion in programming?

A

A programming technique where a method calls itself to solve a problem by breaking it into smaller identical problems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between linear and non-linear recursion?

A

Linear recursion makes only a single recursive call each time the function runs, while non-linear recursion makes multiple recursive calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two essential components of a recursive method?

A
  1. Base case(s) that provide non-recursive solutions for simple inputs 2. Recursive calls that make progress toward the base case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is tail recursion?

A

When there is only one recursive call at the very end of a method, with no deferred operations building up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a tree data structure?

A

A non-linear ADT that stores information in a hierarchy, consisting of nodes connected by edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a leaf node and an internal node?

A

A leaf node has no children, while an internal node has at least one child

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the height of a tree?

A

The length of the longest path from the root to a leaf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the four common tree traversal methods?

A
  1. Pre-Order (root, left, right) 2. In-Order (left, root, right) 3. Post-Order (left, right, root) 4. Level Order (level by level, left to right)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Binary Search Tree (BST)?

A

A binary tree where for each node: left subtree contains elements less than the node’s value, and right subtree contains elements greater than or equal to the node’s value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What makes a tree ‘balanced’?

A

All leaves of the tree are on the same level or within one level of each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a degenerate tree?

A

An unbalanced tree where most nodes have at most one child, essentially degrading into a linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the three main steps in recursive problem-solving?

A
  1. Break the problem into smaller problems 2. Solve until reaching a known simple solution 3. Build the complete solution from smaller pieces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the time complexity of Binary Search?

A

O(log n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What determines the shape of a Binary Search Tree?

A

The order in which elements are added to the tree

17
Q

What is an expression tree?

A

A binary tree that represents an arithmetic expression where internal nodes contain operations and leaf nodes contain operands

18
Q

What is indirect recursion?

A

When two or more methods call each other in a cycle (e.g., Method A calls Method B, which calls Method A)

19
Q

What is the level of a node in a tree?

A

The number of edges between the root and the node

20
Q

What is the order we follow for Pre-Order traversal?

A

visit root first, traverse subtrees left to right.

21
Q

What is the order we follow for In-Order traversal?

A

traverse left subtree, then visit root, then traverse right subtree.

22
Q

What is the order we follow for Post-Order traversal?

A

traverse subtrees from left to right, then visit the root.

23
Q

What is the order we follow for Level Order traversal?

A

visit each node at each level of the tree from top (root) to bottom, left to right.