WeekB Flashcards
What is a Datastructure?
A data organization, management and storage format that enables efficient access and modification through convenient operations
What are the different types of DataStructures?
Linear
Hierarchical
Types of Linear Data Structures
- Arrays
- Linked-List
- Stack
- Queues
Types of Hierarchical Data Structures
- Trees
- Graphs
- Heaps
What is a Linear Data Structure
The data items are arranged in an orderly manner where the elements are attached adjacently.
The data elements can be accessed in one time single run).
Simpler to implement, Single level, memory inefficient.
What is a Hierarchical Data Structure
It arranges the data in a sorted order and there exists a relationship between the data elements.
Traversing of data elements in one go is not possible.
Complex to implementation, Multiple levels, memory efficient.
What is an Array?
Basic Data Structure, often used in the implementation of other data structures.
Fixed number of elements, accessed by their index.
Homogenous (of the same data type), and sequential in memory.
What is a Linked List
A sequence of data structures called nodes in which one nodes reference points to the next.
The first node is called the head, the last is called the tail.
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.
it’s implementations operates under FIFO(First In First Out). Both ends are open for operations.
Methods: poll, remove, peek, and element
Adding elements is enqueuing (only to the backend)
Removing elements is dequeuing(only to the front end).
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
collection (lower case)
a collection of entities, or an aggregate Data Structure i.e. Arrays and Maps
Collection (uppercasae)
Interface within the Collection API
Collections (with an s)
Utility Class that has static, convenient methods that operate on Data Structures in the Collections API or return them.
Collections API
Iterable-I
|
Collection-I
/ | \
List-I Set-I Queues-I
| | | \
ArrayList HashSet Priority Queue Deque-I
| | | |
LinkedList TreeSet Array Q LinkedList
| |
Stack LinkedList
|
Vector
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?
Access via index(positional access):allows you to interact with the elements based on their position in the ArrayList * get, set, add, addAll, and remove.
A re-sizable array Implemented using arrays Increases size by 50% each time it needs to increase size Default size is 10 Can only hold objects
ArrayList vs LinkedList
Link list is only good if yours adding and removing a lot of elements
Array List is more efficient overall
What is a set?
an interface apart of Collections API
Does not allow duplicated objects
Does not in general guarantee insertion order
Sets are equal if they contain the same elements
Examples:
Hashset: Maintains no order, stores in hash table, best performance
treeset: Maintains value order (it will compare each value order and printout in order)
very slow performance
LinkedHashSet Maintains insertion order, weaker performance
What is a map?
A part of the aggregate data Structures //Consist of key, value pairs. //Each key has to be unique and can be only mapped to one value //A key can be mapped to a duplicate value
Maps are not iterable, but the set of their keys are iterable
HashMap vs TreeMap vs HashTable vs LinkedHashMap
•HashMap:
allows duplicate values, not duplicate keys
* allows a single null key and its allows multiple null value
* does not guarantee order
•TreeMap:
does not allow null key, but does allow null values
* Sorted according to the natural ordering of the keys
LinkedHashMap
it maintains insertion order
•HashTable: No null keys No null values Thread safe Deprecated
abstract class
special class that can’t be instantiated.
You need abstract class to set up a structure/feature.
Able to reuse.
every abstract class is going to contain atleast 1 abstract methods
can contain concrete methods. .
“contract based” - abstract methods MUST be overridden in subclass
abstract class syntex
public abstract class Animal { //abstract method
public abstract void breathe(); }
interface
special type of class that can't be instantiated specify what a class must do but not how it does it lack instance variable * characterized by behavior * can mimic multiple inheritance w/ interfaces * classes can implements interface 0+ * interfaces can extend (inherit) other interfaces 0+ * All variable are implicitly static, public, and final (java8)
abstract parent with abstract child syntex
Animal Parent, Fish Child public abstract class Fish extends Animal{
public abstract void swim(); }