Fundamentals Flashcards

1
Q

default values of primitive numeric types

A

0 (page 84)

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

default values of boolean types

A

false (page 84)

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

default values of reference types

A

null

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

default no-argument constructor default instance values

A

default equal primitive, boolean and reference default values (page 84)

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

equality of reference variables

A

== tests whether or no they have the same identity: wether the references are equal. equals() tests whether the data-type values are the same and can be implemented by the client.

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

Bags

A

A collection where removing items is not supported-its purpose is to provide clients with the ability to collect items and then to iterate through the collected items. Can also test if bag is empty and find its number of items. (Page 124)

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

Dijkstra’s Two-Stack Algorithm

A

Push opera da onto the operand stack
Push operators onto the operator stack
Ignore left parentheses
For right parenthesis, pop an operator, pop the requisite number of operands, and push onto the operand stack the result of applying that operator to this operands

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

Linked List

A

A recursive data structure that is either empty (null) or a node having a generic item and a reference to a linked list.

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

Insert at beginning LL

A

Time it takes is independent of length of the list.

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

Remove from beginning LL

A

Running time is independent of the length of the list.

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

Insert at the end LL

A

Need a link to the last node in the list. Every method that modifies the list needs code to check whether that variable needs to be modified.

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

Insert/remove at other positions LL

A

Take time proportional to the length of the list. Doubly-linked list is the standard solution.

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

Harmonic Sum

A

1 + 1/2 + 1/3 + … 1/n ~ ln n

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

Triangular Sum

A

1 + 2 + 3 + … + n ~ n**2/2

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

Geometric Sum

A

1 + 2 + 4 + 8 + … + n = 2n - 1 ~ 2n when n = 2**n

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

Stirling’s Approximation

A

log2n! = lg1 + lg2 + lg3 + … + lgn ~ nlgn

17
Q

Binomial Coefficient

A

n on top, k on bottom (n choose k), number of ways to choose an unordered subset of k from a fixed set of n elements n!/k!(n-k)! ~ n**k/k! when k is small

18
Q

Exponential Approximation

A

(1-1/x)**x ~ 1/e

19
Q

LL Queue Implementation

A

First is head of LL, last is end of LL. Enqueue at end, dequeue at beginning of list.

20
Q

Iterators implementation

A

Class implements Iterable, the class then overwrites an iterator method which returns an Iterator. A private class then implements Iterator and implements hasNext, remove and next (usually not remove).

21
Q

LL vs ArrayList Stack

A

LL: Every operation takes constant time in worst case but extra time and space to deal with the links
AL: Every operation takes constant amortized time but less wasted space
AL is faster overall time, but LL ensures that no operation will be much larger than any other.