Problems
five pirates have 100 gold coins. they have to divide up the loot. in order of seniority (suppose pirate 5 is most senior, pirate 1 is least senior), the most senior pirate proposes a distribution of the loot. they vote and if at least 50% accept the proposal, the loot is divided as proposed. otherwise the most senior pirate is executed, and they start over again with the next senior pirate.
[Read More]
sum it up
<br /> <!--<br /> /\* Font Definitions \*/<br /> @font-face<br /> {font-family:"Cambria Math";<br /> panose-1:2 4 5 3 5 4 6 3 2 4;<br /> mso-font-charset:1;<br /> mso-generic-font-family:roman;<br /> mso-font-format:other;<br /> mso-font-pitch:variable;<br /> mso-font-signature:0 0 0 0 0 0;}<br /> @font-face<br /> {font-family:"Arial Unicode MS";<br /> panose-1:2 11 6 4 2 2 2 2 2 4;<br /> mso-font-charset:128;<br /> mso-generic-font-family:swiss;<br /> mso-font-pitch:variable;<br /> mso-font-signature:-134238209 -371195905 63 0 4129279 0;}<br /> @font-face<br /> {font-family:"\\@Arial Unicode MS";<br /> panose-1:2 11 6 4 2 2 2 2 2 4;<br /> mso-font-charset:128;<br /> mso-generic-font-family:swiss;<br /> mso-font-pitch:variable;<br /> mso-font-signature:-134238209 -371195905 63 0 4129279 0;}<br /> /\* Style Definitions \*/<br /> p.
[Read More]
Palindrome years
Problem:
This year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards).
10/02/2001
when was the last date that this occurred on? (see if you can do it in your head!)
Solution:
we know the year has to be less than 2001 since we already have the palindrome for 10/02. it can’t be any year in 1900 because that would result in a day of 91.
[Read More]
Red marbles, blue marbles
Problem
You have two jars, 50 red marbles, 50 blue marbles. you need to place all the marbles into the jars such that when you blindly pick one marble out of one jar, you maximize the chances that it will be red. (when picking, you’ll first randomly pick a jar, and then randomly pick a marble out of that jar) you can arrange the marbles however you like, but each marble must be in a jar.
[Read More]
Reverse a string - word by word
Problem: Reverse “the house is blue”, the answer should be “blue is house the”. the words are reversed, but the letters are still in order (within the word).
Solution:
The solution can be attained by first reversing the string normally, and then just reversing each word.
initial: the house is blue
reverse: eulb si esuoh eht
Now reverse the word at its place
initial: the house is blue
reverse: eulb si esuoh eht
wanted : blue is house the
17 September Solutions
Answers
b
c
b
a
d
d
Solutions:
1)
Number of ordered pairs = 1;
because D=5, G=1
**Step 1.** a + b + c + d = d + e + f + g = g + h + i = 17 Means, ( a + b + c + d )+ (d +e + f + g )+ (g +h + i ) = 17 +17+17 = 17 x 3 = 51 a + b + c + d + e + f + g + h + i +( d + g ) = 51 **Step 2.
[Read More]
Create a copy of a tree
Node *copy(mynode *root)
{
Node *temp;
if(root==NULL)return(NULL);
temp = (mynode *) malloc(sizeof(mynode));
temp->value = root->value;
temp->left = copy(root->left);
temp->right = copy(root->right);
return(temp);
}
tree1.h fully updated
//We will do following Functions:
1. lookup
2. Insert
3. printTree,printPost, printPre
4. Selection Function
5. Delete(Hence implemented - child0,child1,child2, inorder2 functions)
#ifndef TREE1_H
#define TREE1\_H ``` ``` \# include <stdio.h> # include <stdlib.h>
#define isChildless(p) p->left==NULL &&p->right==NULL enum BOOL{false,true} ;
typedef enum BOOL BOOL; ``` ``` struct node { int data;
struct node\* left; struct node* right;
} ; typedef struct node node;
/*
Given a binary tree, return true if a node with the target data is found in the tree.
[Read More]
Deleting a node from a Binary Search Tree
Suppose we want to delete a node k. First we need to search for the node k. Offcourse k should not be null.
Then we have three cases:
1. The node to be deleted has no children - The memory occupied by this node must be freed and either the left link or the right link of the parent of this node must be set to NULL.
2. The node to be deleted has exactly one child -
[Read More]
Inorder successor OR Predecessor of BST node
It is important to understand inorder successor of BST because it helps us understand deletion of node from a tree, when the node deleted has 2 children.
To find the inorder successor of node u:
If u has a right child, r, then succ(u) is the leftmost descendent of r
Otherwise, succ(u) is the closest ancestor, v, of u (if any) such that u is descended from the left child of v.
[Read More]