Algorithm Interview Questions set 2/Algorithm Interview Questions and Answers for Freshers & Experienced

Show me three different ways of fetching every third item in the list.

There are three different ways to do this: via a yield function, a list comprehension, or a for loop.

Posted Date:- 2021-09-10 06:23:47

What is the difference between a list and a tuple [in Python]?

You should know the answer about these default data structures in Python as it’s frequently asked. In short, lists are mutable (they can be modified) while tuples are immutable (they cannot be modified). Lists are ordered by one central index, while a tuple may hold multiple data types together in an index-like-form.

Posted Date:- 2021-09-10 06:22:49

What are Red-Black Trees and B-Trees? What is the best use case for each of them?

Both Red-Black Trees and B-Trees are balanced search trees that can be used on items that can have a comparison operator defined on them. They allow operations like minimum, maximum, predecessor, successor, insert, and delete, in O(log N) time (with N being the number of elements). Thus, they can be used for implementing a map, priority queue, or index of a database, to name a few examples.

Red-Black Trees are an improvement upon Binary Search Trees. Binary Search Trees use binary trees to perform the named operations, but the depth of the tree is not controlled - so operations can end up taking a lot more time than expected. Red-Black Trees solve this issue by marking all nodes in the tree as red or black, and setting rules of how certain positions between nodes should be processed. Without going into too much detail, this method guarantees that the longest branch isn’t more than twice as long as the shortest branch, so each branch is shorter than 2*log_base2(N).

This is the ideal structure for implementing ordered maps and priority queues. B-Trees branch into K-2K branches (for a given number K) rather than into 2, as is typical for binary trees. Other than that, they behave pretty similarly to a binary search tree. This has the advantage of reducing access operations, which is particularly useful when data is stored on secondary storage or in a remote location. This way, we can request data in larger chunks, and by the time we finish processing a previous request, our new request is ready to be handled. This structure is often used in implementing databases, since they have a lot of secondary storage access.

Posted Date:- 2021-09-10 06:20:55

What are Divide and Conquer algorithms? Describe how they work. Can you give any common examples of the types of problems where this approach might be used?

Divide and Conquer algorithms are a paradigm for solving problems that involve several basic steps. First, we divide the problem into smaller pieces and work to solve each of them independently. Once we’ve solved all of the pieces, we take all of the resulting smaller solutions and combine them into a single integrated comprehensive solution.

This process can be performed recursively; that is, each “sub problem” can itself be subdivided into even smaller parts if necessary.. This recursive division of the problem is performed until each individual problem is small enough to become relatively trivial to solve.

Some common examples of problems that lend themselves well to this approach are binary search, sorting algorithms (e.g., Merge Sort, Quicksort), optimization of computationally complex mathematical operations (Exponentiation, FFT, Strassen’s algorithm), and others.

Posted Date:- 2021-09-10 06:19:01

What Are The Criteria Of Algorithm Analysis?

An algorithm is generally analyzed by two factors.

<> Time complexity
<> Space complexity

Time complexity deals with the quantification of the amount of time taken by a set of code or algorithm to process or run as a function of the amount of input. In other words, the time complexity is efficiency or how long a program function takes to process a given input.

Space complexity is the amount of memory used by the algorithm to execute and produce the result.

Posted Date:- 2021-09-10 06:08:44

What is the difference between the Breadth First Search (BFS) and Depth First Search (DFS)?

1. BFS and DFS both are the traversing methods for a graph. Graph traversal is nothing but the process of visiting all the nodes of the graph.
2. The main difference between BFS and DFS is that BFS traverses level by level whereas DFS follows first a path from the starting to the end node, then another path from the start to end, and so on until all nodes are visited.
3. Furthermore, BFS uses queue data structure for storing the nodes whereas DFS uses the stack for traversal of the nodes for implementation.
4. DFS yields deeper solutions that are not optimal, but it works well when the solution is dense whereas the solutions of BFS are optimal.
5. You can learn more about BFS here: Breadth First Search and DFS here: Depth First Search.

Posted Date:- 2021-09-10 06:06:37

What are the applications of graph data structure?

Graphs are used in wide varieties of applications. Some of them are as follows:

1>> Social network graphs to determine the flow of information in social networking websites like facebook, linkedin etc.
2>> Neural networks graphs where nodes represent neurons and edge represent the synapses between them
3>> Transport grids where stations are the nodes and routes are the edges of the graph.
4>> Power or water utility graphs where vertices are connection points and edge the wires or pipes connecting them.
5>> Shortest distance between two end points algorithms.

Posted Date:- 2021-09-10 06:05:08

What is the time complexity of basic operations get() and put() in HashMap class?

The time complexity is O(1) assuming that the hash function used in hash map distributes elements uniformly among the buckets.

Posted Date:- 2021-09-10 06:02:53

How does HashMap handle collisions in Java?

1. The java.util.HashMap class in Java uses the approach of chaining to handle collisions. In chaining, if the new values with same key are attempted to be pushed, then these values are stored in a linked list stored in bucket of the key as a chain along with the existing value.

2. In the worst case scenario, it can happen that all key might have the same hashcode, which will result in the hash table turning into a linked list. In this case, searching a value will take O(n) complexity as opposed to O(1) time due to the nature of the linked list. Hence, care has to be taken while selecting hashing algorithm.

Posted Date:- 2021-09-10 06:02:23

How do you find the height of a node in a tree?

The height of the node equals the number of edges in the longest path to the leaf from the node, where the depth of a leaf node is 0.

