Saturday, May 19, 2018

PYTHON

What is Python?

Python is a popular programming language. It was created in 1991 by Guido van Rossum.
It is used for:
  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.
Python is a general purpose, dynamic, high level and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn and provides lots of high-level data structures.
Python is easy to learn yet powerful and versatile scripting language which makes it attractive for Application Development.
Python's syntax and dynamic typing with its interpreted nature, makes it an ideal language for scripting and rapid application development.
Python supports multiple programming pattern, including object oriented, imperative and functional or procedural programming styles.
Python is not intended to work on special area such as web programming. That is why it is known as multipurpose because it can be used with web, enterprise, 3D CAD etc.
We don't need to use data types to declare variable because it is dynamically typed so we can write a=10 to assign an integer value in an integer variable.
Python makes the development and debugging fast because there is no compilation step included in python development and edit-test-debug cycle is very fast.


What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-orientated way or a functional way.

Python History

  • Python laid its foundation in the late 1980s.
  • The implementation of Python was started in the December 1989 by Guido Van Rossum at CWI in Netherland.
  • In February 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.
  • In 1994, Python 1.0 was released with new features like: lambda, map, filter, and reduce.
  • Python 2.0 added new features like: list comprehensions, garbage collection system.
  • On December 3, 2008, Python 3.0 (also called "Py3K") was released. It was designed to rectify fundamental flaw of the language.
  • ABC programming language is said to be the predecessor of Python language which was capable of Exception Handling and interfacing with Amoeba Operating System.
  • Python is influenced by following programming languages:
    • ABC language.
    • Modula-3

Python Syntax compared to other programming languages

  • Python was designed to for readability, and has some similarities to the English language with influence from mathematics.
  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

JSON

What is JSON?

JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. Squarespace uses JSON to store and organize site content created with the CMS.

Example

Append ?format=json-pretty to the URL of any page on your Squarespace site and you'll be able to view the JSON data for the site.

Keys and Values

The two primary parts that make up JSON are keys and values. Together they make a key/value pair.
  • Key: A key is always a string enclosed in quotation marks.
  • Value: A value can be a string, number, boolean expression, array, or object.
  • Key/Value Pair: A key value pair follows a specific syntax, with the key followed by a colon followed by the value. Key/value pairs are comma separated.


Types of Values

  • Array: An associative array of values.
  • Boolean: True or false.
  • Number: An integer.
  • Object: An associative array of key/value pairs.
  • String: Several plain text characters which usually form a word.
Numbers, booleans and strings are self-evident, so we'll skip over those sections. Arrays and Objects are explained in more depth below.

Saturday, May 12, 2018

JavaScript

JavaScript is an object-based scripting language that is lightweight and cross-platform.
JavaScript is not compiled but translated. The JavaScript Translator (embedded in browser) is responsible to translate the JavaScript code.

JavaScript is used to create interactive websites. It is mainly used for:
  • Client-side validation
  • Dynamic drop-down menus
  • Displaying data and time
  • Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and prompt dialog box)
  • Displaying clocks etc.

Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.


The script tag specifies that we are using JavaScript.
The text/javascript is the content type that provides information to the browser about the data.
The document.write() function is used to display dynamic content through JavaScript. We will learn about document object in detail later.


3 Places to put JavaScript code

  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external javaScript)

JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
  1. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
  2. After first letter we can use digits (0 to 9), for example value1.
  3. JavaScript variables are case sensitive, for example x and X are different variables.

JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function.


JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
  1. Primitive data type
  2. Non-primitive (reference) data type
JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type.


The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript.
  1. If Statement
  2. If else statement
  3. if else if statement

Choose color and Change text Color

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
       var f= $("#b").val();
$("#p").css("color",f);
    });
});

</script>
</head>
<body>
<form>
<input type="color" id="b" />

<p id="p">Hello</p>

<button>Click me</button>
</form>
</body>
</html>

Friday, May 4, 2018

