Available Balance
Binary Search Tree – Searching, Deletion

Searching a BST is even simpler than insertion. The pseudocode is self-explanatory but we will look brie°y at the premise of the algorithm nonetheless.
We have talked previously about insertion, we go either left or right with the right subtree containing values that are ¸ x where x is the value of the node
we are inserting. When searching the rules are made a little more atomic and at any one time we have four cases to consider:

1. the root = ; in which case value is not in the BST; or
2. root.Value = value in which case value is in the BST; or
3. value < root.Value, we must inspect the left subtree of root for value; or
4. value > root.Value, we must inspect the right subtree of root for value.
1) algorithm Contains(root, value)
2) Pre: root is the root node of the tree, value is what we would like to locate
3) Post: value is either located or not
4) if root = ; 5) return false
6) end if
7) if root.Value = value
8) return true
9) else if value < root.Value
10) return Contains(root.Left, value)
11) else
12) return Contains(root.Right, value)
13) end if
14) end Contains

Deletion

Removing a node from a BST is fairly straightforward, with four cases to consider:

1. the value to remove is a leaf node; or
2. the value to remove has a right subtree, but no left subtree; or
3. the value to remove has a left subtree, but no right subtree; or
4. the value to remove has both a left and right subtree in which case we


promote the largest value in the left subtree.
There is also an implicit ¯fth case whereby the node to be removed is the only node in the tree. This case is already covered by the ¯rst, but should be
noted as a possibility nonetheless. Of course in a BST a value may occur more than once. In such case the ¯rst occurrence of that value in the BST will be removed.

The Remove algorithm given below relies on two further helper algorithms named FindP arent, and FindNode which are described in x3.4 and x3.5 re-
spectively.

Rate This Content
Binary Search Tree – Insertion, Introduction

Binary search trees (BSTs) are very simple to understand. We start with a root node with value x, where the left subtree of x contains nodes with values < x
and the right subtree contains nodes whose values are ¸ x. Each node follows the same rules with respect to nodes in their left and right subtrees. BSTs are of interest because they have operations which are favourably fast: insertion, look up, and deletion can all be done in O(log n) time. It is important to note that the O(log n) times for these operations can only be attained if the BST is reasonably balanced; for a tree data structure with self balancing properties see AVL tree de¯ned in x7).

In the following examples you can assume, unless used as a parameter alias that root is a reference to the root node of the tree.

Insertion

As mentioned previously insertion is an O(log n) operation provided that the tree is moderately balanced.
1) algorithm Insert(value)
2) Pre: value has passed custom type checks for type T
3) Post: value has been placed in the correct location in the tree
4) if root = ; 5) root à node(value)
6) else
7) InsertNode(root, value)
8) end if
9) end Insert

1) algorithm InsertNode(current, value)
2) Pre: current is the node to start from
3) Post: value has been placed in the correct location in the tree
4) if value < current.Value
5) if current.Left = ; 6) current.Left à node(value)
7) else
8) InsertNode(current.Left, value)
9) end if
10) else
11) if current.Right = ; 12) current.Right à node(value)
13) else
14) InsertNode(current.Right, value)
15) end if
16) end if
17) end InsertNode

The insertion algorithm is split for a good reason. The ¯rst algorithm (non- recursive) checks a very core base case – whether or not the tree is empty. If
the tree is empty then we simply create our root node and ¯nish. In all other cases we invoke the recursive InsertNode algorithm which simply guides us to
the ¯rst appropriate place in the tree to put value. Note that at each stage we perform a binary chop: we either choose to recurse into the left subtree or the
right by comparing the new value with that of the current node. For any totally ordered type, no value can simultaneously satisfy the conditions to place it in
both subtrees.

Rate This Content
Linked Lists – Deletion, Reverse Traversal

As you may of guessed the cases that we use for deletion in a doubly linked list are exactly the same as those de¯ned in x2.1.3. Like insertion we have the added task of binding an additional reference (Previous) to the correct value.

