Data Structures & Collections Flashcards
What are the different types of data structures?
Linear -Arrays -Linked-Lists -Stack -Queue Hierarchal -Trees -Graph -Heaps
What are Data Structures?
A data organization, management, and storage format that enables efficient access and modification through convenient operations.
What are basic data structure operations?
Inserting, Deleting, Searching, Iterating, Sorting, Merging
What is an Array?
Basic Data Structure, often used in the implementation of other data structures
What is a Linked Lists?
A sequence of data structures are called nodes in which one nodes reference points to the next. The first node is called the head, the last is called the tail.
What are the different types of Linked Lists?
- Simple Linked List - Each node only has one reference to the next ( Goes from head to tail ) the tail points to null.
- Doubly Linked List - Each node has a reference forward to the nest node and backwards to the previous node (except the head and tail) the head and tail points to null.
- Circular Linked List - The tail has reference to the head node.
Linked List vs. Arrays
Linked List are better at insertion and deletion than arrays.
One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements. If you want to access a particular item then you have to start at the head and follow the references until you get to that item.
Another disadvantage is that a linked list uses more memory compared with an array - we extra 4 bytes (on 32-bit CPU) to store a reference to the next node.
What is a Stack?
A Linear data structure and a type of list that operations to the element follows LIFO (Last In First Out) aka operations only occur on the top element.
Like a stack of plates.
Removing the top element is called popping.
To obtain the value at the top but not removing it is called peaking.
Placing an object on the top is called pushing.
What is a Queue?
An interface within the Collections API that it’s implementations are much like lines for a rollercoaster or lines at the grocery store, operates under FIFO(First In First Out). Both ends are open for operations.
Adding elements is enqueuing (only to the backend)
Removing elements is dequeuing(only to the front end).
What is a Deque?
A interface apart of the Collections API that extends from Queue and is a double ended Queue that can add and remove from both ends, FIFO and LIFO
What is a Tree?
A very common heirarchical data structure, Much like an OS file system structure or an In memory representation of an HTML document. Each element is represented by a node.
Root node is the first node
Parent nodes have references to child nodes.
Sibling nodes have the same parent
Leaf nodes are nodes that have no child
A branch is a complete line (path) from the leaf to the root
collections vs Collection vs Collections
collection - a collection of entities, or an aggregate Data Structure i.e. Arrays and Maps
Collection - Interface within the Collections API
Collections - Utility Class that has static, convenient methods that operate on Data Structures in the Collections API or return them.
Collections API
Starts from the Iterable Class then Colllections class inherits the Iterable class. Under the Collections class you have these interfaces -List 1.) ArrayList 2.) LinkedList 3.) Stack 4.) Vector -Set 1.)HashSet 2.)TreeSet 3.)(maybe) LinkedHashSet -Queue 1.) PriorityQueue 2.)ArrayQueue 3.)LinkedList
What is a List
Lists are an interface that have positional access i.e. indexing, allows duplicates, and is always sequentially ordered. Real world example is like a train, each train car resembles a node, linked to the other.
What is an ArrayList?
Implemented using arrays
Increases size by 50% each time it needs to increase size Default size is 10
Can only hold objects