Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
241 commits
Select commit Hold shift + click to select a range
3726e71
Add files via upload
komaljoshi252 Oct 2, 2021
cd90a43
Merge pull request #4 from komaljoshi252/main
drishyadamodaran Oct 2, 2021
0f242e0
Fix: Unstructured code
Ayushchaudhary-Github Oct 2, 2021
f419712
Merge pull request #5 from YushChaudhary/patch-1
drishyadamodaran Oct 2, 2021
87e889b
Create maxprofit.py
alen-kuriakose Oct 2, 2021
81e5acb
Create Find an Element in an array.py
Ayushchaudhary-Github Oct 2, 2021
616d0dd
Merge pull request #6 from alen-kuriakose/main
drishyadamodaran Oct 2, 2021
1ecf8b3
Merge pull request #7 from YushChaudhary/patch-2
drishyadamodaran Oct 2, 2021
cad7d60
Create Mergesort.cpp
Lokender10 Oct 2, 2021
d36abf8
Merge pull request #8 from Lokender10/patch-1
drishyadamodaran Oct 2, 2021
2ed4fe7
Create Quicksort.cpp
Lokender10 Oct 2, 2021
fcf83af
Merge pull request #10 from Lokender10/patch-3
drishyadamodaran Oct 2, 2021
444b6dd
Create Union of Two Sorted Arrays.cpp
04018002718 Oct 2, 2021
a18bc9a
Create SHUFFLIN.cpp
rahulsg98 Oct 2, 2021
d8c41ae
Merge pull request #11 from 04018002718/patch-1
drishyadamodaran Oct 2, 2021
85b869a
Merge pull request #12 from 0901IT201046/main
drishyadamodaran Oct 2, 2021
ca2675a
Create Tower Of Hanoi.cpp
mohit0204 Oct 2, 2021
2b3a87b
Create mergesort.py
uzzal623 Oct 2, 2021
17b8774
Median of 2 Sorted Arrays
dhruvgarg02 Oct 2, 2021
cd4061f
Radix Sort
PritamRane Oct 2, 2021
84bc8e6
Merge pull request #13 from mohit0204/patch-1
drishyadamodaran Oct 2, 2021
9aa0f63
Merge pull request #14 from uzzal623/main
drishyadamodaran Oct 2, 2021
2afb87b
Merge pull request #15 from PritamRane/main
drishyadamodaran Oct 2, 2021
885a712
Merge pull request #16 from dhruvgarg02/main
drishyadamodaran Oct 2, 2021
6385619
CPP selection sort
Oct 2, 2021
30c4bb5
Create FakeGCD.cpp
gb07bh Oct 2, 2021
f8951f0
Create FAKESWAP.py
gb07bh Oct 2, 2021
218d01a
Create README.md
drishyadamodaran Oct 2, 2021
89b34c9
Merge pull request #17 from jayeshjidge/main
drishyadamodaran Oct 2, 2021
87e1a70
added merge-sort in C language - iterative and recuursive
imsushant12 Oct 2, 2021
0228065
Added Matrix-Addition C Program
nithishrcta Oct 2, 2021
e25d87f
Create Split_Array_Largest_Sum.java
abhishekprasad2384 Oct 2, 2021
17c7f75
Merge pull request #20 from imsushant12/merge-sort-C
drishyadamodaran Oct 2, 2021
674ef0b
added Binary Tree to DLL problem (GFG) in JAVA
imsushant12 Oct 2, 2021
4508854
Merge pull request #19 from gb07bh/main
drishyadamodaran Oct 2, 2021
e6412af
Merge pull request #21 from nithishrcta/main
drishyadamodaran Oct 2, 2021
98816f4
Merge pull request #22 from abhishekprasad2384/main
drishyadamodaran Oct 2, 2021
31655a3
Merge pull request #23 from imsushant12/CP
drishyadamodaran Oct 2, 2021
54ac391
Binary Search
Oct 2, 2021
635492e
Update README.md
drishyadamodaran Oct 2, 2021
d6d2cbb
Create kth largest element in array.cpp
shweta-kansal Oct 2, 2021
8745a04
Merge pull request #24 from jayeshjidge/main
drishyadamodaran Oct 2, 2021
c091d35
Merge Sort in JavaScript
ayush-1909 Oct 2, 2021
f9b3f0e
Create Merge_Sort_Algo.java
Asuna-AS Oct 2, 2021
4a03153
Added Maximum Subarray Sum problem Solution in C++
rutuja206 Oct 2, 2021
ef2d9f5
Create Stock Buy And Sell to Maximize Profit in C++
rutuja206 Oct 2, 2021
422c4bd
Create Stock Buy Sell to Maximize Profit in C++
rutuja206 Oct 2, 2021
3d8fa9e
Added a question and solution in Company wise
Oct 2, 2021
cbdfa25
Create Bubble_sort.cpp
debachaks Oct 3, 2021
27385c5
BinarySearch
srishti1302 Oct 3, 2021
39be1bc
Update kth largest element in array.cpp
shweta-kansal Oct 3, 2021
382d292
New code kadane_algo.cpp
shadowfax999 Oct 3, 2021
ababbe3
Create Search an element in sorted and rotated array.cpp
mohit0204 Oct 3, 2021
053fb6b
Added Floyd Warshall Algorithm
atharvaka1996 Oct 3, 2021
599bd77
Merge pull request #34 from atharvaka1996/main
drishyadamodaran Oct 3, 2021
e5f87d5
Merge pull request #33 from mohit0204/patch-2
drishyadamodaran Oct 3, 2021
48b40ca
Merge pull request #25 from a-ayush19/main
drishyadamodaran Oct 3, 2021
fa584c1
Merge pull request #32 from shadowfax999/main
drishyadamodaran Oct 3, 2021
94511fb
Merge pull request #31 from shweta-kansal/main
drishyadamodaran Oct 3, 2021
d22fbd0
Merge pull request #30 from srishti1302/main
drishyadamodaran Oct 3, 2021
08eaa0b
Factorial_calculator.cpp
Saiyam7404 Oct 3, 2021
3d224d2
Reverse_a_number.cpp
Saiyam7404 Oct 3, 2021
ae12104
Merge pull request #26 from arunim-iiitlCS/main
drishyadamodaran Oct 3, 2021
2951362
Merge pull request #28 from ApoorvaKaushal09/AmazonQuestion
drishyadamodaran Oct 3, 2021
61c8819
Merge pull request #29 from debachaks/new
drishyadamodaran Oct 3, 2021
82b2aca
Merge pull request #35 from Saiyam7404/main
drishyadamodaran Oct 3, 2021
5cb3a45
Create generate_pattern.cpp
harsh2k2 Oct 3, 2021
5cbf604
Merge pull request #1 from harsh2k2/harsh2k2-patch-1
harsh2k2 Oct 3, 2021
40f4c56
merge sort implementation in c++
Richa-15 Oct 3, 2021
ad1fdc1
Create binary_search_Recursive.cpp
avk29 Oct 3, 2021
df95855
Create heap_sort.cpp
avk29 Oct 3, 2021
6fcfc4e
Create Deletion_in_Array.cpp
avk29 Oct 3, 2021
c070f8c
Create Linear_Search.cpp
avk29 Oct 3, 2021
30d7306
Create Merge_Two_Arrays.cpp
avk29 Oct 3, 2021
4346227
Create Reverse_Array.cpp
avk29 Oct 3, 2021
f0d3c83
Create insertion-sort.cpp
varsha080 Oct 3, 2021
c6955f1
Merge pull request #43 from varsha080/main
drishyadamodaran Oct 3, 2021
6e74b5d
Merge pull request #42 from avk29/patch-5
drishyadamodaran Oct 3, 2021
cae2873
Merge pull request #41 from avk29/patch-4
drishyadamodaran Oct 3, 2021
fdaf87e
Merge pull request #40 from avk29/patch-3
drishyadamodaran Oct 3, 2021
bff7a4b
Merge pull request #39 from avk29/patch-2
drishyadamodaran Oct 3, 2021
59d656e
Create RemoveDuplicatesFromaSortedLinkedList.cpp
mr-jay-250 Oct 3, 2021
fdd6ef7
Merge pull request #38 from avk29/patch-1
drishyadamodaran Oct 3, 2021
6b23c41
Merge pull request #37 from avk29/main
drishyadamodaran Oct 3, 2021
7be5b36
Merge pull request #44 from mr-jay-250/patch-1
drishyadamodaran Oct 3, 2021
066bf6f
Create Matrix Multiplication.c
pallavieee Oct 3, 2021
c08d403
Create Trie.cpp
morpheus521 Oct 3, 2021
3bc2d21
Added z function algorithm
mrd3847 Oct 3, 2021
c125848
Merge pull request #46 from morpheus521/main
drishyadamodaran Oct 3, 2021
ce43566
Merge pull request #47 from mrd3847/main
drishyadamodaran Oct 3, 2021
50bf044
feat:add nqueen problem
sooohka Oct 3, 2021
fad1a88
Create databse.cpp
abhishek213-alb Oct 3, 2021
8bb0a43
Adding remove_duplicates_in_sorted_array.cpp
VishalSehgal525 Oct 3, 2021
a945786
feat:add knight moves problem
sooohka Oct 3, 2021
2a62f79
feat:add knight moves problem
sooohka Oct 3, 2021
fba6c47
feat:add knight moves problem
sooohka Oct 3, 2021
9e9118f
Added autobiographical number
akarshan2602 Oct 3, 2021
a842405
Mergesort
srishti1302 Oct 3, 2021
2200ef3
moved merge sort program to Algorithms folder
Richa-15 Oct 3, 2021
47ac6d1
Create Longest_Harmonious_Subsequence.java
Vivekpusti Oct 3, 2021
0745cd2
Create Matrix multiplication.c
pallavieee Oct 3, 2021
8f49f13
Create Matrixmultiplication.c
pallavieee Oct 3, 2021
2d47ddc
added shellsort.cpp
Mayur2506 Oct 3, 2021
b67630b
Delete Matrix Multiplication.c
pallavieee Oct 3, 2021
2b0c2b8
Delete Matrixmultiplication.c
pallavieee Oct 3, 2021
a5cfb46
Added FindElementInArray.cs to C#
jhueppauff Oct 3, 2021
403ddc7
Competitive Code
swapnil-092 Oct 3, 2021
b2fa67d
Add files via upload
Atharvp18 Oct 3, 2021
54274a8
added
Dhruvil-Dave Oct 3, 2021
1c064e7
KMP_Algo.c
srishti1302 Oct 3, 2021
298021c
Merge pull request #61 from Dhruvil-Dave/main
drishyadamodaran Oct 3, 2021
a3ace33
Merge pull request #36 from Richa-15/main
drishyadamodaran Oct 3, 2021
b464646
Merge pull request #48 from sooohka/addproblem
drishyadamodaran Oct 3, 2021
c280b6e
Merge pull request #49 from abhishek213-alb/main
drishyadamodaran Oct 3, 2021
0abef38
Merge pull request #50 from VishalSehgal525/main
drishyadamodaran Oct 3, 2021
d943d4f
Merge pull request #51 from sooohka/addproblem1
drishyadamodaran Oct 3, 2021
0bfbcd8
Merge pull request #54 from Vivekpusti/main
drishyadamodaran Oct 3, 2021
ae4241c
Merge pull request #59 from Atharvp18/main
drishyadamodaran Oct 3, 2021
fd25a1d
Merge pull request #58 from swapnil-092/main
drishyadamodaran Oct 3, 2021
38d1e96
Merge pull request #57 from jhueppauff/patch-1
drishyadamodaran Oct 3, 2021
3dad486
Merge pull request #56 from pallavieee/main
drishyadamodaran Oct 3, 2021
6d2adc1
Merge pull request #55 from Mayur2506/main
drishyadamodaran Oct 3, 2021
936733f
Maximum Subarray Sum
rutuja206 Oct 3, 2021
36cc745
BuyStockAndSell
rutuja206 Oct 3, 2021
4e891af
Delete Maximum Subarray Sum
rutuja206 Oct 3, 2021
3de0bd5
Delete Stock Buy And Sell to Maximize Profit in C++
rutuja206 Oct 3, 2021
78b8595
Delete Stock Buy Sell to Maximize Profit in C++
rutuja206 Oct 3, 2021
895d85c
Merge pull request #27 from rutuja206/main
drishyadamodaran Oct 3, 2021
980b754
Programs Added
LalitKumar-2001 Oct 3, 2021
8b2914f
Create inverted_pattern.cpp
Oct 3, 2021
2d306cd
Create Move all zeroes to end
rutuja206 Oct 3, 2021
5d0c74f
Create MajorityElementInarray
rutuja206 Oct 3, 2021
0b01be5
Print subsets of given array
ALCHEMAX42 Oct 3, 2021
b0483f6
Update-2
ALCHEMAX42 Oct 3, 2021
5ab0882
Create GCDalgo.java
sktagrwl Oct 3, 2021
e579956
Added MaxAndSecondMax.java
OnkarSathe Oct 3, 2021
9369a66
Merge pull request #60 from OnkarSathe/main
drishyadamodaran Oct 3, 2021
39c64a2
added question for check bst in amazon section
ravi4713 Oct 4, 2021
1a57c62
Create Merge sort.c
pallavieee Oct 4, 2021
4562449
Create circular queue.c
pallavieee Oct 4, 2021
d730638
Create Insertion_sort.cpp
Lokender10 Oct 4, 2021
59154bd
lexicographically minimum rotation of a string
srishti1302 Oct 4, 2021
1c36543
Delete c_cpp_properties.json
akarshan2602 Oct 4, 2021
bfc397d
deshaw_company_question
pandapritish25 Oct 4, 2021
8bda511
move to company wise solution
pandapritish25 Oct 4, 2021
af3d235
Create Brian Kernighan’s Algorithm.py
AviratGupta Oct 4, 2021
a457063
Kindergarten_Adventures Hackerrank Solutionin C++
Oct 4, 2021
48e51e5
Create longest_rep_sub_sequence.java
Anisha100 Oct 4, 2021
3909913
Create 0001spiral_traversal_2d.java
Anisha100 Oct 4, 2021
926765f
Add files via upload
prajnakalpa Oct 4, 2021
398fde8
Add files via upload
prajnakalpa Oct 4, 2021
6d8338e
Added Solution to Arrays Left Rotation
Dhruvil-Dave Oct 4, 2021
d84c558
Added Priority Queue in Java
Dil-key Oct 4, 2021
c2c9d86
Merge pull request #81 from Dil-key/dilkiLakshani
drishyadamodaran Oct 4, 2021
1ea7225
Merge pull request #80 from Dhruvil-Dave/main
drishyadamodaran Oct 4, 2021
579564e
Merge pull request #79 from prajnakalpa/main
drishyadamodaran Oct 4, 2021
57d7e39
Merge pull request #78 from Anisha100/patch-2
drishyadamodaran Oct 4, 2021
924cae1
Merge pull request #77 from Anisha100/patch-1
drishyadamodaran Oct 4, 2021
b281d71
Merge pull request #76 from Shivaminc/Kindergarten_Adventures
drishyadamodaran Oct 4, 2021
e75fba9
Create Count set bits in a integer.cpp
pchat99 Oct 4, 2021
a2c7677
Merge pull request #52 from srishti1302/main
drishyadamodaran Oct 4, 2021
6bbe33b
Delete KMP_Algo.c
drishyadamodaran Oct 4, 2021
16c1af7
Revert "Mergesort"
drishyadamodaran Oct 4, 2021
6878615
Merge pull request #75 from AviratGupta/main
drishyadamodaran Oct 4, 2021
226b5ad
Merge pull request #53 from akarshan2602/hacktober
drishyadamodaran Oct 4, 2021
47cd6c9
Merge pull request #62 from harsh2k2/generate_pattern
drishyadamodaran Oct 4, 2021
e3abeb7
Merge pull request #74 from pandapritish25/main
drishyadamodaran Oct 4, 2021
109ffe6
Merge pull request #72 from Lokender10/patch-5
drishyadamodaran Oct 4, 2021
d030bb2
Merge pull request #63 from LalitKumar-2001/main
drishyadamodaran Oct 4, 2021
b4b67c1
Added some Bit Manipulation problems
pchat99 Oct 4, 2021
2a81e08
Permutation Minimization by Deque
Sagnikban Oct 4, 2021
0341942
Merge pull request #70 from pallavieee/main
drishyadamodaran Oct 4, 2021
4935836
Committing KadanesAlgo.java
vanditkhurana Oct 4, 2021
cc18238
Update 2unique_numbers.cpp
pchat99 Oct 4, 2021
c57adb0
Update 3unique_numbers.cpp
pchat99 Oct 4, 2021
5bbf7c8
Update Count set bits in a integer.cpp
pchat99 Oct 4, 2021
f247e61
Update copy_set_bits_in_range.cpp
pchat99 Oct 4, 2021
7a96480
Add Symmetric Tree Question
anu106 Oct 4, 2021
db5774f
Update count_setbits_from_1_to_n.cpp
pchat99 Oct 4, 2021
8297ca3
Update divide_integer_by_2.cpp
pchat99 Oct 4, 2021
d97a718
Update numbers_bits_to_be_flipped.cpp
pchat99 Oct 4, 2021
e508d0f
Merge pull request #65 from rutuja206/main
drishyadamodaran Oct 4, 2021
29362bc
Merge pull request #86 from anu106/main
drishyadamodaran Oct 4, 2021
3d31aa1
Merge pull request #85 from vanditkhurana/patch-1
drishyadamodaran Oct 4, 2021
6158bb7
Merge pull request #84 from Sagnikban/branch
drishyadamodaran Oct 4, 2021
387de4c
Merge pull request #66 from ALCHEMAX42/main
drishyadamodaran Oct 4, 2021
2632721
Merge pull request #67 from sktagrwl/main
drishyadamodaran Oct 4, 2021
62bba54
Merge pull request #68 from ravi4713/main
drishyadamodaran Oct 4, 2021
78ce187
Merge pull request #83 from pchat99/main
drishyadamodaran Oct 4, 2021
f7b50e8
Merge pull request #87 from OnkarSathe/main
drishyadamodaran Oct 4, 2021
437ce3a
Create Print all Codes - String(C++))
SamyakJainnnn Oct 4, 2021
28a7e2c
Created program for coin change problem
MrLakshay Oct 4, 2021
428d9b5
Merge pull request #88 from MrLakshay/patch-1
drishyadamodaran Oct 4, 2021
e56440f
Merge pull request #89 from SamyakJainnnn/main
drishyadamodaran Oct 4, 2021
a6e80bf
Move the elements.cpp
Sonu589 Oct 4, 2021
c98461c
Merge pull request #91 from Sonu589/patch-1
drishyadamodaran Oct 4, 2021
0b11dab
BRESENHAM LINE DRAWING ALGORITHM
ABHIGPT401 Oct 4, 2021
adffaed
Create Subarray With 0 sum
rutuja206 Oct 4, 2021
b07537f
Merge pull request #93 from rutuja206/main
drishyadamodaran Oct 4, 2021
6d2e132
Merge pull request #92 from ABHIGPT401/main
drishyadamodaran Oct 4, 2021
5852928
Create Find_middle_of_a_linkedlist.cpp
arjun-rai912 Oct 4, 2021
ff3e62f
Add files via upload
onewaynoo Oct 4, 2021
11f930a
Create triplet sum to a given value
rutuja206 Oct 4, 2021
27be2a1
Adding java program to find maximum contiguous sum
hitesh181 Oct 4, 2021
bdb2e0c
Merge pull request #96 from rutuja206/main
drishyadamodaran Oct 4, 2021
f67d65c
Merge pull request #94 from arjun-rai912/main
drishyadamodaran Oct 4, 2021
c85f9b6
Merge pull request #82 from drishyadamodaran/revert-52-main
drishyadamodaran Oct 4, 2021
f896864
Merge pull request #95 from onewaynoo/main
drishyadamodaran Oct 4, 2021
4b28660
added equilibrium.java
OnkarSathe Oct 4, 2021
71f6f12
Merge branch 'drishyadamodaran:main' into main
OnkarSathe Oct 4, 2021
a515318
add some programs
Danushan99 Oct 5, 2021
b0fb026
Moved to Folder
hitesh181 Oct 5, 2021
2677452
Moved to Solutions folder
hitesh181 Oct 5, 2021
a503e42
Rename Question.txt to Maximum Contiguous sum.txt
hitesh181 Oct 5, 2021
e13d9b5
Create Quick_sort.cpp
Lokender10 Oct 5, 2021
8eb9ee2
Add Codeforces 1560B
anu106 Oct 5, 2021
d93d948
added question asked in amazon
onewaynoo Oct 5, 2021
e0b0e68
Create LazySegmentedTree.cpp
VanshikaSingh10 Oct 5, 2021
04ed14f
Create FractionalKnapsack.cpp
VanshikaSingh10 Oct 5, 2021
accc7b6
Create Twins.cpp
danish-p7 Oct 5, 2021
a5f1428
Merge pull request #104 from danish-p7/main
drishyadamodaran Oct 5, 2021
c7326f7
Merge pull request #98 from Danushan99/main
drishyadamodaran Oct 5, 2021
5a3bd11
Merge pull request #99 from Lokender10/patch-2
drishyadamodaran Oct 5, 2021
4a00cca
Merge pull request #102 from VanshikaSingh10/main
drishyadamodaran Oct 5, 2021
7414fb9
Merge pull request #100 from anu106/main
drishyadamodaran Oct 5, 2021
820015d
Merge pull request #101 from onewaynoo/main
drishyadamodaran Oct 5, 2021
cd2276c
Create Vanya and Lanterns.cpp
danish-p7 Oct 5, 2021
bdebe1c
added min steps to 1 using DP
HemangPaliwal Oct 5, 2021
21dccd1
Added solution
Dhruvil-Dave Oct 5, 2021
ad57fd2
Solution of Coin change problem using dp
samriddhiambashta Oct 5, 2021
d523ad6
Merge pull request #105 from danish-p7/main
drishyadamodaran Oct 5, 2021
fe505b3
Merge pull request #108 from samriddhiambashta/main
drishyadamodaran Oct 5, 2021
fbc90ef
Merge pull request #107 from Dhruvil-Dave/main
drishyadamodaran Oct 5, 2021
3895b6d
Merge pull request #106 from HemangPaliwal/main
drishyadamodaran Oct 5, 2021
791ceca
Rename CompanywiseSolution/Morgan Stanley/Questions/Maximum Contiguou…
hitesh181 Oct 5, 2021
bd679fb
Rename CompanywiseSolution/Morgan Stanley/Solutions/Maximum Contiguou…
hitesh181 Oct 5, 2021
637e46e
Rename CompanywiseSolution/Morgan Stanley/Max contiguous sum/Question…
hitesh181 Oct 5, 2021
6020669
Rename CompanywiseSolution/Morgan Stanley/Maximum contiguous sum/Ques…
hitesh181 Oct 5, 2021
d6f74b2
Merge branch 'drishyadamodaran:main' into main
hitesh181 Oct 5, 2021
633ff0d
Moved max contigous sum and added lower case program
hitesh181 Oct 5, 2021
60566e7
Moved max contigous sum and added lower case program
hitesh181 Oct 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
45 changes: 45 additions & 0 deletions Algorithms/BinarySearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//srishti1302
#include <stdio.h>
#define COMPARE(x,y) ( (x)<(y)?-1:(x)==(y)? 0 :1 )
int binsearch(int a[20],int k,int left,int right)
{

if(left<right)
{
int middle=(left+right)/2;
switch(COMPARE(a[middle],k))
{
case -1: return binsearch(a,k,middle+1,right);
break;

case 0: return middle;
break;

case 1: return binsearch(a,k,left,middle-1);
break;
}
}
return -1;
}
int main()
{
int n,a[20],k,res;
printf("Enter size of the array: ");
scanf("%d",&n);
printf("\nEnter the array elements:\n");
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter the number to be searched:\n");
scanf("%d",&k);

res=binsearch(a,k,0,n-1);
if(res==-1)
printf("Element not found!!");
else
printf("\nThe number %d is found at positon %d in the given list",k,res+1);

return 0;
}



