Home » Archives for April 2019

## Print path from root to a given node in a binary tree

in
Algorithm,
Binary Tree,
Datastructure,
Interviews
- on 11:05:00
- No comments

## Simple Deadlock Program in Java

in
Interviews,
Java,
Multithreading
- on 19:42:00
- No comments

### Simple java program to create Deadlock.

Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.

Let's consider an example, in the office we have shared Printer and Scanner where Employees has ability to do scanning and printing.

1.

**John**has bunch of documents that it wants to Print first and also want to take a Scan later.

(Print and Scan)

2.

**Michael**has bunch of documents that it wants to Scan first and also want to take a Print later.

(Scan and Print)

## Difference between process and thread

in
Interviews,
Java,
Multithreading
- on 10:25:00
- No comments

### Difference between process and thread.

Point 1:

A process is an executing instance of an application.

Thread is independent path of execution within a process. Process can have multiple threads,

Point 2:

Threads itself is capable enough to do all the things a process does and thread is a part of process that is why thread can be termed as light-weight process.

Point 3:

Since all the Threads are part of a same Process they all share same memory allocated by Process.

Process use memory allocated by OS.

Point 4:

Inter-thread communication between threads is easy whereas Inter-process communication is difficult.

Point 5:

Processes have independent data and code segments.

Thread shares the data segment, code segment, files etc. with its peer threads.

Point 6:

Process switching is complex as compared to thread switching because of the amount of variables need to be maintained in both of the case.

Per process items | Per thread items |
---|---|

Address space | Program counter |

Global variables | Registers |

Open files | Stack |

Child processes | State |

Pending alarms | |

Signals and signal handlers | |

Accounting information |

### You may also like to see

#### Sort Linked list using Merge sort

#### Bubble Sort

#### Heap Sort

#### Selection Sort

#### Insertion Sort

#### How ConcurrentHashMap works and ConcurrentHashMap interview questions

#### How Much Water Can A Bar Graph with different heights can Hold

#### Interview Questions-Answer Bank

**Enjoy !!!!**

**If you find any issue in post or face any error while implementing, Please comment.**

## Delete Middle Node of Linked List in Java

in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 04:13:00
- No comments

## Check linked list is palindrome or not in java

in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 17:45:00
- No comments

## Find Running Median from a Stream of Integers

in
Algorithm,
Datastructure,
Heap,
Interviews
- on 03:58:00
- No comments

## Find Moving Average of Last N numbers in a Stream.

in
Algorithm,
Datastructure,
Interviews
- on 22:34:00
- No comments

### Find Moving Average of Last N numbers in a Stream.

You are given a stream of numbers, calculate moving average of last N numbers in a stream.

In other words,

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

Lets see sample input and output for better understanding:

## Search element In Sorted Rotated Array in Java

in
Array,
Binary Search,
Interviews
- on 02:12:00
- No comments

### Search the element In Sorted Rotated Array in Java.

Given an array which is sorted in ascending order and is rotated, say for example

Example: original array [1,2,3,4,5,6,7] might become [3,4,5,6,7,1,2]

You are given a key to search. If key is found in the array return its index, otherwise return -1.

**You may assume no duplicate exists in the array, find an element in the rotated array in**

__Note:__O(log n) time.

Lets see sample input and output:

## Find first non repeated character in a string in Java.

in
Interviews,
Strings
- on 03:11:00
- No comments

## Find largest number in Binary Search Tree which is less than or equal to N

in
Algorithm,
Binary Search Tree,
Datastructure,
Interviews
- on 01:01:00
- No comments

### Largest number in Binary Search Tree which is less than or equal to N.

We have a binary search tree and a number N. Our goal is to find the greatest number in the binary search tree that is less than or equal to N. Print -1 if the the value of the element doesn't exists.

We have to find the largest number inside the binary search tree that is smaller than or equal to the target number N.

Lets see sample input and output: