0% found this document useful (0 votes)
94 views6 pages

DAA Interview Questions and Answers Guide

The document is a compilation of frequently asked interview questions and answers related to Design and Analysis of Algorithms (DAA). It covers various topics including algorithm definitions, sorting techniques (Bubble, Selection, Quick, Merge, Insertion), search methods (Linear, Binary), and concepts like NP-Complete, Dynamic Programming, and Greedy Algorithms. Additionally, it discusses specific algorithms such as Dijkstra's, Kruskal's, and Floyd's, along with their applications and advantages.

Uploaded by

Pratibha S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views6 pages

DAA Interview Questions and Answers Guide

The document is a compilation of frequently asked interview questions and answers related to Design and Analysis of Algorithms (DAA). It covers various topics including algorithm definitions, sorting techniques (Bubble, Selection, Quick, Merge, Insertion), search methods (Linear, Binary), and concepts like NP-Complete, Dynamic Programming, and Greedy Algorithms. Additionally, it discusses specific algorithms such as Dijkstra's, Kruskal's, and Floyd's, along with their applications and advantages.

Uploaded by

Pratibha S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Prepared By , Mrs.

Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

DAA Interview Questions and Answers


A list of top frequently asked DAA Interview Questions and answers are given below.
1) What is Algorithm?
The name 'Algorithm' refers to the sequence of instruction that must be followed to clarify a problem.
The logical description of the instructions which may be executed to perform an essential function.
Algorithms are usually generated independent of primary languages, i.e., an algorithm can be achieved
programming language.

2) What is Asymptotic Notation?


A way to represents the behavior of functions in the limit or without bounds.
The notations are described in terms of methods whose domains are the set of natural numbers N= {0, 1, 2
Such notations are convenient for defining the worst-case running time function T(n).
It can also be extended to the domain of the real number.

3) What is the time complexity of Algorithm?


The time complexity of an algorithm denoted the total time needed by the program to run to completion.
It is generally expressed by using the big O notation.

4) Explain the algorithms for Bubble sort and give a suitable example.
In bubble sort technique the list is split into two sub-lists sorted and unsorted. The smallest component is bu
unsorted sub-list. After moving the smallest component, the imaginary wall moves one element ahead. The
was initially written to bubble up the highest item in the list. But there is no difference whether the highest
is bubbled. This technique is simple to understand but time-consuming. In this type, two successive compo
compared, and swapping is done. Thus, step-by-step entire array items are checked, given a list of 'n' elem
bubble sort needed up to n-1 passes to sort the record.

5) Explain the algorithm for selection sort and give a suitable example.
In selection sort, the list is split into two sub-lists sorted and unsorted. These two lists are split by an imagin
We find the smallest item from unsorted sub-list and swap it to the starting. And the wall moves one item a
the sorted file is increases and an unsorted file is decreased.
Assume that we have a file on n elements. By applying a selection sort, the first item is compared with all re
(n-1) elements. The smallest item is placed at the first location. Again, the second item is compared with th
elements. At the time of the comparison, the smaller item is swapped with a bigger item. Similarly, the ent
checked for smallest component, and then swapping is done accordingly. Here we need n-1 passes or repet

6) Explain the algorithms for QUICK sort (partition exchange sort) and give a suitable example.
Quicksort is based on division. It is also called a partition exchange sorting. The basic concept of quick sort
to pick one item from an array and rearranges the remaining item around it. This element split the main list
sublists. This chosen item is known as a pivot. Once the pivot is selected, then it shifts all the components le
pivot to the left of value pivot, and all the items higher than the pivot are shifted to the right side. This proc
choosing pivot and division the list is tested recursively until sub-lists consisting of only one element.
7) What is NP-Comlete?
An NP-Complete problem is a problem in NP that is as difficult as any other trouble in this class because any
in NP can be decreased to it in Polynomial-time.

8) Differentiate Time Efficiency and Space Efficiency?


Time Efficiency measured by estimate the number of times the essential algorithms functions are executed
Space Efficiency is measured by calculating the number of additional memory units consumed by the algori

9) What is the Order of Algorithm?


The order of algorithm is standard documentation of an algorithm that has been developed to represent a
task that bound the estimated time for algorithms. The order of an algorithm is a method of defining its effi
Prepared By , Mrs. Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

It is commonly referred to as O-notation.

10) What is Brute Force?


Brute Force is a straightforward method for solving problem, usually directly based on the problem's statem
descriptions of the concepts involved.

