Category Archives: Data Structures

Binary Search Test

import org.testng.annotations.Test; /** * Binary Search Test * @author asharda * */ public class BSearchTest { /** * Check if Number is Present in Array */ @Test public void testBinarySearch() { int arr[]={1,5,7,8,12,19}; boolean b=bSearch(arr,19); if(b==true) { System.out.println(“Number Found”); } … Continue reading

Posted in Data Structures, Java, Uncategorized | Leave a comment

Bubble Sort C++

/* *bubblesort.cpp * * Created on: May 28, 2017 * Author: asharda */ #include<iostream> using namespace std; void bubblesort(int arr[],int size) { int temp; for (int i=0;i<size;i++) { for (int j=i+1;j<size;j++) { if(arr[i] >arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; }//end of … Continue reading

Posted in C++, Data Structures, Uncategorized | Leave a comment

Matrix Add,Multiply and Subtract using Python

”’ Created on Apr 23, 2017 Matrix Addition,Multiplication and Division using Python Numpy @author: asharda ”’ import numpy as np x=np.array([[5,5],[5,5]],dtype=np.float64) y=np.array([[1,2],[3,4]],dtype=np.float64) print(“Sub”,x-y) print(“Multiply”,x*y) print(“Add”,x+y)   This assumes you already have numpy installed.

Posted in Data Structures, Python | Leave a comment

Lists as Stack in Python

”’ Created on Feb 12, 2017 @author: asharda ”’ stack=[3,4,5] stack.append(10) stack.pop() stack.append(6) print (stack)

Posted in Data Structures, Python | Leave a comment

Using Maps -Java

@Test public void testMap() { HashMap<String,Integer> hm=new HashMap<String,Integer>(); hm.put(“Ashish”, 26); hm.put(“Sneha”, 06); Iterator itr=hm.entrySet().iterator(); while(itr.hasNext()) { Map.Entry mp=(Map.Entry)itr.next(); System.out.println(“Key seen is “+mp.getKey()+”Value seen is “+mp.getValue()); }

Posted in Data Structures, Java | Leave a comment

Basic Queue Progream

@Test public void testQueue() { Queue<Integer> queue=new LinkedList<Integer>(); queue.add(10); queue.add(20); while(!queue.isEmpty()){ System.out.println(queue.poll()); } }

Posted in Data Structures, Java | Leave a comment