ECE 4050 Final Exam Review Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the ordering for stack ADT?

A

Last in is first out

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

What are the main functions used in stack ADT?

A

bool isEmpty()
bool push(itemType newItem)
bool pop()
itemType peek()

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

What are the main functions of list ADT?

A

bool isEmpty()
int length()
int itemCount()
bool insert(location, item)
bool remove(location)
itemType return(location)
bool replace(itemType)

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

How is ADT list different from other ADTs?

A

The user specifies WHERE the data goes
Working with location instead of the items/values themselves

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

What happens when you want to insert or remove an item in an array-based ADT list?

A

Insert: shift everything under that position downward by 1.
Remove: shift everything up after removal

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

T/F: We don’t use the 0 index for array-based ADT list implementation

A

True, we have a 0 index, but we start at 1
The maximum is then +1 compared to the defaultSize since we don’t use the zero from default size.

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

Compare the advantages/disadvantages of array-based ADT list and link-based ADT list

A

Arrays are great for search and storing - O(1).
Arrays are not good for insert/remove - worst insert/remove at beginning means O(n) because shift everything up or down. Best insert/remove at end, no shifting.

Linked list: worst O(n) search and store, need to travel across all the nodes.
Good for insertion, removal (changes in general) because no shifting.

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

Changing the value of an entry at a given position on the list would probably be the task of which of these methods?
push
get
insert
replace

A

Replace

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

Which list method has only 1 parameter?
isEmpty
setEntry
insert
remove

A

remove - just need location

isEmpty doesn’t take parameters
setEntry needs value and location
insert needs value and location

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

What should be returned by the list operation (aList.insert(2,x)).getEntry(2) ?
false
2
x
an exception is thrown

A

x
insert(2,x) means insert a value x at position 2
getEntry(2) means return the value at position 2, which is x.
getEntry is not a bool, so not false
2 is the location, not the value

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

What would be returned by the list operation (bList.insert(3,x)).remove(3)?
2
x
false
bList

A

There are two options: true (not given as an option), and bList. This is because we insert a value x at position 3 and then remove the value at position 3. This is possible, so remove is true, but it also means the list is unchanged.

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

T/F: In an array based implementation of a stack, the stack can grow and shrink dynamically.

A

False
We cannot change arrays dynamically

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

T/F: The ADT list can have an arbitrary length.

A

True - in an array, we get to set the length arbitrarily
In a linked implementation, the list can grow to any length

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

What is the range of entry numbers for which it is legal to insert a new entry in a list?

A

From 1 to k+1 where k is item count (k+1 since we should always be able to add to the end of the list)
use k instead of n since n is often the max

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

In either the link based or array based implementation of the ADT List, what is the single parameter for both the remove and getEntry methods?

A

position - lists work based on positions

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

What is the first step in the deletion process for a linked implementation of the ADT List?
return the node to the system

disconnect the node from the linked chain by changing pointers

locate the node you want to delete

the order of these steps don’t matter

A

Locate the node you want to delete
can’t delete things if you can’t find them

16
Q

Which of the following is NOT part of the human cost of developing a computer program?

efficiency
readability
modifiability
maintainability

A

efficiency - it is solely dependent on the algorithm used and not the human
all other ones require a human to work on

16
Q

Algorithm efficiency is a concern for
small problems only
large problems only
medium sized problems only
all sizes

A

large problems only
for small sized problems, the difference in efficiency is minimal

17
Q

Which of these growth rates increases the fastest?
1
n
n^2
logn

A

n^2 is fastest
followed by n, logn, 1

18
Q

Which of the following growth-rate functions indicates a problem whose time requirement is independent of the size of the problem?
1
n
n^2
logn

A

1 - an O(1) means it takes the same amount of time to complete any size, so it is independent of size

19
Q

A linear function has the growth rate of
1
n
2^n
logn

A

n - if you don’t know this, you’re cooked

20
Q

T/F: If Algorithm A requires time proportional to n, and Algorithm B requires time proportional to n^2, B’s time requirement increases at a slower rate than A’s time requirement

A

False: if Algorithm B is O(n^2), then it grows faster than Algorithm A’s O(n), so the time it requires increases at a faster rate than A

21
Q

Each merge step of the mergesort requires __ major operations
3n-1
4n-1
(n-1)/2
n-1

A

3n-1

22
Q

Which sorting algorithm

A