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