DS Quespaper

  1. Search, insert and delete in an unsorted array
  2. Search, insert and delete in a sorted array
  3. Given an array A[] and a number x, check for pair in A[] with sum as x
  4. Majority Element
  5. Find the Number Occurring Odd Number of Times
  6. Find the Missing Number
  7. Searching in an array where adjacent differ by at most k
  8. Merge an array of size n into another array of size m+n
  9. Searching in an array where adjacent differ by at most k
  10. Maximum Subarray Sum Excluding Certain Elements
  11. Leaders in an array
  12. Find the only repetitive element between 1 to n-1
  13. Sort elements by frequency | Set 1
  14. Count Inversions in an array | Set 1 (Using Merge Sort)
  15. Two elements whose sum is closest to zero
  16. Shortest Un-ordered Subarray
  17. Shortest Un-ordered Subarray
  18. Check for Majority Element in a sorted array
  19. Union and Intersection of two sorted arrays
  20. Ceiling in a sorted array
  21. Find the two repeating elements in a given array
  22. Sort an array of 0s, 1s and 2s
  23. Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
  24. Equilibrium index of an array
  25. Count number of occurrences (or frequency) in a sorted array
  26. Find the repeating and the missing | Added 3 new methods
  27. Median in a stream of integers (running integers)
  28. Find a Fixed Point in a given array
  29. Find sub-array with given sum
  30. Find a triplet that sum to a given value
  31. Find the two numbers with odd occurrences in an unsorted array
  32. Find a pair with the given difference
  33. Find four elements that sum to a given value | Set 1 (n^3 solution)
  34. Find four elements that sum to a given value | Set 2 ( O(n^2Logn) Solution)
  35. Median of two sorted arrays of different sizes
  36. Count the number of possible triangles
  37. Find a peak element
  38. Find number of pairs (x, y) in an array such that x^y > y^x
  39. Count all distinct pairs with difference equal to k
  40. Find if there is a sub-array with 0 sum
  41. Given a sorted array and a number x, find the pair in array whose sum is closest to x
  42. Count 1’s in a sorted binary array
  43. Print All Distinct Elements of a given integer array
  44. Construct an array from its pair-sum array
  45. Find common elements in three sorted arrays
  46. Find the first repeating element in an array of integers
  47. Find position of an element in a sorted array of infinite numbers
  48. Check if a given array contains duplicate elements within k distance from each other
  49. Find the element that appears once
  50. Find Union and Intersection of two unsorted arrays
  51. Delete an element from array (Using two traversals and one traversal)
  52. Count frequencies of all elements in array in O(1) extra space and O(n) time
  53. Trapping Rain Water
  54. Count triplets with sum smaller than a given value
  55. Count Inversions of size three in a given array
  56. Merge two sorted arrays with O(1) extra space
  57. Find lost element from a duplicated array
  58. Count pairs with given sum

  1. Search, insert and delete in an unsorted array
  2. Search, insert and delete in a sorted array
  3. Given an array A[] and a number x, check for pair in A[] with sum as x
  4. Majority Element
  5. Find the Number Occurring Odd Number of Times
  6. Find the Missing Number
  7. Searching in an array where adjacent differ by at most k
  8. Merge an array of size n into another array of size m+n
  9. Searching in an array where adjacent differ by at most k
  10. Maximum Subarray Sum Excluding Certain Elements
  11. Leaders in an array
  12. Find the only repetitive element between 1 to n-1
  13. Sort elements by frequency | Set 1
  14. Count Inversions in an array | Set 1 (Using Merge Sort)
  15. Two elements whose sum is closest to zero
  16. Shortest Un-ordered Subarray
  17. Shortest Un-ordered Subarray
  18. Check for Majority Element in a sorted array
  19. Union and Intersection of two sorted arrays
  20. Ceiling in a sorted array
  21. Find the two repeating elements in a given array
  22. Sort an array of 0s, 1s and 2s
  23. Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
  24. Equilibrium index of an array
  25. Count number of occurrences (or frequency) in a sorted array
  26. Find the repeating and the missing | Added 3 new methods
  27. Median in a stream of integers (running integers)
  28. Find a Fixed Point in a given array
  29. Find sub-array with given sum
  30. Find a triplet that sum to a given value
  31. Find the two numbers with odd occurrences in an unsorted array
  32. Find a pair with the given difference
  33. Find four elements that sum to a given value | Set 1 (n^3 solution)
  34. Find four elements that sum to a given value | Set 2 ( O(n^2Logn) Solution)
  35. Median of two sorted arrays of different sizes
  36. Count the number of possible triangles
  37. Find a peak element
  38. Find number of pairs (x, y) in an array such that x^y > y^x
  39. Count all distinct pairs with difference equal to k
  40. Find if there is a sub-array with 0 sum
  41. Given a sorted array and a number x, find the pair in array whose sum is closest to x
  42. Count 1’s in a sorted binary array
  43. Print All Distinct Elements of a given integer array
  44. Construct an array from its pair-sum array
  45. Find common elements in three sorted arrays
  46. Find the first repeating element in an array of integers
  47. Find position of an element in a sorted array of infinite numbers
  48. Check if a given array contains duplicate elements within k distance from each other
  49. Find the element that appears once
  50. Find Union and Intersection of two unsorted arrays
  51. Delete an element from array (Using two traversals and one traversal)
  52. Count frequencies of all elements in array in O(1) extra space and O(n) time
  53. Trapping Rain Water
  54. Count triplets with sum smaller than a given value
  55. Count Inversions of size three in a given array
  56. Merge two sorted arrays with O(1) extra space
  57. Find lost element from a duplicated array
  58. Count pairs with given sum