Docsity

Optimal Data Structures & Algorithms: Greedy & Abstract Types, Exercises of Data Structures and Algorithms

Toggle sidebar
bg1
REG NO : BBIT/55742/2016
NAME : PAUL MUTHURI KIRAMANA
COURSE : BARCHELOR IN BUSINNES INFORMATION TECHNOLOGY
UNIT CODE : BIT4105
UNIT NAME : ADVANCED DATA STRUCTURES AND ALGORITHMS
TASK : CAT 1&2
(a)ALGORITHMS ARE ANALYSED BASED ON THEIR COMPLEXITY. EXPLAIN THE
CONCEPT OF ALGORITHM ANALYSIS INTERMS OF
(i)Optimality (2 marks)
An algorithm for a given problem is optimal if its complexity reaches the lower bound over all the
algorithms solving this problem. An optimal algorithm is an algorithm that solves a problem in the best
possible way, meaning there are no better algorithms for this.
(ii)Reduction (2 marks)
Reductions are operations that convert one problem into another. Reduction refers
to translation of instances from one type of problem to instances of another such
that the answers are preserved.
Reductions are a way to show that two problems are essentially identical. A fast
algorithm for one of the problems implies a fast algorithm for the other.
pf3
pf4
pf5

Partial preview of the text

Download Optimal Data Structures & Algorithms: Greedy & Abstract Types and more Exercises Data Structures and Algorithms in PDF only on Docsity!

REG NO : BBIT/55742/

NAME : PAUL MUTHURI KIRAMANA

COURSE : BARCHELOR IN BUSINNES INFORMATION TECHNOLOGY

UNIT CODE : BIT

UNIT NAME : ADVANCED DATA STRUCTURES AND ALGORITHMS

TASK : CAT 1&

(a)ALGORITHMS ARE ANALYSED BASED ON THEIR COMPLEXITY. EXPLAIN THE CONCEPT OF ALGORITHM ANALYSIS INTERMS OF

(i)Optimality (2 marks)

An algorithm for a given problem is optimal if its complexity reaches the lower bound over all the algorithms solving this problem. An optimal algorithm is an algorithm that solves a problem in the best possible way, meaning there are no better algorithms for this.

(ii)Reduction (2 marks)

Reductions are operations that convert one problem into another. Reduction refers to translation of instances from one type of problem to instances of another such that the answers are preserved.

Reductions are a way to show that two problems are essentially identical. A fast algorithm for one of the problems implies a fast algorithm for the other.

(b)EXPLAIN THE CONCEPT OF GREEDY ALGORITHM. WHAT ARE THE FEATURES AND CHARACTERISTICS OF PROBLEMS SOLVED BY GREEDY ALGORITHM (4 MARKS).

A greedy algorithm always makes the choice that seems to be the 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. A problem must comprise these two components for a greedy algorithm to work.

  • It has optimal substructures. The optimal solution for the problem contains optimal solutions to the sub-problems.
  • It has a greedy property (hard to prove its correctness!). If you make a choice that seems the best at the moment and solve the remaining sub-problems later, you still reach an optimal solution. You will never have to reconsider your earlier choices.

Characteristics and Features of Problems solved by Greedy Algorithms

To construct the solution in an optimal way, algorithm maintains two sets.

  • One contains chosen items
  • The other contains rejected items.

Components of greedy algorithms

  • A candidate set, from which a solution is created.
  • A selection function, which chooses the best candidate to be added to the solution.
  • A feasibility function that is used to determine if a candidate can be used to contribute to a solution.
  • An objective function, which assigns a value to a solution, or a partial solution, and
  • A solution function, which will indicate when we have discovered a complete solution

(c)DESCRIBE THE GREEDY ALGORITHM AND LIST DOWN THE FEATURES AND CHARACTERISTICS OF PROBLEMS SOLVED BY IT (5MARKS)

Greedy Algorithm works by making the decision that seems most promising at any moment. It never reconsiders this decision, whatever situation may arise later.

Features and characteristics of problems solved by greedy algorithm To construct the solution in an optimal way, algorithm maintains two sets.

  • One contains chosen items
  • The other contains rejected items.

The greedy algorithm consists of four functions.

  • A function that checks whether chosen set of items provide a solution.
  • A function that checks the feasibility of a set.
  • The selection function tells which of the candidates is the most promising.

independent view. The process of providing only the essentials and hiding the details is known as abstraction. (f)EXPLAIN HOW LINEAR EQUATIONS CAN BE RESOLVED IN A CASE OF TWO UNKNOWNS USING THE SIMULTANEOUS METHOD. USE EXAMPLE OF CHOICE TO ILLUSTRATE YOUR EXPLANATION (5MARKS).

Steps.

  • Step 1: Simplify if needed.
  • Step 2: Solve one equation for either variable.
  • Step 3: Substitute what you get for step 2 into the other equation
  • Step 4: Solve for the remaining variable.
  • Step 5: Solve for second variable.
  • Step 6: Check the proposed ordered pair solution in BOTH original equations.

Example.

  • Solve the system of equations by the substitution method

Step 1: Simplify if needed.

Both of these equations are already simplified. No work needs to be done here.

Step 2: Solve one equation for either variable.

It does not matter which equation or which variable you choose to solve for. Just keep it simple.

Since the x in the second equation has a coefficient of 1, that would mean we would not have to divide by a number to solve for it and run the risk of having to work with fractions. The easiest route here is to solve the second equation for x, and we definitely want to take the easy route.

You would not be wrong to either choose the other equation and/or solve for y, again you want to keep it as simple as possible.

Solving the second equation for x we get:

Step 3 and Step 4: Substitute what you get for step 2 into the other equation and Solve for the remaining variable

  • Substitute the expression y + 1 for x into the first equation and solve for y:

Step 5: Solve for second variable.

  • Plug in 3 for y into the equation in step 2 to find xโ€™s value.

Step 6: Check the proposed ordered pair solution in BOTH original equations.

You will find that if you plug the ordered pair (4, 3) into BOTH equations of the original system, that this is a solution to BOTH of them.

  • (4, 3) is a solution to our system.

REFERENCE

  • https://www.geeksforgeeks.org
  • https://en.wikipedia.org/wiki/Greedy_algorithm
  • https://www.hackerearth.com