Posted Date:- 2021-09-10 06:01:10

Explain the jagged array.

It is an array whose elements themselves are arrays and may be of different dimensions and sizes.

Posted Date:- 2021-09-10 06:00:39

Explain how the encryption algorithm works?

Encryption is the technique of converting plaintext into a secret code format it is also called as "Ciphertext." To convert the text, the algorithm uses a string of bits called as "keys" for calculations. The larger the key, the higher the number of potential patterns for Encryption. Most of the algorithm use codes fixed blocks of input that have a length of about 64 to 128 bits, while some uses stream method for encryption.

Posted Date:- 2021-09-10 05:57:27

How to delete a node in a given link list? Write an algorithm and a program?

Write a function to delete a given node from a Singly Linked List. The function must follow the following constraints:

<> The function must accept a pointer to the start node as the first argument and node to be deleted as the second argument, i.e., a pointer to head node is not global.
<> The function should not return a pointer to the head node.
<> The function should not accept pointer to pointer to head node.
We may assume that the Linked List never becomes empty.

Suppose the function name is delNode(). In a direct implementation, the function needs to adjust the head pointer when the node to be deleted the first node.

Posted Date:- 2021-09-10 05:56:30

How do you search for a target key in a linked list?

To find the target key in a linked list, you have to apply sequential search. Each node is traversed and compared with the target key, and if it is different, then it follows the link to the next node. This traversal continues until either the target key is found or if the last node is reached.

Posted Date:- 2021-09-10 05:53:03

Briefly explain recursive algorithm.

Recursive algorithm targets a problem by dividing it into smaller, manageable sub-problems. The output of one recursion after processing one sub-problem becomes the input to the next recursive process.

Posted Date:- 2021-09-10 05:52:17

What is Fibonacci search?

Fibonacci search is a search algorithm that applies to a sorted array. It makes use of a divide-and-conquer approach that can significantly reduce the time needed in order to reach the target element.

Posted Date:- 2021-09-10 05:51:20

What is Huffman’s algorithm?

Huffman’s algorithm is used for creating extended binary trees that have minimum weighted path lengths from the given weights. It makes use of a table that contains the frequency of occurrence for each data element.

Posted Date:- 2021-09-10 05:49:48

What is a graph?

A graph is one type of data structure that contains a set of ordered pairs. These ordered pairs are also referred to as edges or arcs and are used to connect nodes where data can be stored and retrieved.

Posted Date:- 2021-09-10 05:47:38

Give a basic algorithm for searching a binary search tree.

1. if the tree is empty, then the target is not in the tree, end search
2. if the tree is not empty, the target is in the tree
3. check if the target is in the root item
4. if a target is not in the root item, check if a target is smaller than the root’s value
5. if a target is smaller than the root’s value, search the left subtree
6. else, search the right subtree

Posted Date:- 2021-09-10 05:47:09

Differentiate STACK from ARRAY.

Stack follows a LIFO pattern. It means that data access follows a sequence wherein the last data to be stored when the first one to be extracted. Arrays, on the other hand, does not follow a particular order and instead can be accessed by referring to the indexed element within the array.

Posted Date:- 2021-09-10 05:46:29

Which sorting algorithm is considered the fastest?

There are many types of sorting algorithms: quick sort, bubble sort, balloon sort, radix sort, merge sort, etc. Not one can be considered the fastest because each algorithm is designed for a particular data structure and data set. It would depend on the data set that you would want to sort.

Posted Date:- 2021-09-10 05:46:06

What is the minimum number of queues needed when implementing a priority queue?

The minimum number of queues needed in this case is two. One queue is intended for sorting priorities while the other queue is used for actual storage of data.

Posted Date:- 2021-09-10 05:45:38

Do all declaration statements result in a fixed reservation in memory?

Most declarations do, with the exemption of pointers. Pointer declaration does not allocate memory for data, but for the address of the pointer variable. Actual memory allocation for the data comes during run-time.

Posted Date:- 2021-09-10 05:45:08

In what data structures are pointers applied?

Pointers that are used in linked list have various applications in the data structure. Data structures that make use of this concept include the Stack, Queue, Linked List and Binary Tree.

Posted Date:- 2021-09-10 05:44:42

How to find all possible words in a board of characters (Boggle game)?

In the given dictionary, a process to do a lookup in the dictionary and an M x N board where every cell has a single character. Identify all possible words that can be formed by order of adjacent characters. Consider that we can move to any of the available 8 adjacent characters, but a word should not have multiple instances of the same cell.


dictionary[] = {"Java", "Point","Quiz"};
Array[][] = {{'J', 'T', 'P',},
{'U', 'A', 'A'},
{'Q', 'S', 'V'}};
isWord(str): returns true if str is present in dictionary
else false.


Following words of the dictionary are present

Posted Date:- 2021-09-10 05:43:51

R4R Team
R4R provides Algorithm Freshers questions and answers (Algorithm Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Algorithm Interview Questions set 2,Algorithm Freshers & Experienced Interview Questions and Answers,Algorithm Objetive choice questions and answers,Algorithm Multiple choice questions and answers,Algorithm objective, Algorithm questions , Algorithm answers,Algorithm MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Algorithm fresher interview questions ,Algorithm Experienced interview questions,Algorithm fresher interview questions and answers ,Algorithm Experienced interview questions and answers,tricky Algorithm queries for interview pdf,complex Algorithm for practice with answers,Algorithm for practice with answers You can search job and get offer latters by studing .learn in easy ways .