Java Data Structures and Algorithms

Click on the flashcard to see the answer



What is a Java ArrayList?

An ArrayList is a resizable array, part of Java's Collections Framework, providing the ability to dynamically manage the size.

What is a Java HashMap?

HashMap is a collection class that stores items in key/value pairs, allowing efficient retrieval based on the key.

What is a LinkedList in Java?

A LinkedList is a data structure consisting of a sequence of elements, where each element points to the next, enabling efficient insertions or deletions.

How does a Stack work in Java?

A Stack is a Last In, First Out (LIFO) data structure, meaning the last element added is the first one to be removed.

Describe a Java TreeSet.

A TreeSet is a sorted collection that uses a Red-Black tree to order the elements, providing efficient retrieval of elements sorted by their natural order or a custom comparator.

What is a PriorityQueue in Java?

A PriorityQueue is a data structure that always servesthe lowest (min heap) or highest (max heap) priority element first.

What is a Java Hashtable?

A Hashtable is a data structure that maps keys to values for highly efficient lookups, but unlike HashMap, it is synchronized and thread-safe.

Explain the concept of a Queue in Java.

A Queue is a First In, First Out (FIFO) data structure where elements are added at the end and removed from the start.

What are some common sorting algorithms used in Java?

Common sorting algorithms include Quick Sort, Merge Sort, Bubble Sort, and Insertion Sort.

Describe the binary search algorithm.

Binary search is a searching algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search interval in half.

What is the difference between Comparable and Comparator in Java?

Comparable is used to sort objects using natural ordering, defined within the class, whereas Comparator allows sorting objects by multiple criteria, external to the class.

What is a graph data structure in Java?

A graph is a collection of nodes (vertices) connected by edges, representing various scenarios such as networks, circuits, or maps.

Explain depth-first search (DFS).

Depth-first search is an algorithm for traversing or searching tree or graph data structures that explores as far as possible along a branch before backtracking.

Explain breadth-first search (BFS).

Breadth-first search is an algorithm for traversing or searching tree or graph data structures that explores all neighbor nodes at the present depth prior to moving on to nodes at the next depth level.

What is the Big O notation?

Big O notation is a mathematical notation used to describe the upper bound performance or the worst-case scenario of an algorithm in terms of time or space consumption.