• ina

can enyone help me?
I have this exercise:

count the leafs of a binary tree thet are divisible by 10

• Himanshu Dagar

One way is traverse a tree in any order you want . While traversing check that (node->left==NULL&&node->right==NULL&&node->value%10==0)
Time complexity:- O(n)
n-number of nodes in binary tree

• ARGHA

JEST QUESTION 2014

Given an array of M integers .Up to index N the array is filled with positive integers and beyond N all the array elements are negative.M is much larger than N.
Design an algorithm to find the index N with complexity of log(N).

• Jeff

binary search

• mukund pb

I think binary search will be log(M) and not log(N) as asked in the question. This may not be the best approach

• Vikas Varshney

First find the location of FIRST negative number using step size of power of 2.this will take constant time as power of 2 grows exponentially.O(1)

Then use the binary search between positive and negative no. in log(N) time.

• swarnim

There are 8 cubicles in a room. In each cubicle, there are 8 computers. There are a total of 60 members. Constraint#1 – A team can contain a minimum of 2 members and a maximum of 6 members. Constraint#2 – In every cubicle, not more than 1 computer can be unallocated. Constraint#3 – All team members of a team must be in the same cubicle..anyone plz answer how to write algo on this??

• swarnim

Return the longest possible word from the English dictionary by combining symbols of the Periodic Table. Constraint – Symbols containing 2 characters cannot be broken & used independently. E.g. – Sodium’s symbol Na cannot be broken into N & a, you have to use Na together,how to write algo on this??

• saivineet89

Get dictionary and load it to a list. Then sort it and traverse it backward and check if the that word can be made. The first word is your answer.

• v kumar

• v kumar

i want step wise algorithm for pascal triangle using nested for loops in the form of
1
1 2 1
1 3 3 1
1 4 6 4 1

• Raj Kishor

//A program to display the Pascal’s Triangle.

//Created by RAJ.

#include

using namespace std;

main()

{

unsigned int term,t;

int i,j,k,n;

cout<>n;

for(i=0;i0;j–)

cout<<" ";

term=1;

for(k=0;k<=i;k++)

{

t=term;

while(t)

{

cout<<"b";

t/=10;

}

cout<<term<<" ";

term=term*(i-k)/(k+1);

}

cout<<endl;

}

return 0;

}

• Raj Kishor

``` //A program to display the Pascal's Triangle. //Created by RAJ. #include using namespace std; main() { unsigned int term,t; int i,j,k,n; cout<>n; for(i=0;i0;j--) cout<<" "; term=1; for(k=0;k<=i;k++) { t=term; while(t) { cout<<"b"; t/=10; } cout<<term<<" "; term=term*(i-k)/(k+1); } cout<<endl; } return 0; } ```

• Raj Kishor

//A program to display the Pascal’s Triangle.
//Created by RAJ.
#include
using namespace std;
main()
{
unsigned int term,t;
int i,j,k,n;
cout<>n;
for(i=0;i0;j–)
cout<<" ";
term=1;
for(k=0;k<=i;k++)
{
t=term;
while(t)
{
cout<<"b";
t/=10;
}
cout<<term<<" ";
term=term*(i-k)/(k+1);
}
cout<<endl;
}
return 0;
}

• saivineet89

They’re all powers of 11

• v kumar

i want step wise algorithm for pascal triangle using nested for loops in the form of
1
1 2 1
1 3 3 1
1 4 6 4 1

• sukoon sharma

i want some new problems on transfer and conquer algorithm not the ones used in textbooks

• Yo

``` #include```

``` using namsespace std; int geeksforgeeks(int n){ if(n==1) cout<<"GEEKS FOREVER"<<endl; else geeksforgeeks(n-1); } int main(){#include using namespace std; int geeksforgeeks(int n){ if(n==1) return 0; geeksforgeeks(n-1); cout<<"GEEKS FOREVER"<<endl; return 0; } int main(){ geeksforgeeks(5); } geeksforgeeks(20); } ```

• gwpark

So incredible job, guy. I’m so impressed. I’ve just read about dynamic programming, and I think the code you inserted is very helpful for me to understand more deeply about dynamic programming. Actually, I was finding some tutorial about algorithm in my native language, but I just decided to get around here to study algorithms (also study English). Thank you.

Hello….Can any one write an algorithm like find Fibonacci no from 1-20??
I need dat…plx reply me as soon as possible……..

• piyush bansal

a = 0
b = 1
c=a+b
a = b
b = c
again loop from start

play with this algo as per your requirement

• Chaithanya Kanumolu

We have a D.P solution for fibonacci series.

it looks like:
a[0]=1;
a[1]=1;
int i=2;
for(;a[i]<=20;i++)
a[i]=a[i-1]+a[i-2];
for(int j=1;j<=i;j++)
sop(a[j]);
Intentionally I have avoided a[0] in sop since 1 gets repeated twice.
I hope this helps.

• ARUN

don’t ask for homework questions here , this platform is for quality discussion .

• mysticPrince

Nice List of Algorithms! Good Work geeks!

• samg

Hello,

Thank you for helping me with this. I need to design an algorithm for the following.

From the table below, I want to find out a set of 7 names that gives the largest sum of marks possible with keeping the total fees less than 4000.

Just to be clear, here is the problem in different words.

Desired output:
Set of 7 names (Name1,Name2,Name3,Name4,Name5,Name6,Name7)that gives the largest sum of Marks
(Marks1+Marks2+Marks3+Marks4+Marks5+Marks6+Marks7) should be the largest, satisfying the given condition.

