The document describes several algorithms related to dynamic programming. It presents algorithms for computing the Fibonacci numbers, coin changing, matrix multiplication, longest common subsequence, shortest paths in graphs, and transitive closure. The algorithms use dynamic programming techniques like memoization and storing intermediate results in tables to solve problems more efficiently.
Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again.
it contains the detail information about Dynamic programming, Knapsack problem, Forward / backward knapsack, Optimal Binary Search Tree (OBST), Traveling sales person problem(TSP) using dynamic programming
Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again.
it contains the detail information about Dynamic programming, Knapsack problem, Forward / backward knapsack, Optimal Binary Search Tree (OBST), Traveling sales person problem(TSP) using dynamic programming
Computer graphics lab report with code in cppAlamgir Hossain
This is the lab report for computer graphics in cpp language. Basically this course is only for the computer science and engineering students.
Problem list:
1.Program for the generation of Bresenham Line Drawing.
2. Program for the generation of Digital Differential Analyzer (DDA) Line Drawing.
3. Program for the generation of Midpoint Circle Drawing.
4. Program for the generation of Midpoint Ellipse Drawing.
5. Program for the generation of Translating an object.
6. Program for the generation of Rotating an Object.
7. Program for the generation of scaling an object.
All programs are coaded in cpp language .
This file contains all the practicals with output regarding GTU syllabus. so it will help to IT and Computer engineering students. It is really knowledgeable so refer these for computer graphics practicals.
Venay Magen is the lead artist for the stone band MN3. He is a supporter for some imperative political and social reasons. His genuine name is Rahul. He possesses numerous intriguing sets of glasses.
Venay Magen likes the shading red, particularly on Tuesdays. He cherishes to drink bourbon (on all days). He figured out how to drink whisky from his youth companion Zippo, when they went to class together at Mount Temple Comprehensive School. He is best known as the lead vocalist for the band MN3.
Computer graphics lab report with code in cppAlamgir Hossain
This is the lab report for computer graphics in cpp language. Basically this course is only for the computer science and engineering students.
Problem list:
1.Program for the generation of Bresenham Line Drawing.
2. Program for the generation of Digital Differential Analyzer (DDA) Line Drawing.
3. Program for the generation of Midpoint Circle Drawing.
4. Program for the generation of Midpoint Ellipse Drawing.
5. Program for the generation of Translating an object.
6. Program for the generation of Rotating an Object.
7. Program for the generation of scaling an object.
All programs are coaded in cpp language .
This file contains all the practicals with output regarding GTU syllabus. so it will help to IT and Computer engineering students. It is really knowledgeable so refer these for computer graphics practicals.
Venay Magen is the lead artist for the stone band MN3. He is a supporter for some imperative political and social reasons. His genuine name is Rahul. He possesses numerous intriguing sets of glasses.
Venay Magen likes the shading red, particularly on Tuesdays. He cherishes to drink bourbon (on all days). He figured out how to drink whisky from his youth companion Zippo, when they went to class together at Mount Temple Comprehensive School. He is best known as the lead vocalist for the band MN3.
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...Ansel Halliburton
What would happen if shipping companies hired mercenaries to attack Somali pirates? Find out in these slides for a talk given at the UC Davis Interdisciplinary Graduate & Professional Student Symposium in 2011.
AIT partner university, the Capital University of Economics and Business (CUEB), Beijing consists of 14 colleges and departments, including business administration, accountancy, finance, banking and economics. Some 20,000 students attend the university, undertaking programmes at bachelor, master and doctoral degree level. Approximately half of this number are full-time undergraduate students.
Whenever we want to perform analysis of an algorithm, we need to calculate the complexity of that algorithm. But when we calculate complexity of an algorithm it does not provide exact amount of resource required. So instead of taking exact amount of resource we represent that complexity in a general form (Notation) which produces the basic nature of that algorithm. We use that general form (Notation) for the analysis process.
Contents of the presentation:
- ABOUT ME
- Bisection Method using C#
- False Position Method using C#
- Gauss Seidel Method using MATLAB
- Secant Mod Method using MATLAB
- Report on Numerical Errors
- Optimization using Golden-Section Algorithm with Application on MATLAB
Digital signal Processing all matlab code with Lab report Alamgir Hossain
Digital signal processing(DSP) laboratory with matlab software....
Problem List :
1.To write a Matlab program to evaluate the impulse response of the system.
2.Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum.
3.To Generate continuous time sinusoidal signal, discrete time cosine signal.
4.To find the DFT / IDFT of given signal.
5.Program for generation of Sine sequence.
6.Program for generation of Cosine sequence.
7. Program for the generation of UNIT impulse signal
8. Program for the generation of Exponential signal.
Problem descriptionThe Jim Thornton Coffee House chain is .docxelishaoatway
Problem description
The Jim Thornton Coffee House chain is planning expansion into Calgary. It has selected many
possible sites for new coffee houses. The possible sites are joined by roads that form a spanning tree.
To eliminate competition with itself, the company has determined that it should not choose two
sites that are adjacent in this tree. From its market evaluation, the company has also determined
the expected profit per year for each site. Your job is to determine what sites Jim Thornton should
choose for his coffee houses.
a. Define this problem precisely, by defining the required Input and the required Output. Use
mathematical notation.
b. Write a recursive equation for the function that maximizes the profit per year. Include a
short argument that your equation is correct.
c. Write an efficient algorithm that computes the maximum profit per year, and also computes
the sites that should be chosen. Your algorithm should run in time that is polynomial in the
input size.
d. What is the asymptotic running time of your algorithm? Defend your answer.
Your algorithm and proofs should be precise and concise (as well, of course, as correct.) Elegance
of your solution counts.
2
CPSC 413 — Winter, 2013
Home Work Exercise #8
March 16, 2013
1. Exercise 1 Chapter 6, page 312 of the textbook.
Answer:
(a) A counterexample is given in Figure 1. The given algorithm finds an independent set of
weight 8. However, the maximum total weight is 10 by adding the nodes at two ends to
the independent set.
5 58
Figure 1: A counterexample to the algorithm of 1(a)
(b) A counterexample is given in Figure 2. The given algorithm finds an independent set of
weight 11. However, the maximum total weight is 19 by adding the nodes at two ends to
the independent set.
10 12 9
Figure 2: A counterexample to the algorithm of 1(b)
(c) Input: An array A = (a1, . . . , an) of n integers. (I use “array” rather than “set” here
because the elements in a set do not have the notion of order.)
Output: A set S = {aα1, . . . , aαm} ⊆ A, which satisfies
(1)
m∑
i=1
aαi is maximum;
(2) ∀i ∈ {1, . . . , m}, ̸ ∃j ∈ {1, . . . , m} s.t. |αi − αj| = 1.
Optimization function. Indset[i] denotes the maximum independent set of an array with
i positive integers (a1, . . . , ai). Let OPT [i] denote the total weight of Indset[i]. The
optimization function is
OPT [0] = 0, OPT [1] = max{0, a1},
OPT [i] =
{
OPT [i − 1] if OPT [i − 1] ≥ OPT [i − 2] + ai
OPT [i − 2] + ai otherwise
Correctness of the optimization function. It is trivial if n = 0 or 1. When n ≥ 2, there
are two cases to be considered. Case 1: Indset[n] includes an. Then Indset[n] must not
include an−1. And Indset[n]−{an} must be a maximum independent set of (a1, . . . , an−2).
This can be easily verified by a replacement argument. If the statement is not true, then
the total weight of Indset[n] − {an} is less than OPT [n − 2]. Then Indset[n − 2] ∪ {an}
has total weight larger than Indset[n] does, and this co.
At Digidev, we are working to be the leader in interactive streaming platforms of choice by smart device users worldwide.
Our goal is to become the ultimate distribution service of entertainment content. The Digidev application will offer the next generation television highway for users to discover and engage in a variety of content. While also providing a fresh and
innovative approach towards advertainment with vast revenue opportunities. Designed and developed by Joe Q. Bretz
Young Tom Selleck: A Journey Through His Early Years and Rise to Stardomgreendigital
Introduction
When one thinks of Hollywood legends, Tom Selleck is a name that comes to mind. Known for his charming smile, rugged good looks. and the iconic mustache that has become synonymous with his persona. Tom Selleck has had a prolific career spanning decades. But, the journey of young Tom Selleck, from his early years to becoming a household name. is a story filled with determination, talent, and a touch of luck. This article delves into young Tom Selleck's life, background, early struggles. and pivotal moments that led to his rise in Hollywood.
Follow us on: Pinterest
Early Life and Background
Family Roots and Childhood
Thomas William Selleck was born in Detroit, Michigan, on January 29, 1945. He was the second of four children in a close-knit family. His father, Robert Dean Selleck, was a real estate investor and executive. while his mother, Martha Selleck, was a homemaker. The Selleck family relocated to Sherman Oaks, California. when Tom was a child, setting the stage for his future in the entertainment industry.
Education and Early Interests
Growing up, young Tom Selleck was an active and athletic child. He attended Grant High School in Van Nuys, California. where he excelled in sports, particularly basketball. His tall and athletic build made him a standout player, and he earned a basketball scholarship to the University of Southern California (U.S.C.). While at U.S.C., Selleck studied business administration. but his interests shifted toward acting.
Discovery of Acting Passion
Tom Selleck's journey into acting was serendipitous. During his time at U.S.C., a drama coach encouraged him to try acting. This nudge led him to join the Hills Playhouse, where he began honing his craft. Transitioning from an aspiring athlete to an actor took time. but young Tom Selleck became drawn to the performance world.
Early Career Struggles
Breaking Into the Industry
The path to stardom was a challenging one for young Tom Selleck. Like many aspiring actors, he faced many rejections and struggled to find steady work. A series of minor roles and guest appearances on television shows marked his early career. In 1965, he debuted on the syndicated show "The Dating Game." which gave him some exposure but did not lead to immediate success.
The Commercial Breakthrough
During the late 1960s and early 1970s, Selleck began appearing in television commercials. His rugged good looks and charismatic presence made him a popular brand choice. He starred in advertisements for Pepsi-Cola, Revlon, and Close-Up toothpaste. These commercials provided financial stability and helped him gain visibility in the industry.
Struggling Actor in Hollywood
Despite his success in commercials. breaking into large acting roles remained a challenge for young Tom Selleck. He auditioned and took on small parts in T.V. shows and movies. Some of his early television appearances included roles in popular series like Lancer, The F.B.I., and Bracken's World. But, it would take a
Barbie Movie Review - The Astras.pdffffftheastras43
Barbie Movie Review has gotten brilliant surveys for its fun and creative story. Coordinated by Greta Gerwig, it stars Margot Robbie as Barbie and Ryan Gosling as Insight. Critics adore its perky humor, dynamic visuals, and intelligent take on the notorious doll's world. It's lauded for being engaging for both kids and grown-ups. The Astras profoundly prescribes observing the Barbie Review for a delightful and colorful cinematic involvement.https://theastras.com/hca-member-gradebooks/hca-gradebook-barbie/
240529_Teleprotection Global Market Report 2024.pdfMadhura TBRC
The teleprotection market size has grown
exponentially in recent years. It will grow from
$21.92 billion in 2023 to $28.11 billion in 2024 at a
compound annual growth rate (CAGR) of 28.2%. The
teleprotection market size is expected to see
exponential growth in the next few years. It will grow
to $70.77 billion in 2028 at a compound annual
growth rate (CAGR) of 26.0%.
Modern Radio Frequency Access Control Systems: The Key to Efficiency and SafetyAITIX LLC
Today's fast-paced environment worries companies of all sizes about efficiency and security. Businesses are constantly looking for new and better solutions to solve their problems, whether it's data security or facility access. RFID for access control technologies have revolutionized this.
Unveiling Paul Haggis Shaping Cinema Through Diversity. .pdfkenid14983
Paul Haggis is undoubtedly a visionary filmmaker whose work has not only shaped cinema but has also pushed boundaries when it comes to diversity and representation within the industry. From his thought-provoking scripts to his engaging directorial style, Haggis has become a prominent figure in the world of film.
_7 OTT App Builders to Support the Development of Your Video Applications_.pdfMega P
Due to their ability to produce engaging content more quickly, over-the-top (OTT) app builders have made the process of creating video applications more accessible. The invitation to explore these platforms emphasizes how over-the-top (OTT) applications hold the potential to transform digital entertainment.
Hollywood Actress - The 250 hottest galleryZsolt Nemeth
Hollywood Actress amazon album eminent worldwide media, female-singer, actresses, alhletina-woman, 250 collection.
Highest and photoreal-print exclusive testament PC collage.
Focused television virtuality crime, novel.
The sheer afterlife of the work is activism-like hollywood-actresses point com.
173 Illustrate, 250 gallery, 154 blog, 120 TV serie logo, 17 TV president logo, 183 active hyperlink.
HD AI face enhancement 384 page plus Bowker ISBN, Congress LLCL or US Copyright.
Experience the thrill of Progressive Puzzle Adventures, like Scavenger Hunt Games and Escape Room Activities combined Solve Treasure Hunt Puzzles online.
Matt Rife Cancels Shows Due to Health Concerns, Reschedules Tour Dates.pdfAzura Everhart
Matt Rife's comedy tour took an unexpected turn. He had to cancel his Bloomington show due to a last-minute medical emergency. Fans in Chicago will also have to wait a bit longer for their laughs, as his shows there are postponed. Rife apologized and assured fans he'd be back on stage soon.
https://www.theurbancrews.com/celeb/matt-rife-cancels-bloomington-show/
The Unbelievable Tale of Dwayne Johnson Kidnapping: A Riveting Sagagreendigital
Introduction
The notion of Dwayne Johnson kidnapping seems straight out of a Hollywood thriller. Dwayne "The Rock" Johnson, known for his larger-than-life persona, immense popularity. and action-packed filmography, is the last person anyone would envision being a victim of kidnapping. Yet, the bizarre and riveting tale of such an incident, filled with twists and turns. has captured the imagination of many. In this article, we delve into the intricate details of this astonishing event. exploring every aspect, from the dramatic rescue operation to the aftermath and the lessons learned.
Follow us on: Pinterest
The Origins of the Dwayne Johnson Kidnapping Saga
Dwayne Johnson: A Brief Background
Before discussing the specifics of the kidnapping. it is crucial to understand who Dwayne Johnson is and why his kidnapping would be so significant. Born May 2, 1972, Dwayne Douglas Johnson is an American actor, producer, businessman. and former professional wrestler. Known by his ring name, "The Rock," he gained fame in the World Wrestling Federation (WWF, now WWE) before transitioning to a successful career in Hollywood.
Johnson's filmography includes blockbuster hits such as "The Fast and the Furious" series, "Jumanji," "Moana," and "San Andreas." His charismatic personality, impressive physique. and action-star status have made him a beloved figure worldwide. Thus, the news of his kidnapping would send shockwaves across the globe.
Setting the Scene: The Day of the Kidnapping
The incident of Dwayne Johnson's kidnapping began on an ordinary day. Johnson was filming his latest high-octane action film set to break box office records. The location was a remote yet scenic area. chosen for its rugged terrain and breathtaking vistas. perfect for the film's climactic scenes.
But, beneath the veneer of normalcy, a sinister plot was unfolding. Unbeknownst to Johnson and his team, a group of criminals had planned his abduction. hoping to leverage his celebrity status for a hefty ransom. The stage was set for an event that would soon dominate worldwide headlines and social media feeds.
The Abduction: Unfolding the Dwayne Johnson Kidnapping
The Moment of Capture
On the day of the kidnapping, everything seemed to be proceeding as usual on set. Johnson and his co-stars and crew were engrossed in shooting a particularly demanding scene. As the day wore on, the production team took a short break. providing the kidnappers with the perfect opportunity to strike.
The abduction was executed with military precision. A group of masked men, armed and organized, infiltrated the set. They created chaos, taking advantage of the confusion to isolate Johnson. Johnson was outnumbered and caught off guard despite his formidable strength and fighting skills. The kidnappers overpowered him, bundled him into a waiting vehicle. and sped away, leaving everyone on set in a state of shock and disbelief.
The Immediate Aftermath
The immediate aftermath of the Dwayne Johnson kidnappin
Orpah Winfrey Dwayne Johnson: Titans of Influence and Inspirationgreendigital
Introduction
In the realm of entertainment, few names resonate as Orpah Winfrey Dwayne Johnson. Both figures have carved unique paths in the industry. achieving unparalleled success and becoming iconic symbols of perseverance, resilience, and inspiration. This article delves into the lives, careers. and enduring legacies of Orpah Winfrey Dwayne Johnson. exploring how their journeys intersect and what we can learn from their remarkable stories.
Follow us on: Pinterest
Early Life and Backgrounds
Orpah Winfrey: From Humble Beginnings to Media Mogul
Orpah Winfrey, often known as Oprah due to a misspelling on her birth certificate. was born on January 29, 1954, in Kosciusko, Mississippi. Raised in poverty by her grandmother, Winfrey's early life was marked by hardship and adversity. Despite these challenges. she demonstrated a keen intellect and an early talent for public speaking.
Winfrey's journey to success began with a scholarship to Tennessee State University. where she studied communication. Her first job in media was as a co-anchor for the local evening news in Nashville. This role paved the way for her eventual transition to talk show hosting. where she found her true calling.
Dwayne Johnson: From Wrestling Royalty to Hollywood Superstar
Dwayne Johnson, also known by his ring name "The Rock," was born on May 2, 1972, in Hayward, California. He comes from a family of professional wrestlers, with both his father, Rocky Johnson. and his grandfather, Peter Maivia, being notable figures in the wrestling world. Johnson's early life was spent moving between New Zealand and the United States. experiencing a variety of cultural influences.
Before entering the world of professional wrestling. Johnson had aspirations of becoming a professional football player. He played college football at the University of Miami. where he was part of a national championship team. But, injuries curtailed his football career, leading him to follow in his family's footsteps and enter the wrestling ring.
Career Milestones
Orpah Winfrey: The Queen of All Media
Winfrey's career breakthrough came in 1986 when she launched "The Oprah Winfrey Show." The show became a cultural phenomenon. drawing millions of viewers daily and earning many awards. Winfrey's empathetic and candid interviewing style resonated with audiences. helping her tackle diverse and often challenging topics.
Beyond her talk show, Winfrey expanded her empire to include the creation of Harpo Productions. a multimedia production company. She also launched "O, The Oprah Magazine" and OWN: Oprah Winfrey Network, further solidifying her status as a media mogul.
Dwayne Johnson: From The Ring to The Big Screen
Dwayne Johnson's wrestling career took off in the late 1990s. when he became one of the most charismatic and popular figures in WWE. His larger-than-life persona and catchphrases endeared him to fans. making him a household name. But, Johnson had ambitions beyond the wrestling ring.
In the early 20
2. Algorithm 8.1.1 Computing the Fibonacci Numbers, Version 1 This dynamic-programming algorithm computes the Fibonacci number f [ n ]. It uses the formulas f [1] = 1; f [2] = 1; f [ n ] = f [ n - 1] + f [ n - 2], n ≥ 3. At the conclusion of the algorithm, the array f holds the first n Fibonacci numbers. Input Parameters: n Output Parameters: None fibonacci1 ( n ) { // f is a local array f [1] = 1 f [2] = 1 for i = 3 to n f [ i ] = f [ i - 1] + f [ i - 2] return f [ n ] }
3. Algorithm 8.1.1 Computing the Fibonacci Numbers, Version 2 This dynamic-programming algorithm computes the Fibonacci number f n . It uses the formulas f 1 = 1; f 2 = 1; f n = f n - 1 + f n - 2 , n ≥ 3. It saves the two preceding Fibonacci numbers in the variables f_twoback and f_oneback in order to compute the next Fibonacci number. Input Parameters: n Output Parameters: None fibonacci2 ( n ) { if ( n == 1 || n == 2) return 1 f_twoback = 1 f_oneback = 1 for i = 3 to n { f = f_twoback + f_oneback f_twoback = f_oneback f_oneback = f } return f }
4. Computing the Fibonacci Numbers Recursively This algorithm computes the Fibonacci number f n recursively using the formulas f 1 = 1; f 2 = 1; f n = f n - 1 + f n - 2 , n ≥ 3. Input Parameters: n Output Parameters: None fibonacci_recurs ( n ) { if ( n == 1) return 1 if ( n == 2) return 1 return fibonacci_recurs ( n - 2) + fibonacci_recurs ( n - 1) }
5. Computing the Fibonacci Numbers with Memoization This algorithm computes the Fibonacci number f n recursively (with memoization) using the formulas f 1 = 1; f 2 = 1; f n = f n - 1 + f n - 2 , n ≥ 3.
6. Input Parameters: n Output Parameters: None memoized_fibonacci ( n ) { for i = 1 to n results [ i ] = -1 // -1 means undefined return memoized_fibonacci_recurs ( results , n ) } memoized_fibonacci_recurs ( results , n ) { if ( results [ n ] != -1) return results [ n ] if ( n == 1) val = 1 else if ( n == 2) val = 1 else { val = memoized_fibonacci_recurs ( results , n - 2) val = val + memoized_fibonacci_recurs ( results , n - 1) } results [ n ] = val return val }
7. Algorithm 8.2.1 Coin Changing Using Dynamic Programming, Version 1 This dynamic-programming algorithm computes the minimum number of coins to make change for a given amount. The input is an array denom that specifies the denominations of the coins, denom [1] > denom [2] > ··· > denom [ n ] = 1, and an amount A . The output is an array C whose value, C [ i ][ j ], is the minimum number of coins to make change for the amount j , using coins i through n , 1 ≤ i ≤ n, 0 ≤ j ≤ A.
8. Input Parameters: denoma , A Output Parameters: None dynamic_coin_change1 ( denom , A , C ) { n = denom . last for j = 0 to A C [ n ][ j ] = j for i = n - 1 downto 1 for j = 0 to A if ( denom [ i ] > j || C [ i + 1][ j ] < 1 + C [ i ][ j - denom [ i ]]) C [ i ][ j ] = C [ i + 1][ j ] else C [ i ][ j ] = 1 + C [ i ][ j - denom [ i ]] }
9. Algorithm 8.2.2 Coin Changing Using Dynamic Programming, Version 2 This dynamic-programming algorithm computes the minimum number of coins to make change for a given amount and tracks which coins are used. The input is an array denom that specifies the denominations of the coins, denom [1] > denom [2] > ··· > denom [ n ] = 1, and an amount A . The output consists of arrays C and used . The value, C [ i ][ j ], is the minimum number of coins to make change for the amount j , using coins I through n , 1 ≤ i ≤ n, 0 ≤ j ≤ A. The value, used [ i ][ j ], is true or false to signify whether coin i appears in the smallest set of coins computed by Algorithm 8.2.1 for the amount j using only coins i through n . The values of i and j satisfy 1 ≤ i ≤ n, 0 ≤ j ≤ A.
10. Input Parameters: denom , A Output Parameters: C , used dynamic_coin_change2 ( denom , A , C , used ) { n = denom . last for j = 0 to A { C [ n ][ j ] = j used [ n ][ j ] = true } for i = n - 1 downto 1 for j = 0 to A if ( denom [ i ] > j || C [ i + 1][ j ] < 1 + C [ i ][ j - denom [ i ]]) C [ i ][ j ] = C [ i + 1][ j ] used[ i ][ j ] = false else C [ i ][ j ] = 1 + C [ i ][ j - denom [ i ]] used[ i ][ j ] = true } }
11. Algorithm 8.2.4 Computing a Minimum- Size Set of Coins for a Given Amount This algorithm outputs a minimum-size set of coins to make change for an amount j using any of coins i through n with denominations specified by Algorithm 8.2.2. The algorithm inputs the index i , the amount j , the array denom of Algorithm 8.2.2, and the array used computed by Algorithm 8.2.2.
12. Input Parameters: i , j , denom , used Output Parameters: None optimal_coins_set ( i , j , denom , used ) { if ( j == 0) return if ( used [ i ][ j ]) { println (“Use a coin of denomination ” + denom [ i ]) optimal_coins_set ( i , j - denom [ i ], denom , used ) } else optimal_coins_set ( i + 1, j , denom , used ) }
13. Algorithm 8.3.1 Optimal Matrix Multiplication This algorithm computes the minimum number of scalar multiplications to multiply a sequence of n matrices. The input is the array size that contains the sizes of the matrices to be multiplied. The first matrix is size [0] × size [1]; the second is size [1] × size [2]; and so on. The n th matrix is size [ n - 1] × size [ n ]. The output is the array s whose value, s [ i ][ j ], is the minimum number of scalar multiplications to multiply matrices i through j . The value ∞ is the largest available integer value.
14. Input Parameters: size Output Parameters: s opt_matrix_mult ( size , s ) { n = size . last for i = 1 to n s [ i ][ i ] = 0 // w = j - i for w = 1 to n - 1 for i = 1 to n - w { j = w + i s [ i ][ j ] = ∞ for k = i to j - 1 { q = s [ i ][ k ] + s [ k + 1][ j ] + size [ i - 1] * size [ k ] * size [ j ] if ( q < s [ i ][ j ]) s [ i ][ j ] = q } } }
15. Algorithm 8.4.2 Computing the Length of a Longest Common Subsequence This dynamic-programming algorithm computes the length c [ i ][ j ] of a longest common subsequence of a [1], ... , a[ i ] and b [1], ... , b [ j ] for i = 0, ... , m and j = 0, ... , n . Input Parameters: a , b Output Parameters: c LCS ( a , b , c ) { m = a . last n = b . last for i = 0 to m c [ i ][0] = 0 for j = 1 to n c[0][ j ] = 0 for i = 1 to m for j = 1 to n if ( a [ i ] != b [ j ]) c [ i ][ j ] = max ( c [ i - 1][ j ], c [ i ][ j - 1]) else c [ i ][ j ] = 1 + c [ i - 1][ j - 1] }
16. Algorithm 8.4.3 Computing a Longest Common Subsequence This algorithm uses the array c computed by Algorithm 8.4.2 to output a longest common subsequence. The array a of length m is the first sequence input to Algorithm 8.4.2, and n is the length of the second sequence input to Algorithm 8.4.2. Input Parameters: a , m (length of a ), n (length of second sequence), c (contains lengths of longest common subsequences) Output Parameters: None LCS_print ( a , m , n , c ) { if ( c [ m ][ n ] == 0) return if ( c [ m ][ n ] == c [ m - 1][ n ]) LCS_print ( a , m - 1, n , c ) else if ( c [ m ][ n ] == c [ m ][ n - 1]) LCS_print ( a , m , n - 1, c ) else { LCS_print ( a , m - 1, n - 1, c ) print ( a [ m ]) } }
17. Algorithm 8.5.3 Floyd’s Algorithm, Version 1 This algorithm computes the length of a shortest path between each pair of vertices in a simple, undirected, weighted graph G . All weights are nonnegative. The input is the adjacency matrix A of G . The output is the matrix A whose ij th entry is the length of a shortest path from vertex i to vertex j . Input Parameter: A Output Parameter: A all_paths ( A ) { n = A . last for k = 1 to n // compute A ( k ) for i = 1 to n for j = 1 to n if ( A [ i ][ k ] + A [ k ][ j ] < A [ i ][ j ]) A [ i ][ j ] = A [ i ][ k ] + A [ k ][ j ] }
18. Algorithm 8.5.4 Floyd’s Algorithm, Version 2 This algorithm computes the length of a shortest path between each pair of vertices in a simple, undirected, weighted graph G and stores the vertex that follows the first vertex on each shortest path. All weights are nonnegative. The input is the adjacency matrix A of G . The output is the matrix A whose ij th entry is the length of a shortest path from vertex i to vertex j and the matrix next whose ij th entry is the vertex that follows i on a shortest path from i to j .
19. Input Parameter: A Output Parameter: A , next all_paths ( A , next ) { n = A . last // initialize next: if no intermediate // vertices are allowed next [ i ][ j ] = j for i = 1 to n for j = 1 to n next [ i ][ j ] = j for k = 1 to n // compute A ( k ) for i = 1 to n for j = 1 to n if ( A [ i ][ k ] + A [ k ][ j ] < A [ i ][ j ]) { A [ i ][ j ] = A [ i ][ k ] + A [ k ][ j ] next [ i ][ j ] = next [ i ][ k ] } }
20. Algorithm 8.5.5 Finding a Shortest Path This algorithm outputs a shortest path from vertex i to vertex j in a simple, undirected, weighted graph G . It assumes that matrix next has already been computed by Algorithm 8.5.4. Input Parameters: next , i , j Output Parameters: None print_path ( next , i , j ) { // if no intermediate vertices, just // print i and j and return if ( j == next [ i ][ j ]) { print ( i + “ ” + j ) return } // output i and then the path from the vertex // after i ( next [ i ][ j ]) to j print ( i + “ ”) print_path ( next , next [ i ][ j ], j ) }
21. Algorithm 8.5.12 Warshall’s Algorithm This algorithm computes the transitive closure of a relation R on {1, ... , n }. The input is the matrix A of R . The output is the matrix A of the transitive closure of R . Input Parameters: A Output Parameters: A transitive_closure ( A ) { n = A . last for k = 1 to n for i = 1 to n for j = 1 to n A [ i ][ j ] = A [ i ][ j ] ( A [ i ][ k ] A [ k ][ j ]) }