12 changes: 12 additions & 0 deletions Algorithms/Brian Kernighan’s Algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def countSetBits(n):

count = 0
while (n):
n &= (n-1)
count+= 1
return count


# Program to test function countSetBits
i = 9
print(countSetBits(i)
32 changes: 32 additions & 0 deletions Algorithms/Bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<iostream>
using namespace std;

//Bubble sort : swap two elements walaa technique

int main(){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}

int counter = 1;
while(counter<n){
for(int i=0;i<n-counter;i++){
if(arr[i]>arr[i+1]){
if(arr[i]>arr[i+1]){
int temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}

}
}
counter++;
}
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}

}
71 changes: 71 additions & 0 deletions Algorithms/CreateHeap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <iostream>
#include <vector>

using namespace std;

void Insert(vector<int>& vec, int key){
// Insert key at the end
auto i = vec.size();
vec.emplace_back(key);

// Rearrange elements: O(log n)
while (i > 0 && key > vec[i % 2 == 0 ? (i/2)-1 : i/2]){
vec[i] = vec[i % 2 == 0 ? (i/2)-1 : i/2];
i = i % 2 == 0 ? (i/2)-1 : i/2;
}
vec[i] = key;
}

void InsertInplace(int A[], int n){
int i = n;
int temp = A[n];
while (i > 0 && temp > A[i % 2 == 0 ? (i/2)-1 : i/2]){
A[i] = A[i % 2 == 0 ? (i/2)-1 : i/2];
i = i % 2 == 0 ? (i/2)-1 : i/2;
}
A[i] = temp;
}

