DSA Mini Q&A Module – Arrays, ArrayList, Linked List, and Stack

DSA Mini Q&A Module

DSA Mini Q&A Module

1. Arrays

Q1: What is an array?

An array is a collection of elements of the same type stored in contiguous memory locations. Each element is accessed by an index starting from 0.

Q2: Advantages of arrays

  • Fast access via index (O(1))
  • Easy to iterate

Q3: Disadvantages of arrays

  • Fixed size (cannot grow/shrink dynamically)
  • Inserting/deleting in middle is expensive (O(n))

Q4: Array vs ArrayList

Feature Array ArrayList
Size Fixed Dynamic
Data type Same type (primitive or object) Objects only
Memory Contiguous Flexible, resizable
Performance Faster for access Slightly slower due to dynamic resizing

2. ArrayList

Q1: What is an ArrayList?

A resizable array in Java, part of java.util, which can grow automatically and store objects.

Q2: Pros over array

  • Dynamic size
  • Built-in methods (add(), remove(), contains())

Q3: Cons

  • Slower than array for primitive types (stores objects, autoboxing overhead)
  • Not synchronized (use Vector if you need thread safety)

3. Linked List

Q1: What is a linked list?

A linear data structure where each element (node) contains data + pointer to next node.

Types

  • Singly Linked List – each node points to next node
  • Doubly Linked List – nodes have next and previous pointers
  • Circular Linked List – last node points to first node, can be singly or doubly

Q2: Pros & Cons

Feature Linked List Array
Dynamic size Yes No
Insert/delete Fast (O(1) if node known) Slow (O(n))
Random access Slow (O(n)) Fast (O(1))
Memory Extra pointer memory Contiguous, less overhead

Q3: When is a doubly linked list better?

When you need reverse traversal or easier deletion of a node if you have a pointer to it.

Q4: Circular vs Singly

Circular is better for queues or round-robin tasks, as you can loop back to start easily.

4. Stack

Q1: What is a stack?

A LIFO (Last-In-First-Out) data structure. Operations include push() → add element, pop() → remove top element, peek() → see top element.

Q2: Implementation

  • Array-based – fixed size, fast access, O(1) push/pop if not full
  • Linked List-based – dynamic size, memory overhead for pointers, O(1) push/pop

Q3: Array vs Linked List Stack

Feature Array Linked List
Size Fixed Dynamic
Memory Contiguous Pointer overhead
Push/Pop O(1) O(1)
Wasted space Possible if not full None

Q4: Why use a stack?

  • Expression evaluation (infix, postfix, prefix)
  • Undo operations in editors
  • Function call stack (recursion)

5. Conceptual “Why/When” Questions

  • Why choose ArrayList over Array? → Dynamic size and frequent insertions/deletions
  • Why choose LinkedList over ArrayList? → Frequent insertions/deletions in the middle
  • Why choose doubly linked list over singly? → Reverse traversal or easier deletion
  • Why array stack over linked list stack? → Simple, fast, less memory overhead when size is known
  • Why linked list stack over array stack? → Dynamic size, no overflow

If You need check out our, Fundamentals of java Blog L I N K
Common Mistakes in JAVA beginner level

Comments

Popular posts from this blog

Software Engineering Explained: Definition, Process Models, and Challenges

Java Basics – What, Why, and the Real Story

Beginner's Guide to the World Wide Web: Websites, Domains, Networks & More!