Queens, Hanoi, and Queues Flashcards

1
Q

constructor for the general boardd

A

No inputs. assumes an 8 by 8 is desired
creates a board with all false.
sets boardSize to 8
sets queenscount to 0

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

copy constructor for queens

A

board size is the input.
creates an n by n board with all false.
sets boardSize to input boardsize
sets queenscount to 0

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

The key was that the count of the number of queens has dual meaning.

A

Besides the number of queens on the board, it is also the next row for placing a queen

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

time for the towers of hanoi problem with recoursion

A

exponential time since the number of moves is 2n – 1 for n disks
even if you could do this iteratively, it would stay exponential time because the number of moves stays the same

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

time for the fibbonacci sequence with recoursion

A

asking it to find the 100th term, it feels exponential time. Indeed it is exponential time although an iterative solution would be linear time. So, here recursion really hurts

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

is solveQueensProblem a standard recoursive function

A

olveQueensProblem is NOT a standard recursive function because it contains iteration too. It needs both to implement the technique called backtracking

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

rui = spike is equal to

A

rui.operator= (spike)

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

this

A

address of the calling class object

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

*this

A

this is a pointer that points to a clone of the current object

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

3 things i need to delete when there is a circularly linked node of size 1

A

delete the connection(next is nullptr)
delete the node (delete node)
set it to null (node = nullptr)

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

what do i need to do in order to delete the first item from a queue

A

delptr is first item(backptr next)
first item is now second item(backptr next is delptr next)
null delptrs connection(delptr next is nullptr)
delete delptr

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

when getting the size of a queue when must i loop until

A

until backptr next is backptr

you must then add another count for the final node

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

how to prevent work from a=a in the operator= member function

A

you only do copies in if(this != &rhsq)

then return *this at teh end

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

write a client which did cascading =’s

A

zach = rui = spike;

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

also saw that rui = spike; is equivalent to

A

rui.operator=(spike)

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

o what part of the code allows the cascading of < Tried it and it worked with

A

cout &laquo_space;spike &laquo_space;rui;

17
Q

why is operator&laquo_space;not a method function

A

it is called on teh left with an ostream object not a queue object

18
Q

method function

A

called with a queue function on the left

19
Q

is operator= a queue function

A

yes

20
Q

what does making operator&laquo_space;a firend do

A

but designating this function as a friend in queue.h allows it to access data members of class Queue in its code

21
Q

designate operator&laquo_space;as a friend

A

friend ostream& operator&laquo_space;(ostream& output, const Queue& rhsq);

22
Q

• ADT Queue:

A

data object is a queue which is a First In First Out List

as opposed to a stack which is a Last In First Out List

23
Q

facts about queue

A

• queue.cpp using a circularly linked list with only a backptr
coded constructor, isEmpty, and the beginning of lineup

24
Q

towers of hanoi how many moves?

A

2^n-1