├── ES6 ├── build │ ├── bundle.js │ ├── style.css │ └── index.html ├── app │ ├── exampleModule.js │ └── es6.js ├── webpack.config.js ├── README.md └── package.json ├── python ├── DjangoTutorial │ ├── blog │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ ├── forms.py │ │ ├── templates │ │ │ └── blog │ │ │ │ ├── post_edit.html │ │ │ │ ├── post_list.html │ │ │ │ ├── post_detail.html │ │ │ │ └── base.html │ │ ├── urls.py │ │ ├── models.py │ │ ├── static │ │ │ └── css │ │ │ │ └── blog.css │ │ └── views.py │ ├── DjangoTutorial │ │ ├── __init__.py │ │ ├── wsgi.py │ │ ├── urls.py │ │ └── settings.py │ ├── db.sqlite3 │ └── manage.py ├── DataStructures │ ├── AVLTrees │ │ ├── App.py │ │ ├── Node.py │ │ └── BalancedTree.py │ ├── Heaps │ │ ├── App.py │ │ └── Heap.py │ ├── TernarySearchTrees │ │ ├── App.py │ │ ├── Node.py │ │ └── TST.py │ ├── Stacks │ │ ├── App.py │ │ └── Stack.py │ ├── Queues │ │ ├── App.py │ │ └── Queue.py │ ├── LinkedLists │ │ ├── App.py │ │ ├── Node.py │ │ └── LinkedList.py │ └── BinarySearchTrees │ │ ├── App.py │ │ ├── BinarySearchTree.py │ │ └── Node.py ├── GraphAlgorithms │ ├── BreadthFirstSearch │ │ ├── Node.py │ │ ├── App.py │ │ └── BFS.py │ ├── DepthFirstSearch │ │ ├── Node.py │ │ ├── DFS.py │ │ └── App.py │ ├── Kruskal │ │ ├── Vertex.py │ │ ├── Node.py │ │ ├── Edge.py │ │ ├── App.py │ │ ├── Algorithm.py │ │ └── DisjointSet.py │ ├── BellmanFord │ │ ├── Edge.py │ │ ├── Vertex.py │ │ ├── Algorithm.py │ │ └── App.py │ ├── Dijkstra │ │ ├── Edge.py │ │ ├── Vertex.py │ │ ├── Algorithm.py │ │ └── App.py │ └── Prims │ │ ├── Vertex.py │ │ ├── Edge.py │ │ ├── App.py │ │ └── Algorithm.py ├── SearchAlgorithms │ ├── HashTable │ │ ├── App.py │ │ └── HashTable.py │ ├── BinarySearch │ │ └── BinarySearch.py │ └── SequentialSearch │ │ └── Sequential.py ├── SortingAlgorithms │ ├── BubbleSort │ │ └── BubbleSort.py │ ├── SelectionSort │ │ └── SelectionSort.py │ ├── InsertionSort │ │ └── InsertionSort.py │ ├── MergeSort │ │ └── MergeSort.py │ ├── QuickSort │ │ └── QuickSort.py │ └── ShellSort │ │ └── ShellSort.py └── DataAnalysis │ └── numpy │ └── NumPy.ipynb ├── Rust ├── helloWorld.rs └── rust.rs ├── PHP ├── 1_helloWorld.php ├── 7_sendingEmail.php ├── 5_whileLoops.php ├── 8_getMethodToSendData.php ├── 4_ifStatements.php ├── 6_forAndForEachLoops.php ├── 2_variables.php └── 3_arrays.php ├── java ├── DataStructures │ ├── BinarySearchTree │ │ ├── Node.java │ │ └── BST.java │ ├── LinkedList │ │ ├── Node.java │ │ └── LinkedList.java │ ├── Stack │ │ └── Mystack.java │ ├── Heap │ │ └── Heap.java │ └── Queue │ │ └── Myqueue.java ├── JavaTutorial │ ├── java.iml │ └── src │ │ ├── Variable.java │ │ ├── HelloWorld.java │ │ └── ControlStatements.java ├── GraphAlgorithms │ ├── topological_sort │ │ ├── Main.java │ │ └── Graph.java │ ├── BreadthFirstSearch │ │ ├── BreadthFirstSearch.iml │ │ └── src │ │ │ ├── App.java │ │ │ ├── BFS.java │ │ │ └── Vertex.java │ └── DepthFirstSearch │ │ ├── DepthFirstSearch.iml │ │ └── src │ │ ├── App.java │ │ ├── DFS.java │ │ └── Vertex.java └── SortingAlgorithm │ ├── SelectionSort.java │ ├── InertionSort.java │ └── CountingSort.java ├── .gitignore ├── C ├── iii_if-elseif-else.c ├── i_helloWorld.c ├── v_while_dowhile.c ├── ii_variables.c ├── iv_loop_switch.c └── vi_function.c ├── LICENSE └── README.md /ES6/build/bundle.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/DjangoTutorial/DjangoTutorial/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Rust/helloWorld.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello World!"); 3 | } -------------------------------------------------------------------------------- /PHP/1_helloWorld.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /python/DjangoTutorial/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pranavj1001/LearnLanguages/HEAD/python/DjangoTutorial/db.sqlite3 -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BlogConfig(AppConfig): 5 | name = 'blog' 6 | -------------------------------------------------------------------------------- /ES6/build/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 5rem; 3 | } 4 | .starter-template { 5 | padding: 3rem 1.5rem; 6 | text-align: center; 7 | } 8 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Post 3 | 4 | # Register your models here. 5 | admin.site.register(Post) 6 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from .models import Post 3 | 4 | class PostForm(forms.ModelForm): 5 | 6 | class Meta: 7 | model = Post 8 | fields = ('title', 'text',) -------------------------------------------------------------------------------- /java/DataStructures/BinarySearchTree/Node.java: -------------------------------------------------------------------------------- 1 | package BinarySearchTree; 2 | class Node{ 3 | int data; 4 | Node left; 5 | Node right; 6 | Node(int d){ 7 | data=d; 8 | left=null; 9 | right=null; 10 | } 11 | } -------------------------------------------------------------------------------- /python/DataStructures/AVLTrees/App.py: -------------------------------------------------------------------------------- 1 | from BalancedTree import BalancedTree 2 | 3 | tree = BalancedTree() 4 | 5 | tree.insert(4) 6 | tree.insert(6) 7 | tree.insert(5) 8 | tree.insert(4) 9 | 10 | tree.tarverseInOrder() -------------------------------------------------------------------------------- /python/GraphAlgorithms/BreadthFirstSearch/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | def __init__(self, name): 5 | self.name = name 6 | self.neighbourList = [] 7 | self.visited = False -------------------------------------------------------------------------------- /python/GraphAlgorithms/DepthFirstSearch/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | def __init__(self, name): 5 | self.name = name 6 | self.neighbourList = [] 7 | self.visited = False -------------------------------------------------------------------------------- /java/DataStructures/LinkedList/Node.java: -------------------------------------------------------------------------------- 1 | package LinkedList; 2 | class Node{ 3 | int data; 4 | Node next; 5 | Node(){ 6 | data=0; 7 | next=null; 8 | } 9 | Node(int d){ 10 | data=d; 11 | next=null; 12 | } 13 | } -------------------------------------------------------------------------------- /python/GraphAlgorithms/Kruskal/Vertex.py: -------------------------------------------------------------------------------- 1 | class Vertex(object): 2 | 3 | # constructor 4 | # provides the basic structure of the vertex 5 | def __init__(self, name): 6 | self.name = name 7 | self.node = None 8 | -------------------------------------------------------------------------------- /python/DataStructures/Heaps/App.py: -------------------------------------------------------------------------------- 1 | from Heap import Heap 2 | 3 | newHeap = Heap() 4 | 5 | newHeap.insert(12) 6 | newHeap.insert(-3) 7 | newHeap.insert(23) 8 | newHeap.insert(4) 9 | newHeap.insert(100) 10 | 11 | newHeap.displayHeap() 12 | -------------------------------------------------------------------------------- /python/DataStructures/TernarySearchTrees/App.py: -------------------------------------------------------------------------------- 1 | from TST import TST 2 | 3 | newTree = TST() 4 | 5 | newTree.put("dovah", 2131) 6 | newTree.put("pranav", 904) 7 | newTree.put("yolo", 12) 8 | newTree.put("geralt", 901) 9 | 10 | print(newTree.get("pranav")) -------------------------------------------------------------------------------- /python/GraphAlgorithms/DepthFirstSearch/DFS.py: -------------------------------------------------------------------------------- 1 | def dfs(node): 2 | 3 | node.visited = True 4 | print("%s -> " % node.name) 5 | 6 | # use recursion to traverse through the nodes 7 | for i in node.neighbourList: 8 | if not i.visited: 9 | dfs(i) -------------------------------------------------------------------------------- /python/GraphAlgorithms/Kruskal/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | # provides the basic structure of the node 5 | def __init__(self, height, nodeID, parentNode): 6 | self.height = height 7 | self.nodeID = nodeID 8 | self.parentNode = parentNode -------------------------------------------------------------------------------- /python/GraphAlgorithms/BellmanFord/Edge.py: -------------------------------------------------------------------------------- 1 | class Edge(object): 2 | 3 | # constructor 4 | # provides the basic structure of the edge 5 | def __init__(self, weight, startVertex, targetVertex): 6 | self.weight = weight 7 | self.startVertex = startVertex 8 | self.targetVertex = targetVertex -------------------------------------------------------------------------------- /python/GraphAlgorithms/Dijkstra/Edge.py: -------------------------------------------------------------------------------- 1 | class Edge(object): 2 | 3 | # constructor 4 | # provides the basic structure of the edge 5 | def __init__(self, weight, startVertex, targetVertex): 6 | self.weight = weight 7 | self.startVertex = startVertex 8 | self.targetVertex = targetVertex -------------------------------------------------------------------------------- /python/GraphAlgorithms/Prims/Vertex.py: -------------------------------------------------------------------------------- 1 | class Vertex(object): 2 | 3 | # constructor 4 | # provides the basic structure of the vertex 5 | def __init__(self, name): 6 | self.name = name 7 | self.visited = False 8 | self.predecessor = None 9 | self.neighbourList = [] 10 | -------------------------------------------------------------------------------- /python/DataStructures/TernarySearchTrees/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | # the basic structure of the node of a TST 5 | def __init__(self, char): 6 | self.char = char 7 | self.leftNode = None 8 | self.middleNode = None 9 | self.rightNode = None 10 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/templates/blog/post_edit.html: -------------------------------------------------------------------------------- 1 | {% extends 'blog/base.html' %} 2 | 3 | {% block content %} 4 |

New post

5 |
{% csrf_token %} 6 | {{ form.as_p }} 7 | 8 |
9 | {% endblock %} -------------------------------------------------------------------------------- /python/SearchAlgorithms/HashTable/App.py: -------------------------------------------------------------------------------- 1 | from HashTable import HashTable 2 | 3 | newHashTable = HashTable(10) 4 | 5 | newHashTable.insert(78, 'Dovah') 6 | newHashTable.insert(8, 'Geralt') 7 | newHashTable.insert(9, 'Snake') 8 | newHashTable.insert(91, 'Quiet') 9 | newHashTable.insert(8, 'Viper') 10 | 11 | print(newHashTable.get(8)) 12 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from . import views 3 | 4 | urlpatterns = [ 5 | url(r'^$', views.post_list, name='post_list'), 6 | url(r'^post/(?P\d+)/$', views.post_detail, name='post_detail'), 7 | url(r'^post/new/$', views.post_new, name='post_new'), 8 | url(r'^post/(?P\d+)/edit/$', views.post_edit, name='post_edit'), 9 | ] -------------------------------------------------------------------------------- /PHP/7_sendingEmail.php: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /ES6/app/exampleModule.js: -------------------------------------------------------------------------------- 1 | const carCompanies = ['bmw', 'audi', 'toyota']; 2 | let carModels = ['x5 2017', 'a8', 'supra']; 3 | let divide = (number1, number2) =>{ 4 | return number1/number2; 5 | } 6 | export {carCompanies, carModels, divide}; 7 | export default divide;//syntax to declare a default method 8 | 9 | class Circle { 10 | constructor(radius){ 11 | this.radius = radius; 12 | } 13 | } 14 | 15 | export {Circle}; 16 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/Dijkstra/Vertex.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Vertex(object): 4 | 5 | # constructor 6 | # provides the basic structure of the vertex 7 | def __init__(self, name): 8 | self.name = name 9 | self.predecessor = None 10 | self.neighbourList = [] 11 | # initially minDistance = the largest positive integer supported by the platform’s Py_ssize_t type 12 | self.minDistance = sys.maxsize -------------------------------------------------------------------------------- /python/GraphAlgorithms/BellmanFord/Vertex.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class Vertex(object): 4 | 5 | # constructor 6 | # provides the basic structure of the vertex 7 | def __init__(self, name): 8 | self.name = name 9 | self.predecessor = None 10 | self.neighbourList = [] 11 | # initially minDistance = the largest positive integer supported by the platform’s Py_ssize_t type 12 | self.minDistance = sys.maxsize -------------------------------------------------------------------------------- /python/GraphAlgorithms/BreadthFirstSearch/App.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | from BFS import bfs 3 | 4 | node1 = Node("A") 5 | node2 = Node("B") 6 | node3 = Node("C") 7 | node4 = Node("D") 8 | node5 = Node("E") 9 | node6 = Node("F") 10 | 11 | node1.neighbourList.append(node2) 12 | node1.neighbourList.append(node3) 13 | node2.neighbourList.append(node4) 14 | node2.neighbourList.append(node5) 15 | node3.neighbourList.append(node6) 16 | 17 | bfs(node1) 18 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/DepthFirstSearch/App.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | from DFS import dfs 3 | 4 | node1 = Node("A") 5 | node2 = Node("B") 6 | node3 = Node("C") 7 | node4 = Node("D") 8 | node5 = Node("E") 9 | node6 = Node("F") 10 | 11 | node1.neighbourList.append(node2) 12 | node1.neighbourList.append(node3) 13 | node2.neighbourList.append(node4) 14 | node2.neighbourList.append(node5) 15 | node3.neighbourList.append(node6) 16 | 17 | dfs(node1) 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | python/DjangoTutorial/.idea 2 | python/DjangoTutorial/DjangoTutorial/__pycache__ 3 | python/DjangoTutorial/blog/__pycache__ 4 | python/DjangoTutorial/blog/migrations/__pycache__ 5 | *.pyc 6 | *~ 7 | __pycache__ 8 | myvenv 9 | db.sqlite3 10 | /static 11 | .DS_Store 12 | python/DataStructures/**/.idea 13 | .ipynb_checkpoints 14 | 15 | python/**/**/.idea 16 | 17 | **/GraphAlgorithms/**/.idea 18 | java/GraphAlgorithms/**/out/ 19 | 20 | Rust/helloWorld 21 | Rust/rust 22 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/templates/blog/post_list.html: -------------------------------------------------------------------------------- 1 | {% extends 'blog/base.html' %} 2 | 3 | {% block content %} 4 | {% for post in posts %} 5 |
6 |
7 | {{ post.published_date }} 8 |
9 |

{{ post.title }}

10 |

{{ post.text|linebreaksbr }}

