aastha
Forum Replies Created

AuthorPosts

Merge sort is used to sort element of an array. In merge sort the existing array is divided into two equal halves which are sorted (result of subproblem) separately and merged again to give the array in sorted form.
Merge sort uses divide and conquer approach.
Steps Involved: –
Array A, Size n,
1. Divide the A in two halves A1, A2 containing
• n/2 elements each if n is even.
• First (n1)/2 and last (n+1)/2 elements respectively.
2. Repeat Step 1 on A1 and A2 separately in Step 1 until size of A1=1 and size of A2= 1.
3. Merging A1 and A2 into A.
initialize i,j,k= 0.
while(i< sizeof(A1) && j<sizeof(A2))
If(A1[i]<= A2[j])
A[k]= A1[i]
i++, k++
else
A[k]= A2[j]
j++, k++
while(i< sizeof(A1)) //if(sizeof(A1)> sizeof(A2)
A[k]= A1[i]
k++, i++
while(j<sizeof(A2)) //if(sizeof(A2)> sizeof(A1)
A[k]= A1[j]
k++, j++Time Complexity
Size decreases by a factor of 2 for each sub problem and there are two recursive calls made at each step therefore,
T(n)= 2T(n/2) + cn
Therefore time complexity of merge sort is of the order O(n log(n)).Quick sort is a sorting algorithm used to sort elements of an array. Quick sort make use of a pivot which is selected using randomized selection or constrained selection and sort the array in reference with the pivot element. All the elements which are smaller in value than pivot element is placed at right of the pivot and all elements greater than pivot are placed at right of pivot hence placing pivot at correct position (position at which pivot element would be present if the array was sorted).
Quick sort uses divide and conquer approach.
Selection of pivot: –
• Last element is selected as pivot.
• First element is selected as pivot.
• Pivot is selected at random.
• Pivot is selected as median of the array.Steps involved: –
ArrayA, Size n, i= iterator to separate element larger and smaller than pivot, j= iterator to travers1. Set i= A[0], j= A[1], swap pivot element with first element.
2. If (A[1]< pivot)
i++, j++.
else j++
3. while (j! = n1)
if(A[j]< pivot)
swap(A[i+1], A[j])
i++, j++
else j++
4. swap(A[0], A[i]) //to move pivot to its exact position.
5. Recurs Step 1,2,3,4 on subarrays A1 and A2
Where A1= array of elements on left of pivot.
A2= array of elements on right of pivot.Time Complexity
1. Best Case
Best case of quick sort occurs when pivot is selected as the middle element of the array. As problem size is decreased by a factor of 2.
Therefore,
T(n)= 2T(n/2) + cn
So complexity of algorithm is of the order O(nlog(n)) (by Master Method ).2. Worst Case
Worst case of quick sort occurs when pivot is selected as either the smallest or the largest elements in the array. As size of the array will decrease by 1 unit and each recursive call will have n1 elements to sort.
So, complexity of algorithm is of the order O(n2).Binary search is a searching algorithm used for searching an element in sorted array. It proceeds by neglecting half the size of array and then recur the same searching process on the halfsized array.
Binary Search uses divide and conquer approach.
Steps Involved: –
Array A, size of array n, element to be searched e.
1. Compare e with middle element of the array.
2. If e matches then, e is present at the middle position.
3. If e is less than middle element, then repeat STEP1 and STEP2 on left side of the A (i.e. elements present at left of middle element).
4. If e is greater than middle element, then repeat STEP1 and STEP2 on right side of the A (i.e. elements present at right of middle element).Time Complexity
T(n)= T(n/2) + c
Comparing this to Master Method the above expression belongs to second case. Therefore time complexity of binary search is of the order O(log n).Variation and Uses
1. Find first occurrence of an element.
This can be done by altering the termination condition.
a) Terminate when there is only one element left in A.
b) Terminate if middle element is equal to the key and element on the left of the middle element (A [mid 1]) is not equal to the key.April 11, 2016 at 9:06 am in reply to: What is the difference between variable and parameter? #15596Variable
In the field of programming we can define variable as a value that can be change depending on the conditions or the information passed to the program. As we know program consist of instructions and instructs computer what to do and program use data when it is running. Data contain some fixed value that never change, variable value that are usually initialized to “0” and some of the default values because actual value supplied by the user of the program or computer. Constants and variables both are type of data types. It also determine and limits the form of the data.
Parameter
This is one of the special kind of variable in the programming language which is basically used to pass information between functions or procedures. So the function of parameter is bind to procedures or functions which pass the actual information which is sometimes known as arguments. There are some of the specified rules that are passed to functions are determined by the programming language. Don’t get confused with perimeter as it defines the external boundaries of a situation but not able to assessing it, we can define that as a static measure of the sample.
Cursor in SQL is a temporary work area that is created in the system memory whenever the SQL statement is executed. This contain information of the statement you selected and the row of the data accessed by it. Basically the temporary work area is used to store the data received from the database, and manipulate it. A cursor have a capability to hold more than one row, but process only one row at a time. Cursor hold the set of row that known as active set. Cursor is mainly of two type Implicit and Explicit.
When cursor should be used by implicit and explicit way
Implicit
Implicit cursors are created by default when the statements like INSERT, UPDATE, DELETE all DML statements are executed. When they are created? When the SELECT statement that returns just one row is executed.Explicit
Explicit cursor is used when SELECT statement is executing and returning more than one row. This cursor is able to store multiple records that can be processed at a time which are known as current row. Once the row is fetched then cursor move to the next row.We can define wrapper as a data that give direction and frame the main data, and framed data is setup for the program or required in the program so that we can run that program successfully. Sometimes this technique seems on internet where “http://”and “ftp://” descried as wrapper that wrap the internet address that URL follow. By help the help of bracketing symbols the technique is to be used on internet. If we talk about programming it is a program or a script that combined with another program and make them possible to run successfully. It also helps in data transmission, wraps the data that provide information and also encapsulate it so that it can view by intended recipient. To encapsulate the data wrapper consist of a header that precedes the data and trailer that follow it. The advantage of the wrapper vary with the different technology. Basically wrapper used in the situation where primitive data type is not allowed, so a wrapper class can provide many utility methods also.
A stored procedure is a stored routine which consist set of SQL statements that stored on the server. It can also be defined as a method that encapsulate repetitive tasks. The method is allow for the variable declarations, flow control which is useful in many different programming language. The method is useful for controlling access to data, preserve information that entered in the consistent manner and improve the productivity in terms of statement need to be written for once in stored procedure. First we need to define the procedure according to the functionality we need to perform then we need to preserve it by giving it the unique name. Whenever defined procedure is required anywhere we need to CALL it and then EXECUTE.
MySQL stored procedure advantages
As we know the stored procedure help to increase the performance of the application by once created procedures and again and compiled and stored in the database. The way MySQL use stores procedure is slightly different because they compile on demand and after compiling it puts in into a cache. So, maintain its own stored procedure cache for every single connection. For example if an application use the same stored procedure multiple times in a single connection then the compiled version is used and in the other way it behave like a simple query to execute something. The main purpose of using stored procedure is that, they reduce traffic between the application and the database server as they are stored on the server only. They are scalable, reliable to use and secure also.
Introduction to Bayes’ Theorem
Bayes’ theorem sometimes called as Bayes’Law and Bayes’Rule is a theorem of probability that stated by Reverend Thomas Bayes. The theorem describes the probability of the event that based on some of the conditions that might be related to event. This theorem apply in wide variety of range, ranging from marine biology to the development of the spam folder for email system. The main purpose of the theorem is try to find out the relationship between theory and evidence. Now look at the theorem and the terminologies involved in it.
P(TE)=(P(E│T)×P(T))/(P(E│T)×P(T)+P(E│¬T)×P(¬T))
Here T stands for Theory that we are going to going to test, and E stands for evidence on this the theory depends either it seems to confirm or disallow. For any proposition we use P(S) where S should be true and here P(T) represents estimate of the probability that we are considering so we can call this as a prior probability of T. ¬T shows the negation of T that means proposition of T is false.
 This reply was modified 4 years, 4 months ago by aastha.

AuthorPosts