void CreateHeap(vector<int>& vec, int A[], int n){
// O(n log n)
for (int i=0; i<n; i++){
Insert(vec, A[i]);
}
}

void createHeap(int A[], int n){
for (int i=0; i<n; i++){
InsertInplace(A, i);
}
}

template <class T>
void Print(T& vec, int n, char c){
cout << c << ": [" << flush;
for (int i=0; i<n; i++){
cout << vec[i] << flush;
if (i < n-1){
cout << ", " << flush;
}
}
cout << "]" << endl;
}


int main() {

cout << "Create Heap" << endl;
int b[] = {10, 20, 30, 25, 5, 40, 35};
Print(b, sizeof(b)/sizeof(b[0]), 'b');

vector<int> v;
CreateHeap(v, b, sizeof(b)/sizeof(b[0]));
Print(v, v.size(), 'v');

cout << "Inplace Insert" << endl;
createHeap(b, sizeof(b)/sizeof(b[0]));
Print(b, sizeof(b)/sizeof(b[0]), 'b');


return 0;
}
36 changes: 36 additions & 0 deletions Algorithms/Deletion_in_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
using namespace std;

void display(int A[],int n){
for(int i=0; i<n; i++)
cout << A[i] << " ";
}

void arr_delete(int A[], int index, int length){

for(int i= index; i<length; i++){
A[i] = A[i+1];
}
}