11 |
12 | {% endfor %} 13 | {% endblock %} -------------------------------------------------------------------------------- /java/JavaTutorial/java.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/topological_sort/Main.java: -------------------------------------------------------------------------------- 1 | package topological_sort; 2 | 3 | /** 4 | * Created by USER on 27-10-2017. 5 | */ 6 | public class Main { 7 | public static void main(String ags[]){ 8 | Graph gp =new Graph(6,true); 9 | gp.addEdges(5,2); 10 | gp.addEdges(5,0); 11 | gp.addEdges(4,0); 12 | gp.addEdges(4,1); 13 | gp.addEdges(2,3); 14 | gp.addEdges(3,1); 15 | 16 | //gp.printEdges(); 17 | gp.DFS(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /python/DjangoTutorial/DjangoTutorial/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for DjangoTutorial project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoTutorial.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/BreadthFirstSearch/BreadthFirstSearch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/DepthFirstSearch/DepthFirstSearch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PHP/5_whileLoops.php: -------------------------------------------------------------------------------- 1 | "; 9 | $i++; 10 | } 11 | echo "

"; 12 | 13 | 14 | $i = 1; 15 | while ($i <= 10) { 16 | echo "5 x ".$i." = ".($i*5)."
"; 17 | $i++; 18 | } 19 | echo "

"; 20 | 21 | //traversing the array 22 | $i = 0; 23 | while ($i < sizeof($family)) { 24 | echo $family[$i]."
"; 25 | $i++; 26 | } 27 | 28 | ?> 29 | -------------------------------------------------------------------------------- /C/iii_if-elseif-else.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a; 4 | printf("\nEnter a number :\n"); 5 | scanf("%d",&a); 6 | //'if' statement checks condition if its true than execute statements associated with it, else move for 'else if' and so on at last 'else' statement(optional) 7 | if(a>0){ 8 | printf("\nEntered number is positive\n"); 9 | } 10 | //there can be multipe 'else if' statements 11 | else if(a<0){ 12 | printf("\nEntered number is negative\n"); 13 | } 14 | else{ 15 | printf("\nEntered is Zero\n"); 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /python/DataStructures/Stacks/App.py: -------------------------------------------------------------------------------- 1 | from Stack import Stack 2 | 3 | newStack = Stack() 4 | 5 | newStack.push(23) 6 | newStack.push(90) 7 | newStack.push(12) 8 | newStack.push(76) 9 | newStack.push(34) 10 | newStack.push(98) 11 | 12 | print("======") 13 | 14 | newStack.viewFullStack() 15 | 16 | newStack.pop() 17 | 18 | print("======") 19 | 20 | newStack.viewFullStack() 21 | 22 | print("======") 23 | 24 | newStack.isEmpty() 25 | 26 | print("======") 27 | 28 | newStack.size() 29 | 30 | print("======") 31 | 32 | newStack.viewTop() 33 | 34 | print("======") 35 | 36 | -------------------------------------------------------------------------------- /PHP/8_getMethodToSendData.php: -------------------------------------------------------------------------------- 1 |
"; 14 | 15 | ?> 16 | 17 |

What's your name?

18 | 19 |
20 | 21 | 22 |
23 | -------------------------------------------------------------------------------- /C/i_helloWorld.c: -------------------------------------------------------------------------------- 1 | #include //include information about standard library.'stdio.h' is standard input output (library)header file that stores pre-defined function like printf(),scanf() etc 2 | int main() //define function named main() .Execution of C program starts from main() 3 | { 4 | printf("hello, world\n"); //main() calls library function printf to print sequence of characters 5 | //'\n' represent the newline 6 | return 0; //since main() is defined as int ,so it will return a value.And 'return 0' represent end of execution 7 | } -------------------------------------------------------------------------------- /ES6/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: ['babel-polyfill', './app/index.js'], 3 | output: { 4 | path: './build', 5 | // if the above line does not work, try `path: __dirname + '/build'` 6 | filename: 'bundle.js' 7 | }, 8 | module: { 9 | loaders: [ 10 | { 11 | test: /\.js$/, // a regular expression that catches .js files 12 | exclude: /node_modules/, 13 | loader: 'babel-loader' 14 | } 15 | ] 16 | }, 17 | devServer: { 18 | port: 3000, // most common port 19 | contentBase: './build', 20 | inline: true 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/Kruskal/Edge.py: -------------------------------------------------------------------------------- 1 | class Edge(object): 2 | 3 | # constructor 4 | # provides the basic structure of the edge 5 | def __init__(self, weight, startVertex, targetVertex): 6 | self.weight = weight 7 | self.startVertex = startVertex 8 | self.targetVertex = targetVertex 9 | 10 | # for sorting purposes 11 | def __cmp__(self, other): 12 | return self.cmp(self.weight, other.weight) 13 | 14 | def __lt__(self, other): 15 | selfPriority = self.weight 16 | otherPriority = other.weight 17 | return selfPriority < otherPriority -------------------------------------------------------------------------------- /python/GraphAlgorithms/Prims/Edge.py: -------------------------------------------------------------------------------- 1 | class Edge(object): 2 | 3 | # constructor 4 | # provides the basic structure of the edge 5 | def __init__(self, weight, startVertex, targetVertex): 6 | self.weight = weight 7 | self.startVertex = startVertex 8 | self.targetVertex = targetVertex 9 | 10 | # for sorting purposes 11 | def __cmp__(self, other): 12 | return self.cmp(self.weight, other.weight) 13 | 14 | def __lt__(self, other): 15 | selfPriority = self.weight 16 | otherPriority = other.weight 17 | return selfPriority < otherPriority -------------------------------------------------------------------------------- /java/SortingAlgorithm/SelectionSort.java: -------------------------------------------------------------------------------- 1 | class SelectionSort{ 2 | public static void selection_sort(int arr[],int n){ 3 | int temp,pos; 4 | for(int i=0;iarr[j]){ 9 | temp=arr[j]; 10 | pos=j; 11 | } 12 | } 13 | arr[pos]=arr[i]; 14 | arr[i]=temp; 15 | } 16 | } 17 | public static void main(String[] args) { 18 | int arr[]=new int[]{5,3,4,9,1,0,7,2}; 19 | selection_sort(arr,8); 20 | for (int i=0;i<8 ;i++ ) { 21 | System.out.println(arr[i]); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /java/SortingAlgorithm/InertionSort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class InertionSort{ 3 | static void insertion_sort(int arr[],int n){ 4 | int currEle,j; 5 | for(int i=1;i=0&&arr[j]>currEle){ 9 | arr[j+1]=arr[j]; 10 | j--; 11 | } 12 | arr[j+1]=currEle; 13 | } 14 | } 15 | public static void main(String args[]){ 16 | int arr[]=new int[]{5,6,1,8,3,9,4,0}; 17 | int n=arr.length; 18 | insertion_sort(arr,n); 19 | System.out.println("Sorted array is "); 20 | for(int i=0;i 5 | {% if post.published_date %} 6 |
7 | {{ post.published_date }} 8 |
9 | {% endif %} 10 | {% if user.is_authenticated %} 11 | 12 | {% endif %} 13 |

{{ post.title }}

14 |

{{ post.text|linebreaksbr }}

15 | 16 | {% endblock %} -------------------------------------------------------------------------------- /python/SortingAlgorithms/BubbleSort/BubbleSort.py: -------------------------------------------------------------------------------- 1 | # Bubble Sort 2 | # O(n^2) for worst and average case 3 | # a lot of swapping takes place here 4 | 5 | def bubble_sort(array): 6 | 7 | # for(int i = array.length - 1; i <= 0; i--) 8 | for i in range(len(array)-1, 0, -1): 9 | # for(int j = 0; j < i; j++) 10 | for j in range(i): 11 | # swap whenever a larger element is found 12 | if array[j] > array[j+1]: 13 | array[j], array[j+1] = array[j+1], array[j] 14 | 15 | return array 16 | 17 | array = [14, 143, 53, 37, 453] 18 | print(bubble_sort(array)) 19 | -------------------------------------------------------------------------------- /python/DataStructures/Queues/App.py: -------------------------------------------------------------------------------- 1 | from Queue import Queue 2 | 3 | newQueue = Queue() 4 | 5 | newQueue.enqueue(23) 6 | newQueue.enqueue(65) 7 | newQueue.enqueue(21) 8 | newQueue.enqueue(97) 9 | newQueue.enqueue(83) 10 | newQueue.enqueue(97) 11 | newQueue.enqueue(69) 12 | 13 | print("======") 14 | 15 | newQueue.viewFullQueue() 16 | 17 | print("======") 18 | 19 | newQueue.dequeue() 20 | 21 | print("======") 22 | 23 | newQueue.viewFullQueue() 24 | 25 | print("======") 26 | 27 | newQueue.size() 28 | 29 | print("======") 30 | 31 | newQueue.viewTop() 32 | 33 | print("======") 34 | 35 | newQueue.isEmpty() 36 | 37 | print("======") -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils import timezone 3 | 4 | # Create your models here. 5 | class Post(models.Model): 6 | author = models.ForeignKey('auth.User') 7 | title = models.CharField(max_length=200) 8 | text = models.TextField() 9 | created_date = models.DateTimeField( 10 | default=timezone.now) 11 | published_date = models.DateTimeField( 12 | blank=True, null=True) 13 | 14 | def publish(self): 15 | self.published_date = timezone.now() 16 | self.save() 17 | 18 | def __str__(self): 19 | return self.title -------------------------------------------------------------------------------- /python/DataStructures/LinkedLists/App.py: -------------------------------------------------------------------------------- 1 | from LinkedList import LinkedList 2 | 3 | linkedList = LinkedList() 4 | 5 | linkedList.insertAtEnd(12) 6 | linkedList.insertAtEnd(20) 7 | linkedList.insertAtEnd(80) 8 | linkedList.insertAtEnd(9) 9 | linkedList.insertAtEnd(99) 10 | 11 | linkedList.insertAtPosition(10, 0) 12 | 13 | print("========") 14 | 15 | linkedList.size() 16 | 17 | print("========") 18 | 19 | linkedList.traverseList() 20 | 21 | print("========") 22 | 23 | linkedList.remove(9) 24 | linkedList.size() 25 | 26 | print("========") 27 | 28 | linkedList.traverseList() 29 | 30 | print("========") 31 | 32 | linkedList.size() 33 | 34 | print("========") -------------------------------------------------------------------------------- /python/SortingAlgorithms/SelectionSort/SelectionSort.py: -------------------------------------------------------------------------------- 1 | # Selection Sort 2 | # O(n^2) for worst and average case 3 | 4 | def selection_slot(array): 5 | 6 | # for(int i = array.length - 1; i <= 0; i--) 7 | for i in range(len(array)-1, 0, -1): 8 | maxPosition = 0 9 | 10 | # for(int j = 1; j < i+1; j++) 11 | # logic to move the max element in the last position 12 | for j in range(1, i+1): 13 | if array[j] > array[maxPosition]: 14 | maxPosition = j 15 | array[i], array[maxPosition] = array[maxPosition], array[i] 16 | 17 | return array 18 | 19 | array = [23, 1, 90, 12, 56] 20 | print(selection_slot(array)) -------------------------------------------------------------------------------- /python/GraphAlgorithms/BreadthFirstSearch/BFS.py: -------------------------------------------------------------------------------- 1 | # initialize a list to implement a queue 2 | queue = [] 3 | 4 | def bfs(node): 5 | 6 | # set the root node's visited property to be true 7 | node.visited = True 8 | queue.append(node) 9 | 10 | # while there's an element in a queue 11 | while queue: 12 | 13 | # pop the element and print it 14 | node = queue.pop() 15 | print("%s -> " % node.name) 16 | 17 | # traverse through the neighbours of a node 18 | for i in node.neighbourList: 19 | if not i.visited: 20 | i.visited = True 21 | # insert the node at the first position 22 | queue.insert(0, i) -------------------------------------------------------------------------------- /ES6/README.md: -------------------------------------------------------------------------------- 1 | 2 | **if** you already have a ES6 environment setup OR you just want to go through the main file then 'es6.js' file in the 'app' folder is the file that you want. 3 | 4 | **else** 5 | 6 | ## To get started 7 | 8 | 1. Setup this repo on your machine. 9 | 10 | 2. Make sure you have node.js on your machine. 11 | 12 | 3. Open 'node cmd prompt' and 'cd' to the location where you saved this repo. 13 | 14 | 4. type ```$ npm install ``` this will install all the dependencies. 15 | 16 | 5. type ```$ npm start ``` this will start a server on port no. 3000. 17 | 18 | 6. open browser and go to http://localhost:3000/ to view the file. 19 | 20 | 7. press "ctrl + shift + i" key or open the web console. 21 | -------------------------------------------------------------------------------- /python/DataStructures/BinarySearchTrees/App.py: -------------------------------------------------------------------------------- 1 | from BinarySearchTree import BinarySearchTree 2 | 3 | newBST = BinarySearchTree() 4 | 5 | 6 | newBST.insert(12) 7 | newBST.insert(32) 8 | newBST.insert(42) 9 | newBST.insert(90) 10 | newBST.insert(1) 11 | newBST.insert(-2) 12 | 13 | print("=====") 14 | 15 | newBST.traverseInOrder() 16 | 17 | print("=====") 18 | 19 | newBST.remove(42) 20 | newBST.traverseInOrder() 21 | 22 | print("=====") 23 | 24 | print(newBST.getMax()) 25 | 26 | print("=====") 27 | 28 | print(newBST.getMin()) 29 | 30 | print("=====") 31 | 32 | newBST.remove(12) 33 | newBST.traverseInOrder() 34 | 35 | print("=====") 36 | 37 | newBST.insert(45) 38 | 39 | newBST.traverseInOrder() 40 | 41 | print("=====") 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /PHP/4_ifStatements.php: -------------------------------------------------------------------------------- 1 |
"; 14 | 15 | 16 | $age = 17; 17 | if($age >= 18){ 18 | echo "You may proceed....."; 19 | }else{ 20 | echo "You may not proceed....."; 21 | } 22 | echo "

"; 23 | 24 | 25 | //if with AND,OR. 26 | //very similar to javascript. 27 | $age = 20; 28 | if($age >= 18 && $user == "pranav"){ 29 | echo "You may proceed....."; 30 | }else{ 31 | echo "You may not proceed....."; 32 | } 33 | echo "

"; 34 | 35 | ?> 36 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/DepthFirstSearch/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Pranav Jain on 19-Aug-17. 3 | */ 4 | public class App { 5 | 6 | public static void main(String[] args) { 7 | 8 | DFS dfs = new DFS(); 9 | 10 | Vertex vertex1 = new Vertex(1); 11 | Vertex vertex2 = new Vertex(2); 12 | Vertex vertex3 = new Vertex(3); 13 | Vertex vertex4 = new Vertex(4); 14 | Vertex vertex5 = new Vertex(5); 15 | Vertex vertex6 = new Vertex(6); 16 | 17 | vertex1.addNeighbour(vertex2); 18 | vertex1.addNeighbour(vertex3); 19 | vertex2.addNeighbour(vertex4); 20 | vertex2.addNeighbour(vertex5); 21 | vertex3.addNeighbour(vertex6); 22 | 23 | dfs.DFS(vertex1); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/BreadthFirstSearch/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Pranav Jain on 19-Aug-17. 3 | */ 4 | public class App { 5 | 6 | public static void main(String[] args) { 7 | 8 | BFS bfs = new BFS(); 9 | 10 | Vertex vertex1 = new Vertex(1); 11 | Vertex vertex2 = new Vertex(2); 12 | Vertex vertex3 = new Vertex(3); 13 | Vertex vertex4 = new Vertex(4); 14 | Vertex vertex5 = new Vertex(5); 15 | Vertex vertex6 = new Vertex(6); 16 | 17 | vertex1.addNeighbour(vertex2); 18 | vertex1.addNeighbour(vertex3); 19 | vertex2.addNeighbour(vertex4); 20 | vertex2.addNeighbour(vertex5); 21 | vertex3.addNeighbour(vertex6); 22 | 23 | bfs.BFS(vertex1); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /python/SearchAlgorithms/BinarySearch/BinarySearch.py: -------------------------------------------------------------------------------- 1 | # method to search for an element using binary search 2 | def binary_search(array, element): 3 | 4 | first = 0 5 | last = len(array) - 1 6 | 7 | found = False 8 | 9 | while first <= last and not found: 10 | 11 | mid = int((first + last) / 2) 12 | 13 | if array[mid] == element: 14 | found = True 15 | else: 16 | 17 | # consider the first half of the array 18 | if element < array[mid]: 19 | last = mid - 1 20 | 21 | # consider the second half of the array 22 | else: 23 | first = mid + 1 24 | 25 | return found 26 | 27 | array = [11, 23, 45, 55, 67, 88, 99] 28 | print(binary_search(array, 67)) -------------------------------------------------------------------------------- /PHP/6_forAndForEachLoops.php: -------------------------------------------------------------------------------- 1 | "; 8 | } 9 | echo "

"; 10 | 11 | //basic for-loop for traversing the array 12 | for($i = 0; $i < sizeof($family); $i++){ 13 | echo $family[$i]."
"; 14 | } 15 | echo "

"; 16 | 17 | 18 | //foreach loop structure 19 | foreach ($family as $key => $value) { 20 | //Appending Jain 21 | $family[$key] = $value." Witcher"; 22 | //Note: Here Jain will not be printed as the value is set to original value, and not the new appended one. 23 | echo "Array Item = ".$key." is ".$value.".
"; 24 | } 25 | echo "

"; 26 | 27 | 28 | print_r($family); 29 | ?> 30 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/Prims/App.py: -------------------------------------------------------------------------------- 1 | from Vertex import Vertex 2 | from Edge import Edge 3 | from Algorithm import Algorithm 4 | 5 | vertex1 = Vertex("A") 6 | vertex2 = Vertex("B") 7 | vertex3 = Vertex("C") 8 | vertex4 = Vertex("D") 9 | 10 | edge1 = Edge(1, vertex1, vertex2) 11 | edge2 = Edge(1, vertex1, vertex3) 12 | edge3 = Edge(100, vertex1, vertex4) 13 | edge4 = Edge(1, vertex3, vertex4) 14 | edge5 = Edge(0.1, vertex2, vertex4) 15 | 16 | vertex1.neighbourList.append(edge1) 17 | vertex1.neighbourList.append(edge2) 18 | vertex1.neighbourList.append(edge3) 19 | vertex3.neighbourList.append(edge4) 20 | vertex2.neighbourList.append(edge5) 21 | 22 | unvisitedList = [vertex1, vertex2, vertex3, vertex4] 23 | 24 | algorithm = Algorithm(unvisitedList) 25 | algorithm.constructSpannigTree(vertex1) -------------------------------------------------------------------------------- /java/SortingAlgorithm/CountingSort.java: -------------------------------------------------------------------------------- 1 | class CountingSort{ 2 | public static void counting_sort(int a[],int b[],int k){ 3 | int c[]=new int[k]; 4 | for (int j=0;j 0 and array[pos-1] > currentElement: 19 | array[pos] = array[pos-1] 20 | pos -= 1 21 | array[pos] = currentElement 22 | 23 | return array 24 | 25 | array = [2, 33, 12, 89, 1, 30] 26 | print(insertion_sort(array)) -------------------------------------------------------------------------------- /ES6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "setup", 3 | "version": "1.0.0", 4 | "babel": { 5 | "presets": [ 6 | "es2015", 7 | "es2016", 8 | "es2017", 9 | "react" 10 | ] 11 | }, 12 | "description": "", 13 | "main": "index.js", 14 | "scripts": { 15 | "build": "webpack", 16 | "start": "webpack-dev-server" 17 | }, 18 | "keywords": [], 19 | "author": "", 20 | "license": "ISC", 21 | "devDependencies": { 22 | "babel-core": "^6.22.1", 23 | "babel-loader": "^6.2.10", 24 | "babel-polyfill": "^6.22.0", 25 | "babel-preset-es2015": "^6.22.0", 26 | "babel-preset-es2016": "^6.22.0", 27 | "babel-preset-es2017": "^6.22.0", 28 | "babel-preset-react": "^6.23.0", 29 | "react": "^15.4.2", 30 | "react-bootstrap": "^0.30.7", 31 | "react-dom": "^15.4.2", 32 | "webpack": "^1.14.0", 33 | "webpack-dev-server": ">=3.1.11" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /python/DjangoTutorial/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoTutorial.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /python/DjangoTutorial/DjangoTutorial/urls.py: -------------------------------------------------------------------------------- 1 | """DjangoTutorial URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.11/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | 19 | urlpatterns = [ 20 | url(r'^admin/', admin.site.urls), 21 | url(r'', include('blog.urls')), 22 | ] 23 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/Kruskal/Algorithm.py: -------------------------------------------------------------------------------- 1 | from DisjointSet import DisjointSet 2 | 3 | class Algorithm(object): 4 | 5 | # Method to construct a spanning tree 6 | def constructSpanningTree(self, vertexList, edgeList): 7 | 8 | disjointSet = DisjointSet(vertexList) 9 | spanningTree = [] 10 | 11 | edgeList.sort() 12 | 13 | for edge in edgeList: 14 | u = edge.startVertex 15 | v = edge.targetVertex 16 | 17 | # check whether the edges don't form a cycle 18 | # if they don't then add the edge to the spanning tree 19 | # and union the two nodes 20 | if disjointSet.find(u.parentNode) != disjointSet.find(v.parentNode): 21 | spanningTree.append(edge) 22 | disjointSet.union(u.parentNode, v.parentNode) 23 | 24 | # print the spanning tree by printing all the edges 25 | for edge in spanningTree: 26 | print(edge.startVertex.name, "-", edge.targetVertex.name) -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/static/css/blog.css: -------------------------------------------------------------------------------- 1 | h1 a { 2 | color: #FCA205; 3 | font-family: 'Lobster'; 4 | } 5 | 6 | .page-header { 7 | background-color: #ff9400; 8 | margin-top: 0; 9 | padding: 20px 20px 20px 40px; 10 | } 11 | 12 | .page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active { 13 | color: #ffffff; 14 | font-size: 36pt; 15 | text-decoration: none; 16 | } 17 | 18 | .content { 19 | margin-left: 40px; 20 | } 21 | 22 | h1, h2, h3, h4 { 23 | font-family: 'Lobster', cursive; 24 | } 25 | 26 | .date { 27 | color: #828282; 28 | } 29 | 30 | .save { 31 | float: right; 32 | } 33 | 34 | .post-form textarea, .post-form input { 35 | width: 100%; 36 | } 37 | 38 | .top-menu, .top-menu:hover, .top-menu:visited { 39 | color: #ffffff; 40 | float: right; 41 | font-size: 26pt; 42 | margin-right: 20px; 43 | } 44 | 45 | .post { 46 | margin-bottom: 70px; 47 | } 48 | 49 | .post h1 a, .post h1 a:visited { 50 | color: #000000; 51 | } 52 | -------------------------------------------------------------------------------- /java/JavaTutorial/src/Variable.java: -------------------------------------------------------------------------------- 1 | public class Variable { 2 | 3 | public static void main(String args[]){ 4 | //declaring Variable a,b of integer type 5 | //integer size 4 bytes 6 | int a,b; 7 | b=20; 8 | 9 | //declaring Variable f1,f2 of floating point type 10 | //float size 4 bytes 11 | float f1,f2; 12 | f1 = 5; 13 | f2 = 2; 14 | 15 | //long size 8 bytes 16 | long ll; 17 | ll=150; 18 | 19 | //type cast long is converted into int 20 | a=(int)ll; 21 | float f3; 22 | f3=f1/f2; 23 | 24 | //in java '+' is used for concatenation 25 | System.out.println("a = "+a+" b = "+b); 26 | 27 | System.out.println("f1 = "+f1+" f2 = "+f2+" f3 = "+f3); 28 | 29 | //type cast 30 | System.out.println("f3 = "+f3+"\ntype cast f3 = "+(int)f3); 31 | 32 | //boolean variable can be assigned to true or false 33 | boolean c=true; 34 | System.out.println("c = "+c); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /PHP/2_variables.php: -------------------------------------------------------------------------------- 1 | My Name is $name

"; 9 | 10 | $string1 = "

This is String 1

"; 11 | $string2 = "

This is String 2

"; 12 | 13 | //Unlike in javascript where '+' sign is used for concatenation. 14 | //Here in php '.' is used for concatenation. 15 | echo $string1." ".$string2; 16 | 17 | //sample calculation problem 18 | $myNumber = 45; 19 | $calculation = $myNumber + 3244 / 213; 20 | echo "The result of the calculation is ".$calculation; 21 | 22 | //boolean variables 23 | //on the browser it will be printed 1 if the value is true. 24 | //on the browser nothing or 0 will be printed if the value is false. 25 | $myBool = true; 26 | echo "

This statement is true? ".$myBool."

"; 27 | 28 | //another fancy way of calling variable name 29 | //this way of using '$$' calls the variable whose name is stored in typed variable name. 30 | $variableName = "name"; 31 | echo "

".$$variableName."

"; 32 | 33 | ?> 34 | -------------------------------------------------------------------------------- /python/DataStructures/Queues/Queue.py: -------------------------------------------------------------------------------- 1 | class Queue: 2 | 3 | # constructor 4 | # here we initialize the list that will be used for the queue 5 | def __init__(self): 6 | self.queue = [] 7 | 8 | # method to push elements into queue 9 | def enqueue(self, data): 10 | self.queue.insert(0, data) 11 | 12 | # method to dequeue elements from the queue 13 | def dequeue(self): 14 | return self.queue.pop() 15 | 16 | # method to find the current length of the queue 17 | def size(self): 18 | print(len(self.queue)) 19 | 20 | # method to find whether the queue is empty or not 21 | def isEmpty(self): 22 | if not self.queue: 23 | print("True") 24 | else: 25 | print("False") 26 | 27 | # method to view the top most element 28 | def viewTop(self): 29 | if self.queue: 30 | print(self.queue[len(self.queue) - 1]) 31 | else: 32 | print("There are no elements in the queue") 33 | 34 | # method to view the full queue 35 | def viewFullQueue(self): 36 | for i in self.queue: 37 | print(i) -------------------------------------------------------------------------------- /python/DataStructures/Stacks/Stack.py: -------------------------------------------------------------------------------- 1 | class Stack: 2 | 3 | # constructor 4 | # here we initialize the list that will be used for the stack 5 | def __init__(self): 6 | self.stack = [] 7 | 8 | # method to push element into the stack 9 | def push(self, data): 10 | self.stack.append(data) 11 | 12 | # method to pop topmost i.e. last element from the stack 13 | def pop(self): 14 | self.stack.pop() 15 | 16 | # method to find whether the stack is empty or not 17 | def isEmpty(self): 18 | if not self.stack: 19 | print("True") 20 | else: 21 | print("False") 22 | 23 | # method to find the current length of the stack 24 | def size(self): 25 | print(len(self.stack)) 26 | 27 | # method to view the top most element 28 | def viewTop(self): 29 | if self.stack: 30 | print(self.stack[len(self.stack) - 1]) 31 | else: 32 | print("There are no elements in the stack") 33 | 34 | # method to view the full stack 35 | def viewFullStack(self): 36 | for i in self.stack: 37 | print(i) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Pranav Jain 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/DepthFirstSearch/src/DFS.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | /** 4 | * Created by Pranav Jain on 19-Aug-17. 5 | */ 6 | public class DFS { 7 | 8 | public void DFS(Vertex root){ 9 | 10 | //Stack is the interface and it is initialized as a LinkedList 11 | Stack stack = new Stack<>(); 12 | 13 | //set the root vertex as visited and add it in the stack 14 | root.setVisited(true); 15 | stack.push(root); 16 | 17 | //loop while stack is not Empty 18 | while(!stack.isEmpty()){ 19 | 20 | //pop a vertex 21 | Vertex actualVertex = stack.pop(); 22 | System.out.print(actualVertex + "->"); 23 | 24 | //get the vertex's neighbour list 25 | for(Vertex v : actualVertex.getNeighbourList()){ 26 | //if the neighbour is visited then ignore else set it visited and add it to the stack 27 | if(!v.isVisited()){ 28 | v.setVisited(true); 29 | stack.push(v); 30 | } 31 | } 32 | 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /python/DataStructures/LinkedLists/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | # every node will have a data and a reference to the nextNode 5 | def __init__(self, data): 6 | self.data = data 7 | self.nextNode = None 8 | 9 | # O(n) method to support the remove method from LinkedList.py 10 | def removeRecursive(self, data, previousNode): 11 | 12 | # if node we want to delete is reached 13 | if self.data == data: 14 | # link previous node to the nextnode 15 | previousNode.nextNode = self.nextNode 16 | 17 | # delete stuff i.e. free garbage values 18 | del self.data 19 | del self.nextNode 20 | 21 | # traverse through the linked list 22 | else: 23 | # make sure next node is none i.e. make sure current node is the last node 24 | if self.nextNode: 25 | # make a recursive call to the function where parameters are 26 | # 'data' data that we want to delete and 27 | # 'self' which will act as the previousNode 28 | self.nextNode.removeRecursive(data, self) -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/templates/blog/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Post 6 | 7 | 8 | 9 | 10 | 11 | 12 | {% load staticfiles %} 13 | 14 | 15 | 16 | 17 | 23 |
24 |
25 |
26 | {% block content %} 27 | {% endblock %} 28 |
29 |
30 |
31 | 32 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/BreadthFirstSearch/src/BFS.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Pranav Jain on 19-Aug-17. 3 | */ 4 | 5 | import java.util.LinkedList; 6 | import java.util.Queue; 7 | 8 | public class BFS { 9 | 10 | public void BFS(Vertex root){ 11 | 12 | //Queue is the interface and it is initialized as a LinkedList 13 | Queue queue = new LinkedList<>(); 14 | 15 | //set the root vertex as visited and add it in the queue 16 | root.setVisited(true); 17 | queue.add(root); 18 | 19 | //loop while queue is not Empty 20 | while(!queue.isEmpty()){ 21 | 22 | //pop a vertex 23 | Vertex actualVertex = queue.remove(); 24 | System.out.print(actualVertex + "->"); 25 | 26 | //get the vertex's neighbour list 27 | for(Vertex v : actualVertex.getNeighbourList()){ 28 | //if the neighbour is visited then ignore else set it visited and add it to the queue 29 | if(!v.isVisited()){ 30 | v.setVisited(true); 31 | queue.add(v); 32 | } 33 | } 34 | 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /java/JavaTutorial/src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /*'class' is keyword, its used to declare that new class. 2 | Here 'HelloWorld' is an identifier that is name of class 3 | */ 4 | class HelloWorld { 5 | //program begins with call to main() 6 | //public is access modifier,which allows the programmer to control the visibility of class member. 7 | //class member are all function and all Variable declared and defined in class. 8 | /* 9 | When class member is preceded by public , 10 | then that member may be access by code outside the class in which it is declared. 11 | */ 12 | //static allows main() to be called without instantiate a particular instance of class i.e object of class. 13 | //void implies that main() does not return any value. 14 | //String args[] is used to store information that is available while executing program 15 | public static void main(String args[]){ 16 | /*System is a class in the java.lang package. 17 | out is a static member of the System class, and is an instance of java.io.PrintStream . 18 | println is a method of java.io.PrintStream 19 | */ 20 | System.out.println("Hello World"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java/DataStructures/Stack/Mystack.java: -------------------------------------------------------------------------------- 1 | class Stack{ 2 | final int SIZE=50; 3 | private int stack[]=new int[SIZE]; 4 | private int top; 5 | 6 | Stack(){ 7 | top=-1; 8 | } 9 | void push(int ele){ 10 | if(top=0){ 20 | return stack[--top]; 21 | } 22 | else { 23 | System.out.println("Stack is empty"); 24 | return -1; 25 | } 26 | 27 | } 28 | void display(){ 29 | System.out.println("Stack is (starting from top)"); 30 | for(int i=top;i>=0;i--){ 31 | System.out.print(stack[i]+" "); 32 | } 33 | } 34 | int tops(){ 35 | return top; 36 | } 37 | } 38 | 39 | class Mystack{ 40 | public static void main(String[] args) { 41 | Stack mystack1 = new Stack(); 42 | 43 | for(int i=0;i<15;i++){ 44 | mystack1.push(i*10); 45 | } 46 | 47 | mystack1.display(); 48 | 49 | System.out.println(); 50 | 51 | for(int i=0;i<5;i++){ 52 | System.out.println("pop "+mystack1.pop()); 53 | } 54 | 55 | mystack1.display(); 56 | 57 | System.out.println("\ntop : "+mystack1.tops()); 58 | 59 | } 60 | } -------------------------------------------------------------------------------- /python/SortingAlgorithms/MergeSort/MergeSort.py: -------------------------------------------------------------------------------- 1 | def merge_sort(array): 2 | 3 | if len(array) > 1: 4 | 5 | mid = int(len(array)/2) 6 | leftHalf = array[:mid] 7 | rightHalf = array[mid:] 8 | 9 | print("<>",leftHalf) 10 | print("<>",rightHalf) 11 | 12 | merge_sort(leftHalf) 13 | merge_sort(rightHalf) 14 | 15 | i = 0 16 | j = 0 17 | k = 0 18 | 19 | print(leftHalf) 20 | print(rightHalf) 21 | 22 | while i < len(leftHalf) and j < len(rightHalf): 23 | 24 | if leftHalf[i] < rightHalf[j]: 25 | array[k] = leftHalf[i] 26 | i += 1 27 | else: 28 | array[k] = rightHalf[j] 29 | j += 1 30 | 31 | k += 1 32 | 33 | while i < len(leftHalf): 34 | array[k] = leftHalf[i] 35 | i += 1 36 | k += 1 37 | 38 | while j < len(rightHalf): 39 | array[k] = rightHalf[j] 40 | j += 1 41 | k += 1 42 | 43 | print("Merged", array) 44 | 45 | return array 46 | 47 | array = [12, 56, 1, 90, 23, 15, 19, 1000, 3] 48 | print(merge_sort(array)) -------------------------------------------------------------------------------- /python/SortingAlgorithms/QuickSort/QuickSort.py: -------------------------------------------------------------------------------- 1 | def quick_sort(array): 2 | 3 | quick_sort_help(array, 0, len(array) - 1) 4 | 5 | return array 6 | 7 | def quick_sort_help(array, first, last): 8 | 9 | if first < last: 10 | splitPoint = partition(array, first, last) 11 | 12 | quick_sort_help(array, first, splitPoint-1) 13 | quick_sort_help(array, splitPoint+1, last) 14 | 15 | return array 16 | 17 | def partition(array, first, last): 18 | 19 | pivotValue = array[first] 20 | 21 | leftMark = first+1 22 | rightMark = last 23 | 24 | done = False 25 | 26 | while not done: 27 | 28 | while leftMark <= rightMark and array[leftMark] <= pivotValue: 29 | leftMark += 1 30 | 31 | while rightMark >= leftMark and array[rightMark] >= pivotValue: 32 | rightMark -= 1 33 | 34 | if rightMark < leftMark: 35 | done = True 36 | 37 | else: 38 | array[leftMark], array[rightMark] = array[rightMark], array[leftMark] 39 | 40 | array[first], array[rightMark] = array[rightMark], array[first] 41 | 42 | return rightMark 43 | 44 | array = [23, 1, 90, 11, 9, 999, 12] 45 | print(quick_sort(array)) -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.3 on 2017-07-22 06:51 3 | from __future__ import unicode_literals 4 | 5 | from django.conf import settings 6 | from django.db import migrations, models 7 | import django.db.models.deletion 8 | import django.utils.timezone 9 | 10 | 11 | class Migration(migrations.Migration): 12 | 13 | initial = True 14 | 15 | dependencies = [ 16 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 17 | ] 18 | 19 | operations = [ 20 | migrations.CreateModel( 21 | name='Post', 22 | fields=[ 23 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 24 | ('title', models.CharField(max_length=200)), 25 | ('text', models.TextField()), 26 | ('created_date', models.DateTimeField(default=django.utils.timezone.now)), 27 | ('published_date', models.DateTimeField(blank=True, null=True)), 28 | ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 29 | ], 30 | ), 31 | ] 32 | -------------------------------------------------------------------------------- /C/v_while_dowhile.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | //arr is collection of data of same data type 4 | int a[10]={5,8,11,16,20,25,35,48,55,68};//a[] is array of 10 data of type integer 5 | //a[10] mean there 10 integer i.e a[0],a[1],a[2],a[3],a[4]...a[9] 6 | int find; 7 | printf("\n=========while Loop implementation=========\n"); 8 | 9 | printf("\nEnter interger which you want to find\n"); 10 | scanf("%d",&find); 11 | int i=0; 12 | //in while loop it check foe condition 13 | //if it is true than it execute block of statements of loop 14 | //else loop terminate 15 | while(a[i]!=find && i<10){ 16 | i++; 17 | } 18 | if(a[i]==find){ 19 | printf("\nNumber is found at %d position \n",i); 20 | } 21 | else{ 22 | printf("\nNot Found\n"); 23 | } 24 | 25 | printf("\n=========do-while Loop implementation=========\n"); 26 | int x,y,temp; 27 | printf("\nEnter two number\n"); 28 | scanf("%d %d",&x,&y); 29 | //in do-while first it executes block of statements and than checks condition 30 | //if it is true than it again execute block of statement 31 | //else terminate 32 | do{ 33 | temp=x%y; 34 | x=y; 35 | y=temp; 36 | 37 | }while(y>0); 38 | printf("\nGCD of Entered number is %d\n",x); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /python/SearchAlgorithms/SequentialSearch/Sequential.py: -------------------------------------------------------------------------------- 1 | # method to search for an element in an unordered list 2 | def sequential_search_unordered_list(array, element): 3 | 4 | pos = 0 5 | found = False 6 | 7 | while pos < len(array) and not found: 8 | 9 | if array[pos] == element: 10 | found = True 11 | else: 12 | pos += 1 13 | 14 | return found 15 | 16 | unordered_list = [1, 65, 37, 49, 52] 17 | print(sequential_search_unordered_list(unordered_list, 6)) 18 | 19 | # method to search for an element in an ordered list 20 | # the only difference between the two is that 21 | # we stop when we find an element greater than our search target 22 | def sequential_search_ordered_list(array, element): 23 | 24 | pos = 0 25 | found = False 26 | stopped = False 27 | 28 | while pos < len(array) and not found and not stopped: 29 | 30 | if array[pos] == element: 31 | found = True 32 | else: 33 | if array[pos] > element: 34 | stopped = True 35 | else: 36 | pos += 1 37 | 38 | return found 39 | 40 | ordered_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] 41 | print(sequential_search_ordered_list(ordered_list, 8)) 42 | -------------------------------------------------------------------------------- /C/ii_variables.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | //declaring variable a,b of integer type 5 | int a,b; 6 | //declaring variable ch of character type 7 | char ch; 8 | //declaring variable f1,f2 of floating point type 9 | float f1,f2; 10 | 11 | printf("\nEnter Character:\n"); 12 | //scanf() is input function in stdio.h library 13 | //%c is field format to take character as input 14 | //input charcter is stored at location of ch 15 | scanf("%c",&ch); 16 | 17 | printf("\nEnter two number :\n"); 18 | //%d is field format for integer 19 | scanf("%d %d",&a,&b); 20 | 21 | printf("\nEnter two floating point number :\n"); 22 | //%f is field format for floating point number 23 | scanf("%f %f",&f1,&f2); 24 | 25 | //here each %d or field format is replacesd by variable value respectively 26 | printf("\nSum of %d and %d is %d\n",a,b,a+b); 27 | //Or 28 | //int c=a+b; 29 | //printf("\nSum of %d and %d is %d\n",a,b,c); 30 | 31 | //here at %d Ascii value of ch is replaced 32 | printf("\nASCII value of %c is %d\n",ch,ch); 33 | //or 34 | //int d=ch; 35 | //printf("\nASCII value of %c is %d\n",ch,d); 36 | 37 | printf("\n%f * %f = %f\n",f1,f2,f1*f2); 38 | 39 | printf("\n%0.2f * %0.3f = %0.4f\n",f1,f2,f1*f2); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /python/SortingAlgorithms/ShellSort/ShellSort.py: -------------------------------------------------------------------------------- 1 | # Shell Sort 2 | # O(n(log(n))^2) for worst and average case 3 | 4 | def shell_sort(array): 5 | 6 | # length of the sublist of array 7 | sublistCount = int(len(array)/2) 8 | 9 | print(array) 10 | 11 | # loop till the sublist's length becomes 1 12 | while sublistCount > 0: 13 | # perform insertion sort to every sublist 14 | for start in range(sublistCount): 15 | array = gap_insertion_sort(array, start, sublistCount) 16 | 17 | print("After gaps of ", sublistCount) 18 | print(array) 19 | 20 | sublistCount = int(sublistCount/2) 21 | 22 | print("\nSorted Array") 23 | return array 24 | 25 | # Logic for insertion sort 26 | def gap_insertion_sort(array, start, gap): 27 | 28 | for i in range(start + gap, len(array), gap): 29 | 30 | currentValue = array[i] 31 | pos = i 32 | 33 | while pos >= gap and array[pos-gap] > currentValue: 34 | array[pos] = array[pos-gap] 35 | pos = pos - gap 36 | 37 | array[pos] = currentValue 38 | 39 | return array 40 | 41 | array = [190, 2, 42, 8, 21, 11, 200, 13, 19] 42 | print(shell_sort(array)) -------------------------------------------------------------------------------- /java/GraphAlgorithms/BreadthFirstSearch/src/Vertex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Pranav Jain on 19-Aug-17. 3 | */ 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Vertex { 9 | 10 | //necessary variables 11 | private int data; 12 | private boolean visited; 13 | private List neighbourList; 14 | 15 | //constructor to get the things started 16 | public Vertex(int data){ 17 | this.data = data; 18 | this.neighbourList = new ArrayList<>(); 19 | } 20 | 21 | //method to add a neighbour 22 | public void addNeighbour(Vertex vertex){ 23 | this.neighbourList.add(vertex); 24 | } 25 | 26 | //getter for data 27 | public int getData() { 28 | return data; 29 | } 30 | 31 | //setter for data 32 | public void setData(int data) { 33 | this.data = data; 34 | } 35 | 36 | //getter for visited 37 | public boolean isVisited() { 38 | return visited; 39 | } 40 | 41 | //setter for visited 42 | public void setVisited(boolean visited) { 43 | this.visited = visited; 44 | } 45 | 46 | //getter for neighbour list 47 | public List getNeighbourList() { 48 | return neighbourList; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "" + this.data; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /java/GraphAlgorithms/DepthFirstSearch/src/Vertex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Pranav Jain on 19-Aug-17. 3 | */ 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Vertex { 9 | 10 | //necessary variables 11 | private int data; 12 | private boolean visited; 13 | private List neighbourList; 14 | 15 | //constructor to get the things started 16 | public Vertex(int data){ 17 | this.data = data; 18 | this.neighbourList = new ArrayList<>(); 19 | } 20 | 21 | //method to add a neighbour 22 | public void addNeighbour(Vertex vertex){ 23 | this.neighbourList.add(vertex); 24 | } 25 | 26 | //getter for data 27 | public int getData() { 28 | return data; 29 | } 30 | 31 | //setter for data 32 | public void setData(int data) { 33 | this.data = data; 34 | } 35 | 36 | //getter for visited 37 | public boolean isVisited() { 38 | return visited; 39 | } 40 | 41 | //setter for visited 42 | public void setVisited(boolean visited) { 43 | this.visited = visited; 44 | } 45 | 46 | //getter for neighbour list 47 | public List getNeighbourList() { 48 | return neighbourList; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "" + this.data; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /python/DjangoTutorial/blog/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, get_object_or_404, redirect 2 | from django.utils import timezone 3 | from blog.forms import PostForm 4 | from .models import Post 5 | 6 | # Create your views here. 7 | def post_list(request): 8 | posts = Post.objects.order_by('published_date') 9 | return render(request, 'blog/post_list.html', {'posts' : posts}) 10 | 11 | def post_detail(request, pk): 12 | post = get_object_or_404(Post, pk=pk) 13 | return render(request, 'blog/post_detail.html', {'post': post}) 14 | 15 | def post_new(request): 16 | if request.method == "POST": 17 | form = PostForm(request.POST) 18 | if form.is_valid(): 19 | post = form.save(commit=False) 20 | post.author = request.user 21 | post.published_date = timezone.now() 22 | post.save() 23 | return redirect('post_detail', pk=post.pk) 24 | else: 25 | form = PostForm() 26 | return render(request, 'blog/post_edit.html', {'form': form}) 27 | 28 | def post_edit(request, pk): 29 | post = get_object_or_404(Post, pk=pk) 30 | if request.method == "POST": 31 | form = PostForm(request.POST, instance=post) 32 | if form.is_valid(): 33 | post = form.save(commit=False) 34 | post.author = request.user 35 | post.published_date = timezone.now() 36 | post.save() 37 | return redirect('post_detail', pk=post.pk) 38 | else: 39 | form = PostForm(instance=post) 40 | return render(request, 'blog/post_edit.html', {'form': form}) -------------------------------------------------------------------------------- /python/GraphAlgorithms/Prims/Algorithm.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | class Algorithm(object): 4 | 5 | # constructor 6 | def __init__(self, unvisitedList): 7 | self.unvisitedList = unvisitedList 8 | self.spanningTree = [] 9 | self.edgeHeap = [] 10 | self.fullCost = 0 11 | 12 | # Method to construct a spanning tree 13 | def constructSpannigTree(self, vertex): 14 | 15 | # remove the root node from the unvisited list 16 | self.unvisitedList.remove(vertex) 17 | 18 | # while there are elements in the unvisited list 19 | while self.unvisitedList: 20 | 21 | # traverse through every adjacent edges of the current vertex 22 | # if the the target vertex of the edge is in the unvisited list 23 | # then add it to the heap 24 | for edge in vertex.neighbourList: 25 | if edge.targetVertex in self.unvisitedList: 26 | heapq.heappush(self.edgeHeap, edge) 27 | 28 | # get the min edge 29 | minEdge = heapq.heappop(self.edgeHeap) 30 | 31 | # append it to the tree and print the edge 32 | self.spanningTree.append(minEdge) 33 | print('%s - %s' % (minEdge.startVertex.name, minEdge.targetVertex.name)) 34 | 35 | # calculate the full cost i.e. cost of the minimum cost tree 36 | self.fullCost += minEdge.weight 37 | 38 | # update the vertex for next instance of the while loop 39 | # and also update it from the unvisited list 40 | vertex = minEdge.targetVertex 41 | self.unvisitedList.remove(vertex) -------------------------------------------------------------------------------- /python/DataStructures/BinarySearchTrees/BinarySearchTree.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class BinarySearchTree(object): 4 | 5 | # constructor 6 | # here we initialize the root node 7 | def __init__(self): 8 | self.rootNode = None 9 | 10 | # method to insert a node 11 | def insert(self, data): 12 | # if we are inserting a node for the first time 13 | if not self.rootNode: 14 | self.rootNode = Node(data) 15 | else: 16 | self.rootNode.insertRecursive(data) 17 | 18 | # method to remove a node 19 | def remove(self, dataToRemove): 20 | # check if the tree is empty or not 21 | if self.rootNode: 22 | # if we have to remove the root node 23 | if self.rootNode.data == dataToRemove: 24 | # create a new node 25 | tempNode = Node(None) 26 | # make its leftChild the rootNode 27 | tempNode.leftChild = self.rootNode 28 | # then continue with the remove process 29 | self.rootNode.removeRecursive(dataToRemove, tempNode) 30 | else: 31 | self.rootNode.removeRecursive(dataToRemove, None) 32 | 33 | # method to display the max node of the tree 34 | def getMax(self): 35 | if self.rootNode: 36 | return self.rootNode.getMax() 37 | 38 | # method to display the min node of the tree 39 | def getMin(self): 40 | if self.rootNode: 41 | return self.rootNode.getMin() 42 | 43 | # method to traverse through the tree 44 | def traverseInOrder(self): 45 | if self.rootNode: 46 | self.rootNode.traverseInOrder() -------------------------------------------------------------------------------- /java/DataStructures/Heap/Heap.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | class MaxHeap{ 3 | private int heap[]; 4 | private int size; 5 | public MaxHeap(int a[]){ 6 | size=a.length; 7 | heap=Arrays.copyOf(a,a.length); 8 | } 9 | 10 | public void build_maxheap(){ 11 | for(int i=size/2-1;i>=0;i--){ 12 | max_heapify(i); 13 | } 14 | } 15 | 16 | public void max_heapify(int i){ 17 | int r=right(i); 18 | int l=left(i); 19 | int largest; 20 | if(lheap[i]){ 21 | largest=l; 22 | } 23 | else { 24 | largest=i; 25 | } 26 | if(rheap[largest]){ 27 | largest=r; 28 | } 29 | if(largest != i){ 30 | exchange(i,largest); 31 | max_heapify(largest); 32 | } 33 | } 34 | 35 | private int right(int i){ 36 | return 2*i+2; 37 | } 38 | 39 | private int left(int i){ 40 | return 2*i+1; 41 | } 42 | 43 | private int parent(int i){ 44 | return (int)(i/2); 45 | } 46 | 47 | private void exchange(int i,int j){ 48 | int temp; 49 | temp=heap[i]; 50 | heap[i]=heap[j]; 51 | heap[j]=temp; 52 | } 53 | 54 | public void print(){ 55 | for (int i = 0;i adjlist[]; 12 | Stack finishing; 13 | private final boolean directed; 14 | Graph(int vertex,boolean directed){ 15 | this.vertex=vertex; 16 | adjlist=new LinkedList[vertex]; 17 | this.directed=directed; 18 | finishing=new Stack(); 19 | for(int i=0;i(); 21 | } 22 | } 23 | 24 | void addEdges(int u,int v){ 25 | adjlist[u].add(v); 26 | if(!directed){ 27 | adjlist[v].add(u); 28 | } 29 | } 30 | 31 | void DFS(){ 32 | int visited[]=new int[vertex]; 33 | for(int i=0;i "+temp); 62 | } 63 | System.out.println(); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /python/GraphAlgorithms/Dijkstra/Algorithm.py: -------------------------------------------------------------------------------- 1 | class Algorithm(object): 2 | 3 | # Logic to calculate the shortest path 4 | def calculateShortestPath(self, startVertex): 5 | 6 | # initialize an empty queue 7 | queue = [] 8 | # the minimum distance to the root vertex is 0 and push it in the queue 9 | startVertex.minDistance = 0 10 | queue.insert(0, startVertex) 11 | 12 | # loop till there are vertices in the queue 13 | while queue: 14 | 15 | # pop the element the from the queue 16 | currentVertex = queue.pop() 17 | 18 | # traverse through the adjacent edges of the vertex 19 | # since dijkstra follows greedy approach, 20 | # it finds global optimum from local minimum 21 | for edge in currentVertex.neighbourList: 22 | u = edge.startVertex 23 | v = edge.targetVertex 24 | newDistance = u.minDistance + edge.weight 25 | 26 | # if minimum distance is discovered then 27 | # the startVertex of the current edge becomes the predecessor of the targetVertex 28 | # the minimum distance to reach the targetVertex is updated 29 | # since we just reached the targetVertex, hence add it to the queue 30 | if newDistance < v.minDistance: 31 | v.predecessor = u 32 | v.minDistance = newDistance 33 | queue.insert(0, v) 34 | 35 | # Method to print the the shortest path to the target 36 | def getShortestPathTo(self, targetVertex): 37 | 38 | print("Shortest path to target is: ", targetVertex.minDistance) 39 | 40 | node = targetVertex 41 | 42 | while node: 43 | print("%s -> " %node.name) 44 | node = node.predecessor -------------------------------------------------------------------------------- /PHP/3_arrays.php: -------------------------------------------------------------------------------- 1 |
"; 13 | 14 | 15 | //another way(Manually adding them) of making an array. 16 | $anotherArray[0] = "pizza"; 17 | $anotherArray[1] = "pasta"; 18 | $anotherArray[2] = "burger"; 19 | //we can place value in any position. 20 | $anotherArray[5] = "paneer tikka"; 21 | //the position can also be a string. also known as associative array. 22 | $anotherArray["myFavouriteFood"] = "idk Yet"; 23 | print_r($anotherArray); 24 | echo "

"; 25 | 26 | 27 | //example of associative array. Commonly used for key and value problems. 28 | //The latter one is the cleaner one for representing the array. 29 | //$thirdArray = array("France" => "French" , "USA" => "English" , "India" => "Hindi"); 30 | $thirdArray = array( 31 | 32 | "France" => "French" , 33 | "USA" => "English" , 34 | "India" => "Hindi" 35 | 36 | ); 37 | print_r($thirdArray); 38 | 39 | //printing the size of array. 40 | echo sizeof($thirdArray); 41 | echo "

"; 42 | 43 | 44 | //a way to add another element at the last position of the non-associative array. 45 | $myArray[] = "Jain"; 46 | //Remember changes to the myArray are done after printing it for the first time. therefore it wont be shown there. 47 | //to show the changes, print it again. 48 | print_r($myArray); 49 | echo "

"; 50 | 51 | 52 | //for deleting a member, we use the unset. 53 | unset($thirdArray["France"]); 54 | print_r($thirdArray); 55 | echo sizeof($thirdArray); 56 | 57 | ?> 58 | -------------------------------------------------------------------------------- /C/iv_loop_switch.c: -------------------------------------------------------------------------------- 1 | #include 2 | //LIMIT is define as 5,So whenever limit is used tha it replaced by its value 5 3 | #define LIMIT 5 4 | int main() 5 | { 6 | int i,sum=0; 7 | //for loop 8 | //here first i is initailized to 1 .this initialization is done at starting of for loop 9 | //then it checks whether i<=LIMIT i.e i<=5 10 | //if true than block of statements of loop are executed than i++ i.e i value is increment by 1 11 | //for loop statement is executed till condition is true 12 | for (i=1;i<=LIMIT;i++){ 13 | //for loop statements 14 | sum+=i;//sum=sum+i 15 | } 16 | printf("Sum of first %d Natural number is %d\n",LIMIT,sum ); 17 | 18 | int month; 19 | printf("\nPlease enter valid month in number :\n"); 20 | scanf("%d",&month); 21 | //in switch 22 | //value inside switch(month) i.e month is matched with with value associated with each case 23 | //if match is found than value associated with that match is executed 24 | //else statement associated with default is executed 25 | switch(month){ 26 | case 1: 27 | printf("January"); 28 | break; 29 | case 2: 30 | printf("February"); 31 | break; 32 | case 3: 33 | printf("March"); 34 | break; 35 | case 4: 36 | printf("April"); 37 | break; 38 | case 5: 39 | printf("May"); 40 | break; 41 | case 6: 42 | printf("June"); 43 | break; 44 | case 7: 45 | printf("July"); 46 | break; 47 | case 8: 48 | printf("August"); 49 | break; 50 | case 9: 51 | printf("September"); 52 | break; 53 | case 10: 54 | printf("October"); 55 | break; 56 | case 11: 57 | printf("November"); 58 | break; 59 | case 12: 60 | printf("December"); 61 | break; 62 | default: 63 | printf("Sorry you enterdInvalid month enterd"); 64 | } 65 | 66 | 67 | return 0; 68 | } -------------------------------------------------------------------------------- /python/GraphAlgorithms/Dijkstra/App.py: -------------------------------------------------------------------------------- 1 | from Vertex import Vertex 2 | from Edge import Edge 3 | from Algorithm import Algorithm 4 | 5 | # create the vertices 6 | vertexA = Vertex("A") 7 | vertexB = Vertex("B") 8 | vertexC = Vertex("C") 9 | vertexD = Vertex("D") 10 | vertexE = Vertex("E") 11 | vertexF = Vertex("F") 12 | vertexG = Vertex("G") 13 | vertexH = Vertex("H") 14 | 15 | # create the edges 16 | edge1 = Edge(5, vertexA, vertexB) 17 | edge2 = Edge(8, vertexA, vertexH) 18 | edge3 = Edge(9, vertexA, vertexE) 19 | edge4 = Edge(15, vertexB, vertexD) 20 | edge5 = Edge(4, vertexB, vertexH) 21 | edge6 = Edge(12, vertexB, vertexC) 22 | edge7 = Edge(6, vertexH, vertexF) 23 | edge8 = Edge(7, vertexH, vertexC) 24 | edge9 = Edge(5, vertexE, vertexH) 25 | edge10 = Edge(4, vertexE, vertexF) 26 | edge11 = Edge(20, vertexE, vertexG) 27 | edge12 = Edge(9, vertexD, vertexG) 28 | edge13 = Edge(3, vertexC, vertexD) 29 | edge14 = Edge(11, vertexC, vertexG) 30 | edge15 = Edge(1, vertexF, vertexC) 31 | edge16 = Edge(13, vertexF, vertexG) 32 | 33 | # define the relation between the edges and vertices 34 | vertexA.neighbourList.append(edge1) 35 | vertexA.neighbourList.append(edge2) 36 | vertexA.neighbourList.append(edge3) 37 | vertexB.neighbourList.append(edge4) 38 | vertexB.neighbourList.append(edge5) 39 | vertexB.neighbourList.append(edge6) 40 | vertexH.neighbourList.append(edge7) 41 | vertexH.neighbourList.append(edge8) 42 | vertexE.neighbourList.append(edge9) 43 | vertexE.neighbourList.append(edge10) 44 | vertexE.neighbourList.append(edge11) 45 | vertexD.neighbourList.append(edge12) 46 | vertexC.neighbourList.append(edge13) 47 | vertexC.neighbourList.append(edge14) 48 | vertexF.neighbourList.append(edge15) 49 | vertexF.neighbourList.append(edge16) 50 | 51 | # apply dijkstra's algorithm 52 | dijkstra = Algorithm() 53 | dijkstra.calculateShortestPath(vertexA) 54 | dijkstra.getShortestPathTo(vertexF) -------------------------------------------------------------------------------- /C/vi_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAXLINE 1000 /*maximum input line length*/ 3 | //deeclaration of function 4 | //syntax 5 | //return-type function-name(data-tye argument-name,...); 6 | int getlines(char line[],int max); 7 | int strindex(char source[],char searchfor[]); 8 | 9 | //global variable ,i.e accessed by all function 10 | char pattern[]="ould"; 11 | int main(){ 12 | 13 | int found=0; 14 | char line[MAXLINE]; 15 | //calling function getline() 16 | //here starting address of array line[] is passed as first parameter(arguement) 17 | while(getlines(line,MAXLINE)>0){ 18 | //here calling strindex() 19 | if(strindex(line,pattern)>=0){ 20 | printf("%s",line); 21 | found++; 22 | } 23 | } 24 | return found; 25 | } 26 | //getline(): get line into s ,return length of line 27 | //function defination means define task that function is going to perform 28 | //we can use different names for arguement in declaration and defination of function 29 | //but arguement should have same type and order 30 | int getlines(char s[],int lim){ 31 | int c,i=0; 32 | //getchar() (get character) takes character i.e input entered by user through terminal (linux) or turbo C (windows) 33 | //here is automatic conversion of charcter to its ascii value in order store it in integer type variable 34 | //EOF stands for end of file 35 | while(--lim > 0 && (c = getchar())!= EOF && c!='\n'){ 36 | s[i++]=c; 37 | } 38 | if(c == '\n'){ 39 | s[i++] = c; 40 | } 41 | s[i] = '\0'; 42 | //returning back from where it has been called 43 | return i; 44 | } 45 | 46 | //strindex(): return index of t in s, -1 if none 47 | int strindex(char s[],char t[]){ 48 | int i,j,k; 49 | for(i = 0;s[i]!='\0';i++){ 50 | for(j=i,k=0; t[k]!='\0' && s[j]==t[k];j++,k++) 51 | ; 52 | if(k>0 && t[k] == '\0'){ 53 | return i; 54 | } 55 | } 56 | return -1; 57 | } 58 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/BellmanFord/Algorithm.py: -------------------------------------------------------------------------------- 1 | class Algorithm(object): 2 | 3 | # boolean variable to store value for cycles 4 | HAS_CYCLE = False 5 | 6 | # Logic to calculate the shortest path 7 | def calculateShortestPath(self, vertexList, edgeList, startVertex): 8 | 9 | # the minimum distance to the root vertex is 0 10 | startVertex.minDistance = 0 11 | 12 | # loop for number of vertices times 13 | for i in range(0, len(vertexList) - 1): 14 | 15 | # go through all the edges 16 | # major difference between dijkstra and bellman ford 17 | for edge in edgeList: 18 | 19 | u = edge.startVertex 20 | v = edge.targetVertex 21 | newDistance = u.minDistance + edge.weight 22 | 23 | # if minimum distance is discovered then 24 | # the startVertex of the current edge becomes the predecessor of the targetVertex 25 | # the minimum distance to reach the targetVertex is updated 26 | if newDistance < v.minDistance: 27 | v.minDistance = newDistance 28 | v.predecessor = u 29 | 30 | # go through the edges once more to look for cycles 31 | for edge in edgeList: 32 | 33 | if self.hasCycle(edge): 34 | print("Negative Cycle detected") 35 | Algorithm.HAS_CYCLE = True 36 | return 37 | 38 | # Logic to find the cycle in the graph 39 | def hasCycle(self, edge): 40 | if edge.startVertex.minDistance + edge.weight < edge.targetVertex.minDistance: 41 | return True 42 | else: 43 | return False 44 | 45 | # Method to print the the shortest path to the target 46 | def getShortestPathTo(self, targetVertex): 47 | 48 | if not Algorithm.HAS_CYCLE: 49 | print("Shortest path to target is: ", targetVertex.minDistance) 50 | 51 | node = targetVertex 52 | 53 | while node: 54 | print("%s -> " %node.name) 55 | node = node.predecessor -------------------------------------------------------------------------------- /python/DataStructures/Heaps/Heap.py: -------------------------------------------------------------------------------- 1 | class Heap(object): 2 | # Heap's size 3 | HEAP_SIZE = 10 4 | 5 | # constructor 6 | # here we initialize the heap and the currentPosition 7 | def __init__(self): 8 | self.heap = [0] * Heap.HEAP_SIZE 9 | self.currentPosition = -1 10 | 11 | # Logic to add elements to an heap 12 | def insert(self, data): 13 | # if heap is full then don't insert the element and return 14 | if self.isFull(): 15 | print("Heap is Full") 16 | return 17 | 18 | # increase the currentPosition 19 | self.currentPosition = self.currentPosition + 1 20 | # add the data 21 | self.heap[self.currentPosition] = data 22 | # check whether the newly added element satisfies the conditions of an heap 23 | self.fixUp(self.currentPosition) 24 | 25 | # Logic to order elements in an heap when a new element is added 26 | def fixUp(self, index): 27 | 28 | # find the currentNode's parent index number i.e. position of its parent node 29 | parentIndex = int((index - 1) / 2) 30 | 31 | # since this is a max heap, so swap elements whenever an element larger than its parent node is found 32 | # if you want the heap to be min heap then simply comment the above line and uncomment the below line 33 | # while parentIndex >= 0 and self.heap[parentIndex] < self.heap[index]: 34 | while parentIndex >= 0 and self.heap[parentIndex] < self.heap[index]: 35 | self.heap[index], self.heap[parentIndex] = self.heap[parentIndex], self.heap[index] 36 | index = parentIndex 37 | parentIndex = int((index - 1) / 2) 38 | 39 | # method to display the heap 40 | def displayHeap(self): 41 | 42 | if (self.heap): 43 | for i in self.heap: 44 | print(i) 45 | else: 46 | print("Heap is empty") 47 | 48 | # Method to find out whether the heap is full or not 49 | # used when a new element is added 50 | def isFull(self): 51 | 52 | if self.currentPosition == Heap.HEAP_SIZE: 53 | return True 54 | else: 55 | return False 56 | -------------------------------------------------------------------------------- /python/DataStructures/AVLTrees/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | # here we will create a node and initialize its left and right child with None 5 | # also balance is used here to balance the AVL tree 6 | def __init__(self, data, parentNode): 7 | self.data = data 8 | self.parentNode = parentNode 9 | self.leftChild = None 10 | self.rightChild = None 11 | self.balance = 0 12 | 13 | # method to insert nodes 14 | def insert(self, data, parentNode): 15 | 16 | # if the value of the data to be inserted is less than the current Node then go left 17 | if data < self.data: 18 | # if the leftChild is none then create node below it and the currentNode as its parentNode 19 | if not self.leftChild: 20 | self.leftChild = Node(data, parentNode) 21 | # traverse more 22 | else: 23 | self.leftChild.insert(data, parentNode) 24 | # if the value of the data to be inserted is more than the current Node then go right 25 | else: 26 | # if the rightChild is none then create node below it and the currentNode as its parentNode 27 | if not self.rightChild: 28 | self.rightChild = Node(data, parentNode) 29 | # traverse more 30 | else: 31 | self.rightChild.insert(data, parentNode) 32 | 33 | return parentNode 34 | 35 | # method to traverse in IN-ORDER way i.e. the left child + root node + the right child 36 | def traverseInorder(self): 37 | if self.leftChild: 38 | self.leftChild.traverseInorder() 39 | 40 | print(self.data) 41 | 42 | if self.rightChild: 43 | self.rightChild.traverseInorder() 44 | 45 | # method to get the maximum value 46 | def getMax(self): 47 | if not self.rightChild: 48 | return self.data 49 | else: 50 | return self.rightChild.getMax() 51 | 52 | # method to get the minimum value 53 | def getMin(self): 54 | if not self.rightChild: 55 | return self.data 56 | else: 57 | return self.leftChild.getMin() 58 | -------------------------------------------------------------------------------- /python/GraphAlgorithms/Kruskal/DisjointSet.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class DisjointSet(object): 4 | 5 | # constructor 6 | # provides the basic structure of the union find data structure 7 | def __init__(self, vertexList): 8 | self.vertexList = vertexList 9 | self.rootNodes = [] 10 | self.nodeCount = 0 11 | self.setCount = 0 12 | self.makeSets(vertexList) 13 | 14 | # find() operation traverses up from node to find root. 15 | # The idea of path compression is to make the found root as parent of node 16 | # so that we don’t have to traverse all intermediate nodes again. 17 | def find(self, node): 18 | currentNode = node 19 | 20 | while currentNode.parentNode: 21 | currentNode = currentNode.parentNode 22 | 23 | # naive implementation 24 | # return currentNode.nodeID 25 | 26 | # path compression technique used below 27 | root = currentNode 28 | currentNode = node 29 | 30 | while currentNode != root: 31 | temp = currentNode.parentNode 32 | currentNode.parentNode = root # path compression 33 | currentNode = temp 34 | 35 | return root.nodeID 36 | 37 | # Logic to do union of two sets 38 | def union(self, node1, node2): 39 | 40 | index1 = self.find(node1) 41 | index2 = self.find(node2) 42 | 43 | # if the nodes are in the same set then return 44 | if index1 == index2: 45 | return 46 | 47 | root1 = self.rootNodes[index1] 48 | root2 = self.rootNodes[index2] 49 | 50 | # Attach smaller height tree under root of high height tree 51 | if root1.height < root2.height: 52 | root1.parentNode = root2 53 | elif root1.height > root2.height: 54 | root2.parentNode = root1 55 | else: 56 | root2.parentNode = root1 57 | root1.height += 1 58 | 59 | self.setCount -= 1 60 | 61 | # Method to make sets for every vertex 62 | # in this algo, vertex refers to the vertex of the graph 63 | # and node refers to the node of the sets 64 | def makeSets(self, vertexList): 65 | for v in vertexList: 66 | self.makeSet(v) 67 | 68 | def makeSet(self, vertex): 69 | node = Node(0, len(self.rootNodes), None) 70 | vertex.parentNode = node 71 | self.rootNodes.append(node) 72 | self.setCount += 1 73 | self.nodeCount += 1 -------------------------------------------------------------------------------- /python/GraphAlgorithms/BellmanFord/App.py: -------------------------------------------------------------------------------- 1 | from Vertex import Vertex 2 | from Edge import Edge 3 | from Algorithm import Algorithm 4 | 5 | # create the vertices 6 | vertexA = Vertex("A") 7 | vertexB = Vertex("B") 8 | vertexC = Vertex("C") 9 | vertexD = Vertex("D") 10 | vertexE = Vertex("E") 11 | vertexF = Vertex("F") 12 | vertexG = Vertex("G") 13 | vertexH = Vertex("H") 14 | 15 | # create the edges 16 | edge1 = Edge(5, vertexA, vertexB) 17 | edge2 = Edge(8, vertexA, vertexH) 18 | edge3 = Edge(9, vertexA, vertexE) 19 | edge4 = Edge(15, vertexB, vertexD) 20 | edge5 = Edge(4, vertexB, vertexH) 21 | edge6 = Edge(12, vertexB, vertexC) 22 | edge7 = Edge(6, vertexH, vertexF) 23 | edge8 = Edge(7, vertexH, vertexC) 24 | edge9 = Edge(5, vertexE, vertexH) 25 | edge10 = Edge(4, vertexE, vertexF) 26 | edge11 = Edge(20, vertexE, vertexG) 27 | edge12 = Edge(9, vertexD, vertexG) 28 | edge13 = Edge(3, vertexC, vertexD) 29 | edge14 = Edge(11, vertexC, vertexG) 30 | edge15 = Edge(1, vertexF, vertexC) 31 | edge16 = Edge(13, vertexF, vertexG) 32 | 33 | # define the relation between the edges and vertices 34 | vertexA.neighbourList.append(edge1) 35 | vertexA.neighbourList.append(edge2) 36 | vertexA.neighbourList.append(edge3) 37 | vertexB.neighbourList.append(edge4) 38 | vertexB.neighbourList.append(edge5) 39 | vertexB.neighbourList.append(edge6) 40 | vertexH.neighbourList.append(edge7) 41 | vertexH.neighbourList.append(edge8) 42 | vertexE.neighbourList.append(edge9) 43 | vertexE.neighbourList.append(edge10) 44 | vertexE.neighbourList.append(edge11) 45 | vertexD.neighbourList.append(edge12) 46 | vertexC.neighbourList.append(edge13) 47 | vertexC.neighbourList.append(edge14) 48 | vertexF.neighbourList.append(edge15) 49 | vertexF.neighbourList.append(edge16) 50 | 51 | vertexList = [vertexA, vertexB, vertexC, vertexD, vertexE, vertexF, vertexG, vertexH] 52 | edgeList = [edge1, edge2, edge3, edge4, edge5, edge6, edge7, edge8, edge9, edge10, edge11, edge12, edge13, edge14, edge15, edge16] 53 | 54 | # apply Bellman-Ford algorithm 55 | bellmanFord = Algorithm() 56 | bellmanFord.calculateShortestPath(vertexList, edgeList, vertexA) 57 | bellmanFord.getShortestPathTo(vertexG) 58 | 59 | # to try a cycle example uncomment the code given below 60 | # edge1 = Edge(1, vertexA, vertexB) 61 | # edge2 = Edge(1, vertexB, vertexC) 62 | # edge3 = Edge(1, vertexC, vertexD) 63 | # edge4 = Edge(-15, vertexC, vertexB) 64 | # edge5 = Edge(300, vertexA, vertexD) 65 | # 66 | # vertexA.neighbourList.append(edge1) 67 | # vertexA.neighbourList.append(edge2) 68 | # vertexB.neighbourList.append(edge3) 69 | # vertexC.neighbourList.append(edge4) 70 | # vertexC.neighbourList.append(edge5) 71 | # 72 | # vertexList = [vertexA, vertexB, vertexC, vertexD] 73 | # edgeList = [edge1, edge2, edge3, edge4, edge5] 74 | # 75 | # bellmanFord = Algorithm() 76 | # bellmanFord.calculateShortestPath(vertexList, edgeList, vertexA) 77 | # bellmanFord.getShortestPathTo(vertexD) -------------------------------------------------------------------------------- /java/DataStructures/Queue/Myqueue.java: -------------------------------------------------------------------------------- 1 | import java.util.NoSuchElementException; 2 | class Queue{ 3 | final int MAXSIZE=50; 4 | private int queue[]; 5 | private int start; 6 | private int end; 7 | private int len; 8 | 9 | Queue(){ 10 | queue=new int[MAXSIZE]; 11 | start=-1; 12 | end=-1; 13 | len=0; 14 | } 15 | 16 | void push(int ele){ 17 | //initial stage ,first element is push in queue 18 | if(start == -1 && end == -1){ 19 | start++; 20 | end++; 21 | queue[end]=ele; 22 | len++; 23 | } 24 | //push element in queue if queue is empty 25 | else if(end >= 0 && end < MAXSIZE-1){ 26 | end++; 27 | queue[end]=ele; 28 | len++; 29 | } 30 | else{ 31 | System.out.println("Unable to push ,Queue is full"); 32 | } 33 | } 34 | 35 | void pop(){ 36 | //Queue is empty 37 | if(start==-1){ 38 | System.out.println("Queue is Empty"); 39 | } 40 | //check positon pointed by start 41 | else if(start>=0 && start0){ 67 | System.out.println("------Queue------"); 68 | for (int i=start;i<=end ;i++ ) { 69 | System.out.println(queue[i]); 70 | } 71 | } 72 | else { 73 | System.out.println("Queue is empty"); 74 | } 75 | } 76 | 77 | //return top element of queue 78 | int topQueue(){ 79 | if(len>0){ 80 | return queue[start]; 81 | } 82 | else{ 83 | throw new NoSuchElementException("Underflow Exception"); 84 | } 85 | } 86 | 87 | 88 | } 89 | class Myqueue{ 90 | public static void main(String[] args) { 91 | Queue myQueue1=new Queue(); 92 | 93 | System.out.println("-----push element in queue-----"); 94 | for (int i=0;i<10 ;i++ ) { 95 | System.out.println(i*2); 96 | myQueue1.push(i*2); 97 | } 98 | 99 | myQueue1.display(); 100 | 101 | System.out.println("length of Queue "+myQueue1.lenQueue()); 102 | 103 | System.out.println("-----pop element from queue-----"); 104 | for (int i=0;i<5 ;i++ ) { 105 | myQueue1.pop(); 106 | } 107 | 108 | myQueue1.display(); 109 | System.out.println("length of Queue "+myQueue1.lenQueue()); 110 | 111 | System.out.println("-----Top Element-----"); 112 | try{ 113 | System.out.println("Top Element of Queue "+myQueue1.topQueue()); 114 | } 115 | catch (Exception e) { 116 | System.out.println("Error "+e.getMessage()); 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /python/SearchAlgorithms/HashTable/HashTable.py: -------------------------------------------------------------------------------- 1 | class HashTable(object): 2 | 3 | # constructor 4 | # provides the basic structure of the Hash Table 5 | def __init__(self, size): 6 | self.size = size 7 | self.slots = [None] * self.size 8 | self.value = [None] * self.size 9 | 10 | # Method to insert an element in the table 11 | def insert(self, key, value): 12 | 13 | # first find a hash Value 14 | hashValue = self.hash(key, len(self.slots)) 15 | 16 | # if the slot at the above hash Value is empty 17 | if self.slots[hashValue] == None: 18 | self.slots[hashValue] = key 19 | self.value[hashValue] = value 20 | 21 | else: 22 | 23 | # if the key of the value which is being inserted 24 | # already exists then just update the value 25 | if self.slots[hashValue] == key: 26 | self.value[hashValue] = value 27 | 28 | # else find a new slot 29 | else: 30 | 31 | # take the next slot 32 | nextSlot = self.rehash(hashValue, len(self.slots)) 33 | 34 | # loop through the slots 35 | while self.slots[nextSlot] is not None and self.slots[nextSlot] is not key: 36 | nextSlot = self.rehash(nextSlot, len(self.slots)) 37 | 38 | # if we found an empty slot then insert in it 39 | if self.slots[nextSlot] == None: 40 | self.slots[nextSlot] = key 41 | self.value[nextSlot] = value 42 | 43 | # if the key of the value which is being inserted 44 | # already exists then just update the value 45 | else: 46 | self.value[nextSlot] = value 47 | 48 | # method to find the hash value 49 | def hash(self, key, size): 50 | return key%size 51 | 52 | # method to find the next hash value 53 | def rehash(self, oldHash, size): 54 | return (oldHash + 1) % size 55 | 56 | # method to get the value associated to a key 57 | def get(self, key): 58 | 59 | # initially we look for the key's corresponding original slot 60 | startSlot = self.hash(key, len(self.slots)) 61 | value = None 62 | stop = False 63 | found = False 64 | pos = startSlot 65 | 66 | # loop through the slots 67 | while self.slots[pos] is not None and not found and not stop: 68 | 69 | # if the slot is found 70 | if self.slots[pos] == key: 71 | found = True 72 | value = self.value[pos] 73 | 74 | # try the next hash 75 | else: 76 | pos = self.rehash(pos, len(self.slots)) 77 | 78 | # if we reached the first slot where we started from then stop 79 | if pos == startSlot: 80 | stop = True 81 | 82 | return value -------------------------------------------------------------------------------- /python/DataStructures/TernarySearchTrees/TST.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class TST(object): 4 | 5 | # constructor 6 | # initially rootNode points to None 7 | def __init__(self): 8 | self.rootNode = None 9 | 10 | # function to insert data into the TST 11 | def put(self, key, value): 12 | self.rootNode = self.putItem(self.rootNode, key, value, 0) 13 | 14 | # function to find the correct place to insert a value and key (one char at a time) 15 | def putItem(self, node, key, value, index): 16 | 17 | # get the character from the key 18 | # initially index is zero i.e. get the first char initially 19 | character = key[index] 20 | 21 | # if there's no node for the current character then create a new node 22 | if node is None: 23 | node = Node(character) 24 | 25 | # if the character has a lesser value than the current node then go left 26 | if character < node.char: 27 | node.leftNode = self.putItem(node.leftNode, key, value, index) 28 | 29 | # if the character has a greater value than the current node then go right 30 | elif character > node.char: 31 | node.rightNode = self.putItem(node.rightNode, key, value, index) 32 | 33 | # when the above two conditions are false 34 | # and we have not traversed through the entire characters of the key 35 | # then go middle 36 | elif index < len(key) - 1: 37 | node.middleNode = self.putItem(node.middleNode, key, value, index + 1) 38 | 39 | # insert the value here as we have traversed through the characters of the key 40 | else: 41 | node.value = value 42 | 43 | return node 44 | 45 | # function to get the value from the key 46 | def get(self, key): 47 | node = self.getItem(self.rootNode, key, 0) 48 | 49 | if node is None: 50 | return None 51 | 52 | return node.value 53 | 54 | # function to find the correct place and fetch the value from the TST 55 | def getItem(self, node, key, index): 56 | 57 | # if there's no value i.e. key is incorrect 58 | if node is None: 59 | return None 60 | 61 | # get the character from the key 62 | # initially index is zero i.e. get the first char initially 63 | character = key[index] 64 | 65 | # if the character has a lesser value than the current node then go left 66 | if character < node.char: 67 | return self.getItem(node.leftNode, key, index) 68 | 69 | # if the character has a greater value than the current node then go right 70 | elif character > node.char: 71 | return self.getItem(node.rightNode, key, index) 72 | 73 | # when the above two conditions are false 74 | # and we have not traversed through the entire characters of the key 75 | # then go middle 76 | elif index < len(key) - 1: 77 | return self.getItem(node.middleNode, key, index + 1) 78 | 79 | # return the node as we have traversed through the characters of the key 80 | else: 81 | return node 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LearnLanguages 2 | Learn new and different languages, frameworks and libraries. 3 | 4 |
5 | 6 | Hey there, 7 | 8 | This repo contains the code for learning many languages. I'll be adding more languages. 9 | 10 | **Update** - Initially I had plans to add learning code for languages only but now I'll be adding info about frameworks, data structures and libraries also. 11 | 12 | ### Target Audience 13 | 14 | 1. People who want to learn languages in a short period of time. 15 | 2. People who want the sample code for remembering the syntax of the languages. 16 | 3. People who just want to brush up or update their knowledge of a particular language. 17 | 4. People who want to just clear the basics of a language before an interview. 18 | 19 | ### Added Languages 20 | 21 | 1. ES6 (EcmaScript 2015) 22 | 2. PHP 23 | 3. C 24 | 25 | ### Added Frameworks 26 | 27 | 1. Django - Source: [Django Girls](https://tutorial.djangogirls.org/en/) The tutorial provided here contains all the information that you need to get started with django. I learnt the basics from here. In this repo, I've just posted the complete project that you can build by following the tutorial. You can follow the code given here incase you're having some problems in your code. 28 | 29 | ### Added Data Structures 30 | 31 | 1. Linked Lists - (python, java) 32 | 2. Stacks - (python, java) 33 | 3. Queues - (python, java) 34 | 4. Binary Search Trees - (python, java) 35 | 5. AVL Trees - (python) 36 | 6. Heaps - (python,java) 37 | 7. Ternary Search Trees - (python) 38 | 39 | ### Added Graph Algorithms 40 | 41 | 1. Breadth First Search - (python, java) 42 | 2. Depth First Search - (python, java) 43 | 3. Dijkstra - (python) 44 | 4. Bellman-Ford - (python) 45 | 5. Kruskal - (pyhton) 46 | 6. Prims - (python) 47 | 48 | ### Added Search Algorithms 49 | 50 | 1. Sequential Search - (python) 51 | 2. Binary Search - (python) 52 | 3. Hashing - (python) 53 | 54 | ### Added Sorting Algorithms 55 | 56 | 1. Bubble Sort - (python) 57 | 2. Selection Sort - (python) 58 | 3. Insertion Sort - (python) 59 | 4. Shell Sort - (python) 60 | 5. Merge Sort - (python) 61 | 6. Quick Sort - (python) 62 | 63 | ### Added Python Libraries 64 | 65 | 1. NumPy 66 | 2. Pandas 67 | 68 | ### Upcoming Languages 69 | 70 | 1. java 71 | 2. Python 72 | 3. C# 73 | 74 | ### Upcoming Data Structures 75 | 76 | 1. AVL Trees - (java) 77 | 78 | ### Learning/Reading Strategy for Languages only 79 | 80 | Just go through the code file from the starting. The file is prepared in a such that it starts from basics first and then covers the advanced topics. 81 | Uncomment the 'console.log' lines to read the message as you go through the code. Finally, play around the code and get your hands dirty. 82 | 83 | ### Learning/Reading Strategy for Algorithms and Data Structures 84 | 85 | Just copy the code or clone the repo and try out the code on your machine. Try to experiment with the code by changing input values. Also, print the variables at certain points for more understanding. 86 | 87 | ### Want to contribute? 88 | 89 | Sure, you can add files for new languages or can update the existing files. Just send me a pull request. 90 | 91 | ### Queries? 92 | 93 | email me at pranavj1001@gmail.com 94 | -------------------------------------------------------------------------------- /java/DataStructures/LinkedList/LinkedList.java: -------------------------------------------------------------------------------- 1 | package LinkedList; 2 | class LinkedList{ 3 | int size; 4 | Node head; 5 | Node last; 6 | 7 | LinkedList(){ 8 | size=0; 9 | head=null; 10 | last=null; 11 | } 12 | 13 | void insertAtEnd(int data){ 14 | Node newNode=new Node(data); 15 | if(head==null){ 16 | head=newNode; 17 | last=newNode; 18 | } 19 | else { 20 | last.next=newNode; 21 | last=newNode; 22 | } 23 | size++; 24 | System.out.println(data+" Sucessfully inserted"); 25 | } 26 | 27 | void insertAtPos(int data,int pos){ 28 | int tempPos=pos; 29 | Node temp; 30 | temp=head; 31 | if(size>=pos){ 32 | if(pos==0){ 33 | Node newNode=new Node(data); 34 | newNode.next=head; 35 | head=newNode; 36 | size++; 37 | } 38 | else if(size==pos){ 39 | Node newNode=new Node(data); 40 | last.next=newNode; 41 | last=newNode; 42 | size++; 43 | } 44 | else{ 45 | while(tempPos>1){ 46 | temp=temp.next; 47 | tempPos--; 48 | } 49 | Node temp1; 50 | Node newNode=new Node(data); 51 | temp1=temp.next; 52 | temp.next=newNode; 53 | newNode.next=temp1; 54 | size++; 55 | } 56 | System.out.println(data+" Sucessfully inserted at "+pos); 57 | } 58 | else{ 59 | System.out.println("Size of list is less than poition where you want to insert Node"); 60 | } 61 | } 62 | 63 | void remove(){ 64 | if(head==null){ 65 | System.out.println("List is Empty"); 66 | } 67 | else{ 68 | Node temp; 69 | temp=head; 70 | int delPos=size-1; 71 | while(delPos>1){ 72 | temp=temp.next; 73 | delPos--; 74 | } 75 | System.out.println("removed node is "+(temp.next).data); 76 | temp.next=null; 77 | last=temp; 78 | size--; 79 | } 80 | } 81 | 82 | int lenOfList(){ 83 | return size; 84 | } 85 | 86 | void traverse(){ 87 | Node temp; 88 | temp=head; 89 | if(head!=null){ 90 | System.out.println("----traversing list----"); 91 | while(temp.next!=null){ 92 | System.out.print(temp.data+" --> "); 93 | temp=temp.next; 94 | } 95 | System.out.println(temp.data); 96 | } 97 | else{ 98 | System.out.println("List is Empty"); 99 | } 100 | 101 | } 102 | 103 | public static void main(String[] args) { 104 | LinkedList ll=new LinkedList(); 105 | 106 | System.out.println("----inserting at end---- "); 107 | 108 | ll.insertAtEnd(55); 109 | ll.insertAtEnd(44); 110 | ll.insertAtEnd(23); 111 | ll.insertAtEnd(78); 112 | ll.insertAtEnd(12); 113 | ll.insertAtEnd(43); 114 | ll.insertAtEnd(92); 115 | ll.insertAtEnd(83); 116 | ll.insertAtEnd(61); 117 | ll.insertAtEnd(43); 118 | 119 | System.out.println("Length of List :"+ll.lenOfList()); 120 | 121 | ll.traverse(); 122 | 123 | ll.insertAtPos(100,4); 124 | 125 | System.out.println("Length of List :"+ll.lenOfList()); 126 | 127 | ll.traverse(); 128 | 129 | ll.insertAtPos(990,ll.lenOfList()); 130 | 131 | System.out.println("Length of List :"+ll.lenOfList()); 132 | 133 | ll.traverse(); 134 | 135 | ll.insertAtPos(77,0); 136 | 137 | System.out.println("Length of List :"+ll.lenOfList()); 138 | 139 | ll.traverse(); 140 | 141 | ll.remove(); 142 | 143 | System.out.println("Length of List :"+ll.lenOfList()); 144 | 145 | ll.traverse(); 146 | 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /python/DataStructures/AVLTrees/BalancedTree.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class BalancedTree(): 4 | 5 | def __init__(self): 6 | self.rootNode = None 7 | 8 | def insert(self, data): 9 | parentNode = self.rootNode 10 | 11 | if not self.rootNode: 12 | parentNode = Node(data, None) 13 | self.rootNode = parentNode 14 | else: 15 | parentNode = self.rootNode.insert(data, self.rootNode) 16 | 17 | self.reBalanceTree(parentNode) 18 | 19 | 20 | def reBalanceTree(self, parentNode): 21 | self.setBalance(parentNode) 22 | 23 | if parentNode.balance < -1: 24 | if self.height(parentNode.leftChild.leftChild) >= self.height(parentNode.leftChild.rightChild): 25 | parentNode = self.rotateRight(parentNode) 26 | else: 27 | parentNode = self.rotateLeftRight(parentNode) 28 | elif parentNode.balance > 1: 29 | if self.height(parentNode.rightChild.rightChild) >= self.height(parentNode.rightChild.leftChild): 30 | parentNode = self.rotateLeft(parentNode) 31 | else: 32 | parentNode = self.rotateRightLeft(parentNode) 33 | 34 | if parentNode.parentNode is not None: 35 | self.reBalanceTree(parentNode.parentNode) 36 | else: 37 | self.rootNode = parentNode 38 | 39 | def rotateLeftRight(self, node): 40 | print("Rotation left right") 41 | node.leftChild = self.rotateLeft(node.leftChild) 42 | return self.rotateRight(node) 43 | 44 | def rotateRightLeft(self, node): 45 | print("Rotation right left") 46 | node.rightChild = self.rotateRight(node.rightChild) 47 | return self.rotateLeft(node) 48 | 49 | def rotateLeft(self, node): 50 | print("Rotate Left") 51 | b = node.rightChild 52 | b.parentNode = node.parentNode 53 | 54 | node.rightChild = b.leftChild 55 | 56 | if node.rightChild is not None: 57 | node.rightChild.parentNode = node 58 | 59 | b.leftChild = node 60 | node.parentNode = b 61 | 62 | if b.parentNode is not None: 63 | if b.parentNode.rightChild == node: 64 | b.parentNode.rightChild = b 65 | else: 66 | b.parentNode.leftChild = b 67 | 68 | self.setBalance(node) 69 | self.setBalance(b) 70 | 71 | return b 72 | 73 | def rotateRight(self, node): 74 | print("Rotate Right") 75 | b = node.leftChild 76 | b.parentNode = node.parentNode 77 | 78 | node.leftChild = b.rightChild 79 | 80 | if node.leftChild is not None: 81 | node.leftChild.parentNode = node 82 | 83 | b.rightChild = node 84 | node.parentNode = b 85 | 86 | if b.parentNode is not None: 87 | if b.parentNode.rightChild == node: 88 | b.parentNode.rightChild = b 89 | else: 90 | b.parentNode.leftChild = b 91 | 92 | self.setBalance(node) 93 | self.setBalance(b) 94 | 95 | return b 96 | 97 | def setBalance(self, node): 98 | node.balance = (self.height(node.rightChild) - self.height(node.leftChild)) 99 | 100 | 101 | def height(self, node): 102 | if not node: 103 | return -1 104 | else: 105 | return 1 + max(self.height(node.leftChild), self.height(node.rightChild)) 106 | 107 | def tarverseInOrder(self): 108 | self.rootNode.traverseInorder() -------------------------------------------------------------------------------- /python/DjangoTutorial/DjangoTutorial/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for DjangoTutorial project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.11.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.11/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['127.0.0.1', 'pranavj1001.pythonanywhere.com'] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'blog', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'DjangoTutorial.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')] 59 | , 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'DjangoTutorial.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.sqlite3', 81 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 82 | } 83 | } 84 | 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | # Internationalization 106 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 107 | 108 | LANGUAGE_CODE = 'en-us' 109 | 110 | TIME_ZONE = 'Asia/Kolkata' 111 | 112 | USE_I18N = True 113 | 114 | USE_L10N = True 115 | 116 | USE_TZ = True 117 | 118 | 119 | # Static files (CSS, JavaScript, Images) 120 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 121 | 122 | STATIC_URL = '/static/' 123 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') 124 | -------------------------------------------------------------------------------- /python/DataStructures/BinarySearchTrees/Node.py: -------------------------------------------------------------------------------- 1 | class Node(object): 2 | 3 | # constructor 4 | # here we will create a node and initialize its left and right child with None 5 | def __init__(self, data): 6 | self.data = data 7 | self.leftChild = None 8 | self.rightChild = None 9 | 10 | # method to insert nodes 11 | def insertRecursive(self, data): 12 | 13 | # if the value of the data to be inserted is less than the current Node then go left 14 | if data < self.data: 15 | 16 | # the current node has no left child 17 | if not self.leftChild: 18 | self.leftChild = Node(data) 19 | 20 | # the current node has a left child 21 | else: 22 | self.leftChild.insertRecursive(data) 23 | 24 | # if the value of the data to be inserted is more than the current Node then go right 25 | else: 26 | 27 | # the current node has no right child 28 | if not self.rightChild: 29 | self.rightChild = Node(data) 30 | 31 | # the current node has a right child 32 | else: 33 | self.rightChild.insertRecursive(data) 34 | 35 | # method to remove a node 36 | def removeRecursive(self, data, parentNode): 37 | 38 | # if and elif's aim is to reach to the node which is to be removed 39 | 40 | # if the data to be removed is less than the current node then go left 41 | if data < self.data: 42 | if self.leftChild: 43 | self.leftChild.removeRecursive(data, self) 44 | 45 | # if the data to be removed is more than the current node then go right 46 | elif data > self.data: 47 | if self.rightChild: 48 | self.rightChild.removeRecursive(data, self) 49 | 50 | # we reached the node which is to be removed 51 | else: 52 | 53 | # if the node has 2 children (left and right) 54 | if self.leftChild and self.rightChild: 55 | self.data = self.rightChild.getMin() 56 | self.rightChild.removeRecursive(self.data, self) 57 | 58 | # if the parent node has one left child 59 | elif parentNode.leftChild == self: 60 | 61 | # if the node to be removed has a left child 62 | if self.leftChild: 63 | tempNode = self.leftChild 64 | 65 | # if the node to be removed has a right child 66 | else: 67 | tempNode = self.rightChild 68 | 69 | parentNode.leftChild = tempNode 70 | 71 | # if the parent node has one right child 72 | elif parentNode.rightChild == self: 73 | 74 | # if the node to be removed has a left child 75 | if self.leftChild: 76 | tempNode = self.leftChild 77 | 78 | # if the node to be removed has a right child 79 | else: 80 | tempNode = self.rightChild 81 | 82 | parentNode.rightChild = tempNode 83 | 84 | # method to get the minimum value 85 | def getMin(self): 86 | 87 | if not self.leftChild: 88 | return self.data 89 | else: 90 | return self.leftChild.getMin() 91 | 92 | # method to get the maximum value 93 | def getMax(self): 94 | 95 | if not self.rightChild: 96 | return self.data 97 | else: 98 | return self.rightChild.getMax() 99 | 100 | # method to traverse in IN-ORDER way i.e. the left child + root node + the right child 101 | def traverseInOrder(self): 102 | 103 | if self.leftChild: 104 | self.leftChild.traverseInOrder() 105 | 106 | print(self.data) 107 | 108 | if self.rightChild: 109 | self.rightChild.traverseInOrder() -------------------------------------------------------------------------------- /java/DataStructures/BinarySearchTree/BST.java: -------------------------------------------------------------------------------- 1 | package BinarySearchTree; 2 | class BST{ 3 | //this will be pointing to root of tree 4 | Node root; 5 | BST(){ 6 | root=null; 7 | } 8 | void insert(int d){ 9 | if(root==null){ 10 | Node newNode = new Node (d) ; 11 | root=newNode; 12 | } 13 | else{ 14 | inserting(root,d); 15 | } 16 | System.out.println("Successfully inserted node "+d); 17 | } 18 | 19 | void inserting(Node tempRoot,int d){ 20 | if(tempRoot.data > d){ 21 | if(tempRoot.left == null){ 22 | tempRoot.left=new Node(d); 23 | } 24 | else{ 25 | inserting(tempRoot.left,d); 26 | } 27 | } 28 | else if (tempRoot.data == d) { 29 | //return 0; 30 | } 31 | else { 32 | if(tempRoot.right == null){ 33 | tempRoot.right=new Node(d); 34 | } 35 | else{ 36 | inserting(tempRoot.right,d); 37 | } 38 | } 39 | } 40 | void preorder(Node root){ 41 | if(root == null){ 42 | //System.out.println("tree is Empty"); 43 | } 44 | else { 45 | System.out.print(root.data+" "); 46 | preorder(root.left); 47 | preorder(root.right); 48 | } 49 | } 50 | void inorder(Node root){ 51 | if (root == null) { 52 | //System.out.println("tree is Empty"); 53 | } 54 | else { 55 | inorder(root.left); 56 | System.out.print(root.data+" "); 57 | inorder(root.right); 58 | } 59 | } 60 | void postorder(Node root){ 61 | if (root == null) { 62 | //System.out.println("tree is Empty"); 63 | } 64 | if (root != null) { 65 | postorder(root.left); 66 | postorder(root.right); 67 | System.out.print(root.data+" "); 68 | } 69 | } 70 | int getMin(Node root){ 71 | if(root.left == null){ 72 | return root.data; 73 | } 74 | else { 75 | return getMin(root.left); 76 | } 77 | } 78 | int getMax(Node root){ 79 | if(root.right == null){ 80 | return root.data; 81 | } 82 | else { 83 | return getMax(root.right); 84 | } 85 | } 86 | void delete(int d){ 87 | root=deleting(root,d); 88 | } 89 | 90 | Node deleting(Node root ,int d){ 91 | if(root == null){ 92 | return root; 93 | } 94 | if(d > root.data){ 95 | root.right = deleting(root.right,d); 96 | } 97 | else if (d < root.data) { 98 | root.left = deleting(root.left,d); 99 | } 100 | else{ 101 | if (root.left == null) { 102 | return root.right; 103 | } 104 | else if (root.right == null) { 105 | return root.left; 106 | } 107 | root.data = getMin(root.right); 108 | root.right=deleting(root.right,root.data); 109 | } 110 | return root; 111 | 112 | } 113 | 114 | public static void main(String[] args) { 115 | BST binaryST=new BST(); 116 | 117 | System.out.println("inserting node in trees"); 118 | 119 | binaryST.insert(14); 120 | binaryST.insert(15); 121 | binaryST.insert(4); 122 | binaryST.insert(9); 123 | binaryST.insert(7); 124 | binaryST.insert(18); 125 | binaryST.insert(3); 126 | binaryST.insert(5); 127 | binaryST.insert(16); 128 | binaryST.insert(4); 129 | binaryST.insert(20); 130 | binaryST.insert(17); 131 | binaryST.insert(9); 132 | binaryST.insert(14); 133 | binaryST.insert(5); 134 | 135 | System.out.println("preorder traversal is"); 136 | binaryST.preorder(binaryST.root); 137 | System.out.println(); 138 | 139 | System.out.println("inorder traversal is"); 140 | binaryST.inorder(binaryST.root); 141 | System.out.println(); 142 | 143 | System.out.println("postorder traversal is"); 144 | binaryST.postorder(binaryST.root); 145 | System.out.println(); 146 | 147 | 148 | System.out.println("Minimum value of node in tree:"+binaryST.getMin(binaryST.root)); 149 | 150 | System.out.println("Maximum value of node in tree:"+binaryST.getMax(binaryST.root)); 151 | 152 | System.out.println("Before deleting Node "+18); 153 | binaryST.inorder(binaryST.root); 154 | System.out.println(); 155 | binaryST.delete(18); 156 | System.out.println("After deleting Node "+18); 157 | binaryST.inorder(binaryST.root); 158 | System.out.println(); 159 | } 160 | } -------------------------------------------------------------------------------- /java/JavaTutorial/src/ControlStatements.java: -------------------------------------------------------------------------------- 1 | public class ControlStatements { 2 | public static void main(String args[]){ 3 | /* 4 | * if-else-if statement 5 | * The `if` statements are executed from the top down. 6 | * As soon as one of the conditions controlling the `if` is true, the statement associated with that `if` is executed, and the rest of 7 | the ladder i.e `else if` statement is bypassed. 8 | *If none of the conditions is true, then the final `else` statement will be executed. 9 | * The final `else` acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. 10 | *If there is no final `else` and all other conditions 11 | are false, then no action will take place. 12 | * */ 13 | int month = 4; 14 | String season; 15 | if(month == 12 || month == 1 || month == 2) { 16 | season = "Winter"; 17 | } 18 | else if(month == 3 || month == 4 || month == 5) { 19 | season = "Spring"; 20 | } 21 | else if(month == 6 || month == 7 || month == 8) { 22 | season = "Summer"; 23 | } 24 | else if(month == 9 || month == 10 || month == 11) { 25 | season = "Autumn"; 26 | } 27 | else { 28 | season = "Bogus Month"; 29 | } 30 | System.out.println("April is in the " + season + "."); 31 | 32 | 33 | /* 34 | * Switch statement 35 | * The `switch` statement is Java’s multiway branch statement. It provides an easy way to 36 | dispatch execution to different parts of your code based on the value of an expression. */ 37 | /*The `switch` statement works like this: The value of the expression is compared with each of 38 | the values in the `case` statements. If a match is found, the code sequence following that `case` 39 | statement is executed. If none of the constants matches the value of the expression, then the 40 | `default` statement is executed. However, the `default` statement is optional. If no `case` matches 41 | and no `default` is present, then no further action is taken. 42 | The break statement is used inside the switch to terminate a statement sequence. When a 43 | `break` statement is encountered, execution branches to the first line of code that follows the 44 | entire `switch` statement. This has the effect of “jumping out” of the switch. 45 | Note :Value specified with case should be unique i.e no two case should have same value 46 | */ 47 | /*for loop 48 | * for loop consist of initialization ,test-condition ,iteration 49 | * initialization is done at start of for-loop and it is done once. Generally, this is an expression that sets the value of the loop control variable, 50 | which acts as a counter that controls the loop. 51 | * test-condition it has some boolean value true or false 52 | * if test-condition is true than group of statement is executed 53 | * iteration this is usually an expression that increments or decrements the loop control variable 54 | */ 55 | /* flow of for-loop 56 | * initialization 57 | * than check condition if its true than group of statement is executed else terminate loop 58 | * iterate loop variable ,than again check condition than iteration and soon*/ 59 | for(int i=0; i<6; i++) { 60 | switch (i) { 61 | case 0: 62 | System.out.println("i is zero."); 63 | break; 64 | case 1: 65 | System.out.println("i is one."); 66 | break; 67 | case 2: 68 | System.out.println("i is two."); 69 | break; 70 | case 3: 71 | System.out.println("i is three."); 72 | break; 73 | default: 74 | System.out.println("i is greater than 3."); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ES6/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Password Generator 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 53 | 54 |
55 | 56 |
57 |

Secure Code Generator

58 |

This webapp simply creates unique secure code which can be used as your password or as an uniqueURL code.

59 |

The whole app is developed majorly from ES6.

60 |
61 | 62 |
63 | 64 | 65 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /python/DataStructures/LinkedLists/LinkedList.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class LinkedList(object): 4 | 5 | # constructor 6 | # here we will initialize current head and the counter 7 | def __init__(self): 8 | self.head = None 9 | self.counter = 0 10 | 11 | # O(1) method to add elements at starting position 12 | def insertAtStart(self, data): 13 | 14 | # increment counter 15 | self.counter += 1 16 | 17 | # make a new node 18 | newNode = Node(data) 19 | 20 | # if we are inserting the first element to a linked list which no nodes till now 21 | if not self.head: 22 | # the head now points to the first element 23 | self.head = newNode 24 | 25 | # if we are inserting the first element to a linked list which already has > 0 nodes 26 | else: 27 | # the new node's nextnode now points to the previous node 28 | newNode.nextNode = self.head 29 | # the head now points to the first element 30 | self.head = newNode 31 | 32 | # O(1) method to find number of elements of a linkedlist 33 | def size(self): 34 | print("Size ->", self.counter) 35 | 36 | # O(n) method to insert a node at the end 37 | def insertAtEnd(self, data): 38 | 39 | # if the linked list didn't have any prior elements then call insertAtStart function 40 | if not self.head: 41 | self.insertAtStart(data) 42 | return 43 | 44 | # increment counter 45 | self.counter += 1 46 | 47 | # create a new node 48 | newNode = Node(data) 49 | # for traversing create a current node 50 | actualNode = self.head 51 | 52 | # traverse till we not reach the end 53 | while actualNode.nextNode: 54 | actualNode = actualNode.nextNode 55 | 56 | # now add the new node 57 | actualNode.nextNode = newNode 58 | 59 | # O(n) method to add an element in a given position 60 | def insertAtPosition(self, data, position): 61 | 62 | # if user gave wrong values for the position 63 | if (position < 0) or (position > self.counter): 64 | print("Sorry can't add") 65 | 66 | # if user wants to add the element at start 67 | elif position == 0: 68 | self.insertAtStart(data) 69 | 70 | # logic to add elements in between 71 | else: 72 | 73 | # increment counter 74 | self.counter += 1 75 | 76 | # create a new node 77 | newNode = Node(data) 78 | # for traversing create a current node 79 | actualNode = self.head 80 | 81 | # traverse till we not reach the position 82 | for i in range(0, position-1): 83 | actualNode = actualNode.nextNode 84 | 85 | # temporary variable to hold the nextNode value 86 | temp = actualNode.nextNode 87 | 88 | # now add the new node 89 | actualNode.nextNode = newNode 90 | # update the nextNode value of the new node 91 | newNode.nextNode = temp 92 | 93 | # O(n) method to remove an node 94 | def remove(self, data): 95 | 96 | # decrement counter 97 | self.counter -= 1 98 | 99 | # make sure that there are nodes in the linked list and start doesn't point to None 100 | if self.head: 101 | # if our luck shines and the start points to the node which we want to remove 102 | if data == self.head.data: 103 | # now head points to the next node 104 | self.head = self.head.nextNode 105 | 106 | # if start doesn't point to the node which we want to remove 107 | else: 108 | # call the function from Node.py 109 | self.head.removeRecursive(data, self.head) 110 | 111 | # O(n) method to traverse through the linked list 112 | def traverseList(self): 113 | 114 | # for traversing create a current node 115 | actualNode = self.head 116 | 117 | # traverse through the linked list and print the nodes 118 | while actualNode: 119 | print("%d" % actualNode.data) 120 | actualNode = actualNode.nextNode -------------------------------------------------------------------------------- /Rust/rust.rs: -------------------------------------------------------------------------------- 1 | // Chapter 1 2 | // ------------------ print macros start ------------------ 3 | // Macros: Macros look like functions, except that their name ends with a bang !, 4 | // but instead of generating a function call, macros are expanded into source code 5 | // that gets compiled with the rest of the program. eg. println! 6 | // println! -> prints statement to console in a new line 7 | 8 | // !!!--- start uncommenting from line below ---!!! 9 | // fn main() { 10 | // println!("April has {} days.", 31); 11 | // println!("{month} has {numberOfDays} days.", 12 | // month = "January", 13 | // numberOfDays = "31"); 14 | // // Special formating is used here 15 | // // {:b} -> converts 2 to 10 (binary form) 16 | // println!("{} of {:b} people know binary, the other half doesn't", 1, 2); 17 | // let width = 6; 18 | // println!("{number:>width$} {spaces} spaces and {number}", number = 1, width = width, spaces = width - 1); 19 | // println!("{}", format!("{:05}", 12)); 20 | 21 | // // rounds off the number 22 | // let pi = 3.141592; 23 | // println!("Pi is roughly {:.3}", pi); 24 | // } 25 | // !!!--- end uncommenting from line above ---!!! 26 | // ------------------ print macros end ------------------ 27 | 28 | // Chapter 2 29 | // ------------------ Debugging start ------------------ 30 | // In JS we use console.log() for logging and debugging purposes. 31 | // console.log() can be used to print pretty any type of object. 32 | // However, in Rust this is not possible as all types which want to use 33 | // std::fmt formatting traits require an implementation to be printable. 34 | // The fmt::Debug trait makes this very straightforward. 35 | // All types can derive (automatically create) the fmt::Debug implementation. 36 | // This is not true for fmt::Display which must be manually implemented. 37 | // Below given example shows automatic derive(Debug) implementation 38 | // and manual Display implementation. 39 | 40 | // !!!--- start uncommenting from line below ---!!! 41 | // Import (via `use`) the `fmt` module to make it available. 42 | // use std::fmt::{self, Formatter, Display}; 43 | // #[derive(Debug)] 44 | // struct Person<'a> { 45 | // name: &'a str, 46 | // age: u8 47 | // } 48 | 49 | // // Implement `Display` for `Person`. 50 | // impl<'a> fmt::Display for Person<'a> { 51 | // fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 52 | // // Try `write!` to see if it errors. If it errors, return 53 | // // the error. Otherwise continue. 54 | // write!(f, "(Name is {} and Age is {})", self.name, self.age)?; 55 | // write!(f, "") 56 | // } 57 | // } 58 | 59 | // #[derive(Debug)] 60 | // struct Color { 61 | // red: u8, 62 | // green: u8, 63 | // blue: u8, 64 | // } 65 | 66 | // impl Display for Color { 67 | // // `f` is a buffer, this method must write the formatted string into it 68 | // fn fmt(&self, f: &mut Formatter) -> fmt::Result { 69 | // // `write!` is like `format!`, but it will write the formatted string 70 | // // into a buffer (the first argument) 71 | // write!(f, "RGB ({}, {}, {}) 0x{:02.X}{:02.X}{:02.X}", 72 | // self.red, self.green, self.blue, self.red, self.green, self.blue) 73 | // } 74 | // } 75 | 76 | // fn main() { 77 | // let name = "Peter"; 78 | // let age = 27; 79 | // let peter = Person { name, age }; 80 | 81 | // println!("Compare Person"); 82 | // println!("Debug: Normal {:?}", peter); 83 | // println!("Debug: Pretty {:#?}", peter); 84 | // println!("Display: {}", peter); 85 | 86 | // for color in [ 87 | // Color { red: 128, green: 255, blue: 90 }, 88 | // Color { red: 0, green: 3, blue: 254 }, 89 | // Color { red: 0, green: 0, blue: 0 }, 90 | // ].iter() { 91 | // // Switch this to use {} once you've added an implementation 92 | // // for fmt::Display 93 | // println!("{:}", *color); 94 | // } 95 | // } 96 | // !!!--- end uncommenting from line above ---!!! 97 | // ------------------ Debugging end ------------------ 98 | 99 | // Chapter 3 100 | // ------------------ Primitives start ------------------ 101 | // Rust provides access to a wide variety of primitives. 102 | 103 | // !!!--- start uncommenting from line below ---!!! 104 | // use std::fmt; 105 | // use std::mem; 106 | 107 | // #[derive(Debug)] 108 | // struct Matrix(f32, f32, f32, f32); 109 | 110 | // impl fmt::Display for Matrix { 111 | // // `f` is a buffer, this method must write the formatted string into it 112 | // fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 113 | // write!(f, "( {} {} ) \n( {} {} )", self.0, self.1, self.2, self.3) 114 | // } 115 | // } 116 | 117 | // fn transpose(matrix: Matrix) -> Matrix { 118 | // Matrix(matrix.0, matrix.2, matrix.1, matrix.3) 119 | // } 120 | 121 | // // This function borrows a slice 122 | // fn analyze_slice(slice: &[i32]) { 123 | // println!("first element of the slice: {}", slice[0]); 124 | // println!("the slice has {} elements", slice.len()); 125 | // } 126 | 127 | // fn main() { 128 | // // Variables can be type annotated. 129 | // let logical: bool = true; 130 | 131 | // let a_float: f64 = 1.0; // Regular annotation 132 | // let an_integer = 5i32; // Suffix annotation 133 | 134 | // // Or a default will be used. 135 | // let default_float = 3.0; // `f64` 136 | // let default_integer = 7; // `i32` 137 | 138 | // // A type can also be inferred from context 139 | // let mut inferred_type = 12; // Type i64 is inferred from another line 140 | // inferred_type = 4294967296i64; 141 | 142 | // // A mutable variable's value can be changed. 143 | // let mut mutable = 12; // Mutable `i32` 144 | // mutable = 21; 145 | 146 | // // Error! The type of a variable can't be changed. 147 | // //mutable = true; 148 | 149 | // // Variables can be overwritten with shadowing. 150 | // let mutable = true; 151 | 152 | // // Integer addition 153 | // // We need to tell the compiler the type of the literals we use. 154 | // println!("1 + 2 = {}", 1u32 + 2); 155 | 156 | // // Integer subtraction 157 | // // We need to tell the compiler the type of the literals we use. 158 | // println!("1 - 2 = {}", 1i32 - 2); 159 | 160 | // // Short-circuiting boolean logic 161 | // println!("true AND false is {}", true && false); 162 | // println!("true OR false is {}", true || false); 163 | // println!("NOT true is {}", !true); 164 | 165 | // // Bitwise operations 166 | // println!("0011 AND 0101 is {:04b}", 0b0011u32 & 0b0101); 167 | // println!("0011 OR 0101 is {:04b}", 0b0011u32 | 0b0101); 168 | // println!("0011 XOR 0101 is {:04b}", 0b0011u32 ^ 0b0101); 169 | // println!("1 << 5 is {}", 1u32 << 5); 170 | // println!("0x80 >> 2 is 0x{:x}", 0x80u32 >> 2); 171 | 172 | // // Use underscores to improve readability! 173 | // println!("One million is written as {}", 1_000_000u32); 174 | 175 | // // A tuple with a bunch of different types 176 | // let long_tuple = (1u8, 2u16, 3u32, 4u64, 177 | // -1i8, -2i16, -3i32, -4i64, 178 | // 0.1f32, 0.2f64, 179 | // 'a', true); 180 | 181 | // // Values can be extracted from the tuple using tuple indexing 182 | // println!("long tuple first value: {}", long_tuple.0); 183 | // println!("long tuple second value: {}", long_tuple.1); 184 | 185 | // // Tuples can be tuple members 186 | // let tuple_of_tuples = ((1u8, 2u16, 2u32), (4u64, -1i8), -2i16); 187 | 188 | // // Tuples are printable 189 | // println!("tuple of tuples: {:?}", tuple_of_tuples); 190 | 191 | // // But long Tuples cannot be printed 192 | // // let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13); 193 | // // println!("too long tuple: {:?}", too_long_tuple); 194 | // // TODO ^ Uncomment the above 2 lines to see the compiler error 195 | 196 | // // To create one element tuples, the comma is required to tell them apart 197 | // // from a literal surrounded by parentheses 198 | // println!("one element tuple: {:?}", (5u32,)); 199 | // println!("just an integer: {:?}", (5u32)); 200 | 201 | // //tuples can be destructured to create bindings 202 | // let tuple = (1, "hello", 4.5, true); 203 | 204 | // let (a, b, c, d) = tuple; 205 | // println!("{:?}, {:?}, {:?}, {:?}", a, b, c, d); 206 | 207 | // let matrix = Matrix(1.1, 1.2, 2.1, 2.2); 208 | // println!("{:?}", matrix); 209 | // println!("{}", matrix); 210 | // println!("{}", transpose(matrix)); 211 | 212 | // // Fixed-size array (type signature is superfluous) 213 | // let xs: [i32; 5] = [1, 2, 3, 4, 5]; 214 | 215 | // // All elements can be initialized to the same value 216 | // let ys: [i32; 500] = [0; 500]; 217 | 218 | // // Indexing starts at 0 219 | // println!("first element of the array: {}", xs[0]); 220 | // println!("second element of the array: {}", xs[1]); 221 | 222 | // // `len` returns the size of the array 223 | // println!("array size: {}", ys.len()); 224 | 225 | // // Arrays are stack allocated 226 | // println!("array occupies {} bytes", mem::size_of_val(&ys)); 227 | 228 | // // Arrays can be automatically borrowed as slices 229 | // println!("borrow the whole array as a slice"); 230 | // analyze_slice(&xs); 231 | 232 | // // Slices can point to a section of an array 233 | // println!("borrow a section of the array as a slice"); 234 | // analyze_slice(&ys[1 .. 4]); 235 | 236 | // // Out of bound indexing causes compile error 237 | // // println!("{}", xs[5]); 238 | // } 239 | // !!!--- end uncommenting from line above ---!!! 240 | // ------------------ Primitives end ------------------ 241 | 242 | // Chapter 4 243 | // ------------------ Custom Types start ------------------ 244 | // Rust custom data types are formed mainly through the two keywords: 245 | 246 | // struct: define a structure 247 | // enum: define an enumeration 248 | // Constants can also be created via the const and static keywords. 249 | 250 | // !!!--- start uncommenting from line below ---!!! 251 | 252 | // !!!--- end uncommenting from line above ---!!! 253 | 254 | // ------------------ Custom Types end -------------------- -------------------------------------------------------------------------------- /ES6/app/es6.js: -------------------------------------------------------------------------------- 1 | console.log("Hey, there!"); 2 | 3 | //simple ES5 var declaration 4 | var limit = 1000; 5 | //console.log(limit); 6 | 7 | //ES6 var declaration 8 | let newLimit = 10000; 9 | newLimit += 100;//you can change the value of the 'let' var 10 | //console.log(newLimit); 11 | 12 | //ES6 const var declaration 13 | const absoluteLimit = 100000; 14 | //absoluteLimit += 1100; will show error 15 | //console.log(absoluteLimit); 16 | 17 | //not able to change data doesn't prevent us from manipulating the data 18 | const fruits = ['apple', 'mango', 'strawberry']; 19 | fruits.push('pineapple');//you cannot reassign data but you can add data 20 | //console.log(fruits); 21 | 22 | //Block Scoping 23 | //advantage of 'let' 24 | let var1 = 10; 25 | 26 | { 27 | let var1 = 100; 28 | //console.log('Block var1', var1); 29 | } 30 | 31 | //console.log('original var1', var1); 32 | //Output: 33 | //Block var1 10 34 | //original var 10 35 | //let supports Block Scoping 36 | 37 | //if we were using the old style ie 'var' 38 | var var2 = 20; 39 | 40 | { 41 | var var2 = 50; 42 | //console.log('Block var2', var2); 43 | } 44 | 45 | //console.log('original var2', var2); 46 | //Output: 47 | //Block var2 50 48 | //original var2 50 49 | //var doesn't support Block Scoping 50 | 51 | //if we use the const type declaration 52 | const var3 = 30; 53 | 54 | { 55 | const var3 = 300; 56 | //console.log('Block var3', var3); 57 | } 58 | 59 | //console.log('original var3', var3); 60 | //Output: 61 | //Block var3 30 62 | //original var3 300 63 | //const supports Block Scoping 64 | 65 | //Template Literals 66 | //referred to strings that have embedded expressions within them 67 | let companyName = 'bmw'; 68 | let carName = companyName + ' x5';//traditional method 69 | //console.log(carName); 70 | let fullCarName = `${companyName} x5`;//Template Literal is used here. Note you have to use `` and not this '' 71 | //console.log(fullCarName); 72 | 73 | //Spread Operators 74 | //one simply pass an array with Spread Operators 75 | let array1 = [10, 20, 30, 40]; 76 | let array2 = [...array1, 50, 60];//value of array1 is spreaded in array2 77 | //console.log(array2); 78 | 79 | //Rest Parameters 80 | //similar to Spread Operators 81 | function getNumbers(...array3){ 82 | //console.log(array3); 83 | } 84 | //getNumbers(array2); 85 | getNumbers(2, 5, 7 , 8, 9); 86 | 87 | //Destructuring Assignments 88 | //The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. 89 | //for arrays 90 | let array4 = [1, 2, 3]; 91 | //the traditional way 92 | //let one = array4[0]; 93 | //let two = array4[1]; 94 | //with Destructuring Assignments 95 | let [one, twos] = array4; 96 | //console.log(one, twos); 97 | //for objects 98 | let person = {name: 'Dovah', heightInCm: '180', weightInKg: '82'}; 99 | //the traditional way 100 | //let heightInCm = person.heightInCm; 101 | //let weightInKg = person.weightInKg; 102 | //Destructuring Assignments 103 | //let {heightInCm, weightInKgs} = person; wont work, the names should match the names in the objArray 104 | let {heightInCm, weightInKg} = person; 105 | //console.log(heightInCm, weightInKg); 106 | 107 | //Arrow function 108 | //Arrow Functions are considered to be Anonymous by default 109 | //the traditional Anonymous function expression 110 | // var greet = function() { 111 | // console.log("Hello"); 112 | // } 113 | //the Anonymous arrow function expression 114 | //similarly you can also define arrow functions for other Anonymous functions like the one in setTimeout(()=>{},timeInMSecs); 115 | //just remember the '=>' 116 | let greet = () => { 117 | //console.log("Hola"); 118 | } 119 | greet(); 120 | 121 | //Helper Methods 122 | //Types of Helper Methods 123 | // 1) Map Helper Metods 124 | let numberArray = [10, 20, 30]; 125 | // let square = (number) => { 126 | // return number * number; 127 | // } 128 | // let squaredArray = numberArray.map(square); 129 | // or 130 | let squaredArray = numberArray.map((number) => number * number ); 131 | //console.log(squaredArray); 132 | // 2) Filter Helper Methods 133 | let fruitPrices = [12, 15, 25, 10, 19, 22]; 134 | let reasonableFruitPrices = fruitPrices.filter((price) => price <= 15); 135 | //console.log(reasonableFruitPrices); 136 | 137 | //String Helper Methods 138 | // 1) Repeat Method 139 | //used to create a large string by just concatenating string a number of times 140 | //let stringToRepeat = "Witcher 3 is the" + "e".repeat(3) + " game" + "!".repeat(5); 141 | //let us use the Template Literals 142 | let stringToRepeat = `Witcher 3 is the${"e".repeat(3)} game${"!".repeat(5)}`; 143 | //console.log(stringToRepeat); 144 | // 2) startsWith and endsWith 145 | //will return a boolean value 146 | //console.log(stringToRepeat.startsWith("Witcher"));//O/P -> true//endsWith is similar except the obvious change. 147 | // 3) includes 148 | //will return a boolean value 149 | //just search for the string in a string 150 | //console.log(stringToRepeat.includes("ee"));//O/P -> true 151 | 152 | //check numbers 153 | // 1) isFinite helps to validate our code to help us to not to break our code 154 | let luggageInfo = (name, weight) => { 155 | return Number.isFinite(weight); 156 | } 157 | // console.log(luggageInfo('mobile', Infinity));//O/P -> false 158 | // console.log(luggageInfo('mobile', 45));//O/P -> true 159 | // console.log(luggageInfo('mobile', Math.pow(9, 67)));//O/P -> true 160 | 161 | // 2) isSafeInteger, in above isFinite returned true when put the weight as 9^67 but JS handles numbers only upto 2^53, so 9^67 cannot be handled in usual manners and thus its not a safe isSafeInteger 162 | let safeLuggageInfo = (name, weight) => { 163 | return Number.isSafeInteger(weight); 164 | } 165 | // console.log(safeLuggageInfo('mobile', Math.pow(9, 67)));//O/P -> false 166 | 167 | //Modules 168 | //Modules refer to reusable pieces of code in our application. 169 | //they appear independently in their own separate files 170 | import {carCompanies, carModels, divide} from './exampleModule' 171 | //import divie from './exampleModule' //syntax to get the default method 172 | //console.log(carCompanies, carModels); 173 | //console.log(divide(4,2)); 174 | 175 | //Class 176 | //Classes are "special functions", and just as you can define function expressions and function declarations, the class syntax has two components: class expressions and class declarations 177 | //Unlike Functions, classes are not hoisted 178 | //this will throw an error 179 | // var p = new Rectangle(); // ReferenceError 180 | // class Rectangle {} 181 | //Class Declaration: 182 | class Rectangle1 { 183 | constructor(height, width, colour) { 184 | this.height = height; 185 | this.width = width; 186 | this.colour = colour; 187 | } 188 | getColour() { 189 | console.log(`The rectangle with ${this.height}cm height and ${this.width}cm width has a ${this.colour} colour`); 190 | } 191 | 192 | }; 193 | //Similar to function expressions, here also we have Class Expressions: 194 | // unnamed 195 | var Rectangle2 = class { 196 | constructor(height, width) { 197 | this.height = height; 198 | this.width = width; 199 | } 200 | }; 201 | // named 202 | var Rectangle = class Rectangle3 { 203 | constructor(height, width) { 204 | this.height = height; 205 | this.width = width; 206 | } 207 | }; 208 | 209 | //create an instance of Rectangle1 210 | let rectABCD = new Rectangle1(23, 18, "red"); 211 | //console.log(rectABCD); 212 | //rectABCD.getColour(); 213 | 214 | //Inheritance in classes 215 | class RoundedRectangle extends Rectangle1 { 216 | constructor(height, width, colour, cornerRadius){ 217 | super(height, width, colour); 218 | this.cornerRadius = cornerRadius; 219 | } 220 | getColour(){ 221 | console.log(`The roundRectangle with ${this.height}cm height ${this.width}cm width and ${this.cornerRadius}cm cornerRadius has a ${this.colour} colour`); 222 | } 223 | } 224 | 225 | let roundRectEFGH = new RoundedRectangle(27, 89, "blue", 6); 226 | //console.log(roundRectEFGH); 227 | //roundRectEFGH.getColour(); 228 | import {Circle} from './exampleModule';//imported class from exampleModule.js 229 | //create an instance of Circle 230 | let circleO = new Circle(56); 231 | //console.log(circleO); 232 | 233 | //Static Methods in Classes 234 | //The static keyword defines a static method for a class. Static methods are called without instantiating their class and cannot be called through a class instance. Static methods are often used to create utility functions for an application. 235 | class Square { 236 | static area(sideLength){ 237 | return sideLength*sideLength; 238 | } 239 | } 240 | let squareABCD = Square.area(56); 241 | //console.log(squareABCD); 242 | 243 | //Prototypes 244 | //Every JavaScript object has a prototype. The prototype is also an object. 245 | //All JavaScript objects inherit their properties and methods from their prototype. 246 | function shipInfo(name, type, inServiceSince){ 247 | this.name = name; 248 | this.type = type; 249 | this.inServiceSince = inServiceSince; 250 | 251 | this.numberOfFloors = (floors) => `${this.name} has ${floors} floors.`; 252 | 253 | } 254 | //add another property 255 | shipInfo.prototype.numberofCrewMembers; 256 | //add another property function 257 | //Can't use arrow function here because arrow functions don't create 'this' object for the function prototype to reference 258 | //therefore use the normal function 259 | shipInfo.prototype.info = function(companyName){ 260 | return `${this.name} is owned by ${companyName}`; 261 | }; 262 | //create an instance 263 | let ship1 = new shipInfo("Oasis of the Seas", "Cruise Ship", "2009"); 264 | ship1.numberofCrewMembers = 750; 265 | //console.log(ship1); 266 | //console.log(ship1.numberOfFloors(20)); 267 | //console.log(ship1.info("Royal Caribbean International")); 268 | 269 | //Data Structures 270 | // 1) Set -> similar to array but can only store unique values. 271 | let set = new Set(); 272 | //add method 273 | //integers 274 | set.add(30); 275 | set.add(13); 276 | set.add(12); 277 | //strings 278 | set.add("string"); 279 | //objects 280 | set.add({firstObject: 60, secondObject: 70}); 281 | //console.log(set); 282 | //console.log(set.size);// to know the size 283 | //console.log(set.has("string"));// to check for an element 284 | //to convert an array to set 285 | let flowers = ["rose", "lily", "daffodils"]; 286 | let flowersSet = new Set(flowers); 287 | //console.log(flowers); 288 | //console.log(flowersSet); 289 | //to traverse through the set 290 | for (let element of flowersSet.values()){ 291 | //console.log(element); 292 | } 293 | //trick to get unique elements from a string 294 | let sentence = "fansakjvbjvbsdhvhbsdhvbabvjabjaisoalkmz,nawnfkjgvnajkfalmaskldmasdm"; 295 | let sentenceArray = sentence.split(""); 296 | let sentenceSet = new Set(sentenceArray); 297 | //console.log(sentenceArray); 298 | //console.log(sentenceSet); 299 | 300 | // 2) Maps -> has keys and values. Each key is unique. 301 | let map = new Map(); 302 | //map.set method takes two Parameters: key and value 303 | //strings as keys 304 | let keyOfMap = "SampleKey"; 305 | let valueOfMap = "SampleValue"; 306 | map.set(keyOfMap, valueOfMap); 307 | map.set("SampleKey1", "SampleValue1"); 308 | //object as a key 309 | let keyOfMap2 = {sampleObject: 'SampleKey2'}; 310 | map.set(keyOfMap2, "SampleValue2"); 311 | //function as a key 312 | let keyOfMap3 = function() {}; 313 | map.set(keyOfMap3, "SampleValue3"); 314 | //console.log(map); 315 | //convert an array to a Map 316 | let numberArray1 = [[1, 'one'], [2, 'two'], [3, 'three']]; 317 | let numberSet = new Map(numberArray1); 318 | //console.log(numberSet); 319 | //to traverse through the map 320 | for (let [key, value] of numberSet.entries()){ 321 | //console.log(`${key} => ${value}`); 322 | } 323 | //trick to get unique elements from a string 324 | let sentence1 = "jahbahbchabcjksaufgabshjabchabnzbchuyasbfabncjhbahbshcbsajkcbashbcvjhasb"; 325 | let sentence1Map = new Map(); 326 | let currentLetter; 327 | for( let i = 0; i < sentence1.length; i++){ 328 | currentLetter = sentence1[i]; 329 | if(!(sentence1Map.has(currentLetter))){ // similar to if(sentence1Map.has(currentLetter) == false) // if the currentLetter is not in the map 330 | sentence1Map.set(currentLetter, 1); 331 | }else{ // if the currentLetter has already been added to the map then update its count value 332 | sentence1Map.set(currentLetter, sentence1Map.get(currentLetter) + 1); 333 | } 334 | } 335 | //console.log(sentence1Map); 336 | 337 | //Closures 338 | //A closure is the combination of a function and the lexical environment within which that function was declared. 339 | //we can create function factories and private data with Closures 340 | let sampleFunction = () => { 341 | let data = "Dovahkiin"; //data is a local variable created by sampleFunction 342 | let logData = () => { //logData() is the inner function, a closure 343 | //console.log(data); //use variable declared in the parent function 344 | } 345 | logData(); 346 | } 347 | //console.log(data); //will throw an error 348 | sampleFunction(); 349 | 350 | //Function Factories 351 | //In this example, we have defined a function makeAdder(x), which takes a single argument, x, and returns a new function. 352 | //The function it returns takes a single argument, y, and returns the sum of x and y. 353 | //In essence, makeAdder is a function factory — it creates functions which can add a specific value to their argument. 354 | // let makeAdder = (x) => { 355 | // // can make it shorter, thanks to ES6 356 | // // return (y) => { 357 | // // return x + y; 358 | // // }; 359 | // return y => x + y; 360 | // } 361 | // can make it further shorter, thanks to ES6 362 | let makeAdder = (x) => (y) => x + y; 363 | let add5 = makeAdder(5); 364 | let add10 = makeAdder(10); 365 | //console.log(add5(2)); // 7 366 | //console.log(add10(2)); // 12 367 | 368 | //Private Methods -> used to restrict access 369 | const account = () => { 370 | let amount = 0; 371 | let editAmount = (value) => { 372 | return amount += value; 373 | } 374 | const editAccount = (changeAmount) => editAmount(changeAmount); 375 | const checkAccount = () => amount; 376 | // return { 377 | // editAccount: editAccount, 378 | // checkAccount: checkAccount 379 | // } 380 | //or 381 | return { editAccount, checkAccount } 382 | } 383 | let currentAmount = account(); 384 | //console.log(currentAmount); 385 | currentAmount.editAccount(50); 386 | //console.log(currentAmount.checkAccount()); 387 | currentAmount.editAccount(-10); 388 | //console.log(currentAmount.checkAccount()); 389 | 390 | //Generators 391 | //The function* declaration (function keyword followed by an asterisk) defines a generator function, which returns a Generator object. 392 | function* idMaker() { 393 | let index = 0; 394 | while (index < 3) 395 | yield index++; 396 | } 397 | let gen = idMaker(); 398 | // console.log(gen.next().value); // 0 399 | // console.log(gen.next().value); // 1 400 | // console.log(gen.next().value); // 2 401 | // console.log(gen.next().value); // undefined 402 | 403 | //reseting Generators 404 | function* oddNumbers() { 405 | let addition = 1; 406 | while(true){ 407 | if(reset){ 408 | addition = 1; 409 | } 410 | let reset = yield addition; 411 | addition += 2; 412 | } 413 | } 414 | let oddNumbersSeries = oddNumbers(); 415 | // console.log(oddNumbersSeries.next().value); 416 | // console.log(oddNumbersSeries.next().value); 417 | // console.log(oddNumbersSeries.next().value); 418 | // console.log(oddNumbersSeries.next().value); 419 | // console.log(oddNumbersSeries.next(true).value); 420 | // console.log(oddNumbersSeries.next().value); 421 | // console.log(oddNumbersSeries.next().value); 422 | 423 | //Benefits of Generators against iterators 424 | //Sample iterator 425 | const sampleArrayIterator = (array) => { 426 | let index = 0; 427 | return { 428 | nextItem: () => { 429 | return index < array.length ? 430 | {value: array[index++], done: false} : 431 | {done: true}; 432 | } 433 | }; 434 | } 435 | let iterator = sampleArrayIterator([1, 2, 3]); 436 | // console.log(iterator.nextItem().value); 437 | // console.log(iterator.nextItem().value); 438 | // console.log(iterator.nextItem().value); 439 | 440 | function* sampleArrayGenerator(){ 441 | // yield arguments //to return the full argument array at once 442 | // for (let arg of arguments) { // for loop to traverse 443 | // yield arg; 444 | // } 445 | yield* arguments; //same thing can be done with a just one line of code 446 | } 447 | let gener = sampleArrayGenerator(1, 2, 3); 448 | // console.log(gener.next().value); 449 | // console.log(gener.next().value); 450 | // console.log(gener.next().value); 451 | 452 | //Promises 453 | //The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. 454 | let promise = new Promise((resolve, reject) => { 455 | // We call resolve(...) when what we were doing made async successful, and reject(...) when it failed. 456 | // In this example, we use setTimeout(...) to simulate async code. 457 | setTimeout(() => { 458 | resolve("Success!"); // Yay! Everything went well! 459 | }, 2000); 460 | //reject("Rejected data"); 461 | }); 462 | // use 'then' to handle resolve function and 'catch' to handle reject function 463 | promise.then((successMessage) => { 464 | // successMessage is whatever we passed in the resolve(...) function above. 465 | // It doesn't have to be a string, but if it is only a succeed message, it probably will be. 466 | //console.log("Yay! " + successMessage); 467 | }); 468 | //console.log("This will be logged before the promise"); 469 | 470 | //Fetch method 471 | //The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. 472 | //It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network. 473 | const url = 'http://jsonplaceholder.typicode.com/posts/1'; 474 | // fetch(url, {method: "GET"}) 475 | // .then(result => result.json()) 476 | // .then(jsonFile => console.log(jsonFile)); 477 | -------------------------------------------------------------------------------- /python/DataAnalysis/numpy/NumPy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# NumPy\n", 8 | "\n", 9 | "NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.\n", 10 | "\n", 11 | "In this notebook we'll try various numpy methods and in the process learn more about NumPy.\n", 12 | "\n", 13 | "### Installation\n", 14 | "\n", 15 | "Please follow this [link](https://www.scipy.org/scipylib/download.html)\n", 16 | "\n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Importing NumPy\n", 24 | "\n", 25 | "Once numpy is installed, we can import it in our file" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 1, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import numpy as np" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "## NumPy Arrays\n", 42 | "\n", 43 | "In NumPy, strictly 1-D arrays are known as vectors and 2-D arrays are known as matrices (a matrix can also have only one row or one column). With NumPy arrays we can get access to various pre-written functions from NumPy.\n", 44 | "\n", 45 | "### Creating NumPy Arrays\n", 46 | "\n", 47 | "There are various ways to create NumPy Arrays. Some of them are listed below.\n", 48 | "\n", 49 | "1. **From a Python List**" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "text/plain": [ 60 | "['a', 'b', 'c', 'd']" 61 | ] 62 | }, 63 | "execution_count": 2, 64 | "metadata": {}, 65 | "output_type": "execute_result" 66 | } 67 | ], 68 | "source": [ 69 | "list = ['a', 'b', 'c', 'd']\n", 70 | "list" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 3, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "array(['a', 'b', 'c', 'd'], dtype='10]" 1220 | ] 1221 | }, 1222 | { 1223 | "cell_type": "markdown", 1224 | "metadata": {}, 1225 | "source": [ 1226 | "### Universal Functions\n", 1227 | "\n", 1228 | "NumPy comes with many [universal functions](https://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs). Some of it are in the next cells." 1229 | ] 1230 | }, 1231 | { 1232 | "cell_type": "code", 1233 | "execution_count": 49, 1234 | "metadata": {}, 1235 | "outputs": [ 1236 | { 1237 | "data": { 1238 | "text/plain": [ 1239 | "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])" 1240 | ] 1241 | }, 1242 | "execution_count": 49, 1243 | "metadata": {}, 1244 | "output_type": "execute_result" 1245 | } 1246 | ], 1247 | "source": [ 1248 | "uni_list = np.arange(1,11)\n", 1249 | "uni_list" 1250 | ] 1251 | }, 1252 | { 1253 | "cell_type": "code", 1254 | "execution_count": 50, 1255 | "metadata": {}, 1256 | "outputs": [ 1257 | { 1258 | "data": { 1259 | "text/plain": [ 1260 | "array([ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100])" 1261 | ] 1262 | }, 1263 | "execution_count": 50, 1264 | "metadata": {}, 1265 | "output_type": "execute_result" 1266 | } 1267 | ], 1268 | "source": [ 1269 | "np.square(uni_list)" 1270 | ] 1271 | }, 1272 | { 1273 | "cell_type": "code", 1274 | "execution_count": 51, 1275 | "metadata": {}, 1276 | "outputs": [ 1277 | { 1278 | "data": { 1279 | "text/plain": [ 1280 | "array([ 0.84147098, 0.90929743, 0.14112001, -0.7568025 , -0.95892427,\n", 1281 | " -0.2794155 , 0.6569866 , 0.98935825, 0.41211849, -0.54402111])" 1282 | ] 1283 | }, 1284 | "execution_count": 51, 1285 | "metadata": {}, 1286 | "output_type": "execute_result" 1287 | } 1288 | ], 1289 | "source": [ 1290 | "np.sin(uni_list)" 1291 | ] 1292 | }, 1293 | { 1294 | "cell_type": "code", 1295 | "execution_count": 52, 1296 | "metadata": {}, 1297 | "outputs": [ 1298 | { 1299 | "data": { 1300 | "text/plain": [ 1301 | "array([0. , 0.69314718, 1.09861229, 1.38629436, 1.60943791,\n", 1302 | " 1.79175947, 1.94591015, 2.07944154, 2.19722458, 2.30258509])" 1303 | ] 1304 | }, 1305 | "execution_count": 52, 1306 | "metadata": {}, 1307 | "output_type": "execute_result" 1308 | } 1309 | ], 1310 | "source": [ 1311 | "np.log(uni_list)" 1312 | ] 1313 | }, 1314 | { 1315 | "cell_type": "code", 1316 | "execution_count": 53, 1317 | "metadata": {}, 1318 | "outputs": [ 1319 | { 1320 | "data": { 1321 | "text/plain": [ 1322 | "array([0. , 0.30103 , 0.47712125, 0.60205999, 0.69897 ,\n", 1323 | " 0.77815125, 0.84509804, 0.90308999, 0.95424251, 1. ])" 1324 | ] 1325 | }, 1326 | "execution_count": 53, 1327 | "metadata": {}, 1328 | "output_type": "execute_result" 1329 | } 1330 | ], 1331 | "source": [ 1332 | "np.log10(uni_list)" 1333 | ] 1334 | }, 1335 | { 1336 | "cell_type": "code", 1337 | "execution_count": 54, 1338 | "metadata": {}, 1339 | "outputs": [ 1340 | { 1341 | "data": { 1342 | "text/plain": [ 1343 | "array([ True, True, True, True, True, True, True, True, True,\n", 1344 | " True])" 1345 | ] 1346 | }, 1347 | "execution_count": 54, 1348 | "metadata": {}, 1349 | "output_type": "execute_result" 1350 | } 1351 | ], 1352 | "source": [ 1353 | "np.isfinite(uni_list)" 1354 | ] 1355 | } 1356 | ], 1357 | "metadata": { 1358 | "kernelspec": { 1359 | "display_name": "Python 3", 1360 | "language": "python", 1361 | "name": "python3" 1362 | }, 1363 | "language_info": { 1364 | "codemirror_mode": { 1365 | "name": "ipython", 1366 | "version": 3 1367 | }, 1368 | "file_extension": ".py", 1369 | "mimetype": "text/x-python", 1370 | "name": "python", 1371 | "nbconvert_exporter": "python", 1372 | "pygments_lexer": "ipython3", 1373 | "version": "3.6.2" 1374 | } 1375 | }, 1376 | "nbformat": 4, 1377 | "nbformat_minor": 2 1378 | } 1379 | --------------------------------------------------------------------------------