STACKS, QUEUES, RECURSION
TREES
GRAPHS
HASHING
SORTING
100

What data structure is typically used to evaluate a postfix expression?

Stack

100

What is the height of a tree with only one node?

0

100

What data structure is commonly used in BFS traversal.

Queue

100

What is the main advantage of using a hash table over an array?

Faster average-case lookup time (O(1))

100

What is the worst case time complexity of Shell Sort

O(n^2)

200

What is the time complexity of enqueue and dequeue operations in a circular queue implemented using an array?

O(1)

200

DAILY DOUBLE!! What traversal order results in a sorted output for a Binary Search Tree?

In-Order Traversal

200

True or false: All trees are graphs but not all graphs are trees

True

200

What is a collision in hashing, and name one resolution method.

When two keys hash to the same index; method: chaining or open addressing (linear/Quadratic probing, double hashing)

200

What is the best-case time complexity of Insertion Sort.

O(n)

300

Describe what happens if you forget the base case in a recursive function.

No terminating condition: Stack overflow/Infinite Recursion/Application crash.

300

Write the pre-order traversal of this tree: A -> (B, C), B -> (D, E), C -> (F)

A B D E C F

300

What is a topological sort and when is it applicable.

An ordering of vertices in a Directed acyclic graph, such that for every direct edge u->v, u comes before v in the ordering.

300

Define load factor and its importance in hash tables.

Load factor = (# elements) / (table size); affects performance and triggers resizing

300

Why is quicksort not a stable sort?

Because it may reorder equal elements during partitioning. Elements equal to the pivot can get swapped across.

400

Implement a recursive function to calculate the sum of all elements in an array.

int sum(int[], int n) {

if (n==0) return 0; 

return arr[n-1]+ sum(arr,  n-1); }
400

What is the time complexity of searching in a balanced binary search tree?

O(log n)

400

DAILY DOUBLE!! Give an algorithm that can be used to detect a cycle in a graph

Maintain visited array. Recursively perform DFS at each current vertex. If you arrive at a node that is in the visited array then there is a cycle.

400

Explain double hashing and how it addresses clustering.

Double hashing uses a second hash function to determine the step size for probing, It reducing primary clustering compared to linear probing.

400

Explain a sorting algorithm that uses a divide-and Conquer approach and guarantees O(n log n) in all cases)

Mergesort. Recursively divides the array in half until each element is in its own array. Merges divided halves into final sorted array.

500

A queue is simulated by using two stacks. Briefly explain the logic.

Use one stack for enqueue; for dequeue, pop all elements into the second stack, then pop the top; If the next operation is enqueue, put all elements back and append to queue

500

Given a binary tree, give an algorithm to determine if it is height-balanced.

At each node, recursively do DFS on each subtree to determine if the height difference is <= 1. If so then it is height-balance.

500

Given an undirected graph, explain how to find the number of connected components.

Maintain list of unvisited nodes. where the list of unvisited is not emply: Increment counter to 1. Perform DFS or BFS from every unvisited node. If a node is visited remove it from the list. Return counter

500

Provide the pseudocode algorithm for the insert operation for a hash table using hash function k mod n and linear probing.

Loop from hash(key), check index until empty, insert. Wrap around using mod.

500

Provide an algorithm for Heapsort.

1.) Build Heap from array. 2.)Repeatedly extract the Minimum element (root of the heap). 3.)Replace with the last element of the heap. 4.) Heapify the root. 5.) Add the extracted element to the next position of the array.

M
e
n
u