int main(){

int n,m;
cout<<"Enter size of the array: ";
cin>>n;
cout<<"Enter length of the array: ";
cin>>m;
int A[n];

for(int i=0; i<m; i++){
cin>>A[i];
}

//Example function call to delete 2nd element
arr_delete(A,2,m);

display(A,m-1);

return 0;

}
74 changes: 74 additions & 0 deletions Algorithms/Diagnolmatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include<iostream>
using namespace std;

class Diagnol
{
private:
int *A;
int n;
public:
Diagnol()
{
n=2;
A=new int[2];
}
Diagnol(int n)
{
this->n=n;
A=new int[n];
}
~Diagnol()
{
delete []A;
}
void Set(int i, int j,int x);
int Get(int i, int j);
void Display();
};

void Diagnol::Set(int i, int j,int x)
{
if(i==j)
A[i-1]=x;
}

int Diagnol::Get(int i, int j)
{
if(i==j)
return A[i-1];
else
return 0;
}

void Diagnol::Display()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if(i==j)
cout<<A[i]<<" ";
else
{
cout<<"0 ";
}

}
cout<<endl;

}

}


int main()
{
Diagnol d(4);
d.Set(1,1,5);
d.Set(2,2,8);
d.Set(3,3,9);
d.Set(4,4,12);

d.Display();
return 0;
}
45 changes: 45 additions & 0 deletions Algorithms/Find_middle_of_a_linkedlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<iostream>
using namespace std;
class node{
public:
int data;
node *next;//yaha address store karvana tha toh aysy likha
node(int data){
this->data=data;
next=NULL;
}
};
node *middlenode(node *head){
node *slow=head;
node *fast=head->next;
while(fast && fast->next){
slow=slow->next;
fast=fast->next->next;
}
if(fast!=NULL){
return slow->next;
}
return slow;
}

