## Running Python code on JVM using Jython

Follow Below Steps :

**1) Download Jython2.1.jar **

**2) Download jsr223-api.jar**

**3) Add above jar files in the Class path .**

**4) Java code sample to excute the python on JVM:**

public static void testPython() {

ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor(“python”);

//Example -1:

Object obj= executor.executeScript(new StaticScriptSource(“def foo(y):\n\tx=y\n\treturn y\nz=foo(2)”));

System.out.println(“Excuted successfully ::::”+obj.toString());

//Example -2 :

Object obj2 = executor.executeScript(new ResourceScriptSource(new FileSystemResource(“D:/xyz.py”)));

System.out.println(“Output ::::::::”+ obj2);}

## Twilio Vs Nexmo -SMS service

Twilio offers more than just SMS, with their Voice IVR API being the unique API. Nexmo doesn’t offer any voice API, and the inbound numbers they offered is strictly for SMS only. So if you want the same number that can receive SMS and also receive phone calls, Twilio is the only one that can do that.

## SAP Hana – Feeding data from xodata to Pie/Bar Chart

**SAP Hana , Getting the data from xodata and feeding it to pie / bar chart for Analytical views **

In your view.js file , define the pie/ bar chart object as below

sap.ui.jsview(“view.ViewName”, {

getControllerName : function() {

return “view.ViewName”;

},createContent : function(oController) {

var oPage = new sap.m.Page(“homePage”, {

showNavButton : false,

showFooter : false

});var dataset = new sap.viz.ui5.data.FlattenedDataset({

dimensions : [

{

axis : 1, // must be one for the x-axis, 2 for y-axis

name : ‘COLOUMN’, //Any name .. preferrably db column name

value : “{COLOUMN}” //database column that you get in while access .xodata

}],measures : [ {

group : 1,

name : “XYZ_COUNT”,

value : “{XYZ_COUNT}” // this is database count for the columb you chose}],

data : {

path : “/XXXXXXX”, // this is your context that you define in your .xodata file}

});var pie = new sap.viz.ui5.Pie({

width : “100%”,

height : “300px”,

showLegend : false,

plotArea : {

‘colorPalette’ : d3.scale.category20().range()

},

title : {

visible :true,

text : ‘Graph Name’

},

dataset : dataset

});oPage.addContent(pie);

return oPage;

}

});

## SAP Hana – Different Charts

## search on sorted array which has been rotated to unknown pivot

**Binary search with change :**

int start = array[0];

int end = array[length -1];

int mid = array[length/2];

int left = 0;

int right = length – 1;while (left <= right) {

int middle = left + (right-left)/2;

if (array[middle] == find) return middle;if (array[left] <= array[middle]) {

if (find >= array[left] && find < array[middle])

right = middle – 1;

else

left = middle + 1;

}

else {

if (find > array[middle] && find <= array[right])

left = middle + 1;

else

right = middle – 1;

}

}

return -1;

## Quick sort & Merge sort

Quick sort is nothing but a series of recursive calls to partitioning and the fastest comparison sort on arrays in practice.

Merge sort is stable comparison sort, which also works on linked lists .

## Sorting algorithm Comparision

A good implementation uses O(log N) auxiliary storage in the form of stack space for recursion.

A stable sort is one that’s guaranteed not to reorder elements with identical keys.

*Sorting algorithm Comparision*

**Bubble sort –**

**Stable sort .**- Time complexity – O(n) on best , O(N^2) in the worst case .
- Memory -O(1).

**Insertion sort**

**Stable sort.**- O(N^2) time complexity.
- Useful for adding new data to a presorted list.

**Merge sort –**

**stable sort .**- O(N log N) time complexity
- Downsides to it are that it uses O(N) auxiliary space and has a slightly larger constant than a quick sort.
- Uses extra memory

**Selection sort: **

**Not stable sort .**- Time complexity -O(n^2) .
- Memory -O(1) auxiliary space.

**Quick Sort:**

**Not stable sort .**- Time complexity – O(N log N) on average, O(N^2) in the worst case .
- Memory – log n on average, worst case is n

**Heap Sort :**

**Not stable sort .**- Time complexity- O(Nlog N)
- It’s guaranteed to be O(N log N), and uses O(1) auxiliary space, meaning that you won’t unexpectedly run out of heap or stack space on very large inputs.
- Slower than quicksort.
- Memory -O(1) auxiliary space.