Chandu
Try this i will work
Chandu
*it
Anonymous
Worked bro thanks alot
Chandu
👍
__.whizz.__
Hi
__.whizz.__
I don't know c program
__.whizz.__
Anybody want to teach me
Anonymous
Anyone?
Just think about how the tree is built. If it's a binary tree every node has up to two children nodes. This mean that, assuming it is balanced, at each level you have 2M nodes, where M is the number of nodes of the previous level. Therefore if you have a total of N nodes, you can go as deep as log(N)
AJAY
Kisi ke pass DSA ke handwritten notes hai to please send me
Anshul
For a binary tree calculating height takes o(n) time right? Then why for height balanced tree it is o(logn)
Anonymous
What you are saying is it not true for any binary tree?
Not really. A binary tree can be developed just on "one side". A balanced one has to be developed equally both sides
Anonymous
Just Google some visual representation and you'll understand what I'm saying
Anshul
Anshul
Just Google some visual representation and you'll understand what I'm saying
I've searched but for the height of height balanced binary tree I have not found anything that can help my doubt
Anonymous
But a balanced tree can be like this too. That it have only one child at some nodes
Yes. In that case it is O(log(N) + 1) ~ O(log(N)) Did you get it? It is true that the deepest level can be uncompleted, but it does not really affect time complexity
Anshul
So the height can be calculated in o(logn) time or does it mean the height is log n
Anonymous
So the height can be calculated in o(logn) time or does it mean the height is log n
The height is O(log(N)), therefore it takes logarithmic time to traverse it till bottom
Anshul
But calculating the height will still take O(number of nodes) time right?
Anshul
Because to calculate height, I make a recursive function which at every node ask the height of its left and right sub trees and returns it's height as max of both heights + 1
Anshul
So to traverse each node I'm making n number of calls. n being the number of nodes
Anonymous
It takes O(log(N))
Anonymous
The number of times you function gets called is equal to the number of levels of the tree, right? Every time, starting from the root node, you check if it has a left or right children. If so, you call the same function on one of the two, right? Therefore you are calling that function for every tree level
Anshul
Thanks brother
Anonymous
Thanks brother
No problem
Anshul
👍
mystery
#include <iostream> using namespace std; int main() { long num; cin>>num; cout<<endl; // Reading input from STDIN unsigned long long a,b,sum=0; long i; while(i<num) { cin>>a>>b; cout<<endl; long long j; while(j<=a) { if(j%b==0) { if((j%b)%b==0) { sum+=(j/b)/b; } else{ sum+=j/b; } } else { sum+=j; } } cout<<sum<<endl; } }
Anshul
If j and i are 0 at start so the complexity will be O(a*num). What are the constraints
Anonymous
I tried many times i can't figure it out
I'd suggest you: 1 - Provide an explanation about what your code should do 2 - State the expected output and the output or error you got 3 - Send a minimal working example of your faulty code in a well-formatted fashion
Anonymous
Anybody want to teach me
/get cbook /get cppbookguide
Anonymous
Can anyone help me with the time complexity of this? When I am compiling it on hacker earth it is showing time limit exceeded error
I'd suggest you: 1 - Provide an explanation about what your code should do 2 - State the expected output and the output or error you got 3 - Send a minimal working example of your faulty code in a well-formatted fashion
Anonymous
@OxFFFFFFFF What about the following message in the rules? 1 - Provide an explanation about what your code should do 2 - State the expected output and the output or error you got 3 - Send a minimal working example of your faulty code in a well-formatted fashion
ZukiZest
for (j = x; j <= 4 * x * y; j += y / x)
Anonymous
Milwaukee
Hello can anyone assist Describe how parameters are passed between a function call and a function in programming. For each way of passing parameter write a program segment to show how it is implemented.
klimi
バレンタインがいない柴(食用不可)
Anonymous
Hm?
Does it break those two rules? * Not checking your problem in google (or any other search engine) first will get you a warn. * Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something.
+
Hello guys for my needs I subclassed QProgressBar and created my own the way Im using it is: create an empty QFrame where I want to put my progress bar in it after that add my progress bar to it in my code with setParent, its ok, but problem is in this way the progress bar widget isn't center, so how can I center it? (without using layout of cource)
Daniel
hello, whats the difference between int const value =5; const int value1 = 5;
Anonymous
hello, whats the difference between int const value =5; const int value1 = 5;
no difference, it is only different if they were pointers
ANONYMOUS
i read from txt pairs of numbers how can i check it only 2 numbers in each line and not 3 I want show the line is the problem for example:
ANONYMOUS
the pairs file:
ANONYMOUS
3 25 35 14 42 30 60 70
ANONYMOUS
my code: scanf("%d", &numOfPairs); arrNum = (int *)malloc(sizeof(int) * numOfPairs * numbersInPair); for (int i = 0; i < numOfPairs * numbersInPair; i += 2) { int num1, num2; if (scanf("%d %d \n", &num1, &num2) == 2) { arrNum[i] = num1; arrNum[i + 1] = num2; } else { printf("illegal input at line %d \n", i); } }
ANONYMOUS
console: illegal input at line 4
Anonymous
/get
Anonymous
i read from txt pairs of numbers how can i check it only 2 numbers in each line and not 3 I want show the line is the problem for example:
Isn't it easier to count the number of blank spaces on each line? If there should be only one pair of numbers per line, then there should be exactly one horizontal blank space per line.
Droningbro
/get cbook /get cppbookguide
Can u send me guidebook of cpp also ,m currently working on cpp😅
Steven
Print this pattern in c++ (no of rows =4) ABCD BCDE CDEF DEFG
printf("ABCD\nBCDE\nCDEF\nDEFG");
Suyash
Help me to write Java code Que.) Reverse a String and print it on console "Java Skills"
Chandu
/report
Anonymous
Heyyy
ANONYMOUS
int i, c; FILE *fp; char str[100]; fp = fopen("./pairs.txt", "r"); if (dup2(fileno(fp), STDIN_FILENO < 0)) { printf("Error opening file"); return -1; } if (feof(fp)) printf("Error reading file"); scanf("%d", &numOfPairs); arrNum = (int *)malloc(sizeof(int) * numOfPairs * numbersInPair); for (int i = 0; i < numOfPairs * numbersInPair; i += 2) { int num1, num2; scanf("%d %d", &num1, &num2); arrNum[i] = num1; arrNum[i + 1] = num2; }
Sandeep
If I have hash that stores the frequency of the key...then how do I create a vector which is sorted based on the frequency
Артём
If I have hash that stores the frequency of the key...then how do I create a vector which is sorted based on the frequency
Iterate over that hash table adding values to the vector. Btw, you can't restore hashed key.
ANONYMOUS
{ int index, i, numOfPairs; int c; FILE *file; file = fopen("./pairs.txt", "r"); if ((c = getc(file)) == EOF) { perror("Error opening file"); //or return 1; fclose(file); } while ((c = getc(file)) != EOF) putchar(c); { if (pid == ROOT) fscanf(file, "%d", &numOfPairs); allNumbers = (int *)malloc(sizeof(int) * numOfPairs * numbersInPair); //need multiply in 2 numbers for each pair while (!feof(file) && numOfPairs > 0) { int x, y, arrIndex = 0; numOfPairs--; fscanf(file, "%d %d", &x, &y); allNumbers[arrIndex] = x; printf("The X : %d\n", x); allNumbers[arrIndex + 1] = y; printf("THE Y : %d\n", y); arrIndex + 2; } fclose(file); }
ANONYMOUS
it get array garbage
Anshul
i wrote a code for this, "Construct Binary Tree from Preorder and Inorder Traversal". for sample test cases it runs fine but when i submit the code it gives a run time error and i can't understand the reason why