View allAll Photos Tagged Divideandconquer

14/06/12 @ Hot Damn! / The Spectrum

14/06/12 @ Hot Damn! / The Spectrum

modern interior design for a living room on double volume, with gas fire place and TV unit, with a library above the fireplace @divideandconquer

14/06/12 @ Hot Damn! / The Spectrum

14/06/12 @ Hot Damn! / The Spectrum

modern interior design for a living room on double volume, with gas fire place and TV unit, with a library above the fireplace @divideandconquer

We are all ONE!

This does not mean we are all one species, although we are.

This does not mean we are all connected, although we are.

This does not mean we are all a part of something bigger, although we are.

It means,

We are all ONE!

  

------------------------------

What will you do today to empower your life?

 

This quote is taken from my book "Empowering Thoughts". 280 pages of thoughts to empower your life. Available worldwide now from your favourite online bookstores. Learn more at the link below.

 

Wishing you a beautiful and empowered day,

James Cole

 

empoweringmeditations.com/book

 

#Allconnected #Awakening #Awareness #Consciousness #Divideandconquer #Empoweringmeditations #EmpoweringThoughts #Higherconsciousness #Humanity #Humanrace #JamesCole #Life #Love #Onelove #Oneness #Onerace #Oneracehumanrace #Onespecies #Partofsomethingbigger #Peace #Racism #Seperation #Sexism #Spiritualawakening #Theuniverse #Togetherweareone #Togetherwearestronger #Unity #Universe #Weareallone

modern interior design for a living room on double volume, with gas fire place and TV unit, with a library above the fireplace @divideandconquer

Problem Statement

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Example

nums =

6

Explanation:

 

has the largest sum = 6.

nums =

-1

Approach 1 (Divide and Conquer)

In this approach we will be discussing about divide and conquer technique to solve this problem. We are trying to find that contiguous subarray which has maximum sum. So we can say that the optimum subarray may lie in any part of the array. So we make three cases which will cover all possibilities:

 

Case 1:

Max subarray lies completely in the left half of the array.

Case 2:

Max subarray lies completely in the right half of the array.

Case 3:

Partial portion of max subarray lies in the left half and another partial portion of it lies in the second half (i.e. subarray is crossing the mid element of the array)

 

As we can see case 1 and case 2 is basically a subproblem of N/2 sized array having same definition as main problem. Where N is the size of the current array. So we can simply recurs the function over two halves of the array.

Now the main part is case 3 which we have to solve in the current function and then we can return the maximum sum out of these 3 cases.

 

Lets see how we can solve for case 3:

 

Suppose we have array =

We find mid index to divide it into two equal halves.

mid index = (0+9)/2 = 4

 

As case 3 is saying that max sum will cross the mid element.

 

www.tutorialcup.com/leetcode-solutions/maximum-subarray-l...

Problem Statement

"Scramble String" problem states that you are given two strings. Check if the second string is a scrambled string of first one or not?

 

Explanation

Let string s = "great"

Representation of s as binary tree by recursively dividing it into two non-empty sub-strings.

 

This string can be scrambled by choosing any non leaf node and swapping it's children.

 

Therefore "rgeat" is a scrambled string of original string i.e. "great".

 

Example

s1 = "great"

 

s2 = "rgeat"

Yes

Explanation: As shown above in the images, we can see scrambling "great" results in "great". And thus the result is Yes.

s1 = "abcde"

 

s2 = "caebd"

No

 

Algorithm for Scramble String Problem

1. Initialize the two string variables s1 and s2 of the same size.

2. Create a function to check is the second string is the scrambled string of first string which accepts two string variables as it's a parameter.

3. Check if the first string is equal to the second string, return true.

4. After that, sort the first string using the inbuilt sort function.

5. Similarly, sort the second string using the inbuilt sort function.

6. Check again if the first string is not equal to the second string, return false.

7. Else create a variable scramble of the boolean type and initialize it as false.

8.

 

www.tutorialcup.com/interview/string/scramble-string.htm

We are all ONE!

This does not mean we are all one species, although we are.

This does not mean we are all connected, although we are.

This does not mean we are all a part of something bigger, although we are.

It means,

We are all ONE!

  

------------------------------

What will you do today to empower your life?

 

This quote is taken from my book "Empowering Thoughts". 280 pages of thoughts to empower your life. Available worldwide now from your favourite online bookstores. Learn more at the link below.

 

Wishing you a beautiful and empowered day,

James Cole

 

empoweringmeditations.com/book

 

#Allconnected #Awakening #Awareness #Consciousness #Divideandconquer #Empoweringmeditations #EmpoweringThoughts #Higherconsciousness #Humanity #Humanrace #JamesCole #Life #Love #Onelove #Oneness #Onerace #Oneracehumanrace #Onespecies #Partofsomethingbigger #Peace #Racism #Seperation #Sexism #Spiritualawakening #Theuniverse #Togetherweareone #Togetherwearestronger #Unity #Universe #Weareallone

2