Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
11 views
Algorithms - Notes
The topics covered in this are: What is an algorithm? Algorithm Properties Efficiency of the algorithm Asymptotic analysis
Uploaded by
prathisimha
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Algorithms- Notes For Later
Download
Save
Save Algorithms- Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
11 views
Algorithms - Notes
The topics covered in this are: What is an algorithm? Algorithm Properties Efficiency of the algorithm Asymptotic analysis
Uploaded by
prathisimha
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Algorithms- Notes For Later
Carousel Previous
Carousel Next
Save
Save Algorithms- Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
Pulloort Prathibh, Lecturer Introduction to Algorithms What is Algorithm? > An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task. +> Algorithm is not the complete code or program, it is just the core logic (solution) of a problem, which can be expressed either as an informal high level description as pseudo code or using 2 flowchart. + Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. > Algorithms are generally created independent of underlying languages, ie. an algorithm can be implemented in more than one programming language. Characteristics of an Algorithm An algorithm should have the following characteristics ~ 1. Unambiguous - Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning, Input - an algorithm should have 0 or more well-defined inputs. Output - an algorithm should have 1 or more well-defined outputs, and should match the desired output. 4. Finiteness - Algorithms must terminate after a finite number of steps. 5. Feasibility - should be feasible with the available resources. 6. Independent ~ an algorithm should have step-by-step directions, which should be independent of any programming code. Algorithm Analysis ‘+ Efficiency of an algorithm can be analyzed at two different stages, Before implementation and After implementation. They are ~ 1. Priori Analysis: [ “Priori” means “before”] © Hence Priori analysis means checking the algorithm before its implementation. * In this, the algorithm is checked when it is written in the form of theoretical steps. ie., this is a theoretical analysis of an algorithm. ‘Efficiency of an algorithm is measured by assuming that all other factors, For example, processor speed, are constant and have no effect on the implementation, 2.A Posterior Analysis: [“Posterior” means “after”] ‘* Hence Posterior analysis means checking the algorithm after its implementation. * inthis, the algorithm is checked by implementing it in any programming language and executing it this is an empirical analysis of an algorithm. ‘* This analysis helps to get the actual and real analysis report about correctness, space required, time consumed etc. Algorithm Efficiency © Ameasure of the average execution time necessary for an algorithm to complete work on a set of data, ‘© Algorithm efficiency is characterized by its order. ‘©The complexity of an algorithm is a function describing the efficiency of the algorithm in terms of the amount of data the algorithm must process. © Usually there are natural units for the domain and range of this function, © There are two main measures of the efficiency of an algorithm. 1. Time Complexity 2. Space ComplexityPulloort Prathibh, Lecturer Time Complexity © Time comple: tocompletion. 'y of an algorithm represents the amount of time required by the algorithm to run * The time complexity of an algorithm is also calculated by determining following 2 components: © Constant time part: Any instruction that is executed just once comes in this part. For example, input, output, iFelse, switches, ete. © Variable Time Part: Any instruction that is executed more than once, say n times comes in this part, For example, loops, recursion, ete. ‘Time requirements can be defined as a numerical function T(n), where T(n) can be measured as the number of steps, provided each step consumes constant time. For example, addition of two n-bit integers takes n steps. * Consequently, the total computational time is T{n) = cn, where c is the time taken for the addition of two bits, Here, we observe that T(n) grows linearly as the input size increases. Space Complexity ‘Space complexity of an algorithm refers to the amount of memory that this algorithm requires to execute and get the result ‘+ This can be for inputs, temporary operations, or outputs. ‘The space complexity of an algorithm is calculated by determining following 2 components: (© Fixed Part: This refers to the space that is definitely required by the algorithm. For example, input variables, output variables, program size, etc. © Variable Part: This refers to the space that can be different based on the implementation of the algorithm. For example, temporary variables, dynamic memory allocation, recursion stack space, etc. Asymptotic Analysis / Asymptotic Notations ‘Asymptotic analysis of an algorithm refers to defining the mathematical foundation / framing of its run-time performance. © Using asymptotic analysis, we can very well conclude the best case, average case, and worst case scenario of an algorithm. ‘© Asymptotic analysis is input bound i.e., if there's no input to the algorithm, it is concluded to work ina constant time. Other than the "input" all other factors are considered constant. © Asymptotic analysis refers to computing the running time of any operati computation. mathematical units of © The time required by an algorithm falls under three types — ° Best Case - Minimum time required for program execution. ° Average Case - Average time required for program execution. © Worst Case - Maximum time req Asymptotic Notations od for program execution. Following are the commonly used asymptotic notations to calculate the running time complexity of an algorithm * ONotation * Notation © @ NotationPulloort Prathibh, Lecturer Big Oh Notation, O 2 The notation O(n) is the formal way to express the upper bound of an algorithm's running time. 2 It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete. For example, for a function fin) Z Omega Notation, Q # The notation O(n) is the formal way to express the lower bound of an algorithm's running time. It measures the best case time complexity or 9» the best amount of time an algorithm can possibly take to complete. fe For example, for a function fn) k Theta Notation, @ The notation @{n) is the formal way to express both the lower bound and the upper bound of an algorithm's running time. It is represented as follows — Algorithm Design Tools k ‘The two popular tools used in the representation of algorithms are the following: 1. Pseudo code 2. Flowchart Pseudo code % An algorithm can be written in any of the natural languages such as English, German, French, ete. % One of the commonly used tools to define algorithms is the pseudo code. % Pseudo code is one of the tools that can be used to write a preliminary plan that can be developed into a computer program. % A pseudo code is an English-like presentation of the code required for an algorithm, % Pseudo code is a generic way of describing an algorithm without use of any — specific programming language syntax. % It is, as the name suggests, pseudo code —it cannot be executed on a real computer, but it models and resembles real programming code, and is written at roughly the same level _ of detail. Flowchart > A very effective tool to show the logie flow of a program is the flowchart A flowchart is a pictorial representation of an algorithm, > It hides all the details of an algorithm by giving a picture; it shows how the algorithm flows from beginning to end. } A flowchart is a schematic representation of an algorithm or a stepwise process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. i Flowcharts are used in designing or documenting a process or program > Flowcharts are usually drawn using some standard _ symbols; however, some special symbols can also be developed when required PagesPullootPrathibha Lecturer Flowchart Symbols To calculate the average of two numbers Symbol Name Function Take numa, Start/end nova represents a start ume rend point. Alive is connector that sh — ‘Arrows relationships between the Average = representative shapes. (oumtenum2y/2 Input/Output A parallelogram represents input or ouptut. an wo (=) Decision A diamond indicates a decision,
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel