Skip to content

Instantly share code, notes, and snippets.

View pbesra's full-sized avatar
🎯
Focusing

Prakash Besra pbesra

🎯
Focusing
View GitHub Profile
@pbesra
pbesra / System Design.md
Created June 30, 2022 19:10 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@pbesra
pbesra / countingSort.cpp
Last active March 29, 2020 19:09
Counting sort (cpp)
// programming language: C++
// Running time complexity: O(n+K), where K is the maximum element in the array
// Space complexity: O(n+K)
#include <iostream>
using namespace std;
void countingSort(int* a, int n){
// initial maximum value
int mx=a[0];
@pbesra
pbesra / AVLTree.cpp
Created February 3, 2020 20:13
AVL Tree
#include <iostream>
using namespace std;
class Node{
public:
int data;
Node* left;
Node* right;
int height;
Node(int data){
this->data=data;
@pbesra
pbesra / linkedlist.cpp
Created January 12, 2020 19:02
Linked list in C++
#include <iostream>
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
this->data=d;
this->next=NULL;
@pbesra
pbesra / heapSort.cpp
Created January 6, 2020 19:32
Heap sort
/*
max heap
*/
#include <iostream>
using namespace std;
int capacity=0;
int maxCapacity=64;
void maxHeapify(int* a, int k, int n){
int left=2*k+1;
int right=2*k+2;
@pbesra
pbesra / main.java
Last active December 24, 2019 18:05
Peak finding algorithm
// Algorithm
// Input: Array A[n], find a peak element in araray A. The peak element is
//not necessarily a global maxima
/*
For an element,Search(A, 0, A.length-1)
midElement=(start+end)/2
1. If (midElement==end && a[midElement]>=a[midElement-1]) || (midElement==0 && a[midElement]>=a[midElement+1]) || (A[midElement]>=A[midElement-1] && A[midElement]>=A[midElement+1])
----> return mid
2. else if(A[midElement-1]>A[midElement])
-----> Search left array Search(A, sstart, midElement-1)
@pbesra
pbesra / main.cpp
Created January 29, 2019 13:25
Segment Tree | C++ | Sum range in an array
#include <iostream>
#include <cmath>
using namespace std;
int getMid(int x, int y){
return((x+y)/2);
}
int segTreeUtil(int* a, int* s, int ss, int se, int c){
if(ss==se){
s[c]=a[ss];
//cout << "c: " << c << ", s[c]: " << s[c] << endl;
@pbesra
pbesra / infix_to_postfix_main.cpp
Last active January 17, 2019 11:24
Infix to Post expression | Postfix expression evaluation | C++
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
// precedence of each operator
bool precedence(char stack_top, char strin){
if(strin=='-'){
if(stack_top=='+' or stack_top=='*' or stack_top=='/' or stack_top=='^'){
return(true);
}
@pbesra
pbesra / main_diamond.cpp
Last active January 16, 2019 07:01
Diamond shape | C++
#include <iostream>
using namespace std;
void solution(int n){
// prints top triangle.
int m=2*n-1;
int t1=m/2;
int t2=m/2;
int t3=m/2;
int t4=m/2;
for(int i=0;i<n;i++){
@pbesra
pbesra / main.cpp
Last active January 14, 2019 18:57
Tree shape | Pascal triangle using asterisk | C++
#include <iostream>
using namespace std;
int main(){
int n=4;
cout << "enter n: " << endl;
cin >> n;
cout << "result: " << endl;
int start=n-1; // this where * starts in every row.
int t=0;
for(int i=0;i<n;i++){