DSA Inerview Questions Flashcards
What is data-structure?
Data structure is a way of defining, storing & retriving of data in a structural & systemetic way. A data structure may contain different type of data items.
What are various data-structures available?
Data structure availability may vary by programming languages. Commonly available data structures are list, arrays, stack, queues, graph, tree etc.
What is algorithm?
Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order to get the desired output.
Why we need to do algorithm analysis?
A problem can be solved in more than one ways. So, many solution algorithms can be derived for a given problem. We analyze available algorithms to find and implement the best suitable algorithm.
What are the criteria of algorithm analysis?
An algorithm are generally analyzed on two factors − time and space. That is, how muchexecutiontime and how muchextra spacerequired by the algorithm.
What is asymptotic analysis of an algorithm?
Asymptotic analysis of an algorithm, refers to defining the mathematical boundation/framing of its run-time performance. Using asymptotic analysis, we can very well conclude the best case, average case and worst case scenario of an algorithm.
What are asymptotic notations?
Asymptotic analysis can provide three levels of mathematical binding of execution time of an algorithm:
- Best case is represented by Ω(n) notation.
- Worst case is represented by Ο(n) notation.
- Average case is represented by Θ(n) notation.
What is linear data structure?
A linear data-structure has sequentially arranged data items. The next time can be located in the next memory address. It is stored and accessed in a sequential manner. Array and list are example of linear data structure.
What are common operations that can be performed on a data-structure?
The following operations are commonly performed on any data-structure :
- Insertion− adding a data item
- Deletion− removing a data item
- Traversal− accessing and/or printing all data items
- Searching− finding a particular data item
- Sorting− arranging data items in a pre-defined sequence
Briefly explain the approaches to develop algorithms.
There are three commonly used approaches to develop algorithms −
- Greedy Approach− finding solution by choosing next best option
- Divide and Conquer− diving the problem to a minimum possible sub-problem and solving them independently
- Dynamic Programming− dividing the problem to a minimum possible sub-problem and solving them combinedly
Give some examples greedy algorithms.
The below given problems find their solution using greedy algorithm approach −
- 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
What are some examples of divide and conquer algorithms?
The below given problems find their solution using divide and conquer algorithm approach −
- Merge Sort
- Quick Sort
- Binary Search
- Strassen’s Matrix Multiplication
- Closest pair (points)
What are some examples of dynamic programming algorithms?
The below given problems find their solution using divide and conquer algorithm approach −
- Fibonacci number series
- Knapsack problem
- Tower of Hanoi
- All pair shortest path by Floyd-Warshall
- Shortest path by Dijkstra
- Project scheduling
What is a linked-list?
A linked-list is a list of data-items connected with links i.e. pointers or references. Most modern high-level programming language does not provide the feature of directly accessing memory location, therefore, linked-list are not supported in them or available in form of inbuilt functions.
What is stack?
In data-structure, stack is an Abstract Data Type (ADT) used to store and retrieve values in Last In First Out method.
Why do we use stacks?
Stacks follows LIFO method and addition and retrieval of a data item takes only Ο(n) time. Stacks are used where we need to access data in the reverse order or their arrival. Stacks are used commonly in recursive function calls, expression parsing, depth first traversal of graphs etc.
What operations can be performed on stacks?
The below operations can be performed on a stack −
- push()− adds an item to stack
- pop()− removes the top stack item
- peek()− gives value of top item without removing it
- isempty()− checks if stack is empty
- isfull()− checks if stack is full
What is a queue in data-structure?
Queue is an abstract data structure, somewhat similar to stack. In contrast to stack, queue is opened at both end. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Why do we use queues?
As queues follows FIFO method, they are used when we need to work on data-items in exact sequence of their arrival. Every operating system maintains queues of various processes. Priority queues and breadth first traversal of graphs are some examples of queues.