1) algorithm Remove(head, value)
2) Pre: head is the head node in the list
3) value is the value to remove from the list
4) Post: value is removed from the list, true; otherwise false
5) if head = ; 6) return false
7) end if
8) if value = head.Value
9) if head = tail
10) head à ; 11) tail à ; 12) else
13) head à head.Next
14) head.Previous à ; 15) end if
16) return true
17) end if
18) n à head.Next
19) while n 6= ; and value 6= n.Value
20) n à n.Next
21) end while
22) if n = tail
23) tail à tail.Previous
24) tail.Next à ; 25) return true
26) else if n 6= ; 27) n.Previous.Next à n.Next
28) n.Next.Previous à n.Previous
29) return true
30) end if
31) return false
32) end Remove

Singly linked lists have a forward only design, which is why the reverse traversal algorithm de¯ned in x2.1.5 required some creative invention. Doubly linked lists make reverse traversal as simple as forward traversal (de¯ned in x2.1.4) except that we start at the tail node and update the pointers in the opposite direction. Figure 2.6 shows the reverse traversal algorithm in action.

1) algorithm ReverseTraversal(tail)
2) Pre: tail is the tail node of the list to traverse
3) Post: the list has been traversed in reverse order
4) n à tail
5) while n 6= ; 6) yield n.Value
7) n à n.Previous
8) end while
9) end ReverseTraversal

Linked lists are good to use when you have an unknown number of items to store. Using a data structure like an array would require you to specify the size
up front; exceeding that size involves invoking a resizing algorithm which has a linear run time. You should also use linked lists when you will only remove
nodes at either the head or tail of the list to maintain a constant run time. This requires maintaining pointers to the nodes at the head and tail of the list
but the memory overhead will pay for itself if this is an operation you will be performing many times. What linked lists are not very good for is random insertion, accessing nodes by index, and searching. At the expense of a little memory (in most cases 4 bytes would su±ce), and a few more read/writes you could maintain a count variable that tracks how many items are contained in the list so that accessing such a primitive property is a constant operation – you just need to update count during the insertion and deletion algorithms. Singly linked lists should be used when you are only performing basic in- sertions. In general doubly linked lists are more accommodating for non-trivial operations on a linked list. We recommend the use of a doubly linked list when you require forwards and backwards traversal. For the most cases this requirement is present. For example, consider a token stream that you want to parse in a recursive descent fashion. Sometimes you will have to backtrack in order to create the correct parse tree. In this scenario a doubly linked list is best as its design makes
bi-directional traversal much simpler and quicker than that of a singly linked

Rate This Content
Beauty & Style – IS BEAUTY REALLY SKIN DEEP?

43. While we don’t particularly recommend the practice of mendhi for everyday USA, it would be helpful in covering up some of those age spots, wouldn’t it? Try this tip. Apply vitamin E oil directly to the spots to fade the discoloration.

44. There is also a product that’s been around since Grandma was a youngster. It’s called porcelana and women have credited it for removing age spots for decades.

45. If you spend hours at a time on the computer, be sure you use a rest for your wrists. It will help ward off carpal tunnel syndrome

46. Your nails. Press on? Glue on? Paint on? Take your pick, there are nothing but choices out there. If you have your acrylic nails
done in a nail salon, understand that you do so at your own risk! It seems as though there is a nail salon on every corner in every city in the USA. If
the salon you are using does not replace or sanitize their instruments (files, nippers, brushes, etc.) in between customers, run, don’t walk for the
door. When trying out a new salon, arrive early for your appointment. If you are using a “walk in” shop, make certain you let someone go before
you. Sit or stand where you can “catch the action.” Pay close attention to how the nail tech prepares for the new client. Watch carefully to make
certain that he/she is skilled in the trade and does not accidentally break the skin especially if they haven’t sanitized their instruments. You’ve got a
lot at stake here. With the prevalence of aids, hepatitis and other diseases you can’t be too careful. If you see something that just doesn’t set well, get
up and leave. Try a more “upscale” shop next time.