int main(){
node n1(81);
node n2(27);
node n3(56);
node *head=&n1;// this head is storing the address of first link list component so that we can access the whole link list through this
n1.next=&n2;
n2.next=&n3;// this is storing address jaha pehle null stored tha

cout<<"the middle element is "<<middlenode(head)->data;


return 0;


}





//The running time of finding the middle element this way with two pointers is O(n) because once we pass through the entire linked list of n elements, the slower pointer is at the middle node already.
63 changes: 63 additions & 0 deletions Algorithms/Floyd_Warshall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//Problem Statement
//The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem.
//The problem is to find shortest distances between every pair of vertices in a given edge weighted directed Graph.
//Time Complexity: O(V^3)

#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> floyd_warshall(vector<vector<int>> graph) {
vector<vector<int>> dist(graph);

int V = graph.size();

// Iterate over all phases 1,2,....,V
for(int k=0;k<V;k++) {

//Iterate over the 2-D matrix
for(int i=0;i<V;i++) {
for(int j=0;j<V;j++) {

// If vertex k is on the shortest path from
// i to j, then update the value of dist[i][j]
if(dist[i][k]!=INT_MAX && dist[k][j]!=INT_MAX) {
if(dist[i][j] > dist[i][k] + dist[k][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}

//Check for negative edge cycle
for(int i=0;i<V;i++) {
if(dist[i][i] < 0) {
cout<<"Negative edge cycle detected\n";
break;
}
}

return dist;

}

int main() {
vector<vector<int>> graph = {
{0,INT_MAX,-2,INT_MAX},
{4,0,3,INT_MAX},
{INT_MAX,INT_MAX,0,2},
{INT_MAX,-1,INT_MAX,0}
};

auto it = floyd_warshall(graph);

//The shortest path from ith node to jth node
for(int i=0;i<it.size();i++) {
for(int j=0;j<it.size();j++) {
cout<<it[i][j]<<" ";
}
cout<<endl;
}

return 0;
}
Loading