Category Archives: INTERESTING FACTS

Some Motivational ………..

Must Listen inspirational story of APJ Abdul kalam ….

And What a representation  By sir Gulzar……….

 

Advertisements

How is paytm different from bitcoin?

Here are some of the major differences that arise with respect to PayTM and Bitcoin:

  • Both PayTM and Bitcoin are used to transfer funds in the form of rupees and Bitcoin respectively.
  • PayTM is a centralized exchange for money and bitcoin is decentralized.
  • PayTM is a single company where as Bitcoin is composed of individuals, companies, merchants and a lot more people.
  • If ever there is an issue with a transfer of funds, Bitcoin protocol settles it through consensus whereas PayTM would have to be contacted to look into their internal payment processing procedure.
  • Anonymity: Bitcoin is anonymous where as PayTM is required to document all transactions to pay taxes.
  • Ledger of transactions are maintained by PayTM within the PayTM ecosystem and bitcoin transactions are public on the bitcoin blockchain.
  • Paytm makes use of various primitive tech stack whereas bitcoin make use of blockchain technology.
  • Paytm is a subsidiary company on One97 communications whereas Bitcoin is public and isn’t owned by a single company or entity but by the public at large.

At the end of the day, there are numerous differences that differentiate between PayTM/Paypal and bitcoin mainly because both are so very different in relatively all aspects except for the fact that both are designed to transfer value.

Thanks

kundan

Bit Coin in India; Legal or Illegal !!!

Capture.PNG

Bitcoin is in the news for a lot of reasons these daysA form of digital currency, created and supported electronically is named as BitCoin. Bitcoins are not a printed form of currency; they’re produced by people, and increasingly businesses, running computers all around the world, using software that solves mathematical problems. Bitcoin is a cryptocurrency system invented by an unknown programmer or a group of programmer’s. It was released by an unknown programmer under the name of Satoshi Nakamoto as open source software.

This system is peer to peer and transactions take place with users directly, without any intermediary. These transactions are confirmed by network nodes and recorded in a public distributed ledger called a block chain. The system works without a central repository or single administrator. Because of this, bitcoin is called as the first decentralized digital currency.

As of February 2015, over 100,000 merchants and vendors agree to receive bitcoin as payment. According to a research created by Cambridge University in 2017, there are 2.9 to 5.8 million individual users using a cryptocurrency wallet, most of them using bitcoin.

Bitcoin is acquiring 300 percent increase in its value within one year. It could be the kind of investment you may be looking for. However, in animosity of all the curiosity, many of us have wondered if it is safe to accept, store and sell bitcoins in India.

Bitcoins can’t be minted like paper currencies. They can only be mined. There are 21 million bitcoins been created and only 16.8 million or 80 percent of all bitcoins have been mined.

How to buy Bitcoins:-

You can use various digital currency exchanges to buy bitcoin. Credit card can be used for purchase of bitcoins. In India, you can purchase Bitcoin from Zebpay exchange. Zebpay has Android and iPhone app which lets you link your bank account for quick transfers.

Buying Bitcoins can be made by making a payment to Zebpay’s bank account. And can also withdraw the money to your bank account, and can track the data on Bitcoin valuation in the country.

Legality of Bitcoins in India:-

Bitcoin accepting, selling, trading or mining is not illegal by any existing law in India, however, it is not yet officially recognized in India. The Reserve bank of India or the RBI, had earlier cautioned users, holders and traders of Virtualcurrencies (VCs), including Bitcoins.

The central bank had declared that the trading or usages of virtual currency, including bitcoins are not approved by any central bank or monetary authority. It can’t be used as medium for payment.

RBI Deputy Governor R Gandhi warned against crypto-currencies such as Bitcoin. He informed as the Bitcoins possess potential financial, legal, customer protection and security-related risks. Payments by Bitcoins are on peer –to- peer basis and there is no established framework for recourse to customer problems, disputes, etc. There is no legal status for Bitcoins.

At the same time Bitcoins are not banned in the country by the central bank. But not authorised by the central bank of India.

Thanks

kundan

 

World’s Biggest Floating Solar Power Plant launched in China

AAEAAQAAAAAAAAp6AAAAJDE4MzBkYzRkLThiMmYtNGQ2Yy05MDY0LTc1MjVlM2UxNGE4NA.jpg

 

While the United States of America has withdrawn from the Paris Agreement, Asian superpower China is marching towards emission reduction as well as renewable energy commitments. The world’s biggest floating solar power plant has been made operational in Huainan city, Eastern China. The 40-MW plant is situated on a reservoir and is in close proximity to the city. Offshore from Huainan, the plant has been successfully connected with the power grid. Being offshore, it does not take up space and uses less energy than solar farms as seawater acts as a coolant.

