Test 3 Flashcards

1
Q

is one of the most commonly used data structures in computer science

A

A stack

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

The stack’s storage policy is

A

Last-In, First Out , or LIFO

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

What methods can Stacks use?

A
boolean empty()
E peek()
E pop()
E push( E obj )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

a string that reads identically in either direction, letter by letter (ignoring case)

A

Palindrome

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

When analyzing arithmetic expressions, it is important to determine whether an expression is balanced with respect to parentheses.

The problem is further complicated if braces or brackets are used in conjunction with parentheses

The solution is to use:

A

stacks!

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

PITFALL of stacks: attempting to pop an empty stack will:

A

throw an Emptystackexception . You can guard against this by either testing for an empty stack or catching the exception

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

Stacks are so common in computing , that Java included. A Stack class in its early versions:

A
import java.util.Stack; 
Stack myStack = new Stack();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A queue differs from a stack in one important way:

A

a queue a is FIFO list - First-In, First-Out

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

Operating systems use queues to:

A

keep track of tasks waiting for a scarce resource

ensure that the tasks are carried out in FIFO order

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

Queue uses methods:

A
boolean offer(E item) 
E remove() 
E peek()
E element()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The __________ class provides methods for inserting and removing elements at either end of a linked list, which means all _______ methods can be implemented easily

A

Linkedlist

Queue

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

can be used to generate simple solutions to problems that are difficult to solve by other means

A

Recursion

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

reduces a problem into one or more simpler versions of itself

A

Recursion

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

I’m recursive strategy there must be _______________ (the _________), for a small value of n, that can be solved directly

A

at least one case

base case

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

In recursive strategy a problem of a given size n can be reduced to smaller versions of the same problem (____________)

A

recursive case(s)

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

The process of returning from recursive calls and computing the partial results is called

A

unwinding the recursion

17
Q

Java maintains a ___________ on which it saves new information in the form of an _____________

A

run-time stack

activation frame

18
Q

The activation frame contains storage for:

A

method arguments

local variables ( if any)

the return address of the instruction that called the method

19
Q

Whenever a new method is called ( recursive not ), a new activation frame is:

A

pushed onto the run-time stack

20
Q

Mathematicians often use recursive definitions of formulas that lead naturally to recursive algorithms

Examples include :

A

factorials
powers
greatest common divisors (gcd)

21
Q

Known as infinite recursion: the program will eventually throw:

A

Stack OverflowError exception

22
Q

In the factorial method, you could throw an ________________ if n is negative

A

IllegalArgumentException

23
Q

In iteration, a loop condition determines:

A

whether to repeat the loop body or exit the loop

24
Q

A recursive algorithm may be simpler than an iterative algorithm and thus:

A

easier to write, code, debug, and read

25
Q

Recursive methods often have __________________ relative to their iterative counterparts

A

slower execution times

26
Q

The overhead for loop repetition is _______ than the overhead for a method call and return

A

smaller

27
Q

If it is easier to design a solution using recursion , then:

A

you should code it as a recursive method

28
Q

The reduction in efficiency does not outweigh:

A

the advantage of readable code