Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(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
(../StudentHome.aspx)
optimal solutions of various optimization problems, especially in discrete and
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
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
(../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
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.
(../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.
Quick sort:
(../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:
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
Suppose we had to sort an array A. A subproblem would be to sort a sub-section Level Exam
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
https://pwb.hebeon.com/Courses/LanguageHome.aspx?CourseID=105&SID=18587&ccCourseID=106&CourseName=Data+Str… 5/5