Sungrow, the world’s leading photovoltaic system supplier, has set up the plant. Floating solar power plants can be set up on water bodies such as lakes and seas, particularly near cities where land availability is less.

China faces massive air pollution

China, the most populated country on the globe is facing high degrees of air pollution, which is estimated to kill 1.1 million people annually in the country. A major reason for air pollution in China is emissions from automobiles, power plants and factories. The plant will push China towards becoming what some call a green superpower. Solar power is fast becoming key component of the Chinese strategy, as similar projects keep coming up all over China.

China is shutting down polluting factories and thermal power plants. In March, the country cancelled plans of constructing 103 new thermal plants (combined capacity 120 GW). It has also started promoting electric vehicles as well as renewable energy substantially. India can learn a lot from how the Chinese are marching ahead on the road to clean and green energy.

Global warming, climate change, pollution at alarming levels

Global warmingclimate change, and environmental degradation confront mankind, although it’s another matter that US President Donald Trump trashes all evidence and has pulled the USA out of the Paris Climate AccordNASA—also part of the United States—figures point out globally temperatures have increased by over 1 degree since 1880; also, 9 out of the 10 hottest years occurred after 2000. By 2012, Arctic ice shrank to the lowest level. Internationally, sea levels are going up at 3.4 mm per year. It is just a matter of time before human habitation, particularly in the coastal areas, starts getting submerged.

 

Thanks.

kundan

Common Types of Network Attacks

Without security measures and controls in place, your data might be subjected to an attack. Some attacks are passive, meaning information is monitored; others are active, meaning the information is altered with intent to corrupt or destroy the data or the network itself.

Your networks and data are vulnerable to any of the following types of attacks if you do not have a security plan in place.

Eavesdropping

In general, the majority of network communications occur in an unsecured or “cleartext” format, which allows an attacker who has gained access to data paths in your network to “listen in” or interpret (read) the traffic. When an attacker is eavesdropping on your communications, it is referred to as sniffing or snooping. The ability of an eavesdropper to monitor the network is generally the biggest security problem that administrators face in an enterprise. Without strong encryption services that are based on cryptography, your data can be read by others as it traverses the network.

Data Modification

After an attacker has read your data, the next logical step is to alter it. An attacker can modify the data in the packet without the knowledge of the sender or receiver. Even if you do not require confidentiality for all communications, you do not want any of your messages to be modified in transit. For example, if you are exchanging purchase requisitions, you do not want the items, amounts, or billing information to be modified.

Identity Spoofing (IP Address Spoofing)

Most networks and operating systems use the IP address of a computer to identify a valid entity. In certain cases, it is possible for an IP address to be falsely assumed— identity spoofing. An attacker might also use special programs to construct IP packets that appear to originate from valid addresses inside the corporate intranet.

After gaining access to the network with a valid IP address, the attacker can modify, reroute, or delete your data. The attacker can also conduct other types of attacks, as described in the following sections.

Password-Based Attacks

A common denominator of most operating system and network security plans is password-based access control. This means your access rights to a computer and network resources are determined by who you are, that is, your user name and your password.

Older applications do not always protect identity information as it is passed through the network for validation. This might allow an eavesdropper to gain access to the network by posing as a valid user.

When an attacker finds a valid user account, the attacker has the same rights as the real user. Therefore, if the user has administrator-level rights, the attacker also can create accounts for subsequent access at a later time.

After gaining access to your network with a valid account, an attacker can do any of the following:

  • Obtain lists of valid user and computer names and network information.
  • Modify server and network configurations, including access controls and routing tables.
  • Modify, reroute, or delete your data.

Denial-of-Service Attack

Unlike a password-based attack, the denial-of-service attack prevents normal use of your computer or network by valid users.

After gaining access to your network, the attacker can do any of the following:

  • Randomize the attention of your internal Information Systems staff so that they do not see the intrusion immediately, which allows the attacker to make more attacks during the diversion.
  • Send invalid data to applications or network services, which causes abnormal termination or behavior of the applications or services.
  • Flood a computer or the entire network with traffic until a shutdown occurs because of the overload.
  • Block traffic, which results in a loss of access to network resources by authorized users.

Man-in-the-Middle Attack