47. Do not file the corner of your fingernails. It weakens, causing them to break and crac.

48. If your fingernails are brittle, it may be the soap you are using or a hand cream that is perfumed. Most perfumed hand creams contain alcohol which will dry the nails causing them to become brittle.

49. Are your nails cracked, brittle and breaking? Try drinking more water. . .yep. . .back to the water. At least 8 glasses a day. . .and that’s 8 ounce glasses.

Rate This Content
Beauty & Style – IS BEAUTY REALLY SKIN DEEP?

34. Replace eye makeup frequently. An enlightened woman of the 21st century would not be complete without her drawer full of makeup
magic. Unfortunately, you are just as apt to have the same tube of mascara that you used the night of your high school prom! If this describes you,
throw it away. Using the same mascara over and over again leaves you wide open for possible infection. Bacteria is alive and well and flourishing on your trusty little mascara wand. Pitch it out before it gives you trouble. Mascara should be replaced at least every 6 weeks

35. Use special eye moisturizer to keep tissue around the eyes soft and pliable. The skin around the eyes is very thin and easily damaged.

36. If you prefer not to use an eyelash curler, shop for mascara that is specially formulated to self curl

37. To obtain a smoky, sultry look, use a eyeliner pencil and liquid. Apply the penci first and gently smudge. Then apply the liner. Be
careful, a little goes a long way. You’ll love the look!

38. Powder your lashes before applying mascara. It will create a better bond for the mascara to cling to.

39. For “puffy” eyes, soak two teabags in cold water then apply to each eyelid.

40. User a hemorrhoid cream to shrink puffy eye tissue. It will reduce the swelling almost immediately.

41. Slices of raw potato placed under each eye will reduce the dark circles

42. Define and tame contrary eyebrows by using a toothbrush lightly sprayed with air spray. Gently brush into the eyebrow and ‘voila they’ll stay right where you brush them

Did you know. . .that many ancient beauty treatments are still in use today? An example is the East Indian art of painting the hands and feet with Henna. It is known in India as Mendhi and is an ancient Indian art form which has been performed for generations not only in India, but the Middle East, Pakistan and in Africa as well. Women in India traditionally painted henna on their hands and feet, insides of their arms and up their shins most often for a wedding, or other special occasion. The intricate patterns on the hands are particularly beautiful. Nothing will give away your age quicker than the condition of your hands.
Let’s take a look at some tips to try and hold off the ravages of time

Rate This Content
Beauty & Style – IS BEAUTY REALLY SKIN DEEP?

28. If you can wear them, consider switching to contact lenses. Make sure you remember to remove them when swimming. You can easily
lose them in the pool or worse, if you wear soft lenses you could contract a cornea infection that comes from a parasite found in water. The chlorine
won’t kill it and the result of this nasty little dude is not pleasant. You are inviting painful corneal infection that could cause partial or total blindness.

29. Try buying different colored lenses. You might discover a whole new you behind blue eyes!

30. Better yet, check out lasik. If you are a candidate it might give you a whole new lease on life. Of course, it’s a treatment for nearsightedness only, but if that’s your reason for wearing eyeglasses or contact lenses you might want to look into it. Just remember, even though the procedure is done with a laser, it is still a surgical procedure. Take your time and investigate to make certain that you visit a skilled surgeon who has completed many lasik procedures.

31. Take vitamin C, vitamin E and beta-carotene to improve your sight and overall health of your eyes.

32. Avoid caffeine. It negatively impacts the system that they eyes use for focusing. That includes coffee, tea and chocolate. Well, okay, if you can’t quit, at least cut back!

33. Do not over use eye drops. You may just make your eye sredder. Artificial tears are okay, but you should limit or avoid using vasoconstrictors. They will shrink the blood vessels on the surface of your eye. Check with your doctor if you need further explanation on the differences.

