Sei sulla pagina 1di 5

11/05/2020 :: eLearning - Hebeon Technologies ::

   (Login.aspx)
(../StudentHome.aspx)

 EXAM     
? 0/182
 Home (../StudentHome.aspx)
/ Data Structures Using C (LanguageHome.aspx?
Level MCQ Score  Level CC Score  I
CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Structures+Using+C)
Intro

S1
Custom Level
Stage - 1

PROCEED 
S2

Stage - 2

 Dynamic programming S3

Stage - 3
Dynamic programming (usually referred to as DP) is a very powerful technique to solve a
particular class of problems. It demands very elegant formulation of the approach and S4
simple thinking and the coding part is very easy. The idea is very simple, If you have
Stage - 4
solved a problem with the given input, then save the result for future reference, so as to
avoid solving the same problem again..Shortly 'Remember your Past' :).  If the given
S5
problem can be broken up in to smaller sub-problems and these smaller subproblems are
Stage - 5
in turn divided in to still-smaller ones, and in this process, if you observe some over-
lapping subproblems, then it’s a big hint for DP. In addition, the optimal solutions to the
subproblems contribute to the optimal solution of the given problem. S6

Stage - 6

 Greedy algorithm:-
L-E

greedy algorithm, as the name suggests, always makes the choice that seems to be the Level Exam
best at that moment. This means that it makes a locally optimal choice in the hope that
this choice will lead to a globally optimal solution 
Greedy algorithms have some advantages and disadvantages: Menu

 It is quite easy to come up with a greedy algorithm (or even multiple greedy
algorithms) for a problem.

 Analysing the run time for greedy algorithms will generally be much easier than for
other techniques (like Divide and conquer). For the Divide and conquer technique, it

is not clear whether the technique is fast or slow. This is because at each level of
recursion the size of gets smaller and the number of sub-problems increases.

 The difficult part is that for greedy algorithms you have to work much harder to 
understand correctness issues. Even with the correct algorithm, it is hard to prove
why it is correct. Proving that a greedy algorithm is correct is more of an art than a

science. It involves a lot of creativity.

Branch and bound (BB)