As the name indicates, a man-in-the-middle attack occurs when someone between you and the person with whom you are communicating is actively monitoring, capturing, and controlling your communication transparently. For example, the attacker can re-route a data exchange. When computers are communicating at low levels of the network layer, the computers might not be able to determine with whom they are exchanging data.

Man-in-the-middle attacks are like someone assuming your identity in order to read your message. The person on the other end might believe it is you because the attacker might be actively replying as you to keep the exchange going and gain more information. This attack is capable of the same damage as an application-layer attack, described later in this section.

Compromised-Key Attack

A key is a secret code or number necessary to interpret secured information. Although obtaining a key is a difficult and resource-intensive process for an attacker, it is possible. After an attacker obtains a key, that key is referred to as a compromised key.

An attacker uses the compromised key to gain access to a secured communication without the sender or receiver being aware of the attack.With the compromised key, the attacker can decrypt or modify data, and try to use the compromised key to compute additional keys, which might allow the attacker access to other secured communications.

Sniffer Attack

A sniffer is an application or device that can read, monitor, and capture network data exchanges and read network packets. If the packets are not encrypted, a sniffer provides a full view of the data inside the packet. Even encapsulated (tunneled) packets can be broken open and read unless they are encrypted and the attacker does not have access to the key.

Using a sniffer, an attacker can do any of the following:

  • Analyze your network and gain information to eventually cause your network to crash or to become corrupted.
  • Read your communications.

Application-Layer Attack

An application-layer attack targets application servers by deliberately causing a fault in a server’s operating system or applications. This results in the attacker gaining the ability to bypass normal access controls. The attacker takes advantage of this situation, gaining control of your application, system, or network, and can do any of the following:

  • Read, add, delete, or modify your data or operating system.
  • Introduce a virus program that uses your computers and software applications to copy viruses throughout your network.
  • Introduce a sniffer program to analyze your network and gain information that can eventually be used to crash or to corrupt your systems and network.
  • Abnormally terminate your data applications or operating systems.
  • Disable other security controls to enable future attacks.

 

 

Thanks ,

kundan pandey

 

 

 

How GPS navigation works using Breadth-First Search (BFS)

There are differences in the route which I usually take and the one which GPS shows as the shortest, probably due to the algorithms used. I learned from my graph theory data structure classes that Breadth-first search is used in GPS and digital maps. I tried looking for the possible use of Algorithms (Breadth First Search real life application or A* application) used in GPS on the web, but I couldn’t find a lot of details. So here is how BFS is used in GPS

Let’s first understand how GPS sees maps.

Digital maps, unlike humans, see streets as a bunch of nodes. The 2.6-mile road from the Columbus Circle station (59 st) to Cathedral Pkwy (110 st) is called Central Park West. We (humans) consider this road a single entity (You may divide it into few more segments based on metro stations or intersections, but not more than that).

 

But a GPS or any other digital map divides it into hundreds of segments, with some only 24 meters long. A GPS looks at this street as a graph divided into vertices and edges.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained

Considering this, there is a lot of data to be covered and calculated while finding the shortest path.

Before we begin you must know the answers to the following:

What is a graph?

A graph usually looks like the image below and is made up of vertices and edges (represented by lines and circles, respectively).

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

The objective of a graph is to represent a problem as a set of points that are connected in various ways using edges. With the help of such graphs, we tend to solve our problems by applying various algorithms.

Let’s take an example to understand better.

Facebook is a good example to understand graph theory. Facebook has millions of users. If a person needs to find a friend, he can use an array and search. But that would take a  lot of time and memory to search for so many people, making the problem quite complex.

Facebook has millions of users. If a person needs to find a friend, he can use an array and search. But that would take a  lot of time and memory to search for so many people, making the problem quite complex.

But if the same scenario is represented using a graph, the problems tend to get solved easily. With a graph, you know that these two people are actually friends(Though real-life scenarios are not exactly that simple!).Check this video on how graph theory is used in social networks

Graph theories are frequently used in various other fields, such as maps, e-commerce, and computer games.

Before we go further down this road, read this detailed article about graph theory, which explains other important aspects of Graphs such as Directed, Undirected, Cycle or Loop, and Matrix.

What’s the difference between a Graph and a Tree?

A tree is a  special type of graph, i.e., a minimal graph, where there is only one path between two vertices.

So what is Breadth First Search and how does it work?

Depth First Search (DFS) and Breadth First Search (BFS) are algorithms, or in simple terms, they are methods to traverse a graph.

Before I explain BFS, consider this example.

Take a graph with 13 nodes. When  BFS is applied to this graph, the algorithm traverses from node 1 to node 2 and then to nodes 3, 4, 5,v6 (in green)  and so on in the given order.

