YouTube Icon

Interview Questions.

Top 49 Data Structure & Algorithms Interview Questions - Jul 25, 2022

fluid

Top 49 Data Structure & Algorithms Interview Questions

Q1. What Is A Binary Search Tree?

A binary seek tree is a binary tree with a unique provision where a node's left baby have to have value much less than its discern's cost and node's right infant should have fee extra than it's figure cost.

Q2. Tell Me Something About 'insertion Sort'?

Insertion type divides the list into  sub-listing, taken care of and unsorted. It takes one element at time and reveals it suitable location in looked after sub-listing and insert there. The output after insertion is a looked after sub-listing. It iteratively works on all of the elements of unsorted sub-list and inserts them to taken care of sub-listing in order.

Q3. What Is Shell Sort?

Shell type can be stated a version of insertion type. Shell sort divides the list into smaller sublist primarily based on a few gap variable and then every sub-list is taken care of the use of insertion type. In best cases, it may carry out upto Ο(n log n).

Q4. What Is Binary Search?

A binary seek works simplest on looked after lists or arrays. This seek selects the center which splits the complete list into two parts. First the middle is as compared.

This seek first compares the target fee to the mid of the list. If it is not located, then it takes decision on whether or not.

Q5. What Is Algorithm?

Algorithm is a little by little manner, which defines a set of instructions to be done in certain order to get the favored output.

Q6. What Is A Binary Tree?

A binary tree has a unique condition that every node will have two children at most.

Q7. What Is An Avl Tree?

AVL bushes are height balancing binary seek tree. AVL tree tests the peak of left and right sub-trees and assures that the distinction isn't greater than @This difference is known as Balance Factor.

BalanceFactor = top(left-sutree) − peak(right-sutree)

Q8. What Are The Criteria Of Algorithm Analysis?

An algorithm are normally analyzed on two factors − time and space. That is, how an awful lot execution time and how much greater space required by using the algorithm.

Q9. What Is Linear Searching?

Linear seek tries to locate an object in a sequentially organized facts type. These sequentially organized records items known as array or list, are available in incrementing memory vicinity. Linear search compares anticipated facts object with every of statistics gadgets in listing or array. The common case time complexity of linear seek is Ο(n) and worst case complexity is Ο(n2). Data in goal arrays/lists want no longer to be taken care of.

Q10. How Quick Sort Works?

Quick kind makes use of divide and overcome method. It divides the list in smaller 'walls' using 'pivot'. The values which can be smaller than the pivot are arranged in the left partition and more values are arranged within the right partition. Each partition is recursively taken care of the use of short kind.

Q11. What Is Tower Of Hanoi?

Tower of Hanoi, is a mathematical puzzle which includes three tower (pegs) and a couple of earrings. All rings are of various size and stacked upon each other in which the huge disk is constantly below the small disk. The purpose is to transport the tower of disk from one peg to another, without breaking its properties.

Q12. What Is A Minimum Spanning Tree (mst) ?

In a weighted graph, a minimum spanning tree is a spanning tree that has minimal weight that each one other spanning trees of the same graph.

Q13. How Breadth First Traversal Works?

Breadth First Search set of rules(BFS) traverses a graph in a breadthwards motion and uses a queue to don't forget to get the next vertex to start a seek when a lifeless stop happens in any new release.

Q14. What Is Fibonacci Series?

Fibonacci Series generates subsequent number by using including  preceding numbers. For example − 0 1 1 2 3 5 8 13.

Q15. How Depth First Traversal Works?

Depth First Search set of rules(DFS) traverses a graph in a depthward movement and uses a stack to recall to get the following vertex to begin a search while a lifeless give up happens in any new release.

Q16. How Insertion Sort And Selection Sorts Are Different?

Both sorting strategies continues  sub-lists, looked after and unsorted and each take one element at a time and locations it into sorted sub-list. Insertion kind works on the present day element in hand and places it inside the looked after array at suitable region keeping the residences of insertion type. Whereas, choice sort searches the minimal from the unsorted sub-listing and replaces it with the cutting-edge detail in hand.

Q17. How Prim's Algorithm Finds Spanning Tree?

