For anyone entering the dynamic fields of AI and data science, this section offers questions covering machine learning, deep learning, data visualization, and statistical analysis. Be prepared to discuss neural networks, natural language processing, or optimization algorithms. These questions are ideal for careers in AI research, data engineering, and analytics.
Answer: A stack follows LIFO (Last In First Out), while a queue follows FIFO (First In First Out).
Answer: The time complexity is O(h), where h is the height of the tree. In a balanced BST, it's O(log n).
Answer: A binary tree is a tree data structure in which each node has at most two children (i.e., left child and right child). A binary search tree is a binary tree where for each node, the values in the left child are less than the node's value and the values in the right child are greater than the node's valu
Answer: The average time complexity is O(n log n). However, in the worst case, it can be O(n^2).
Answer: A hash table uses a hash function to map keys to indices of a backing array, while a binary search tree uses a binary tree data structure to store keys and their corresponding values.
Answer: Memory management in C++ is manual, using operators like new and delete for dynamic allocation and deallocation.
Answer: Dynamic programming solves problems by breaking them into overlapping subproblems and using memoization. Example: Fibonacci sequence.
Answer: DFS explores as deep as possible along a branch before backtracking; BFS explores level by level.
Answer: Static memory allocation occurs at compile time; dynamic memory allocation happens at runtime.
Answer: Tail recursion is a recursion where the recursive call is the last operation. It can be optimized by compilers to avoid stack growth.
Answer: A hash table uses a hash function to map keys to values. Collisions are handled using methods like chaining or open addressing.
Answer: Garbage collection in Java automatically reclaims memory by identifying and removing objects no longer in use.
Answer: Linear search checks each element sequentially; binary search divides the search space. Linear is for unsorted data; binary is for sorted data.
Answer: Pointers store memory addresses, allowing dynamic memory management and efficient array and string manipulation.
Answer: Linked lists have dynamic size and efficient insertions/deletions, but slower access compared to arrays.
Answer: A trie is a tree-like structure used for efficient retrieval of keys, commonly in autocomplete and dictionaries.
Answer: Pass-by-value copies the actual value; pass-by-reference passes the address, affecting the original value.
Answer: Lambda functions are anonymous functions defined with the lambda keyword, often used for short, simple operations.
Answer: Big-O notation describes the upper bound of an algorithm's time complexity. Example: O(n) for linear search.
Answer: A heap is a complete binary tree with a heap property; a BST has ordered nodes for efficient searching.
Answer: Best: O(n log n), Average: O(n log n), Worst: O(n^2).
Answer: Tail recursion reduces memory usage by reusing stack frames, enabling optimizations.
Answer: Mutexes prevent simultaneous access to resources; semaphores control access to a finite number of resources.
Answer: Greedy algorithms make local optimal choices, while dynamic programming solves subproblems and uses their solutions to optimize the overall problem.
Answer: Divide and conquer breaks down problems into smaller subproblems, solving each recursively to solve the original problem.
Answer: The time complexity is O(n^2).
Answer: Recursive algorithms use function calls to solve subproblems; iterative algorithms use loops to solve subproblems.
Answer: Dijkstra's algorithm finds the shortest path from a source node to all other nodes in a weighted graph.
Answer: Divide-and-conquer breaks a problem into smaller subproblems, solves them recursively, and combines their solutions. Example: Merge Sort.
Answer: TSP is finding the shortest path visiting all cities and returning to the start. Dynamic programming can solve it using the Held-Karp algorithm.
Answer: Backtracking tries all possible solutions recursively and backtracks when a solution is invalid. Example: N-Queens problem.
Answer: Merge sort has O(n log n) complexity, making it more efficient than bubble sort's O(n^2) for large inputs.
Answer: Floyd-Warshall finds shortest paths between all pairs of nodes in a graph.
Answer: Binary search divides a sorted array into halves, narrowing the search space. It requires sorted input and works only for arrays, not linked lists.
Answer: Memoization caches results of expensive function calls to avoid redundant computations in dynamic programming.
Answer: NP-hard problems are at least as hard as NP problems. NP-complete problems are in NP and as hard as any problem in NP. They lack efficient solutions.
Answer: A* uses heuristics for faster pathfinding, while Dijkstraβs algorithm only considers edge weights.
Answer: A minimum spanning tree connects all nodes in a graph with minimal total edge weight. Algorithms: Kruskal's and Prim's.
Answer: Kruskal's algorithm finds a minimum spanning tree by sorting edges by weight and adding them without forming cycles.
Answer: Topological sorting orders vertices in a DAG so that every directed edge points from earlier to later.
Answer: Bubble sort repeatedly swaps adjacent elements; insertion sort places each element in its correct position. Insertion sort is generally faster.
Answer: Quicksort partitions an array around a pivot, sorting recursively. Average case: O(n log n); worst case: O(n^2).
Answer: Boyer-Moore searches by skipping sections of text, using heuristics like bad-character and good-suffix rules for efficiency.
Answer: Bellman-Ford handles negative weights and finds shortest paths from a single source. Dijkstraβs works only with non-negative weights.
Answer: Primβs algorithm builds a minimum spanning tree by starting from a node and adding the smallest connecting edge iteratively.
Answer: KMP efficiently finds substrings in text using a prefix-suffix table to avoid unnecessary comparisons.
Answer: Encapsulation, Abstraction, Inheritance, and Polymorphism.
Answer: Encapsulation hides internal implementation details, exposing only necessary information through public interfaces.
Answer: Inheritance allows classes to derive properties from others. Types: Single, Multiple, Multilevel, Hierarchical, Hybrid.
Answer: Polymorphism enables one interface for different types. Compile-time: method overloading; runtime: method overriding.
Answer: Encapsulation bundles data and methods, restricting access to implementation details.
Answer: Abstraction hides complexity, exposing only relevant details. Example: Using a car without knowing its engine mechanics.
Answer: An abstract class can have method implementations; an interface only defines method signatures.
Answer: A class defines a blueprint; an object is an instanc iation of that blueprint with its own attributes and methods.
Answer: The "this" keyword refers to the current object, allowing access to its attributes and methods.
Was this helpful?