If you consider 1 (in red) as the first node, you observe that BFS gradually moves outward, considering each neighboring node first.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work

This eventually brings us to the accepted definition of the Breadth First Search algorithm:

Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a “search key”‘) and explores the neighbor nodes first, before moving to the next level neighbors.”

Graph Traversal in Maps

Take a look at this simple “Gridworld” which is used for various graph traversal algorithms. Your digital map considers your world a similar grid, which is made up of intersections connected to each other.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

Now for the grid shown, there could be N number of ways to traverse from point A to point P.

Following are two of these N ways in which one can travel from point A to point P.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

So how does an algorithm decide which the shortest way to reach a destination is? Graph Traversal Algorithms!

The BFS algorithm looks at the map as we do; it just can’t perceive it completely. When you have to travel from one destination to another, you draw a line from point A to point B, and then chose the road closest to that line. Algorithms repeat the same method choosing the node nearest to the intersection points, eventually selecting the route with the shortest length.

Let’s take a simple example of GridWorld given above and try solving it using BFS search. Assume you need to travel from location A to location P.

Note: Every vertex in the image is given a number, which is the total distance from the source and an alphabet which represents the previous node.

Breadth First Search for GridWorld 

Step 1 – Visit neighboring nodes to A, i.e, B, E, and F. The vertex to B would become 1-A and since E and F are also at an equal distance as B, hence vertices to both E and F from A, could be denoted as 1-A too. There is the no particular order for node preference but to make it simple, we began with B.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

Step 2 – Since all the neighboring nodes of A have now been traced, we will mark “A” as visited.

And take the next visited node as the source node, which in this case is node B. Visit all the adjacent nodes to B, which are C (2B) and G (2B). Node F is considered in the previous step from A, hence it is not visited again. Once all neighboring nodes from one node are visited, mark them as visited and move to the next step.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

Step 3 – Visit all neighboring nodes of Node E, which are I (2E) and J (2E), and mark E as visited.

Step 4 – Visit neighboring nodes of Node F, which is K (2F). Since all the adjacent nodes have been visited by either B or E, mark node F as visited.

Step 5 – Repeat the process until all the nodes on the grid are visited at least once.

Step 6 – Once all nodes are visited, you would find that the distance required to reach from A to P is 3 and the shortest route is diagonal.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

If you remove all the vertices which are not used to connect the nodes, as in the graph above.

Such graphs are called minimum spanning trees, where each node is connected to at least one vertex.

But in the real world, you can’t always move diagonally. Most of the portions in between the intersection are occupied by houses, shops, malls, and metro stations. So how does BFS work in such circumstances? Let’s understand it with the same GridWorld example, but in this case, the algorithm is not allowed to move or visit a node diagonally.

Step 1 – Consider node A as source and visit all neighboring nodes of A, which are B(1A) and E (1A). Mark A as visited.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

Step 2 – Visit all neighboring nodes of B, node C (2B) and node F (2B), and mark B as visited.

Step 3 – Visit neighboring nodes to E, since F is already visited by B. Visit node I (2E) and mark E as visited

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

Step 4 – Repeat the steps for all nodes until each of them has been visited at least once.  Mark nodes you considered visited.

Step 5 – Remove all the unconnected/unwanted vertices, and convert the graph into a minimum spanning tree connecting each node at least once.

– Highlight the nodes connecting source node A to node P, which has distance 6 and is the shortest path between two nodes.

BFS, GPS, Google Maps, Breadth-First Search, Algorithm, How maps work, BFS application, where is BFS use, BFS application in real life, How does GPS works, What are best use of GPS, How does google map work, How does map works, New York map explained, Google map explained, BFS application, BFS used in real life, BFS used in real life

You now understand why GPS didn’t suggest the path A, E, I, M, N, O, P or A,B,C, D, H, L, P though they were equidistant

Once you’ve understood the way GPS works, you’d wish the world could be a simple Grid! But to a programmer’s disappointment, it isn’t. Hence, for a GPS, distance is not the only factor in choosing a route, rather elapsed time, the speed limit on a route, live traffic update, the number of stop signals all have to be taken into consideration. That’s why you would find your GPS occasionally suggesting winding state highways to travel instead of the usual national highways.

Most of the GPS or digital maps have evolved over BFS to A* algorithm (You can read more about A* algorithm – Here) due to better complexity over a period of time.

Yet, GPS is one of the most amazing devices. Connected to satellites 12,000 miles above the planet, it calculates your position in real time with more than 50,00,000 possibilities for a particular route.