Prim's set of rules treats the nodes as a single tree and keeps on adding new nodes to the spanning tree from the given graph.

Q18. Give Some Examples Greedy Algorithms?

The below given troubles locate their solution the usage of greedy set of rules method:

Travelling Salesman Problem

Prim's Minimal Spanning Tree Algorithm

Kruskal's Minimal Spanning Tree Algorithm

Dijkstra's Minimal Spanning Tree Algorithm

Graph - Map Coloring

Graph - Vertex Cover

Knapsack Problem

Job Scheduling Problem

Q19. What Is Bubble Sort And How Bubble Sort Works?

Bubble sort is evaluation based algorithm in which each pair of adjoining elements is in comparison and elements are swapped if they're no longer in order. Because the time complexity is Ο(n2), it isn't always suitable for large set of facts.

Q20. What Is Hashing?

Hashing is a method to convert a variety of key values into more than a few indexes of an array. By the usage of hash tables, we will create an associative data storage wherein data index can be find by imparting its key values.

Q21. What Are Some Examples Of Dynamic Programming Algorithms?

The below given problems discover their answer the use of divide and conquer algorithm technique:

Fibonacci variety collection

Knapsack problem

Tower of Hanoi

All pair shortest course via Floyd-Warshall

Shortest course by Dijkstra

Project scheduling

Q22. What Is Tree Traversal?

Tree traversal is a technique to visit all of the nodes of a tree. Because, all nodes are linked thru edges (hyperlinks) we usually begin from the foundation (head) node.

There are three ways which we use to traverse a tree:

In-order Traversal

Pre-order Traversal

Post-order Traversal

Q23. What Is Merge Sort And How It Works?

Merge type is sorting algorithm primarily based on divide and triumph over programming method. It continues on dividing the list into smaller sub-listing till all sub-listing has most effective 1 element. And then it merges them in a taken care of way till all sub-lists are ate up. It has run-time complexity of Ο(n log n) and it needs Ο(n) auxiliary space.

Q24. How Kruskal's Algorithm Works?

This set of rules treats the graph as a wooded area and each node it as an character tree. A tree connects to every other best and handiest if it has least fee amongst all to be had alternatives and does now not violate MST homes.

Q25. What Operations Can Be Performed On Stacks?

The under operations can be carried out on a stack:

push() − provides an object to stack

pop() − removes the top stack object

peek() − offers price of top object with out putting off it

isempty() − checks if stack is empty

isfull() − exams if stack is complete

Q26. What Are Common Operations That Can Be Performed On A Data-structure?

The following operations are commonly carried out on any records-structure −

Insertion − adding a statistics object

Deletion − doing away with a facts object

Traversal − having access to and/or printing all data gadgets

Searching − locating a specific statistics item

Sorting − arranging statistics gadgets in a pre-defined sequence

Q27. What Is Data-structure?

Data structure is a manner of defining, storing & retriving of statistics in a structural & systemetic manner. A statistics shape might also include distinctive form of statistics items.

Q28. What Are Asymptotic Notations?

Asymptotic analysis can offer 3 levels of mathematical binding of execution time of an algorithm −

Best case is represented by means of Ω(n) notation.

Worst case is represented by using Ο(n) notation.

Average case is represented by Θ(n) notation.

Q29. Briefly Explain The Approaches To Develop Algorithms?

There are 3 normally used approaches to broaden algorithms:

Greedy Approach − finding answer with the aid of deciding on subsequent best choice

Divide and Conquer − diving the trouble to a minimum possible sub-problem and fixing them independently

Dynamic Programming − diving the trouble to a minimum possible sub-hassle and fixing them combinedly

Q30. What Is A Recursive Function?

A recursive function is one which calls itself, immediately or calls a characteristic that during turn calls it. Every recursive function follows the recursive homes − base standards in which features stops calling itself and revolutionary technique wherein the capabilities attempts to satisfy the bottom criteria in every generation.

Q31. What Is Asymptotic Analysis Of An Algorithm?

Asymptotic analysis of an set of rules, refers to defining the mathematical boundation/framing of its run-time overall performance. Using asymptotic analysis, we are able to thoroughly conclude the satisfactory case, common case and worst case scenario of an algorithm.

