**What are data structures?**

Data structures refer to the way how data are organized and manipulated. When dealing with data structures, we not only focus on one element of data, but rather different sets of data and how they can relate to one another in an organized manner. Computer scientists and engineers continuously look for the ways to make data access more efficient.

**What are the main data structures?**

• Array

• Linked list

• Tree

• Matrix

• Graph

• Hash Table

• Stack

• Queue

**What are java collections?**

Java collections are the libraries in Java JDK that we can use to manipulate the data structures without knowing the implementation underneath. They are also called APIs. They are provided as interfaces and classes.

**What are the main Java APIs?**

• ArrayList

• LinedList

• String

• HashMap

• TreeMap

• LinkedHashMap

• HashSet

• Treeset

• LinedHashSet

• Stack

• PriorityQueue

### Table of Content

1. Data structures

With data structure, we find ways to make data access more efficient. When dealing with data structure, we not only focus on one piece of data, but rather different sets of data and how they can relate to one another in an organized manner.

**Array:**An array is an index-based data structure, which means every element is referred by an index. An array holds same data type elements.

**Linked list:**A linked list is a sequence of nodes in which each node is connected to the node following it. This forms a chain-link of data storage. It consists of data elements and a reference to the next record.

**Tree:**A tree is a collection of nodes connected by edges. Each node points to a number of nodes. A tree represents the hierarchical graphic form.

**Binary tree:**A binary tree has 1 or 2 nodes. It can have a minimum of zero nodes, which occurs when the nodes have NULL values.

**Binary search tree:**A binary search tree (BST) is a binary tree. The left subtree contains nodes whose keys are less than the node’s key value, while the right subtree contains nodes whose keys are greater than or equal to the node’s key value. Moreover, both subtrees are also binary search trees. A binary search tree can retrieve data efficiently.

**Matrix:**A matrix is a double-dimensioned array. It makes use of two indexes rows and columns to store data.

**Graph:**A graph contains a set of nodes and edges. The nodes are also called vertices. Edges are used to connect nodes. Nodes are used to store and retrieve data.

**Stack:**a stack is LIFO data structure in which only the top element can be accessed. The data is added by push and removed by pop on top.

**Queue:**A queue is FIFO data structure. In this structure, new elements are inserted at one end and existing elements are removed from the other end.

**Max-Heap:**A heap is a tree-based data structure in which all the nodes of the tree are in a specific order. Max-heap is a binary tree. It is complete. The data item stored in each node is greater than or equal to the data items stored in its children.

**Min-Heap:**Min-heap is a binary tree. It is complete. The data stored in each node is less than the data items stored in its children.

**Trie:**A Trie is a tree. In a trie, every node (except the root node) stores one character or a digit. By traversing the trie down from the root node to a particular node n, a common prefix of characters or digits can be formed which is shared by other branches of the trie as well.

**Suffix trie:**Suffix trie is a trie containing all the suffixes of the given text. Suffix trie allows particularly fast implementations of many important string operations.

2. Java Collections

Java collection framework is the set of collection types that are included as part of core java. It provides the APIs or methods that you can use directly to operate on the data structures such as Arrays, Linked Lists, stacks, queues, sets and maps. If you master java collection, it will save you tons of time and helps to solve complex problems.

**ArrayList:**ArrayList class is a resizable-array implementation of the List interface. It implements all optional list operations and permits all elements.

**Vector:**Vector is very similar to ArrayList but Vector is synchronised and slow. It is a legacy class. ArrayList is preferred.

**String:**String class is used to create and manipulate strings.

**LinkedList:**LinkedList class is a doubly-linked list implementation of the List and Deque interface. A LinkedList stores its data as a list of elements and every element is linked to its previous and next element.

**HashMap:**A HashMap is a collection class implements Map interface. It requires a hash function and uses hashCode() and equals() methods, in order to put and retrieve elements to and from the collection respectively.

**Hashtable:**Hashtable class is similar to HashMap. It implements Dictionary. Hashtable provides an Enumeration of its keys. It doesn’t allow null as key or value. Please note that since HashMap was created later, it is an advanced version and improvement on the Hashtable. Hashtable is synchronized and slower. HashMap is preferred over Hashtable.

**TreeMap:**TreeMap implements SortedMap interface. It is sorted in the ascending order of its keys. The complexity of the operations is O(logn).

**LinkedHashMap:**LinkedHashMap keeps the inserting order. The complexity is the same as HashMap O(1).

**HashSet:**HashSet class implements Set interface. Duplicate values are not allowed. Its elements are not ordered. NULL elements are allowed in HashSet.

**TreeSet:**TreeSet is implemented using a tree structure. The elements in a TreeSet are sorted. The complexity of operations is O(logn).

**LinkedHashSet:**LinkedHashSet maintains the insertion order. Elements get sorted in the same sequence in which they have been added to the Set. The complexity is the same as HashSet O(1).

**Stack:**Stack class extends Vector class with five operations to support LIFO (Last In First Out). Stack internally has a pointer: TOP, which refers to the top of the Stack element.

**PriorityQueue:**PriorityQueue class is the implementation of Queue, with each element having a priority associated with it. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time.

3. Download

Download Array Implementation (insert, delete, search, traverse)

Download ArrayList methods examples

Download Missing Data Structures in Java Collections

All implementations of data structures in my book

All Java Collections APIs and their methods in my book

Purchase Java Coding Interview Pocket Book (2nd Edition)

Landscape of Data structures and Algorithms (YouTube)