Write a SQL query to get the second highest salary from the table above. Also write a query to find the nth highest salary in SQL, where n can be any number.

Suppose that you are given the following simple database table called Employee that has 2 columns named Employee ID and Salary:

Employee
Employee ID Salary
3 200
4 800
7 450

The easiest way to start with a problem like this is to ask yourself a simpler question first. So, let’s ask ourselves how can we find the highest salary in a table? Well, you probably know that is actually really easy – we can just use the MAX aggregate function:

select MAX(Salary) from Employee;

Remember that SQL is based on set theory

You should remember that SQL uses sets as the foundation for most of its queries. So, the question is how can we use set theory to find the 2nd highest salary in the table above? Think about it on your own for a bit – even if you do not remember much about sets, the answer is very easy to understand and something that you might be able to come up with on your own.

Figuring out the answer to find the 2nd highest salary

What if we try to exclude the highest salary value from the result set returned by the SQL that we run? If we remove the highest salary from a group of salary values, then we will have a new group of values whose highest salary is actually the 2nd highest in the original Employee table.

So, if we can somehow select the highest value from a result set that excludes the highest value, then we would actually be selecting the 2nd highest salary value. Think about that carefully and see if you can come up with the actual SQL yourself before you read the answer that we provide below. Here is a small hint to help you get started: you will have to use the “NOT IN” SQL operator.

Solution to finding the 2nd highest salary in SQL

Now, here is what the SQL will look like:

SELECT MAX(Salary) FROM Employee
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )

Running the SQL above would return us “450”, which is of course the 2nd highest salary in the Employee table.

Subscribe to our newsletter for more free interview questions.

An explanation of the solution

The SQL above first finds the highest salary value in the Employee table using “(select MAX(Salary) from Employee)”. Then, adding the “WHERE Salary NOT IN” in front basically creates a new set of Salary values that does not include the highest Salary value. For instance, if the highest salary in the Employee table is 200,000 then that value will be excluded from the results using the “NOT IN” operator, and all values except for 200,000 will be retained in the results.

This now means that the highest value in this new result set will actually be the 2nd highest value in the Employee table. So, we then select the max Salary from the new result set, and that gives us 2nd highest Salary in the Employee table. And that is how the query above works.

An alternative solution using the not equals SQL operator

We can actually use the not equals operator – the “<>” – instead of the NOT IN operator as an alternative solution to this problem. This is what the SQL would look like:

select MAX(Salary) from Employee
WHERE Salary <> (select MAX(Salary) from Employee )

How would you write a SQL query to find the Nth highest salary?

What we did above was write a query to find the 2nd highest Salary value in the Employee table. But, another commonly asked interview question is how can we use SQL to find the Nth highest salary, where N can be any number whether it’s the 3rd highest, 4th highest, 5th highest, 10th highest, etc? This is also an interesting question – try to come up with an answer yourself before reading the one below to see what you come up with.

The answer and explanation to finding the nth highest salary in SQL

Here we will present one possible answer to finding the nth highest salary first, and the explanation of that answer after since it’s actually easier to understand that way. Note that the first answer we present is actually not optimal from a performance standpoint since it uses a subquery, but we think that it will be interesting for you to learn about because you might just learn something new about SQL. If you want to see the more optimal solutions first, you can skip down to the sections that says “Find the nth highest salary without a subquery” instead.

The SQL below will give you the correct answer – but you will have to plug in an actual value for N of course. This SQL to find the Nth highest salary should work in SQL Server, MySQL, DB2, Oracle, Teradata, and almost any other RDBMS:

SELECT * /*This is the outer query part */
FROM Employee Emp1
WHERE (N-1) = ( /* Subquery starts here */
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)

How does the query above work?

The query above can be quite confusing if you have not seen anything like it before – pay special attention to the fact that “Emp1” appears in both the subquery (also known as an inner query) and the “outer” query. The outer query is just the part of the query that is not the subquery/inner query – both parts of the query are clearly labeled in the comments.

The subquery is a correlated subquery

The subquery in the SQL above is actually a specific type of subquery known as a correlated subquery. The reason it is called a correlated subquery is because the the subquery uses a value from the outer query in it’s WHERE clause. In this case that value is the Emp1 table alias as we pointed out earlier. A normal subquery can be run independently of the outer query, but a correlated subquery can NOT be run independently of the outer query. If you want to read more about the differences between correlated and uncorrelated subqueries you can go here: Correlated vs Uncorrelated Subqueries.