Conditions:
Sum of Fees of 7 names is less than 4000.
Fees1+Fees2+Fees3+Fees4+Fees5+Fees6+Fees7 < 4000

Name Marks Fees
A 87 345
B 4 897
C 87 432
D 34 435
E 6 345
F 3 789
G 9 78
H 8 345
I 7 879
J 8 324
K 87 789
L 43 4536
M 65 234
N 87 897
O 65 978
P 23 324
Q 89 342
R 9 789
S 87 34
T 76 234
U 654 897
V 76 23
W 879 435
X 0 897
Y 435 54
Z 56 23

Regards!

• Chaithanya Kanumolu

I think this is similar to Knapsack problem. DP should help you, I guess.

• Desmond

Knapsack has very less runtime efficiency. . .this takes O(n^2). . .Or better if u replace selection sort with merge sort. . .

#include

#include

main()

{

FILE *fp;

char buff[255];

int i;

struct xxx

{

char name;

float marks;

float fees;

float avg;

};

struct xxx a[26] = {{‘A’, 87 ,345 },

{‘B’, 4 ,897 },

{‘C’, 87 ,432 },

{‘D’, 34 ,435 },

{‘E’, 6 ,345 },

{‘F’, 3 ,789 },

{‘G’, 9 ,78 },

{‘H’, 8 ,345 },

{‘I’, 7 ,879 },

{‘J’, 8 ,324 },

{‘K’, 87 ,789 },

{‘L’, 43 ,4536},

{‘M’, 65 ,234 },

{‘N’, 87 ,897 },

{‘O’, 65 ,978 },

{‘P’, 23 ,324 },

{‘Q’, 89 ,342 },

{‘R’, 9 ,789 },

{‘S’, 87 ,34 },

{‘T’, 76 ,234 },

{‘U’, 654 ,897 },

{‘V’, 76 ,23 },

{‘W’, 879 ,435 },

{‘X’, 0 ,897 },

{‘Y’, 435 ,54 },

{‘Z’, 56 ,23 }};

for (i=0;i<26;i++)

{

a[i].avg = (4000/a[i].fees) * a[i].marks;

printf("%c:%fn",a[i].name,a[i].avg);

}

printf("nnn");

for(i=0;i<25;i++)

{

int pos=i;

int j;

for(j=i+1;ja[pos].avg)

{

pos = j;

}

}

if(pos!=i)

{

float temp = a[i].avg;

a[i].avg = a[pos].avg;

a[pos].avg =temp;

temp = a[i].fees;

a[i].fees = a[pos].fees;

a[pos].fees =temp;

temp = a[i].marks;

a[i].marks = a[pos].marks;

a[pos].marks =temp;

char c =a[i].name;

a[i].name=a[pos].name;

a[pos].name=c;

}

}

for (i=0;i<26;i++)

{

printf("%c:t%ft%.0ft%.0fn",a[i].name,a[i].avg,a[i].marks,a[i].fees);

}

for(i=6;i<26;i++)

{

if((a[i].fees + a[i-1].fees + a[i-2].fees+a[i-3].fees+a[i-4].fees+a[i-5].fees+a[i-6].fees)<=4000 )

{

break;

}

}

int j;

printf("Optimal solution is : n");

for(j=0;j<7;j++)

{

printf ("%c ",a[i–]);

}

}

• mano

hi! i just want to know some problems that could be solved using graph data structure based on vertex or edge coloring…

• manu

kunju paiya. sootha moodu

• Anoop S S

Excellent work

• Hari priya

It’s really helpful!! thank u GeekfforGeeks

• anoop shukla

i got a new way to learn………..i like your data that are being provided

• Chetan

Wow loving it all ..Happy studying.. Good work geeksforgeeks

• Ganesh

Very helpful…. Few more Datastructure and algorithms resources shared here http://www.indiageeks.in/top-5-online-resources-to-learn-data-structures-algorithms/

• vsethuooo

This is great! I can find more algos in the misc page! Why don’t you transfer them here, for easier access!!

• savan

thank you guys

• harish.pendela

Excellent work geeksforgeeks team…!!

• ultimate_coder

excellent

• ultimate_coder

excellent

• Procastinator

Respect!!

• mahesh

You guys are awesome … respect !!!

• Akshay

Whenever I am confused about what to do…I come to geeksforgeeks…its a boon for passionate individuals who loves coding and dreams of bagging a job at software giants like google,microsoft..

• Naaz
``` ```
Great work....thank u guys !!!!!!!!!!

``` ```
• subho

Fantastic job being done by geeksforgeeks guys. Keep it up. really useful…..

• Loving it….

• Nauman

Guys u rock!! 1 of d best website ever!!

• azee

Awesome work guys. Best place to understand code level implementation of different algorithms. Very Very helpful.

• George

Thanks

• Chandana

This is till now the best website for all the knowledge on programming till now, I have come across. Awesome work people. Bless All

• PG

Excellent work guys..keep it up!!

``` ```
/* Paste your code here (You may delete these lines if not writing code) */
``` ```
• Ashish

Exactly the kind of website I was looking for. Alive, informative and to the point. Applause for your efforts.

• gosi
``` ```
indeed , worth a web Portal ...
``` ```
• Shailesh

Great Work,thank you so much…

• Sharat

Thank you for this great work… I love this site!

``` ```
/* Paste your code here (You may delete these lines if not writing code) */
``` ```