Basic DS Flashcards
What are the key 3 differences between an array and a list?
An array is of static size, while a list has a dynamic size. Also, all indices of an array are accessible with O(1) . Lastly, you can’t have any implicit null space between elements in a list
What is a link list?
A list that consists of nodes with a data field and a pointer to the next node
What is a singly-linked list?
A list where each node points to the next in a single direction
What special nodes are included in a linked list field to allow traversal?
A head node @ the beginning or a tail node @ the end
How do doubly-linked nodes and singly-linked nodes differ?
doubly-linked nodes have a previous feild
What special cases arise for the list add/contains method?
null parameter, which is signalled with a IllegalArgumentException
What special cases arise for the remove method?
invalid position & empty list which are signalled by IndexOutOBoundsException
What fields does an array implemented list have in general?
An array that holds the data and a numItems feild
How does a circularly list node differ from a regular linked list?
A circularly linked node’s last node points to the first & vice versa if it is also doubly-linked
What type is a stack?
Last-In-First-Out (LIFO)
What three unique operations does a stack have?
- push: adds to the top of the stack
- pop: remove and returns the top of the stack
- peek: returns the top of the stack
What type is a queue?
First-In-First-Out (FIFO)
What two operations does a queue have?
- enqueue: add to the rear
- dequeuer: removes from the front
To implement a queue with a linked list, what must be done to make the methods efficient?
Create a circularly linked list
What fields are included in the linked list constructor?
A reference to a header node and/or tail pointer and a numItems variable
What type of variables ARE the members of a list with the array implementation vs. the linked list implementation?
arbitrary object, list node object that holds an arbitrary object (with a next field)
What iterator must be used to traverse a list?
An indirect iterator, since the array is not accessible by the iterator class since the data is only accessible through the list field in the iterator class
What main problem does a doubly linked node fix?
The need to traverse to the node just before n
What special cases have to be dealt with when removing a node from a doubly linked list?
When the node is either the first or last node. Thiss can be fixed by making it circular
What special case needs to be dealt with in the remove method of a circular list?
When removing the header node the header pointer needs to be adjusted
What is one main disadvantage of a doubly linked list?
It takes up more memory since each node has more fields
What does pop and peek throw?
EmptyStackException
What does dequeuer throw?
EmptyQueueException
What fields are in the constructor of the array implementation of a stack?
- ) array of objects
- )size constant
- )numItems