The most important thing to understand in the query above is that the subquery is evaluated each and every time a row is processed by the outer query. In other words, the inner query can not be processed independently of the outer query since the inner query uses the Emp1 value as well.

Finding nth highest salary example and explanation

Let’s step through an actual example to see how the query above will actually execute step by step. Suppose we are looking for the 2nd highest Salary value in our table above, so our N is 2. This means that the query will look like this:

SELECT *
FROM Employee Emp1
WHERE (1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)

You can probably see that Emp1 and Emp2 are just aliases for the same Employee table – it’s like we just created 2 separate clones of the Employee table and gave them different names.

Understanding and visualizing how the query above works

Let’s assume that we are using this data:

Employee
Employee ID Salary
3 200
4 800
7 450

For the sake of our explanation, let’s assume that N is 2 – so the query is trying to find the 2nd highest salary in the Employee table. The first thing that the query above does is process the very first row of the Employee table, which has an alias of Emp1.

The salary in the first row of the Employee table is 200. Because the subquery is correlated to the outer query through the alias Emp1, it means that when the first row is processed, the query will essentially look like this – note that all we did is replace Emp1.Salary with the value of 200:

SELECT *
FROM Employee Emp1
WHERE (1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > 200)

So, what exactly is happening when that first row is processed? Well, if you pay special attention to the subquery you will notice that it’s basically searching for the count of salary entries in the Employee table that are greater than 200. Basically, the subquery is trying to find how many salary entries are greater than 200. Then, that count of salary entries is checked to see if it equals 1 in the outer query, and if so then everything from that particular row in Emp1 will be returned.

Note that Emp1 and Emp2 are both aliases for the same table – Employee. Emp2 is only being used in the subquery to compare all the salary values to the current salary value chosen in Emp1. This allows us to find the number of salary entries (the count) that are greater than 200. And if this number is equal to N-1 (which is 1 in our case) then we know that we have a winner – and that we have found our answer.

But, it’s clear that the subquery will return a 2 when Emp1.Salary is 200, because there are clearly 2 salaries greater than 200 in the Employee table. And since 2 is not equal to 1, the salary of 200 will clearly not be returned.

So, what happens next? Well, the SQL processor will move on to the next row which is 800, and the resulting query looks like this:

SELECT *
FROM Employee Emp1
WHERE (1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > 800)

Since there are no salaries greater than 800, the query will move on to the last row and will of course find the answer as 450. This is because 800 is greater than 450, and the count will be 1. More precisely, the entire row with the desired salary would be returned, and this is what it would look like:

EmployeeID Salary
7 450

It’s also worth pointing out that the reason DISTINCT is used in the query above is because there may be duplicate salary values in the table. In that scenario, we only want to count repeated salaries just once, which is exactly why we use the DISTINCT operator.

A high level summary of how the query works

Let’s go through a high level summary of how someone would have come up with the SQL in the first place – since we showed you the answer first without really going through the thought process one would use to arrive at that answer.

Think of it this way – we are looking for a pattern that will lead us to the answer. One way to look at it is that the 2nd highest salary would have just one salary that is greater than it. The 4th highest salary would have 3 salaries that are greater than it. In more general terms, in order to find the Nth highest salary, we just find the salary that has exactly N-1 salaries greater than itself. And that is exactly what the query above accomplishes – it simply finds the salary that has N-1 salaries greater than itself and returns that value as the answer.

Find the nth highest salary using the TOP keyword in SQL Server

We can also use the TOP keyword (for databases that support the TOP keyword, like SQL Server) to find the nth highest salary. Here is some fairly simply SQL that would help us do that:

SELECT TOP 1 Salary
FROM (
      SELECT DISTINCT TOP N Salary
      FROM Employee
      ORDER BY Salary DESC
      ) AS Emp
ORDER BY Salary

To understand the query above, first look at the subquery, which simply finds the N highest salaries in the Employee table and arranges them in descending order. Then, the outer query will actually rearrange those values in ascending order, which is what the very last line “ORDER BY Salary” does, because of the fact that the ORDER BY Default is to sort values in ASCENDING order. Finally, that means the Nth highest salary will be at the top of the list of salaries, which means we just want the first row, which is exactly what “SELECT TOP 1 Salary” will do for us!

Find the nth highest salary without using the TOP keyword

There are many other solutions to finding the nth highest salary that do not need to use the TOP keyword, one of which we already went over. Keep reading for more solutions.

Find the nth highest salary in SQL without a subquery

