ECE 4050 Final Exam Review Flashcards
What is the ordering for stack ADT?
Last in is first out
What are the main functions used in stack ADT?
bool isEmpty()
bool push(itemType newItem)
bool pop()
itemType peek()
What are the main functions of list ADT?
bool isEmpty()
int length()
int itemCount()
bool insert(location, item)
bool remove(location)
itemType return(location)
bool replace(itemType)
How is ADT list different from other ADTs?
The user specifies WHERE the data goes
Working with location instead of the items/values themselves
What happens when you want to insert or remove an item in an array-based ADT list?
Insert: shift everything under that position downward by 1.
Remove: shift everything up after removal
T/F: We don’t use the 0 index for array-based ADT list implementation
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.
Compare the advantages/disadvantages of array-based ADT list and link-based ADT list
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.
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
Replace
Which list method has only 1 parameter?
isEmpty
setEntry
insert
remove
remove - just need location
isEmpty doesn’t take parameters
setEntry needs value and location
insert needs value and location
What should be returned by the list operation (aList.insert(2,x)).getEntry(2) ?
false
2
x
an exception is thrown
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
What would be returned by the list operation (bList.insert(3,x)).remove(3)?
2
x
false
bList
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.
T/F: In an array based implementation of a stack, the stack can grow and shrink dynamically.
False
We cannot change arrays dynamically
T/F: The ADT list can have an arbitrary length.
True - in an array, we get to set the length arbitrarily
In a linked implementation, the list can grow to any length
What is the range of entry numbers for which it is legal to insert a new entry in a list?
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
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?
position - lists work based on positions