Q32. What Is Selection Sort?

Selection type is in-vicinity sorting technique. It divides the facts set into two sub-lists: sorted and unsorted. Then it selects the minimal detail from unsorted sub-listing and places it into the sorted list. This iterates unless all of the factors from unsorted sub-listing are consumed into taken care of sub-list.

Q33. What Are Various Data-systems Available?

Data structure availability may range by way of programming languages. Commonly to be had facts structures are listing, arrays, stack, queues, graph, tree and so forth.

Q34. What Is A Heap In Data Structure?

Heap is a special balanced binary tree records shape in which root-node key's in comparison with its kids and organized therefore. A min-heap, a parent node has key price less than its childs and a max-heap parent node has fee more than its childs.

Q35. Why We Need To Do Algorithm Analysis?

A hassle may be solved in a couple of methods. So, many answer algorithms may be derived for a given hassle. We analyze available algorithms to locate and put into effect the fine suitable set of rules.

Q36. What Is A Tree?

A tree is a minimally related graph having no loops and circuits.

Q37. What Is A Spanning Tree?

A spanning tree is a subset of Graph G, which has all of the vertices protected with minimal viable variety of edges. A spanning tree does no longer have cycles and it can not be disconnected.

Q38. What Is A Graph?

A graph is a pictorial illustration of a set of gadgets in which some pairs of items are related by means of links. The interconnected gadgets are represented by factors termed as vertices, and the links that connect the vertices are called edges.

Q39. Why Do We Use Stacks?

Stacks follows LIFO approach and addition and retrieval of a facts object takes only Ο(n) time. Stacks are used in which we want to get admission to data within the reverse order or their arrival. Stacks are used normally in recursive feature calls, expression parsing, depth first traversal of graphs etc.

Q40. What Is Interpolation Search Technique?

Interpolation seek is an improved variant of binary search. This search set of rules works at the probing position of required value.

Q41. Why Do We Use Queues?

As queues follows FIFO method, they're used whilst we need to work on records-objects in precise series in their arrival. Every working gadget maintains queues of numerous approaches. Priority queues and breadth first traversal of graphs are some examples of queues.

Q42. What Is A Queue In Data-shape?

Queue is an abstract statistics structure, particularly similar to stack. In contrast to stack, queue is opened at each quit. One stop is constantly used to insert records (enqueue) and the opposite is used to cast off statistics (dequeue). Queue follows First-In-First-Out method, i.E., the facts item stored first may be accessed first.

Q43. What Operations Can Be Performed On Queues?

The underneath operations can be finished on a stack:

enqueue() − provides an item to rear of the queue

dequeue() − removes the item from the front of the queue

peek() − offers fee of front object without getting rid of it

isempty() − tests if stack is empty

isfull() − assessments if stack is complete

Q44. How Many Spanning Trees Can A Graph Has?

It relies upon on how linked the graph is. A whole undirected graph can have maximum nn-1 wide variety of spanning trees, in which n is quantity of nodes.

Q45. What Are Some Examples Of Divide And Conquer Algorithms?

The underneath given problems locate their solution using divide and triumph over set of rules method :

Merge Sort

Quick Sort

Binary Search

Strassen's Matrix Multiplication

Closest pair (points)

Q46. What Is A Linked-list?

A linked-listing is a list of statistics-gadgets linked with hyperlinks i.E. Pointers or references. Most present day high-level programming language does now not offer the feature of directly having access to memory location, therefore, related-list are not supported in them or to be had in shape of inbuilt functions.

Q47. What Is Stack?

In information-structure, stack is an Abstract Data Type (ADT) used to store and retrieve values in Last In First Out approach.

Q48. What Is The Prefix And Post Fix Notation Of (a + B) * (c + D) ?

Prefix Notation − * + a b + c d

Postfix Notation − a b + c d + *

Q49. What Is Linear Data Structure?

A linear data-shape has sequentially organized records gadgets. The subsequent time can be located within the next memory deal with. It is stored and accessed in a sequential manner. Array and listing are instance of linear facts shape.




CFG