Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Exposure of Javier Solano, PhD Professor in Computational Physics and System Engineering, National University of Engineering Lima - Peru. Concept, definition and representation of algorithms. Tree constructs, Unified Modeling Languaje (UML).
Optimization is considered to be one of the pillars of statistical learning and also plays a major role in the design and development of intelligent systems such as search engines, recommender systems, and speech and image recognition software. Machine Learning is the study that gives the computers the ability to learn and also the ability to think without being explicitly programmed. A computer is said to learn from an experience with respect to a specified task and its performance related to that task. The machine learning algorithms are applied to the problems to reduce efforts. Machine learning algorithms are used for manipulating the data and predict the output for the new data with high precision and low uncertainty. The optimization algorithms are used to make rational decisions in an environment of uncertainty and imprecision. In this paper a methodology is presented to use the efficient optimization algorithm as an alternative for the gradient descent machine learning algorithm as an optimization algorithm.
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
Abstract Data Types
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
(b) Write out a signature, or interface, that defines the operations of a stack ADT.
(c) Consider a string of characters of the form
... (.( ... ).) ...
where ... indicates an arbitrary sequence of characters (except for parentheses),
(.( indicates an arbitrary number (one or more) of opening parentheses, and
similarly ).) indicates an arbitrary number of closing parentheses.
Using only the stack abstraction operations defined above, write pseudocode for
an algorithm that determines, using a stack, whether or not the number of closing
parentheses is the same as the number of opening parentheses.
You may assume the existence of a function read(str,ch) that reads the next character
of string str into ch.
You may also assume that you can invoke a function reportFail, that will cause
termination with failure, and similarly, reportSuccess causes termination with a
success indication.
Further, you may also assume that you can call a function newStack(S) to create
a new empty stack S, and eos(str) that returns false when you reach the end of
the string.
Solution
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
A data type is a collection of values and a set of operations on those values. That collection and
these operations form a mathematical construct that may be implemented with the use of a
particular hardware or software data structure. The term abstract data type (ADT) refers to the
basic mathematical concept that defines the data type. We have discussed four different
implementations of the list data structure.
In case of implementation of the list with the use of an array, the size of the array gives difficulty
if increased.
To avoid this, we allocate memory dynamically for nodes before connecting these nodes with the
help of pointers.
For this purpose, we made a singly linked list and connected it with the next pointer to make a
chain.
Moving forward is easy but going back is a difficult task.
To overcome this problem, we made a doubly linked list using prev andnext pointers. With the
help of these pointers, we can move forward and backward very easily. Now we face another
problem that the prev pointer of first node and the next pointer of the last node are NULL.
Therefore, we have to be careful in case of NULL pointers. To remove the NULL pointers, we
made the circular link list by connecting the first and last node.
The program employing the list data structure is not concerned with its implementation.
We do not care how the list is being implemented whether through an array, singly linked list,
doubly linked list or circular linked list. It has been witnessed that in these four implementations
of the list, the interface remained the same i.e. it implements the same methods like add, get,
next, start a.
Download Complete Material - https://www.instamojo.com/prashanth_ns/
This Data Structures and Algorithms contain 15 Units and each Unit contains 60 to 80 slides in it.
Contents…
• Introduction
• Algorithm Analysis
• Asymptotic Notation
• Foundational Data Structures
• Data Types and Abstraction
• Stacks, Queues and Deques
• Ordered Lists and Sorted Lists
• Hashing, Hash Tables and Scatter Tables
• Trees and Search Trees
• Heaps and Priority Queues
• Sets, Multi-sets and Partitions
• Dynamic Storage Allocation: The Other Kind of Heap
• Algorithmic Patterns and Problem Solvers
• Sorting Algorithms and Sorters
• Graphs and Graph Algorithms
• Class Hierarchy Diagrams
• Character Codes
GENETIC ALGORITHM FOR FUNCTION APPROXIMATION: AN EXPERIMENTAL INVESTIGATIONijaia
Function Approximation is a popular engineering problems used in system identification or Equation
optimization. Due to the complex search space it requires, AI techniques has been used extensively to spot
the best curves that match the real behavior of the system. Genetic algorithm is known for their fast
convergence and their ability to find an optimal structure of the solution. We propose using a genetic
algorithm as a function approximator. Our attempt will focus on using the polynomial form of the
approximation. After implementing the algorithm, we are going to report our results and compare it with
the real function output.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
2. 8.2
Define an algorithm and relate it to problem solving.
Define three construct and describe their use in algorithms.
Describe UML diagrams and pseudocode and how they are
used in algorithms.
List basic algorithms and their applications.
Describe the concept of sorting and understand the
mechanisms behind three primitive sorting algorithms.
Describe the concept of searching and understand the
mechanisms behind two common searching algorithms.
Define subalgorithms and their relations to algorithms.
Distinguish between iterative and recursive algorithms
ObjectivesObjectives
After studying this chapter, the student should be ableAfter studying this chapter, the student should be able
to:to:
3. 8.3
8-1 CONCEPT8-1 CONCEPT
In this section we informally define anIn this section we informally define an algorithmalgorithm andand
elaborate on the concept using an example.elaborate on the concept using an example.
4. 8.4
Informal definition
An informal definition of an algorithm is:
Algorithm: a step-by-step method for solving a
problem or doing a task.
i
Figure 8.1 Informal definition of an algorithm used in a computer
5. 8.5
Example
We want to develop an algorithm for finding the largest
integer among a list of positive integers. The algorithm
should find the largest integer among a list of any values (for
example 5, 1000, 10,000, 1,000,000). The algorithm should
be general and not depend on the number of integers.
To solve this problem, we need an intuitive approach.
First use a small number of integers (for example, five), then
extend the solution to any number of integers.
Figure 8.2 shows one way to solve this problem. We
call the algorithm FindLargest. Each algorithm has a name to
distinguish it from other algorithms. The algorithm receives
a list of five integers as input and gives the largest integer as
output.
7. 8.7
Defining actions
Figure 8.2 does not show what should be done in each step.
We can modify the figure to show more details.
Figure 8.3 Defining actions in FindLargest algorithm
8. 8.8
Refinement
This algorithm needs refinement to be acceptable to the
programming community. There are two problems. First, the
action in the first step is different than those for the other
steps. Second, the wording is not the same in steps 2 to 5.
We can easily redefine the algorithm to remove these two
inconveniences by changing the wording in steps 2 to 5 to
“If the current integer is greater than Largest, set Largest to
the current integer.” The reason that the first step is different
than the other steps is because Largest is not initialized. If
we initialize Largest to −∞ (minus infinity), then the first
step can be the same as the other steps, so we add a new step,
calling it step 0 to show that it should be done before
processing any integers.
10. 8.10
Generalization
Is it possible to generalize the algorithm? We want to find
the largest of n positive integers, where n can be 1000,
1,000,000, or more. Of course, we can follow Figure 8.4 and
repeat each step. But if we change the algorithm to a
program, then we need to actually type the actions for n
steps!
There is a better way to do this. We can tell the computer to
repeat the steps n times. We now include this feature in our
pictorial algorithm (Figure 8.5).
12. 8.12
8-2 THREE CONSTRUCTS8-2 THREE CONSTRUCTS
Computer scientists have definedComputer scientists have defined three constructsthree constructs for afor a
structured program or algorithm. The idea is that astructured program or algorithm. The idea is that a
program must be made of a combination of only theseprogram must be made of a combination of only these
three constructs:three constructs: sequencesequence,, decisiondecision (selection) and(selection) and
repetitionrepetition (Figure 8.6). It has been proven there is no(Figure 8.6). It has been proven there is no
need for any other constructs. Using only theseneed for any other constructs. Using only these
constructs makes a program or an algorithm easy toconstructs makes a program or an algorithm easy to
understand, debug or change.understand, debug or change.
14. 8.14
Sequence
The first construct is called the sequence. An algorithm, and
eventually a program, is a sequence of instructions, which
can be a simple instruction or either of the other two
constructs.
Decision
Some problems cannot be solved with only a sequence of
simple instructions. Sometimes we need to test a condition.
If the result of testing is true, we follow a sequence of
instructions: if it is false, we follow a different sequence of
instructions. This is called the decision (selection) construct.
15. 8.15
Repetition
In some problems, the same sequence of instructions must be
repeated. We handle this with the repetition or loop
construct. Finding the largest integer among a set of integers
can use a construct of this kind.
16. 8.16
8-3 ALGORITHM REPRESENTATION8-3 ALGORITHM REPRESENTATION
So far, we have used figures to convey the concept of anSo far, we have used figures to convey the concept of an
algorithm. During the last few decades, tools have beenalgorithm. During the last few decades, tools have been
designed for this purpose. Two of these tools,designed for this purpose. Two of these tools, UMLUML andand
pseudocodepseudocode, are presented here., are presented here.
17. 8.17
UML
Unified Modeling Language (UML) is a pictorial
representation of an algorithm. It hides all the details of an
algorithm in an attempt to give the “big picture” and to show
how the algorithm flows from beginning to end. UML is
covered in detail in Appendix B. Here we show only how the
three constructs are represented using UML (Figure 8.7).
19. 8.19
Pseudocode
Pseudocode is an English-language-like representation of an
algorithm. There is no standard for pseudocode—some
people use a lot of detail, others use less. Some use a code
that is close to English, while others use a syntax like the
Pascal programming language.
Pseudocode is covered in detail in Appendix C. Here we
show only how the three constructs can be represented by
pseudocode (Figure 8.8).
21. 8.21
Example 8.1
Write an algorithm in pseudocode that finds the sum of twoWrite an algorithm in pseudocode that finds the sum of two
integers.integers.
22. 8.22
Example 8.2
Write an algorithm to change a numeric grade to a pass/no passWrite an algorithm to change a numeric grade to a pass/no pass
grade.grade.
23. 8.23
Example 8.3
Write an algorithm to change a numeric grade (integer) to a letterWrite an algorithm to change a numeric grade (integer) to a letter
grade.grade.
24. 8.24
Example 8.4
Write an algorithm to find the largest of a set of integers. We doWrite an algorithm to find the largest of a set of integers. We do
not know the number of integers.not know the number of integers.
25. 8.25
Example 8.5
Write an algorithm to find the largest of the first 1000 integers inWrite an algorithm to find the largest of the first 1000 integers in
a set of integers.a set of integers.
26. 8.26
8-4 A MORE FORMAL DEFINITION8-4 A MORE FORMAL DEFINITION
Now that we have discussed the concept of an algorithmNow that we have discussed the concept of an algorithm
and shown its representation, here is a more formaland shown its representation, here is a more formal
definition.definition.
Algorithm:
An ordered set of unambiguous steps that produces a
result and terminates in a finite time.
i
27. 8.27
Ordered set
An algorithm must be a well-defined, ordered set of
instructions.
Unambiguous steps
Each step in an algorithm must be clearly and
unambiguously defined. If one step is to add two integers,
we must define both “integers” as well as the “add”
operation: we cannot for example use the same symbol to
mean addition in one place and multiplication somewhere
else.
28. 8.28
Produce a result
An algorithm must produce a result, otherwise it is useless.
The result can be data returned to the calling algorithm, or
some other effect (for example, printing).
Terminate in a finite time
An algorithm must terminate (halt). If it does not (that is, it
has an infinite loop), we have not created an algorithm. In
Chapter 17 we will discuss solvable and unsolvable
problems, and we will see that a solvable problem has a
solution in the form of an algorithm that terminates.
29. 8.29
8-5 BASIC ALGORITHMS8-5 BASIC ALGORITHMS
Several algorithms are used in computer science soSeveral algorithms are used in computer science so
prevalently that they are considered “basic”. We discussprevalently that they are considered “basic”. We discuss
the most common here. This discussion is very general:the most common here. This discussion is very general:
implementation depends on the language.implementation depends on the language.
30. 8.30
Summation
One commonly used algorithm in computer science is
summation. We can add two or three integers very easily,
but how can we add many integers? The solution is simple:
we use the add operator in a loop (Figure 8.9).
A summation algorithm has three logical parts:
1. Initialization of the sum at the beginning.
2. The loop, which in each iteration adds a new integer to the
sum.
3. Return of the result after exiting from the loop.
32. 8.32
Product
Another common algorithm is finding the product of a list of
integers. The solution is simple: use the multiplication
operator in a loop (Figure 8.10).
A product algorithm has three logical parts:
1. Initialization of the product at the beginning.
2. The loop, which in each iteration multiplies a new integer
with the product.
3. Return of the result after exiting from the loop.
34. 8.34
Smallest and largest
We discussed the algorithm for finding the largest among a
list of integers at the beginning of this chapter. The idea was
to write a decision construct to find the larger of two
integers. If we put this construct in a loop, we can find the
largest of a list of integers.
Finding the smallest integer among a list of integers is
similar, with two minor differences. First, we use a decision
construct to find the smaller of two integers. Second, we
initialize with a very large integer instead of a very small
one.
35. 8.35
Sorting
One of the most common applications in computer science is
sorting, which is the process by which data is arranged
according to its values. People are surrounded by data. If the
data was not ordered, it would take hours and hours to find a
single piece of information. Imagine the difficulty of finding
someone’s telephone number in a telephone book that is not
ordered.
In this section, we introduce three sorting algorithms:
selection sort, bubble sort and insertion sort. These three
sorting algorithms are the foundation of faster sorting
algorithms used in computer science today.
36. 8.36
Selection sorts
In a selection sort, the list to be sorted is divided into two
sublists—sorted and unsorted—which are separated by an
imaginary wall. We find the smallest element from the
unsorted sublist and swap it with the element at the
beginning of the unsorted sublist. After each selection and
swap, the imaginary wall between the two sublists moves
one element ahead.
Figure 8.11 Selection sort
39. 8.39
Bubble sorts
In the bubble sort method, the list to be sorted is also divided
into two sublists—sorted and unsorted. The smallest element
is bubbled up from the unsorted sublist and moved to the
sorted sublist. After the smallest element has been moved to
the sorted list, the wall moves one element ahead.
Figure 8.14 Bubble sort
41. 8.41
Insertion sorts
The insertion sort algorithm is one of the most common
sorting techniques, and it is often used by card players. Each
card a player picks up is inserted into the proper place in
their hand of cards to maintain a particular sequence.
Figure 8.16 Insertion sort
43. 8.43
Searching
Another common algorithm in computer science is
searching, which is the process of finding the location of a
target among a list of objects. In the case of a list, searching
means that given a value, we want to find the location of the
first element in the list that contains that value. There are two
basic searches for lists: sequential search and binary
search. Sequential search can be used to locate an item in
any list, whereas binary search requires the list first to be
sorted.
44. 8.44
Sequential search
Sequential search is used if the list to be searched is not
ordered. Generally, we use this technique only for small lists,
or lists that are not searched often. In other cases, the best
approach is to first sort the list and then search it using the
binary search discussed later.
In a sequential search, we start searching for the target from
the beginning of the list. We continue until we either find the
target or reach the end of the list.
46. 8.46
Binary search
The sequential search algorithm is very slow. If we have a
list of a million elements, we must do a million comparisons
in the worst case. If the list is not sorted, this is the only
solution. If the list is sorted, however, we can use a more
efficient algorithm called binary search. Generally speaking,
programmers use a binary search when a list is large.
A binary search starts by testing the data in the
element at the middle of the list. This determines whether the
target is in the first half or the second half of the list. If it is
in the first half, there is no need to further check the second
half. If it is in the second half, there is no need to further
check the first half. In other words, we eliminate half the list
from further consideration.
48. 8.48
8-6 SUBALGORITHMS8-6 SUBALGORITHMS
The three programming constructs described in SectionThe three programming constructs described in Section
8.2 allow us to create an algorithm for any solvable8.2 allow us to create an algorithm for any solvable
problem. The principles of structured programming,problem. The principles of structured programming,
however, require that an algorithm be broken into smallhowever, require that an algorithm be broken into small
units calledunits called subalgorithmssubalgorithms. Each subalgorithm is in. Each subalgorithm is in
turn divided into smaller subalgorithms. A goodturn divided into smaller subalgorithms. A good
example is the algorithm for the selection sort in Figureexample is the algorithm for the selection sort in Figure
8.13.8.13.
50. 8.50
Structure chart
Another tool programmers use is the structure chart. A
structure chart is a high level design tool that shows the
relationship between algorithms and subalgorithms. It is used
mainly at the design level rather than at the programming
level. We briefly discuss the structure chart in Appendix D.
51. 8.51
8-7 RECURSION8-7 RECURSION
In general, there are two approaches to writingIn general, there are two approaches to writing
algorithms for solving a problem. One usesalgorithms for solving a problem. One uses iterationiteration,,
the other usesthe other uses recursionrecursion. Recursion is a process in. Recursion is a process in
which an algorithm calls itself.which an algorithm calls itself.
52. 8.52
Iterative definition
To study a simple example, consider the calculation of a
factorial. The factorial of a integer is the product of the
integral values from 1 to the integer. The definition is
iterative (Figure 8.21). An algorithm is iterative whenever
the definition does not involve the algorithm itself.
Figure 8.21 Iterative definition of factorial
53. 8.53
Recursive definition
An algorithm is defined recursively whenever the algorithm
appears within the definition itself. For example, the factorial
function can be defined recursively as shown in Figure 8.22.
Figure 8.22 Recursive definition of factorial