Did you know. . . that eye makeup worn by the ancient Egyptians served more than just a cosmetic purpose? It was worn by men and women alike.
It was decorative for certain but they also wore it for medicinal purposes as well as magical reasons. The Egyptian word for eye-palette is a derivative
from their word for “protect.” An eye that wore no makeup was considered to be “unprotected.” An unprotected eye was therefore at risk from the Evil
Eye. The next time you are standing in front of the mirror applying your eye makeup just remember that it is a rite of protection passed along from
Cleopatra to Betty Boop!

Rate This Content
Beauty & Style – IS BEAUTY REALLY SKIN DEEP?

20. Maybe you would prefer something a bit less abrasive, pardon the pun. If so, you might consider a deep peel. This process is
accomplished using an acid and are for moderately deep wrinkles. There are some risks associated with the acid procedure. It isn’t as stable as the
laser resurfacing because there is less control of the acid solution.

21. Have a glycolic or beta peel. This process won’t do much for your wrinkles, but if you are only looking to improve general skin tone, this is the one for you.

22. Try Retin A. If you want to see a smoothing of fine wrinkles and an overall healthy glow that will remove mottling and give your skin a youthful blush, then this is the route to go.

23. You can avoid all the nastiness of the previous treatments by choosing collagen injections. The biggest challenge with this choice is it’s temporary lasting just a few months so you have to repeat the procedure frequently.

24. Stop shaving your legs and use hot wax. Much gentler on your skin.

25. Mix up a tablespoon of brandy along with a smashed up peach and apply to your face for twenty minutes then rinse. Makes for a great summer facial hey don’t call them the “windows to the soul” for nothing! The eyes never lie. If you’re feeling and looking great your eyes will shine and sparkle. If you’re sad and lonely your eyes will give you away every time.

26. If you have red, watery eyes due to allergies, deal with them! There are plenty of medications available to eliminate allergy symptoms. Nothing will detract from your appearance faster than red eyes.

27. If you wear eyeglasses make certain that they do not detract from your appearance. Eyeglasses should complement your eyes,
not cover them. If your frames are unattractive it means you had the wrong sales person. Try again.

Rate This Content
Linked Lists – Traversing the list in reverse order, Doubly Linked List

Traversing a singly linked list in a forward manner (i.e. left to right) is simple as demonstrated in x2.1.4. However, what if we wanted to traverse the nodes in
the linked list in reverse order for some reason? The algorithm to perform such a traversal is very simple, and just like demonstrated in x2.1.3 we will need to
acquire a reference to the predecessor of a node, even though the fundamental characteristics of the nodes that make up a singly linked list make this an
expensive operation. For each node, ¯nding its predecessor is an O(n) operation, so over the course of traversing the whole list backwards the cost becomes O(n2). Figure 2.3 depicts the following algorithm being applied to a linked list with the integers 5, 10, 1, and 40.

1) algorithm ReverseTraversal(head, tail)
2) Pre: head and tail belong to the same list
3) Post: the items in the list have been traversed in reverse order
4) if tail 6= ; 5) curr à tail
6) while curr 6= head
7) prev à head
8) while prev.Next 6= curr
9) prev à prev.Next
10) end while
11) yield curr.Value
12) curr à prev
13) end while
14) yield curr.Value
15) end if
16) end ReverseTraversal

This algorithm is only of real interest when we are using singly linked lists, as you will soon see that doubly linked lists (de¯ned in x2.2) make reverse list traversal simple and e±cient, as shown in x2.2.3.

Doubly Linked List

Doubly linked lists are very similar to singly linked lists. The only di®erence is that each node has a reference to both the next and previous nodes in the list.

The following algorithms for the doubly linked list are exactly the same as
those listed previously for the singly linked list:
1. Searching (de¯ned in x2.1.2)
2. Traversal (de¯ned in x2.1.4)

Insertion

The only major di®erence between the algorithm in x2.1.1 is that we need to
remember to bind the previous pointer of n to the previous tail node if n was
not the ¯rst node to be inserted into the list.
1) algorithm Add(value)
2) Pre: value is the value to add to the list
3) Post: value has been placed at the tail of the list
4) n à node(value)
5) if head = ; 6) head à n
7) tail à n
8) else
9) n.Previous à tail
10) tail.Next à n
11) tail à n
12) end if
13) end Add
Figure 2.5 shows the doubly linked list after adding the sequence of integers
de¯ned in x2.1.1.

