Skip to main content
deleted 28 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
  1. Is my solution really correct? I mean it, does it work regardless of it'sits efficiency? Or in other words, is it right logically? (BTW,I I think it's right,and and I have tested the output when nn is less than 30)

  2. Why is my solution so slow? As you can see, I'm a newbie onto DSA, and it's my first question here.

  1. Is my solution really correct? I mean it does work regardless of it's efficiency? Or in other words, is it right logically? (BTW,I think it's right,and I have tested the output when n is less than 30)

  2. Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here

  1. Is my solution really correct? I mean, does it work regardless of its efficiency? Or in other words, is it right logically? (BTW, I think it's right, and I have tested the output when n is less than 30)

  2. Why is my solution so slow? As you can see, I'm a newbie to DSA.

deleted 33 characters in body; edited tags; edited title
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

Compute the time complexity for this algorithm Lopsided Trees and Recursion

1.Is my solution right? I mean it does work regardlessly of its efficiency? Or in other words,is it right logically? (BTW,I think it's right,and I have tested the output when n is less than 30)

2.Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here. So any tips or explanations are appreciated.

  1. Is my solution really correct? I mean it does work regardless of it's efficiency? Or in other words, is it right logically? (BTW,I think it's right,and I have tested the output when n is less than 30)

  2. Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here

Compute the time complexity for this algorithm

1.Is my solution right? I mean it does work regardlessly of its efficiency? Or in other words,is it right logically? (BTW,I think it's right,and I have tested the output when n is less than 30)

2.Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here. So any tips or explanations are appreciated.

Lopsided Trees and Recursion

  1. Is my solution really correct? I mean it does work regardless of it's efficiency? Or in other words, is it right logically? (BTW,I think it's right,and I have tested the output when n is less than 30)

  2. Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here

added 48 characters in body; Please keep titles as concise as possible.
Source Link
Quaxton Hale
  • 2.6k
  • 1
  • 36
  • 52

How do I compute Compute the time complexity for this algorithm(the slow version written by me)

The originoriginal problem is:

Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is k-balanced if its left and right subtrees differ in height by at most k. A tree is k-balanced if all of its nodes are k-balanced. The empty tree is considered to be k-balanced.

For example, the tree below has height 4.

    o
   / \
  o   o
 / \
o   o
   /
  o

This tree is 2-balanced but not 1-balanced, because the left subtree of the root has height 3 and the right subtree of the root has height 1. Your task is to write a method that takes a balance factor k and a number of nodes n and returns the maximum height of a k-balanced tree with n nodes.

Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is k-balanced if its left and right subtrees differ in height by at most k. A tree is k-balanced if all of its nodes are k-balanced. The empty tree is considered to be k-balanced.

For example, the tree below has height 4.

    o
   / \
  o   o
 / \
o   o
   /
  o

This tree is 2-balanced but not 1-balanced, because the left subtree of the root has height 3 and the right subtree of the root has height

  1. Your task is to write a method that takes a balance factor k and a number of nodes n and returns the maximum height of a k-balanced tree with n nodes.

1.Is my solution right?I I mean it does work regardlessly of its efficiency? Or in other words,is it right logically?  (BTW,I think it's right,and I have tested the output when n is less than 30)

2.Why is my solution soooooso slow? As you can see, I'm a newbie on DSA, and it's my first question here.So So any tips or explanations are appreciated.

How do I compute the time complexity for this algorithm(the slow version written by me)

The origin problem is:

Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is k-balanced if its left and right subtrees differ in height by at most k. A tree is k-balanced if all of its nodes are k-balanced. The empty tree is considered to be k-balanced.

For example, the tree below has height 4.

    o
   / \
  o   o
 / \
o   o
   /
  o

This tree is 2-balanced but not 1-balanced, because the left subtree of the root has height 3 and the right subtree of the root has height 1. Your task is to write a method that takes a balance factor k and a number of nodes n and returns the maximum height of a k-balanced tree with n nodes.

1.Is my solution right?I mean it does work regardlessly of its efficiency? Or in other words,is it right logically?(BTW,I think it's right,and I have tested the output when n is less than 30)

2.Why is my solution sooooo slow? As you can see, I'm a newbie on DSA, and it's my first question here.So any tips or explanations are appreciated.

Compute the time complexity for this algorithm

The original problem is:

Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is k-balanced if its left and right subtrees differ in height by at most k. A tree is k-balanced if all of its nodes are k-balanced. The empty tree is considered to be k-balanced.

For example, the tree below has height 4.

    o
   / \
  o   o
 / \
o   o
   /
  o

This tree is 2-balanced but not 1-balanced, because the left subtree of the root has height 3 and the right subtree of the root has height

  1. Your task is to write a method that takes a balance factor k and a number of nodes n and returns the maximum height of a k-balanced tree with n nodes.

1.Is my solution right? I mean it does work regardlessly of its efficiency? Or in other words,is it right logically?  (BTW,I think it's right,and I have tested the output when n is less than 30)

2.Why is my solution so slow? As you can see, I'm a newbie on DSA, and it's my first question here. So any tips or explanations are appreciated.

Source Link
Loading