Part 1: Your tasks for this assignment are the following:
1. Discuss the use of a binary tree when searching for keys in an array.
If the array is ordered, binary search can be performed on it. The key value is used to search for the item or perform other operations on it.
Binary tree can be created from an array to perform faster searches. Every node in a binary tree can have at most two children.
The two children of each node are called the left child and right child corresponding to their positions.
A node can have only a left child or only a right child, or it can have no children at all.
Left child is always less that its parent, while right child is greater than its parent.
To find a node given its key value, start from the root.
If the key value is same as the node, then node is found.
If key is greater than node, search the right sub tree, else search the left sub tree.
Continue till the node is found or the entire tree is traversed.
Time required to find a node depends on how many levels down it is situated, i.e. O(log N).
· Assume number of nodes N and number of levels L.
· N = 2L -1
· N+1 = 2L
· L = log(N+1)
· The time needed to carry out the common tree operations is proportional to the base 2 log of N
O(log N) time is required for these operations
Discuss the use of a binary tree when searching for keys in a linked list.
Binary Tree can be implemented using linked list. Binary trees are one of the most efficient data structures for sorting data. If the data is sorted (Binary Search Tree), searching will be faster. Binary tree has node. Each one is linked to two different nodes, a left node and a right node. Every node have a comparable key and follows the restriction that the key belonging to any node is larger than nodes is higher than the keys on all the client nodes. In a linked list, the items are associated together through a single next pointer. In a binary tree, each node can have 0, 1 or 2 sub nodes, where (in case of a binary search tree) the key of the left node is lesser than the key of the node and the key of the right node is more than the node. As long as the tree is balanced, the search path to each item is a lot shorter than that in a linked list.
Part 2: Complete the following program:
1. Describe a linked list structure to support binary searching.
With a plain linked list, you cannot do binary search directly, since random access on linked lists is O(n). The main issue, besides that you have no constant-time access to the linked list elements, is that you have no information about the length of the list. In this case, you simply have no way to "cut" the list in 2 halves.
If a linked list is sorted, we can create a method which can return middle node.
A linked list structure to support binary searching is assumed to be like this:
A linked list has a Head pointer, that indicates to the first node of the tilt.
Each node in turn stores some data (represented by 20 , 5 , 32 & 14 in the above image) and a .
Part 1 Your tasks for this assignment are the following1. Disc.docx
1. Part 1: Your tasks for this assignment are the following:
1. Discuss the use of a binary tree when searching for keys in an
array.
If the array is ordered, binary search can be performed on it.
The key value is used to search for the item or perform other
operations on it.
Binary tree can be created from an array to perform faster
searches. Every node in a binary tree can have at most two
children.
The two children of each node are called the left child and right
child corresponding to their positions.
A node can have only a left child or only a right child, or it can
have no children at all.
Left child is always less that its parent, while right child is
greater than its parent.
To find a node given its key value, start from the root.
If the key value is same as the node, then node is found.
If key is greater than node, search the right sub tree, else search
the left sub tree.
Continue till the node is found or the entire tree is traversed.
Time required to find a node depends on how many levels down
it is situated, i.e. O(log N).
· Assume number of nodes N and number of levels L.
· N = 2L -1
· N+1 = 2L
· L = log(N+1)
· The time needed to carry out the common tree operations is
proportional to the base 2 log of N
O(log N) time is required for these operations
Discuss the use of a binary tree when searching for keys in a
linked list.
Binary Tree can be implemented using linked list. Binary trees
are one of the most efficient data structures for sorting data. If
the data is sorted (Binary Search Tree), searching will be faster.
2. Binary tree has node. Each one is linked to two different nodes,
a left node and a right node. Every node have a comparable key
and follows the restriction that the key belonging to any node is
larger than nodes is higher than the keys on all the client nodes.
In a linked list, the items are associated together through a
single next pointer. In a binary tree, each node can have 0, 1 or
2 sub nodes, where (in case of a binary search tree) the key of
the left node is lesser than the key of the node and the key of
the right node is more than the node. As long as the tree is
balanced, the search path to each item is a lot shorter than that
in a linked list.
Part 2: Complete the following program:
1. Describe a linked list structure to support binary searching.
With a plain linked list, you cannot do binary search directly,
since random access on linked lists is O(n). The main issue,
besides that you have no constant-time access to the linked list
elements, is that you have no information about the length of
the list. In this case, you simply have no way to "cut" the list in
2 halves.
If a linked list is sorted, we can create a method which can
return middle node.
A linked list structure to support binary searching is assumed to
be like this:
A linked list has a Head pointer, that indicates to the first node
of the tilt.
Each node in turn stores some data (represented by 20 , 5 , 32 &
14 in the above image) and a pointer to the following node in
the tilt.
Likewise, as seen in a higher place, the last node of the Linked
list has its 'next' pointer, pointing to NULL.
3. This is a linked list structure type:
struct node
{
int data; // Integer data
node * next; // Pointer to next node in Linked List
};
node * head; // Head of linked list
2. Create pseudo code to describe a binary search with this
linked list variation.
We get out the middle node between any two nodes of a linked
list.
node * middleNode( node * startNode , node * endNode)
if( startNode == NULL )
// Linked list is empty
return NULL
END
node * slowPtr = startNode
node * fastPtr = startNode -> next
while ( fastPtr != endNode )
fastPtr = fastPtr -> next
if( fastPtr != endNode )
4. slowPtr = slowPtr -> next // Notice that for
each loop iteration :
fastPtr = fastPtr -> next // slowPtr moves
just one location
// while fastPtr moves two
nodes at a time.
END
END
return slowPtr // At the end , the slowPtr will be
pointing to the middle node
END
node * binarySearch( int valueToSearch )
node * startNode = head
node * endNode = NULL
do
node * middle = middleNode( startNode , endNode )
if( middle == NULL )
// element not present
return NULL
END
if( middle->data == valueToSearch )
return middle
END
else if ( middle->data < valueToSearch )
// need to search in upper half
5. startNode = middle->next
END
else
// need to search in lower half
endNode = middle
END
ENDwhile( endNode == NULL || endNode->next !=
startNode )
// data not present
return NULL
END
Think of a strategy pursued by the company your work for,
another company, or even a sports team. How can game theory
help improve the outcomes for the decision makers? Explain
whether simultaneous-move, repeated-move, or sequential-move
games are most applicable. Are there incentives for collusion?
Should a random strategy be used? What differences in
outcomes might you expect if the decision maker uses game
theory when developing strategies?
Make sure to give specific real-world examples.
1 page (cover and reference page not counted).
This is for an economic course.