11) What are the various criteria used to improve the effectiveness of the algorithm?
Input- Zero or more quantities are externally provided.
Output- At least one quantity is composed
Definiteness- Each instruction is simple and unambiguous
Finiteness- If we trace out the instructions of an algorithm, then for all step the algorithm complete after a
finite number of steps
Effectiveness- Every instruction must be elementary.

12) Explain the algorithms for Merge sort and give a suitable example.
The basic concept of merge sort has split the list into two smaller sub-lists of relatively equal size. Recursive
repeat this method until only one item is left in the sub-list. After this, various sorted sub-lists are combi
original sorted list arrived.

13) What is a Linear Search?


Linear search method is also called a sequential search technique. The linear search is a technique of searc
in a list in sequence. In this technique, the array is searched for the required item from the starting of the
continues until the element is found or the entire list/array has been searched.
Advantages
1. It is an easy and conventional technique of searching for information. The linear or sequential name i
2. which the elements are stored in a systematic manner.
3. The item in the list can be in any order. i.e., the linear search can be tested on the sorted or unsorted
data structure.
Disadvantages
1. This procedure is insufficient when a large number of item is present in the list.
2. It consumes more time and decreases the retrieval rate of the system.
Time complexity: O(n)

14) What is Binary Search?


Binary search is higher than the linear search. However, it cannot be tested on the unsorted data structure.
search is based on the method divide-and-conquer. The binary search begins by testing the data in the mid
of the array. This determines an object is whether in the first half or second half. If the object is in the first h
no need to check in first half. Similarly, we repeat this procedure until we find an object in the list or not fo
middle elements.
To implement a binary search technique, the item must be in sorted order.
Binary Search is performed as follows:
The key is compared with an element in the middle position of an array
o If the key matches with an element, return it, and stop.
o If the key is less than mid position element, then the element to be found must be in the first half of t
o otherwise it must be in the second half of the array.
15) Explain the algorithms for insertion sort and give a suitable example.
Both the selection and bubble sorts exchange items. But insertion sort does not exchange items. In insertio
item is inserted at an appropriate place similar to card insertion. Here the list is split into two parts sorted a
sub-lists. In each pass, the first component of unsorted sublist is picked up and moved into the sorted subli
it in a relevant position. Suppose we have 'n' items, we need n-1 passes to sort the items.
Prepared By , Mrs. Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

16) What do you mean by the optimal solution?


Given the problem with inputs, we recover a subset that appeases come constraints. Any subset that satisfi
these constraints is known as a feasible solution. A feasible solution, which either maximizes or minimizes a
method is known as an optimal solution.

17) Why Hashing?


Suppose we have a huge information set stored in an array. The amount of time needed to lookup an item i
array is either O(log n) or O(n) based on whether the array is sorted or not. If the array is sorted, then a pr
such as a binary search can be used to search the array. Otherwise, the array must be searched linearly. E
may not be desirable if we need to process a very high data set. Therefore we discuss a new procedure call
that allows us to update and fetch any entry in constant time O(1). The constant time or O(1) performance

18) Explain how the encryption algorithm works?


Encryption is the step of converting plaintext into a secret code format called "Cliphertext". To convert the
the algorithm uses a string of bits referred to as "keys" for estimation. The larger the key, the higher the nu
potential patterns for generating the ciphertext. Most encryption algorithm use codes fixed blocks of in
technique.

19) What is Dynamic Programming?


DP is another method for problems with optimal substructure: An optimal solution to a problem include opti
solutions to subproblems. This doesn't necessarily define that every optimal solution to a subproblem will co
to the primary solution.
For divide and conquer (top-down), the subproblems are independent, so we can resolve them in any ord
For the greedy technique (bottom-up), we can always choose the "right" subproblem by a greedy choice.
In dynamic programming, we solve many subproblems and save the results: not all of them will contribut
the bigger problem. Because of optimal substructure, we can be sure that at least some of the subproblem

20) What is the Knapsack Problem?


Given n elements of known weights wiand values vi, i=1, 2? n, and a knapsack of capacity W, find the most
valuable subsets of the elements that fit the knapsack. It is convenient to order the elements of a given inst
in descending order by their value-to-weight ratios. Then the first element gives the best payoff per weight
last one gives the worst payoff per weight unit.

21) What is Warshall's Algorithm?


Warshall's algorithm is a function of dynamic programming procedure, which is used to find the transitive
closure of a directed graph.

22) What is a Greedy Algorithm?


A greedy technique for an optimization problem always makes the option which look best at the moment an
the current subsolution.

23) List the advantage of the greedy algorithm.