☰  The Branch and Bound (BB or B&B) algorithm is first proposed by A. H. Land and
Powered
A. G. Doig in 1960 by Hebeon
for discrete Technologies It
programming. Private Ltd (http://hebeon.com/)
is a general algorithm for finding
 
https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 1/5
11/05/2020 :: eLearning - Hebeon Technologies ::

(../StudentHome.aspx)
optimal solutions of various optimization problems, especially in discrete and

combinatorial optimization. A branch and bound algorithm consists of a systematic


 EXAM     
enumeration of all candidate solutions, where large subsets of fruitless candidates
I
are fathomed, by using upper and lower estimated bounds of the quantity being
Intro
optimized.

 Branch and Bound algorithm, as a method for global optimization for discrete S1

Stage - 1
problems, which are usually NP-hard, searches the complete space of solutions for a

given problem for the optimal solution. By solving a relaxed problem of the original S2
one, fractional solutions are recognized and for each discrete variable, B&B will do Stage - 2

branching and creating two new nodes, thus dividing the solution space into a set of
S3
smaller subsets and obtain the relative upper and lower bound for each node. Since
Stage - 3
explicit enumeration is normally impossible due to the exponentially increasing
number of potential solutions, the use of bounds for the function to be optimized S4

combined with the value of the current best solution found enables this B&B Stage - 4

algorithm to search only parts of the solution space implicitly.


S5
Brute Force Algorithm: Stage - 5

 Brute force is a type of algorithm that tries a large number of patterns to solve a


S6
problem. In some cases, they are extremely simple and rely on raw computing power
Stage - 6
to achieve results.

 A common example of a brute force algorithm is a security threat that attempts to L-E

Level Exam
guess a password using known common passwords. Such an algorithm might also
try dictionary words or even every combination of ASCII strings of a certain length. 
 Brute force algorithms also have non-security applications. For example, a Menu

technique known as data dredging is a brute force method of looking for statistically

significant patterns in data.

Advantages and Disadvantages:


 1.This method is used by default to solve some problems such as sorting,
searching, matrix multiplication, binomial expansion etc.

 2.used for solving smaller instances or modules of a larger problem.


 3.It is inefficient and hence useless when dealing with homogeneous problems of 
higher complexity
 4.Not suitable for solving problems that have an hierarchial structure and involve
logical operations.
 The shortest path problem is about finding a path between 2 vertices in a graph

☰ such that the total sum of the edges weights is minimum.

Powered by Hebeon Technologies Private Ltd (http://hebeon.com/)


 
https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 2/5
11/05/2020 :: eLearning - Hebeon Technologies ::

(../StudentHome.aspx)
 This problem could be solved easily using (BFS) if all edge weights were (1), but
here weights can take any value. Three different algorithms are discussed below
 EXAM     
depending on the use-case.
I

Intro
 Bellman Ford's Algorithm:
S1
 Bellman Ford's algorithm is used to find the shortest paths from the source vertex
Stage - 1
to all other vertices in a weighted graph. It depends on the following concept:
Shortest path contains at most n−1 edges, because the shortest path couldn't have S2

Stage - 2
a cycle.
 So why shortest path shouldn't have a cycle ? S3
 There is no need to pass a vertex again, because the shortest path to all other Stage - 3

vertices could be found without the need for a second visit for any vertices.
S4
Algorithm Steps: Stage - 4

 The outer loop traverses from 0 : n−1.


S5
 Loop over all edges, check if the next node distance > current node distance +
Stage - 5
edge weight, in this case update the next node distance to "current node distance +

edge weight". S6

 This algorithm depends on the relaxation principle where the shortest distance for Stage - 6

all vertices is gradually replaced by more accurate values until eventually reaching
L-E
the optimum solution. In the beginning all vertices have a distance of "Infinity", but
Level Exam
only the distance of the source vertex = 0, then update all the connected vertices

with the new distances (source vertex distance + edge weights), then apply the 
Menu
same concept for the new vertices with new distances and so on. 

 Kruskal’s Algorithm

Kruskal’s Algorithm builds the spanning tree by adding edges one by one into a growing
spanning tree. Kruskal's algorithm follows greedy approach as in each iteration it finds an
edge which has least weight and add it to the growing spanning tree.

Algorithm Steps:
 Sort the graph edges with respect to their weights. 
 Start adding edges to the MST from the edge with the smallest weight until the
edge of the largest weight.
 Only add edges which doesn't form a cycle , edges which connect only
disconnected components.

☰  So now the question is how to check if 2 vertices are connected or not ?

Powered by Hebeon Technologies Private Ltd (http://hebeon.com/)


 
https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 3/5
11/05/2020 :: eLearning - Hebeon Technologies ::

(../StudentHome.aspx)
 This could be done using DFS which starts from the first vertex, then check if the
second vertex is visited or not. But DFS will make time complexity large as it has an
 EXAM     
order of O(V+E) where V is the number of vertices, E is the number of edges. So the
I
best solution is "Disjoint Sets": 
Intro
 Disjoint sets are sets whose intersection is the empty set so it means that they
don't have any element in common. S1

Stage - 1

 Binary search :
S2

Stage - 2
 Binary search is the most popular Search algorithm.It is efficient and also one of
the most commonly used techniques that is used to solve problems. S3
 If all the names in the world are written down together in order and you want to Stage - 3

search for the position of a specific name, binary search will accomplish this in a
S4
maximum of 35 iterations.
Stage - 4
 Binary search works only on a sorted set of elements. To use binary search on a
collection, the collection must first be sorted. S5

 When binary search is used to perform operations on a sorted set, the number of Stage - 5

iterations can always be reduced on the basis of the value that is being searched.
S6

Advantages: Stage - 6

 Compared to linear search (checking each element in the array starting from the
L-E
first), binary search is much faster. Linear search takes, on average N/2 comparisons
Level Exam
(where N is the number of elements in the array), and worst case N comparisons.

Binary search takes an average and worst-case log2(N)log2(N) comparisons. So for 


Menu
a million elements, linear search would take an average of 500,000 comparisons, 
whereas binary search would take 20.
 It’s a fairly simple algorithm, though people get it wrong all the time.
 It’s well known and often implemented for you as a library routine.

 Quick sort:

 Quicksort, or partition-exchange sort, is a sorting algorithm that, on average,


makes O(n log n) comparisons to sort n items.  It was developed by Tony Hoare.

Quicksort is faster in practice than other O(n log n) algorithms such as Bubble sort or
Insertion Sort. Quicksort can be implemented with an in-place partitioning algorithm,
so the entire sort can be done with only O(log n) additional space.

 Quicksort is a comparison sort and is not a stable sort.


☰  Its complexity is as follows:
Powered
 Best Case - O(n log n)by Hebeon Technologies Private Ltd (http://hebeon.com/)  
https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 4/5
11/05/2020 :: eLearning - Hebeon Technologies ::

(../StudentHome.aspx)
 Worst Case - O(n^2) 
 Average Case - O(n log n)
 EXAM     
Quicksort is a divide and conquer algorithm. Quicksort first divides a large list into two I
smaller sub-lists: the low elements and the high elements. Quicksort can then recursively
Intro
sort the sub-lists. The steps are:

 1. Pick an element, called a pivot, from the list. S1

 2. Reorder the list so that all elements with values less than the pivot come before Stage - 1

the pivot, while all elements with values greater than the pivot come after it (equal
S2
values can go either way). After this partitioning, the pivot is in its final position. This
Stage - 2
is called the partition operation.
S3
 3. Recursively sort the sub-list of lesser elements and the sub-list of greater
Stage - 3
elements.

 The base case of the recursion are lists of size zero or one, which never need to be S4
sorted. Stage - 4

 Merge sort: S5

Stage - 5

Divide and Conquer Strategy


S6
 Using the Divide and Conquer technique, we divide a problem into subproblems.
Stage - 6
When the solution to each subproblem is ready, we 'combine' the results from the
subproblems to solve the main problem. L-E

 Suppose we had to sort an array A. A subproblem would be to sort a sub-section Level Exam

of this array starting at index p and ending at index r, denoted as A[p..r].



Divide Menu

If q is the half-way point between p and r, then we can split the subarray A[p..r] into two
arrays A[p..q] and A[q+1, r].

Conquer
In the conquer step, we try to sort both the subarrays A[p..q] and A[q+1, r]. If we haven't
yet reached the base case, we again divide both these subarrays and try to sort them.

Combine
When the conquer step reaches the base step and we get two sorted subarrays A[p..q]
and A[q+1, r] for array A[p..r], we combine the results by creating a sorted array A[p..r] 
from two sorted subarrays A[p..q] and A[q+1, r]

PROCEED 

Powered by Hebeon Technologies Private Ltd (http://hebeon.com/)

https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 5/5

Potrebbero piacerti anche