The solution we gave above actually does not do well from a performance standpoint. This is because the use of the subquery can really slow down the query. With that in mind, let’s go through some different solutions to this problem for different database vendors. Because each database vendor (whether it’s MySQL, Oracle, or SQL Server) has a different SQL syntax and functions, we will go through solutions for specific vendors. But keep in mind that the solution presented above using a subquery should work across different database vendors.

Find the nth highest salary in MySQL

In MySQL, we can just use the LIMIT clause along with an offset to find the nth highest salary. If that doesn’t make sense take a look at the MySQL-specific SQL to see how we can do this:

SELECT Salary FROM Employee 
ORDER BY Salary DESC LIMIT n-1,1

Note that the DESC used in the query above simply arranges the salaries in descending order – so from highest salary to lowest. Then, the key part of the query to pay attention to is the “LIMIT N-1, 1”. The LIMIT clause takes two arguments in that query – the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. So, it’s saying that the offset of the first row to return should be N-1, and the max number of rows to return is 1. What exactly is the offset? Well, the offset is just a numerical value that represents the number of rows from the very first row, and since the rows are arranged in descending order we know that the row at an offset of N-1 will contain the (N-1)th highest salary.

Find the nth highest salary in SQL Server

In SQL Server, there is no such thing as a LIMIT clause. But, we can still use the offset to find the nth highest salary without using a subquery – just like the solution we gave above in MySQL syntax. But, the SQL Server syntax will be a bit different. Here is what it would look like:

SELECT Salary FROM Employee 
ORDER BY Salary DESC OFFSET N-1 ROW(S) 
FETCH FIRST ROW ONLY

Note that I haven’t personally tested the SQL above, and I believe that it will only work in SQL Server 2012 and up. Let me know in the comments if you notice anything else about the query.

Find the nth highest salary in Oracle using rownum

Oracle syntax doesn’t support using an offset like MySQL and SQL Server, but we can actually use the row_number analytic function in Oracle to solve this problem. Here is what the Oracle-specific SQL would look like to find the nth highest salary:

select * from (
  select Emp.*, 
row_number() over (order by Salary DESC) rownumb 
from Employee Emp
)
where rownumb = n;  /*n is nth highest salary*/

The first thing you should notice in the query above is that inside the subquery the salaries are arranged in descending order. Then, the row_number analytic function is applied against the list of descending salaries. Applying the row_number function against the list of descending salaries means that each row will be assigned a row number starting from 1. And since the rows are arranged in descending order the row with the highest salary will have a 1 for the row number. Note that the row number is given the alias rownumb in the SQL above.

This means that in order to find the 3rd or 4th highest salary we simply look for the 3rd or 4th row. The query above will then compare the rownumb to n, and if they are equal will return everything in that row. And that will be our answer!

Find the nth highest salary in Oracle using RANK

Oracle also provides a RANK function that just assigns a ranking numeric value (with 1 being the highest) for some sorted values. So, we can use this SQL in Oracle to find the nth highest salary using the RANK function:

select * FROM (
select EmployeeID, Salary
,rank() over (order by Salary DESC) ranking
from Employee
)
WHERE ranking = N;

The rank function will assign a ranking to each row starting from 1. This query is actually quite similar to the one where we used the row_number() analytic function, and works in the same way as well.

We’ve now gone through many different solutions in different database vendors like Oracle, MySQL, and SQL Server. Hopefully now you understand how to solve a problem like this, and you have improved your SQL skills in the process! Be sure to leave a comment if you have any questions or observations.

12 Incident Management Questions to Crack your Interview

Hi Friends,

there are few question related to incident management……

please have a look……….

 

QUESTION 1: What is your understanding of incident management?

ANSWER 1: An Incident occurs when there is an interruption in the flow of service, or if the quality of the process has reduced. For example, (power cut scenario – finance company – server down). Incident management means restoring the flow of process as soon as possible by rectifying the issue caused due to the incident. It reduces the adverse impact on the business.

 

QUESTION 2: On what factors do you prioritize an Incident?

ANSWER 2: The priority of an Incident can be decided on answering the following questions:

  • Do we have a temporary or an alternate solution while fixing the actual issue?
  • Is this urgent or can it wait? If it can wait, then how long can it wait?
  • What else goes wrong if this is not fixed?
  • What is the financial impact, reputational impact, or SLA (Service Level Agreement) breach?

 

QUESTION 3: Explain – Priority = Impact + Urgency (Priority Matrix)

ANSWER 3: Impact is the level of loss, be it financial or on the business. Urgency is how quick the solution has to be provided. Priority is decided based both on Impact and Urgency.

 

