Skip to content

Commit e6bbd2f

Browse files
changes
1 parent eb26a78 commit e6bbd2f

25 files changed

+2063
-63
lines changed

.DS_Store

2 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

answer.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os, json, requests
2+
from dotenv import load_dotenv
3+
4+
load_dotenv()
5+
6+
CLOUDFLARE_ACCOUNT_ID = os.getenv("CLOUDFLARE_ACCOUNT_ID")
7+
CLOUDFLARE_API_KEY = os.getenv("CLOUDFLARE_API_TOKEN")
8+
9+
def answer_user_question(question: str):
10+
headers = {"Authorization": f"Bearer {CLOUDFLARE_API_KEY}"}
11+
model = "@cf/baai/bge-small-en-v1.5"
12+
url = f"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/run/{model}"
13+
14+
payload = json.dumps({"prompt": question})

assets/AI.pdf

-807 KB
Binary file not shown.

assets/DSA.md

+334
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
DSA INTERVIEW QUESTIONSDSA INTERVIEW QUESTIONS
2+
Dear readers, these Data Structures & Algorithms Interview Questions have been designed
3+
specially to get you acquainted with the nature of questions you may encounter during your
4+
interview for the subject of Data Structures & Algorithms. As per my experience good
5+
interviewers hardly plan to ask any particular question during your interview, normally questions
6+
start with some basic concept of the subject and later they continue based on further discussion
7+
and what you answer:
8+
9+
What is data-structure?
10+
11+
Data structure is a way of defining, storing & retriving of data in a structural & systemetic way. A
12+
data structure may contain different type of data items.
13+
14+
What are various data-structures available?
15+
16+
Data structure availability may vary by programming languages. Commonly available data
17+
structures are list, arrays, stack, queues, graph, tree etc.
18+
19+
What is algorithm?
20+
21+
Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain
22+
order to get the desired output.
23+
24+
Why we need to do algorithm analysis?
25+
26+
A problem can be solved in more than one ways. So, many solution algorithms can be derived for
27+
a given problem. We analyze available algorithms to find and implement the best suitable
28+
algorithm.
29+
30+
What are the criteria of algorithm analysis?
31+
32+
An algorithm are generally analyzed on two factors − time and space. That is, how much
33+
execution time and how much extra space required by the algorithm.
34+
35+
What is asymptotic analysis of an algorithm?
36+
37+
Asymptotic analysis of an algorithm, refers to defining the mathematical boundation/framing of its
38+
run-time performance. Using asymptotic analysis, we can very well conclude the best case,
39+
average case and worst case scenario of an algorithm.
40+
41+
What are asymptotic notations?
42+
43+
Asymptotic analysis can provide three levels of mathematical binding of execution time of an
44+
algorithm −
45+
46+
Best case is represented by Ο n notation.
47+
Worst case is represented by Ω n notation.
48+
Average case is represented by Θ n notation.
49+
What is linear data strucutre?
50+
51+
A linear data-strucutre has sequentially arranged data items. The next time can be located in the
52+
next memory address. It is stored and accessed in a sequential manner. Array and list are example
53+
of linear data structure.
54+
55+
What are common operations that can be performed on a data-structure?
56+
57+
The following operations are commonly performed on any data-structure −
58+
59+
Insertion − adding a data item
60+
Deletion − removing a data item
61+
Traversal − accessing and/or printing all data items
62+
Searching − finding a particular data item
63+
Sorting − arranging data items in a pre-defined sequence
64+
Briefly explain the approaches to develop algorithms.
65+
66+
There are three commonly used approaches to develop algorithms −
67+
68+
Greedy Approach − finding solution by choosing next best option
69+
Divide and Conquer − diving the problem to a minimum possible sub-problem and solving
70+
them independently
71+
Dynamic Programming − diving the problem to a minimum possible sub-problem and
72+
solving them combinedly
73+
Give some examples greedy algorithms.
74+
75+
The below given problems find their solution using greedy algorithm approach −
76+
77+
Travelling Salesman Problem
78+
Prim's Minimal Spanning Tree Algorithm
79+
Kruskal's Minimal Spanning Tree Algorithm
80+
Dijkstra's Minimal Spanning Tree Algorithm
81+
Graph - Map Coloring
82+
Graph - Vertex Cover
83+
Knapsack Problem
84+
Job Scheduling Problem
85+
What are some examples of divide and conquer algorithms?
86+
87+
The below given problems find their solution using divide and conquer algorithm approach −
88+
89+
Merge Sort
90+
Quick Sort
91+
Binary Search
92+
Strassen's Matrix Multiplication
93+
Closest pair points
94+
What are some examples of dynamic programming algorithms?
95+
96+
The below given problems find their solution using divide and conquer algorithm approach −
97+
98+
Fibonacci number series
99+
Knapsack problem
100+
Tower of Hanoi
101+
All pair shortest path by Floyd-Warshall
102+
Shortest path by Dijkstra
103+
Project scheduling
104+
What is a linked-list?
105+
106+
A linked-list is a list of data-items connected with links i.e. pointers or references. Most modern
107+
108+
high-level programming language does not provide the feature of directly accessing memory
109+
location, therefore, linked-list are not supported in them or available in form of inbuilt functions.
110+
111+
What is stack?
112+
113+
In data-structure, stack is an Abstract Data Type ADT used to store and retrieve values in Last In
114+
First Out method.
115+
116+
Why do we use stacks?
117+
118+
Stacks follows LIFO method and addition and retrieval of a data item takes only Ο n time. Stacks are
119+
used where we need to access data in the reverse order or their arrival. Stacks are used
120+
commonly in recursive function calls, expression parsing, depth first traversal of graphs etc.
121+
122+
What operations can be performed on stacks?
123+
124+
The below operations can be performed on a stack −
125+
126+
push − adds an item to stack
127+
pop − removes the top stack item
128+
peek − gives value of top item without removing it
129+
isempty − checks if stack is empty
130+
isfull − checks if stack is full
131+
What is a queue in data-structure?
132+
133+
Queue is an abstract data structure, somewhat similar to stack. In contrast to stack, queue is
134+
opened at both end. One end is always used to insert data enqueue and the other is used to remove
135+
data dequeue. Queue follows First-In-First-Out methodology, i.e., the data item stored first will be
136+
accessed first.
137+
138+
Why do we use queues?
139+
140+
As queues follows FIFO method, they are used when we need to work on data-items in exact
141+
sequence of their arrival. Every operating system maintains queues of various processes. Priority
142+
queues and breadth first traversal of graphs are some examples of queues.
143+
144+
What operations can be performed on Queues?
145+
146+
The below operations can be performed on a stack −
147+
148+
enqueue − adds an item to rear of the queue
149+
dequeue − removes the item from front of the queue
150+
peek − gives value of front item without removing it
151+
isempty − checks if stack is empty
152+
isfull − checks if stack is full
153+
What is linear searching?
154+
155+
Linear search tries to find an item in a sequentially arranged data type. These sequentially
156+
arranged data items known as array or list, are accessible in incrementing memory location.
157+
Linear search compares expected data item with each of data items in list or array. The average
158+
159+
case time complexity of linear search is Ο n and worst case complexity is Ο(n^2 ). Data in target
160+
arrays/lists need not to be sorted.
161+
162+
What is binary search?
163+
164+
A binary search works only on sorted lists or arrays. This search selects the middle which splits the
165+
entire list into two parts. First the middle is compared.
166+
167+
This search first compares the target value to the mid of the list. If it is not found, then it takes
168+
decision on whether.
169+
170+
What is bubble sort and how bubble sort works?
171+
172+
Bubble sort is comparison based algorithm in which each pair of adjacent elements is compared
173+
174+
and elements are swapped if they are not in order. Because the time complexity is Ο(n^2 ), it is not
175+
suitable for large set of data.
176+
177+
Tell me something about 'insertion sort'?
178+
179+
Insertion sort divides the list into two sub-list, sorted and unsorted. It takes one element at time and
180+
finds it appropriate location in sorted sub-list and insert there. The output after insertion is a sorted
181+
sub-list. It iteratively works on all the elements of unsorted sub-list and inserts them to sorted sub-
182+
list in order.
183+
184+
What is selection sort?
185+
186+
Selection sort is in-place sorting technique. It divides the data set into two sub-lists: sorted and
187+
unsorted. Then it selects the minimum element from unsorted sub-list and places it into the sorted
188+
list. This iterates unless all the elements from unsorted sub-list are consumed into sorted sub-list.
189+
190+
How insertion sort and selection sorts are different?
191+
192+
Both sorting techniques maintains two sub-lists, sorted and unsorted and both take one element at
193+
a time and places it into sorted sub-list. Insertion sort works on the current element in hand and
194+
places it in the sorted array at appropriate location maintaining the properties of insertion sort.
195+
Whereas, selection sort searches the minimum from the unsorted sub-list and replaces it with the
196+
current element in hand.
197+
198+
What is merge sort and how it works?
199+
200+
Merge sort is sorting algorithm based on divide and conquer programming approach. It keeps on
201+
dividing the list into smaller sub-list until all sub-list has only 1 element. And then it merges them in
202+
a sorted way until all sub-lists are consumed. It has run-time complexity of Ο nlogn and it needs Ο n
203+
auxiliary space.
204+
205+
What is shell sort?
206+
207+
Shell sort can be said a variant of insertion sort. Shell sort divides the list into smaller sublist based
208+
on some gap variable and then each sub-list is sorted using insertion sort. In best cases, it can
209+
perform upto Ο nlogn.
210+
211+
How quick sort works?
212+
213+
Quick sort uses divide and conquer approach. It divides the list in smaller 'partitions' using 'pivot'.
214+
The values which are smaller than the pivot are arranged in the left partition and greater values
215+
are arranged in the right partition. Each partition is recursively sorted using quick sort.
216+
217+
What is a graph?
218+
219+
A graph is a pictorial representation of a set of objects where some pairs of objects are connected
220+
by links. The interconnected objects are represented by points termed as vertices, and the links
221+
that connect the vertices are called edges.
222+
223+
How depth first traversal works?
224+
225+
Depth First Search algorithm DFS traverses a graph in a depthward motion and uses a stack to
226+
remember to get the next vertex to start a search when a dead end occurs in any iteration.
227+
228+
How breadth first traversal works?
229+
230+
Breadth First Search algorithm BFS traverses a graph in a breadthwards motion and uses a queue
231+
to remember to get the next vertex to start a search when a dead end occurs in any iteration.
232+
233+
What is a tree?
234+
235+
A tree is a minimally connected graph having no loops and circuits.
236+
237+
What is a binary tree?
238+
239+
A binary tree has a special condition that each node can have two children at maximum.
240+
241+
What is a binary search tree?
242+
243+
A binary search tree is a binary tree with a special provision where a node's left child must have
244+
value less than its parent's value and node's right child must have value greater than it's parent
245+
value.
246+
247+
What is tree traversal?
248+
249+
Tree traversal is a process to visit all the nodes of a tree. Because, all nodes are connected via
250+
edges links we always start from the root head node. There are three ways which we use to traverse
251+
a tree −
252+
253+
In-order Traversal
254+
Pre-order Traversal
255+
Post-order Traversal
256+
See the below image of a binary search tree, and traverse it using all available methods −
257+
258+
In-order traversal − 10 14 19 27 31 35 42
259+
Pre-order traversal − 27 14 10 19 35 31 42
260+
Post-order traversal − 10 19 14 31 42 35 27
261+
What is an AVL Tree?
262+
263+
AVL trees are height balancing binary search tree. AVL tree checks the height of left and right sub-
264+
trees and assures that the difference is not more than 1. This difference is called Balance Factor.
265+
266+
BalanceFactor = height(left-sutree) − height(right-sutree)
267+
What is a spanning tree?
268+
269+
A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible
270+
number of edges. A spanning tree does not have cycles and it can not be disconnected.
271+
272+
How many spanning trees can a graph has?
273+
274+
It depends on how connected the graph is. A complete undirected graph can have maximum nn-
275+
number of spanning trees, where n is number of nodes.
276+
277+
How Kruskal's algorithm works?
278+
279+
This algorithm treats the graph as a forest and every node it as an individual tree. A tree connects
280+
to another only and only if it has least cost among all available options and does not violate MST
281+
properties.
282+
283+
How Prim's algorithm finds spanning tree?
284+
285+
Prim's algorithm treats the nodes as a single tree and keeps on adding new nodes to the spanning
286+
287+
tree from the given graph.
288+
289+
What is a minimum spanning tree MST?
290+
291+
In a weighted graph, a minimum spanning tree is a spanning tree that has minimum weight that all
292+
other spanning trees of the same graph.
293+
294+
What is a heap in data structure?
295+
296+
Heap is a special balanced binary tree data structure where root-node key is compared with its
297+
children and arranged accordingly. A min-heap, a parent node has key value less than its childs
298+
and a max-heap parent node has value greater than its childs.
299+
300+
What is a recursive function?
301+
302+
A recursive function is one which calls itself, directly or calls a function that in turn calls it. Every
303+
recursive function follows the recursive properties − base criteria where functions stops calling
304+
itself and progressive approach where the functions tries to meet the base criteria in each
305+
iteration.
306+
307+
What is tower of hanoi?
308+
309+
Tower of Hanoi, is a mathematical puzzle which consists of three tower pegs and more than one
310+
rings. All rings are of different size and stacked upon each other where the large disk is always
311+
below the small disk. The aim is to move the tower of disk from one peg to another, without
312+
breaking its properties.
313+
314+
What is fibonacci series?
315+
316+
Fibonacci Series generates subsequent number by adding two previous numbers. For example − 0
317+
1 1 2 3 5 8 13.
318+
319+
What is hashing?
320+
321+
Hashing is a technique to convert a range of key values into a range of indexes of an array. By
322+
using hash tables, we can create an associative data storage where data index can be find by
323+
providing its key values.
324+
325+
What is interpolation search technique?
326+
327+
Interpolation search is an improved variant of binary search. This search algorithm works on the
328+
probing position of required value.
329+
330+
What is the prefix and post fix notation of a + b * c + d?
331+
332+
Prefix Notation − * + a b + c d
333+
334+
Postfix Notation − a b + c d + *

0 commit comments

Comments
 (0)