โ
DSA Interview Questions & Answers โ Part 1 ๐ง ๐ป
1๏ธโฃ What is a Data Structure?
A: A way to store and organize data for efficient access and modification. Examples: Array, Linked List, Stack, Queue, Tree, Graph.
2๏ธโฃ What is the difference between Array and Linked List?
A:
โฆ Array: Fixed size, contiguous memory, fast random access (O(1)), slow insertion/deletion (O(n)).
โฆ Linked List: Dynamic size, nodes in memory connected via pointers, slower access (O(n)), fast insertion/deletion (O(1)) at head or tail.
3๏ธโฃ What is a Stack? Give an example.
A: Stack is a linear data structure following LIFO (Last In First Out).
โฆ Operations: push, pop, peek
โฆ Example: Browser history, Undo functionality in editors.
4๏ธโฃ What is a Queue? Difference between Queue & Stack?
A: Queue is a linear data structure following FIFO (First In First Out).
โฆ Stack: LIFO โ Last element added is first to remove.
โฆ Queue: FIFO โ First element added is first to remove.
โฆ Example: Print job scheduling, Task scheduling.
5๏ธโฃ What is a Linked List? Types?
A: Linked List is a collection of nodes where each node contains data and a pointer to the next node.
โฆ Types:
โฆ Singly Linked List
โฆ Doubly Linked List
โฆ Circular Linked List
6๏ธโฃ What is the difference between Stack and Heap memory?
A:
โฆ Stack: Stores local variables, function calls; LIFO; automatically managed; faster access.
โฆ Heap: Stores dynamic memory; managed manually or via garbage collection; slower access; flexible size.
7๏ธโฃ What is a Hash Table?
A: A data structure that maps keys to values using a hash function for O(1) average-time access.
โฆ Example: Python dict, Java HashMap.
โฆ Collision Handling: Chaining, Open addressing.
8๏ธโฃ What is the difference between BFS and DFS?
A:
โฆ BFS (Breadth-First Search): Level-wise traversal; uses Queue; finds shortest path in unweighted graphs.
โฆ DFS (Depth-First Search): Deep traversal using Stack/Recursion; uses less memory for sparse graphs.
9๏ธโฃ What is a Binary Search Tree (BST)?
A: A tree where each node:
โฆ Left child < Node < Right child
โฆ Allows O(log n) search, insertion, and deletion on average.
โฆ Not necessarily balanced โ worst-case O(n).
๐ What is Time Complexity?
A: Measure of the number of operations an algorithm takes relative to input size (n).
โฆ Examples:
โฆ O(1) โ Constant
โฆ O(n) โ Linear
โฆ O(log n) โ Logarithmic
โฆ O(nยฒ) โ Quadratic
๐ฌ Double Tap โค๏ธ if you found this helpful!
Post #2674
2.97K
- โค 12