1. The greedy method produces a feasible solution
2. The greedy method is very easy to solve a problem
3. The greedy method implements an optimal solution directly

ADVERTISEMENT
24) What is Minimum Spanning Trees?
A spanning tree for a linked graph is a tree whose vertex set is the same as the vertex set of the given grap
and whose edge set is a subgroup of the edge set of the given graph. i.e., any linked graph will have a span
Weight of a spanning tree w (T) is the total of weights of all edges in T. The Minimum spanning tree (MST) is
Prepared By , Mrs. Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

tree with the smallest feasible weight.

25) What is Kruskal?s Algorithm?


This is a greedy method. A greedy method chooses some local optimum (i.e., selection an edge with the sm
weight in an MST).
Kruskal's algorithm works as follows:
Take a graph with 'n' vertices, keep on adding the shortest (least cost) edge, while avoiding the generation
until (n - 1) edges have been added. Frequently two or more edges may have the same rate. The order in w
edges are decided, in this method, does not matter. Different Minimum spanning tree may result, but they w
26) What is Sorting Network?
A sorting network is a numerical model of a network of wires and comparator modules that is used to sort a
series of numbers. Each comparator connects two wires and sorts the values by outputting the smaller
value to one wire, and the higher to the other. The main difference between sorting networks and compa
algorithms is that with a sorting network, the series of comparisons is set in advance, regardless of the resu
previous comparisons. This independence of comparison series is useful for parallel execution of the metho

27) What is Floyd's algorithm?


Floyd's algorithm is a function, which is used to find all the pairs shortest paths problem. Floyd's algorithm i
to both directed and undirected weighted graph, but they do not include a cycle of a negative length.

28) What is prim's algorithm?


Prim's algorithm is a greedy and efficient technique, which is used to find the minimum spanning the tree o
linked graph.

29) How efficient is prim's algorithm?


The efficiency of the prim's methods depends on the data structure chosen for the graph.

30) What is Dijkstra's Algorithm?


Prepared By , Mrs. Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

Dijkstra's algorithm solves the single-source shortest path method of finding shortest paths from a given ve
(the source), to another vertex of a weighted graph or digraph. Dijkstra's algorithm implements a correct so

31) What are the huffman trees?


A Huffman tree is a binary tree which reduces the weighted path length from the root to the leaves, includin
predefined weights. The essential application of Huffman trees is a Huffman code.

32) What do you mean by Huffman code?


A Huffman code is an optimal prefix tree variable-length encoding technique which assign bit strings to cha
on their frequency in a given text.

33) List the advantage of Huffman's encoding?


Huffman's encoding is one of the essential file compression techniques.
1. It is easy
2. It is flexibility
3. It implements optimal and minimum length encoding

34) What is dynamic Huffman coding?


In dynamic Huffman coding, the coding tree is updated each time a new character is read from the source t
Dynamic Huffman n-coding used to overcome the disadvantage of the simplest version.

35) What is backtracking?


Depth-first node generation with bounding method is known as backtracking. The backtracking technique h
the ability to yield the solution with far fewer than m trials.

36) Write the difference between the Dynamic programming and Greedy method.
Dynamic programming
1. Many numbers of decisions are generated.
2. It gives an optimal solution always
Greedy method
1. Only one sequence of decision is generated.
2. It does not require to provide an optimal solution always.
Read More

37) What is the use of Dijkstra's algorithm?


Dijkstra's procedure is used to solve the single-source shortest-paths method: for a given vertex called the
in a weighted linked graph, find the shortest path to all its other vertices. The single-source shortest-paths p
asks for a family of paths, each leading from the source to various vertex in the graph, though some directio
edges in common.

38) What is meant by n-queen Problem?


The problem is to area n-queens on an n-by-n chessboard so that no two queens charge each other by bein
row or in the same column or the same diagonal.

39) What is the state-space tree?


The processing of backtracking is resolved by constructing a tree of choices being made. This is known as s
Its root describes an initial state before the search for a solution starts. The nodes of the first level in the tr
the choices made for the first element of the solution, the nodes in the second level describe the choices fo

40) What is the assignment problem?


Assigning 'n' people to 'n' jobs so that the total price of the assignment is as low as possible. The instanc
Prepared By , Mrs. Prathibha S , Assistant Professor, Dept of CSE, PESITM , Shimoga

problem can be described as select one element in each row of the matrix so that no two selected items are

Common questions

Powered by AI

