1. There are three cases to consider when deleting a node x from a tree: x has no children, x has one child, or x has two children.
2. If x has two children, its successor y is found and removed instead of x, and y's key is copied to x.
3. The expected time to insert n random keys into an initially empty binary search tree is O(n log n). This is because the average height of the resulting tree is O(log n).
I am Kepha M. I am a Control System Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. in Matlab, McGill University, Canada. I have been helping students with their homework for the past 8 years. I solve assignments related to Control Systems.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Control System Assignments.
I am Nigel J. I am a Computer Network Assignment Expert at computernetworkassignmenthelp.com. I hold a Master's in Computer Science from, the University of Glasgow, UK. I have been helping students with their assignments for the past 15 years. I solve assignments related to Computer Networks.
Visit computernetworkassignmenthelp.com or email support@computernetworkassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Network Assignment.
It is a presentation on some Searching and Sorting Techniques for Computer Science.
It consists of the following techniques:
Sequential Search
Binary Search
Selection Sort
Bubble Sort
Insertion Sort
This is a seminar presentation on "SORTING" for Semester 2 exam at St. Xavier's College.The power point presenation deals with the requirement of sorting in our life,types of sorting techniques,code for implementing them,the time and space complexity of different sorting algorithms,the applications of sorting,its use in the industry and its future scope.The slide show contains .gif files which can't be seen here.For more details or any queries send me a mail at agmajumder@gmail.com
I am Kepha M. I am a Control System Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. in Matlab, McGill University, Canada. I have been helping students with their homework for the past 8 years. I solve assignments related to Control Systems.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Control System Assignments.
I am Nigel J. I am a Computer Network Assignment Expert at computernetworkassignmenthelp.com. I hold a Master's in Computer Science from, the University of Glasgow, UK. I have been helping students with their assignments for the past 15 years. I solve assignments related to Computer Networks.
Visit computernetworkassignmenthelp.com or email support@computernetworkassignmenthelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Network Assignment.
It is a presentation on some Searching and Sorting Techniques for Computer Science.
It consists of the following techniques:
Sequential Search
Binary Search
Selection Sort
Bubble Sort
Insertion Sort
This is a seminar presentation on "SORTING" for Semester 2 exam at St. Xavier's College.The power point presenation deals with the requirement of sorting in our life,types of sorting techniques,code for implementing them,the time and space complexity of different sorting algorithms,the applications of sorting,its use in the industry and its future scope.The slide show contains .gif files which can't be seen here.For more details or any queries send me a mail at agmajumder@gmail.com
Show that the worst-case time complexity for Binary Search is given by.docxmmary455
Show that the worst-case time complexity for Binary Search is given by
when n is not restricted to being a power of 2. Hint: First show that the recurrence equation for W(n) is given by
T(1) = 1
To do this, consider even and odd values of n separately. Then use induction to solve the recurrence equation.
I understand how to find this with base 2 but totally lost otherwise?
Solution
Hi there,
The time to search in an array of N elements is equal to the time to search in an array of N/2 elements plus 1 comparison.
T(N) = T(N/2) + 1
Now we re-write the function in recurrence.
T(N) = T(N/2) + 1
T(N/2) = T(N/4) + 1
T(N/4) = T(N/8) + 1
……
T(4) = T(2) + 1
T(2) = T(1) + 1
Next we sum up the left and the right sides of the equations above:
T(N) + T(N/2) + T(N/4) + T(N/8) + … +T(2) = T(N/2) + T(N/4) + T(N/8) + … +T(2) + T(1) + (1 + 1 + … + 1)
The number of 1’s on the right side is LogN
Finally, we cross the equal terms on the opposite sides and simplify the remaining sum on the right side, we get,
T(N) = T(1) + LogN
T(N) = 1 + LogN as T(1)=1
The worst case time complexityof binary search is:
T(N) = O(LogN)
.
Find the compact trigonometric Fourier series for the periodic signal.pdfarihantelectronics
Find the compact trigonometric Fourier series for the periodic signal x(t) and sketch the
amplitude and phase spectrum for first 4 frequency components. By inspection of the spectra,
sketch the exponential Fourier spectra. By inspection of spectra in part b), write the exponential
Fourier series for x(t)
Solution
ECE 3640 Lecture 4 – Fourier series: expansions of periodic functions. Objective: To build upon
the ideas from the previous lecture to learn about Fourier series, which are series representations
of periodic functions. Periodic signals and representations From the last lecture we learned how
functions can be represented as a series of other functions: f(t) = Xn k=1 ckik(t). We discussed
how certain classes of things can be built using certain kinds of basis functions. In this lecture we
will consider specifically functions that are periodic, and basic functions which are
trigonometric. Then the series is said to be a Fourier series. A signal f(t) is said to be periodic
with period T0 if f(t) = f(t + T0) for all t. Diagram on board. Note that this must be an everlasting
signal. Also note that, if we know one period of the signal we can find the rest of it by periodic
extension. The integral over a single period of the function is denoted by Z T0 f(t)dt. When
integrating over one period of a periodic function, it does not matter when we start. Usually it is
convenient to start at the beginning of a period. The building block functions that can be used to
build up periodic functions are themselves periodic: we will use the set of sinusoids. If the period
of f(t) is T0, let 0 = 2/T0. The frequency 0 is said to be the fundamental frequency; the
fundamental frequency is related to the period of the function. Furthermore, let F0 = 1/T0. We
will represent the function f(t) using the set of sinusoids i0(t) = cos(0t) = 1 i1(t) = cos(0t + 1)
i2(t) = cos(20t + 2) . . . Then, f(t) = C0 + X n=1 Cn cos(n0t + n) The frequency n0 is said to be
the nth harmonic of 0. Note that for each basis function associated with f(t) there are actually two
parameters: the amplitude Cn and the phase n. It will often turn out to be more useful to
represent the function using both sines and cosines. Note that we can write Cn cos(n0t + n) = Cn
cos(n) cos(n0t) Cn sin(n)sin(n0t). ECE 3640: Lecture 4 – Fourier series: expansions of periodic
functions. 2 Now let an = Cn cos n bn = Cn sin n Then Cn cos(n0t + n) = an cos(n0t) + bn
sin(n0t) Then the series representation can be f(t) = C0 + X n=1 Cn cos(n0t + n) = a0 + X n=1 an
cos(n0t) + bn sin(n0t) The first of these is the compact trigonometric Fourier series. The second
is the trigonometric Fourier series.. To go from one to the other use C0 = a0 Cn = p a 2 n + b 2 n
n = tan1 (bn/an). To complete the representation we must be able to compute the coefficients.
But this is the same sort of thing we did before. If we can show that the set of functions
{cos(n0t),sin(n0t)} is in fact an orthogonal set, then we can use the same.
4. 4
Deletion Case 2
…
If xhas exactly one child, then to delete x, simply make p[x] point to that child
5. 5
Deletion Case 3
…
If xhas two children, then to delete it we have to
…
find its successor (or predecessor) y
…
remove y (note that y has at most one child –why?)
…
replace x with y
7. 7
In order traversal of a BST
…
ITW can be thought of as a projection of the BST nodes onto a one dimensional interval
8. 8
BST Sorting
…
Use TreeInsert and InorderTreeWalk to sort a list of nelements, A
TreeSort(A)
01root[T]←NIL
02fori←1ton
03TreeInsert(T,A[i])
04InorderTreeWalk(root[T])
9. 9
…
Sort the following numbers5 10 7 1 3 1 8
…
Build a binary search tree
…
Call InorderTreeWalk
1 1 3 5 7 8 10
BST Sorting (2)
10. 10
In what order should we insert?
…
We want to sort numbers {1,2,…,n}
…
Total time taken to insert these numbers equals the sum of the level numbers of the nodes.
…
Thus if numbers were inserted in ascending order we would get a tree of height n-1 in which there is one node at each level.
…
So total time for insertion in this case is 1+2+3+…+n-1 = O(n2).
11. 11
Inserting a random permutation
…
Suppose we take a random permutation of the keys and inserted them in this order.
…
The total time required for insertion is now a random variable.
…
We want to compute the expected value of this r.v.
…
Recall that the expected value of a r.v. is the average value it takes over a large number of trials.
14. 14
Expected insertion time for a random permutation
…
We will compute the average time taken to insert keys in the order specified by the n! permutations.
…
In other words, for each of the n! permutations we will compute the time taken to insert keys in that order and then compute the average.
…
Let T(n) denote this quantity.
15. 15
Inserting a random permutation (2)
…
Of the n! permutations, there are (n-1)! permutations in which the first element is i.
…
The tree formed in these instances has i as the root. The left subtree has keys 1..(i-1) and the right subtree has keys (i+1)..n
…
Consider the ordering of keys 1..(i-1) in the (n-1)! permutations. All (i-1)! permutations appear and each occurs (n-1)!/(i-1)! times.
16. 16
Inserting a random permuation(3)
…
Recall that if we only had keys 1..(i-1) then average time taken to insert them is T(i-1).
…
The average is taken over all permutations of 1..(i-1).
…
hence total time to insert all (i-1)! permutations is (i-1)!T(i-1).
17. 17
Inserting a random permutation(4)
…
When inserting keys 1..(i-1) into the left subtree, each key has to be compared with the root.
…
This leads to an additional unit cost for each key.
…
So total time to insert all (i-1)! permutations is (i-1)!(T(i-1)+(i-1)).
…
Since each permutation appears (n-1)!/(i-1)! times, total time to insert keys 1..(i-1) is (n-1)!(T(i-1)+(i-1))
18. 18
Inserting a random permutation(5)
…
Time to insert keys 1..(i-1) is (n-1)!(T(i-1)+(i-1))
…
Similarly, time to insert keys (i+1)..n is (n-1)!(T(n-i)+(n-i))
…
Total time to insert all n keys in permutations where the first key is i is (n-1)! (T(i-1)+T(n-i)+ n-1)
…
Total time to insert all n keys in all n! permutations is (n-1)! Σi=1n(T(i-1)+T(n-i)+ n-1).
19. 19
Building the recurrence
…
We are expressing the value of function T() at point n in terms of the value of T() at points 0..n- 1. This is called a recurrence relation.
22. 22
Summing the harmonic series
…
What is the sum ½+ 1/3 + ¼+…1/n?
1/2
1/3
1/4
1/5
1/6
1 2 3 4 5 6 n
x
1/x
It is at most the area under the curve f(x)=1/x between limits 1 and n
1/n
23. 23
The expected time for insertion
Thus the expected time for inserting a randomly chosen permutation of n keys is O(n log n)
24. 24
Minimum time to insert n keys
…
The time required to insert n keys is minimum when the resulting tree has the smallest possible height.
…
A binary tree on n nodes has height at least log2n
…
To insert the n/2 nodes at level log2n we require at least (n/2)log2n time.
…
Hence inserting n keys requires Ω(nlog2n) time.
25. 25
Summary of Running times
…
To insert n keys into a binary search tree which is initially empty requires
…
O(n2) time in the worst case.
…
O(nlog n) time in the best case.
…
O(nlog n) time in the average case; the average is taken over the n! different orders in which the n keys could be inserted.