sushantmax88
BAN USERdo a inorder traversal on binary tree and suming up all integer in node as well keep count of nodes as well.
- sushantmax88 January 03, 2011yeah, if inorder traversal of tree is ascending then , its is a bst.
- sushantmax88 December 31, 2010we can use KMP as well for in this method. use S$R word to find longest palindrom. wher R is reverse of string S.
- sushantmax88 December 29, 2010time take for sorting = n log n and space = O(10)
other method is comparing each element and put it in an array
i=0
a[10] // maintain 10 biggest no in 1 million list
for each key
{ if key>a[i] then
a[i]=key
i++
if i=10 then
i=0;
}
t = linklist of one sorted list
u = linklist of other sorted list.
r = result link list
for ( t++ and u++)
{if t.data < u.data
r->next = t
r = r->next
if t.data = u.data
r->next = t
r= r->next
if t.data >u.data
r->next = u
r= r->next
}
if any one linklist become empty , put other linklist into result as such.
t = linklist of one sorted list
u = linklist of other sorted list.
r = result link list
for ( t++ and u++)
{if t.data < u.data
r->next = t
r = r->next
if t.data = u.data
r->next = t
r= r->next
if t.data >u.data
r->next = u
r= r->next
}
if any one linklist become empty , put other linklist into result as such.
we can create a queue of linklist in which we store the data value and pointer of tree while traversing the tree by any method, like preorder or inorder. then, while inserting new node we can check in queue whether this data value is already present in queue or not. if yeas, call delete(node *H) function, which delete the node.
- sushantmax88 December 21, 2010i think, better do linear search.because anyhow, whatever we are doing complexity is coming out to be O(n). so simply do a linear search,
- sushantmax88 November 17, 2010i also agree with that..
- sushantmax88 November 08, 2010O(n) time complexity..second post is correct
- sushantmax88 November 08, 2010assign two pointer. set first pointer and then set second pointer to be
temp2=start;
temp1=temp2->right;
while (temp1->right!=NULL)
{ if(temp1->right == temp2)
{
printf("linklist contain cycle");
temp1->right=NULL; // break cycle
}
temp1=temp1->right;
}
assign two pointer. set first pointer and then set second pointer to be
temp1=start;
temp2=temp1->right;
while (temp1->right!=NULL)
{ if(temp1->right == temp2)
{
printf("linklist contain cycle");
temp1->right=NULL; // break cycle
}
temp1=temp1->right;
}
a string is always ended by '/0' we can use this end of string character to reverse string.
- sushantmax88 November 02, 2010i can give you the algorithm how to perform.we find out the angle of minutes hand and hour hand reference point which is 12 o'clock in clockwise direction. now we find the difference between angle of both hand. if angle is smaller than 180 its is small sector else its is larger sector. and now we can see second hand. check if it lies between hour hand and minutes hand. it is in small sector. now how to find angles of hour and minutes hand.
for minutes hand. with every increase of 1 minutes 6 degree increase in angle from reference point. so angle = 6 * mm. now for hand .. we have to find exact position of hour hand.now we can find exact position of hour hand with the help of minutes hand. degree of hours hand = (hh+mm/12)* 6.
we can use augmented data structure. which store total no of node in link list on any variable. and store the position of node in node itself. later you can find the nth element from end in O(N) time.
- sushantmax88 October 19, 2010can you please tell how to use recursion for this.
- sushantmax88 October 19, 2010nope.. i mean, when you have list of 1,2,3,4,5,6,7,8,9
your root wil be at middle element. which is 5 now, left side again make it half n make it left child of 5 . same with right side. select middle element n make it right child of 5. every time you are making it half.
1,0 output..
- sushantmax88 October 18, 2010insert element from sorted array into binary search tree. keep a check if the element exist in binary search tee delete duplicate element. searching will take O(log n ) time.
- sushantmax88 October 17, 2010i suppose we can use counting sort, it will take O(n) time to sort. then to find kth element it will scan till k postion that will take O(k) time, so total will be O(n+k)..
- sushantmax88 October 17, 2010another way is,.. sort both list and compare each element. in both array
- sushantmax88 October 17, 2010
i was also thinking the same way
- sushantmax88 January 03, 2011