Data Structures & Algorithms: Stack, Sorting, and Shortest Path Algorithms, Summaries of Data Mining

Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem.

Typology: Summaries

2019/2020

Uploaded on 11/06/2021

hai-nguyen-14
hai-nguyen-14 🇻🇳

4.4

(7)

5 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DATA STRUCTURES & ALGORITHMS
Name: Nguyễn Thị Kiều Vy
Class: GCD0807B
ID: GCD191163
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Data Structures & Algorithms: Stack, Sorting, and Shortest Path Algorithms and more Summaries Data Mining in PDF only on Docsity!

DATA STRUCTURES & ALGORITHMS

Name: Nguyễn Thị Kiều Vy

Class: GCD0807B

ID: GCD

CONTENTS

ADT Stack

  • Define Stack
  • Stack – Operations
  • Stack – Applications

Two sorting algorithms

  • Quick sort
  • Merge sort
  • Compare quick sort & merge sort

 Two network shortest path algorithms

DEFINE

A stack is an abstract data type that holds an ordered, linear sequence of

items. In contrast to a queue, a stack is a last-in, first-out (LIFO) structure.

Example: A stack of plates is a real-life example: you can only take a plate

from the top and only add a plate to the top of the stack. If you want to get to

a plate that isn't at the top of the stack, you'll have to take out all the plates

above it.

In the same way, you can only access the element at the top of a stack data

structure. The last element to be added will be the first to be removed. As a

result, in order to implement a stack, you must keep a pointer to the top of

the stack (the last element to be added).

STACK –

APPLICATION

Stacks have many uses, for example in checking for balanced
parentheses in an expression and converting postfix
(Reverse Polish Notation) to infix notation and vice versa.
They can be used to maintain a list of operations for an
'undo' function in a piece of software, where the most recent
operation is the first to be undone. Stacks are also used to
facilitate recursive subroutines where the state of each call
is stored in a stack frame and placed on a stack.

TOWERS OF HANOI The goal of the puzzle is to move the complete stack to another rod while adhering to the restrictions below:

  • Only one disk at a time can be relocated.
  • Each motion involves moving the topmost disk from one of the rods onto another rod, on top of any other disks that may be present on that rod.
  • No disk may be placed on top of another disk that is smaller.

DEFINE

A sorting algorithm is a method for sorting a lar
ge number of items into a predetermined order, such as
alphabetical, highest-to-lowest value, or shortest-to-longest
distance. Sorting algorithms take input data in the form of
lists of items, perform specific operations on those lists, and
output ordered arrays. Sorting algorithms are used for a
variety of things, including organizing items on a retail
website by price and determining the order of sites on a
search engine results page (SERP).

MERGE SORT

The merge() function is used
for merging two halves. The
merge(arr, l, m, r) is a key
process that assumes that
arr[l..m] and arr[m+1..r] are
sorted and merges the two
sorted sub-arrays into one. See
the following C implementation
for details.

COMPARE

QUICKSORT &

MERGESORT

SHORTEST PATH

ALGORITHMS

BELLMAN-FORD ALGORITHM

  • The Bellman-Ford algorithm solves the single- source problem in the general case, where edges can have negative weights and the graph is directed. If the graph is undirected, it will have to modified by including two edges in each direction to make it directed.
  • Bellman-Ford has the property that it can detect negative weight cycles reachable from the source, which would mean that no shortest path exists. If a negative weight cycle existed, a path could run infinitely on that cycle, decreasing the path cost to - \nifty−∞.

DIJKTRA’S ALGORITHM

  • Dijkstra's algorithm makes use of bradth- first search (which is not a single source shortest path algorithm) to solve the single-source problem. It does place one constraint on the graph: there can be no negative weight edges. However, for this one constraint, Dijkstra greatly improves on the runtime of Bellman-Ford.
  • Dijkstra's algorithm is also sometimes used to solve the all-pairs shortest path problem by simply running it on all vertices in VV. Again, this requires all edge weights to be positive.