QUESTION 4: What is an Emergency Change? How different is it from a Normal Change?

ANSWER 4: Emergency Change is something which has huge impact if not addressed immediately. It is dealt by ECAB (Emergency Change Advisory Board), with shorter time-scales and higher levels of urgency. ECAB does the impact assessment and decides whether to approve or to reject the change request.

 

QUESTION 5: Describe the different phases involved in the Incident Management Process.

ANSWER 5: In the different phases, one needs to:

  • Mitigate risk: Incident management guides you to identify the chances, potential risks, or threats that may cause interruption to a process and thereby mitigate the occurrence of any such incident by planning the pre and post actions, to face the
  • Prepare: Preparing is nothing but planning. Remember – Prevention is always better than cure. Hence, planning is a part of this phase where the incident professional plans the actions that need to be performed for an incident. This is termed as IMP – Incident Management Plan. This IMP leads you with step by step procedures.
  • Respond: One needs to respond to an incident on priority. This is to mitigate the risk occurred and also to reduce further damage. This may also be done by IMRT (Incident Management Response Team).
  • Resolve: The incident team or individual should assess the damage caused and take the responsibility of informing all the members involved in the process about the status of the incident.
  • Recover: In the recovery phase, the Business Continuity Plans (BCP) are implemented and teams or persons connected in testing this plan / phase are well prepared to perform the action. This may include teams like HR, IT desk, operations, server team, BCP team, and so on.
  • Resume: In this phase, incident professionals need to analyze the outcome of the BCP so conducted, whether it has a positive or negative response. Post the analysis, they need to make necessary changes depending on the response, and implement the plan that confirms the BCP plan.

 

QUESTION 6: How do you engage Problem Management while handling incidents?

ANSWER 6: As soon as an Incident is identified as a problem ticket, the problem management team comes into the picture to check the previous and related incidents, and then do a root cause analysis so as to find the reason for the recurring incident. The incident management team provides, the required incident details to the problem manager, and also coordinates with the end user in times of need.

 

QUESTION 7: What type of Incident Management reports did you or your team have?

ANSWER 7: The types are:

  • Average handling time for transactions
  • Average response times based on priority of the incident
  • Average resolution times based on the priority of the incident

 

QUESTION 8: What are the escalation methods that are used in Incident management?

ANSWER 8: There are two types of methods used: the Functional method and the Hierarchical method.

Functional escalation means forwarding or assigning a particular incident from one department to another for resolution.

Hierarchical escalation is done when we don’t get the proper and timely response from the support teams. We escalate it to the senior management above the support team members.

QUESTION 9: Why does an Incident manager need to be aware of new developments and technical changes?

ANSWER 9: An Incident Professional needs to update his knowledge and be aware of the new developments and technical changes because it helps him or her to find upgraded resolutions that may trigger in future.

 

QUESTION 10: What are the daily responsibilities of an Incident Manger?

ANSWER 10: An Incident Manager is responsible of the following activities:

  • Ensuring that the incident backlogs are cleared at the earliest as per the SLAs (Service Level Agreements) and OLAs (Operational Level Agreements)
  • Ensuring that the tickets are routed to the correct support group so that the response and resolution times are not affected.
  • Following the Incident Management Process (as designed)
  • Holding periodical meetings with the stakeholders and other departments involved, to share the new guidelines if any
  • Updating oneself with the new procedures and developments
  • Utilizing the knowledge effectively and keep updating it

 

QUESTION 11: How different is Major Management Process from Incident Management Process?

ANSWER 11: There is some similarity in the two processes. In both the cases, we aim to get the incident resolved at the earliest so as to reduce adverse impact on the business. But there is a slight difference in their approaches. Major incident management is a critical process where the timelines are shorter and urgency levels are higher. The way your team wants to deal with it may depend on your organization structure. Usually someone specific is assigned to take care of that particular major incident – right from the identification of the major incident, bringing in the support team members on to a conference call or a group chat till resolving the incident.

 

QUESTION 12: How is a Major Incident Management bridge call handled?

ANSWER 12: A Major Incident Management bridge call is handled by:

  1. Inviting all the stakeholders on to the call
  2. Inviting them about the criticality
  3. Identifying the appropriate resolver group (in case there are multiple groups related to the incident)
  4. Letting the resolver group acknowledge and take ownership of the incident
  5. Coordinating with the stakeholders in order to keep them posted about the progress
  6. Using Functional or Hierarchical Escalation according to the requirement
  7. Sending timely updates to all stakeholders

thanks

Hands On

http://www.handson.website