Rate This Content
Linked Lists – Deletion, Traversing the list

Deleting a node from a linked list is straightforward but there are a few cases
we need to account for:
1. the list is empty; or
2. the node to remove is the only node in the linked list; or
3. we are removing the head node; or
4. we are removing the tail node; or
5. the node to remove is somewhere in between the head and tail; or
6. the item to remove doesn’t exist in the linked list

The algorithm whose cases we have described will remove a node from any-where within a list irrespective of whether the node is the head etc. If you know
that items will only ever be removed from the head or tail of the list then you can create much more concise algorithms. In the case of always removing from
the front of the linked list deletion becomes an O(1) operation.

1) algorithm Remove(head, value)
2) Pre: head is the head node in the list
3) value is the value to remove from the list
4) Post: value is removed from the list, true; otherwise false
5) if head = ; 6) // case 1
7) return false
8) end if
9) n à head
10) if n.Value = value
11) if head = tail
12) // case 2
13) head à ; 14) tail à ; 15) else
16) // case 3
17) head à head.Next
18) end if
19) return true
20) end if
21) while n.Next 6= ; and n.Next.Value 6= value
22) n à n.Next
23) end while
24) if n.Next 6= ; 25) if n.Next = tail
26) // case 4
27) tail à n
28) end if
29) // this is only case 5 if the conditional on line 25 was false
30) n.Next à n.Next.Next
31) return true
32) end if
33) // case 6
34) return false
35) end Remove

 

Traversing the list

Traversing a singly linked list is the same as that of traversing a doubly linked
list (de¯ned in x2.2). You start at the head of the list and continue until you
come across a node that is ;. The two cases are as follows:
1. node = ;, we have exhausted all nodes in the linked list; or
2. we must update the node reference to be node.Next.
The algorithm described is a very simple one that makes use of a simple
while loop to check the ¯rst case.

1) algorithm Traverse(head)
2) Pre: head is the head node in the list
3) Post: the items in the list have been traversed
4) n à head
5) while n 6= 0
6) yield n.Value
7) n à n.Next
8) end while
9) end Traverse

Rate This Content
Linked Lists – Insertion , Searching and more

In general when people talk about insertion with respect to linked lists of any form they implicitly refer to the adding of a node to the tail of the list. When
you use an API like that of DSA and you see a general purpose method that adds a node to the list, you can assume that you are adding the node to the tail
of the list not the head.

Adding a node to a singly linked list has only two cases:
1. head = ; in which case the node we are adding is now both the head and
tail of the list; or
2. we simply need to append our node onto the end of the list updating the
tail reference appropriately.

1) algorithm Add(value)
2) Pre: value is the value to add to the list
3) Post: value has been placed at the tail of the list
4) n à node(value)
5) if head = ; 6) head à n
7) tail à n
8) else
9) tail.Next à n
10) tail à n
11) end if
12) end Add
As an example of the previous algorithm consider adding the following se-
quence of integers to the list: 1, 45, 60, and 12, the resulting list is that of

Figure 2.2.

 

Searching

Searching a linked list is straightforward: we simply traverse the list checking
the value we are looking for with the value of each node in the linked list. The
algorithm listed in this section is very similar to that used for traversal in x2.1.4.

1) algorithm Contains(head, value)
2) Pre: head is the head node in the list
3) value is the value to search for
4) Post: the item is either in the linked list, true; otherwise false
5) n à head
6) while n 6= ; and n.Value 6= value
7) n à n.Next
8) end while
9) if n = ; 10) return false
11) end if
12) return true
13) end Contains

guys for study about physics so let’s join my post and support

physics – http://literacybase.com/physics-study-electric-charges-and-fields/

If you want to for more accounting for begging

so let’s join our accounting post – Introduction to Accounting – Definition, Meaning

Rate This Content