Encryption algorithms like Huffman coding are effective for data compression because they use variable-length encoding, assigning shorter codes to more frequent elements and longer codes for less frequent ones. This approach reduces the overall amount of space needed to store or transmit data. By focusing encoding efficiency on frequent patterns, Huffman coding minimizes redundancy and achieves optimal compression, which is crucial for efficient data storage and transmission .

The Divide and Conquer paradigm in binary search involves dividing the input array into two halves and then conquering by determining in which half the desired element might reside. Initially, the middle element of the sorted array is compared with the target value; if they are equal, the search is complete. If the target is smaller than the middle element, the search continues on the left half, otherwise, on the right half. This process repeats recursively, effectively halving the search space with each comparison until the target value is found or the array cannot be divided further. This method significantly reduces the number of comparisons needed compared to a linear search, resulting in a time complexity of O(log n).

Hashing is considered preferable for data retrieval in large datasets because it allows for constant time complexity, O(1), operations for both searching and retrieving, which is significantly faster than O(log n) for binary search or O(n) for linear search. This efficiency is achieved through a hash table that directly maps keys to values, providing immediate access to the data. In contrast, other searching algorithms often require the data to be sorted or necessitate multiple comparisons to locate the desired element .

Optimal substructure is a core property in dynamic programming, where the optimal solution to a problem can be constructed from optimal solutions to its subproblems. This property allows dynamic programming algorithms to break complex problems into simpler overlapping subproblems, solve each one, and store their results to avoid redundant computations, leading to an efficient overall solution. An example is the Fibonacci sequence, where the nth Fibonacci number can be obtained by summing the (n-1)th and (n-2)th numbers, with each previous Fibonacci number calculated only once and saved for future use .

Asymptotic notation provides a way to describe the running time of an algorithm as the input size tends towards infinity. It helps in understanding the efficiency by providing a means to describe how the running time or space requirements for an algorithm grow as the input size increases. The notations, such as Big O, Theta, and Omega, are used to represent the worst-case, average-case, and best-case scenarios of an algorithm's time complexity, which is crucial for evaluating its efficiency in large-scale applications .

Dynamic programming solves the 'Knapsack Problem' by creating a table where the rows represent items and columns represent the total weight capacities from 0 to the knapsack's limit. Each cell in the table contains the maximum value that can be attained with that weight limit. As the algorithm progresses, it considers whether to include each item based on its weight and value, using previously computed results to determine the optimal subset of items that maximize the total value without exceeding the weight capacity. This approach efficiently evaluates all combinations of items, ensuring an optimal solution compared to a more exhaustive and potentially slower brute-force method .

Kruskal's Algorithm, which uses a greedy approach to find a minimum spanning tree (MST), may be more efficient than Prim's Algorithm in certain scenarios due to its simplicity in managing edge weights. Kruskal works by sorting all edges and adding the shortest available edge to the MST while avoiding cycles, using disjoint set data structures to manage connected components. Prim's Algorithm, on the other hand, grows the MST from a starting vertex by selecting the shortest edge from the included vertex set, often requiring a priority queue for efficient operation. Kruskal's Algorithm can be more efficient especially when the graph has a few vertices but many edges, while Prim's may perform better with dense graphs due to its vertex-centric approach .

Sorting networks differ from traditional comparison-based sorting algorithms in that they utilize a fixed sequence of comparisons regardless of the input values. This is unlike comparison-based algorithms, where the sequence of comparisons depends on the input data. Each comparator in a sorting network connects two inputs and ensures that the output is always sorted by outputting the smaller value to one output wire and the larger to another. This makes sorting networks highly parallelizable and suitable for hardware implementations, as the sequence is static and can be executed concurrently, unlike the more sequential decision-making in traditional algorithms .

Time efficiency measures the number of times the fundamental operations of an algorithm are executed, which corresponds to how fast an algorithm can run. Space efficiency, on the other hand, is concerned with the amount of additional memory or storage space required by the algorithm. Both metrics are critical in assessing an algorithm's usability, as some algorithms may perform quickly but require extensive memory, or they may be slow but do not use much additional space .

A greedy algorithm may fail to provide an optimal solution in problems where a locally optimal choice does not lead to a globally optimal solution. One classic example is the Knapsack Problem, where choosing items based on the highest value-to-weight ratio does not necessarily yield the most valuable subset of items that fit within a given capacity . For instance, if you have items with weight-value pairs (1, 6), (2, 10), and (3, 12), and a knapsack with capacity 5, the greedy choice would select (1, 6) and (2, 10), but the optimal solution is to pick (2, 10) and (3, 12) which exactly fits the capacity and yields a higher total value.

You might also like