+ All Categories
Home > Data & Analytics > Data structures & algorithms

Data structures & algorithms

Date post: 14-Jan-2017
Category:
Upload: prabhu-r
View: 168 times
Download: 2 times
Share this document with a friend
19
DATA STRUCTURES & ALGORITHMS R.PRABHU 132912 B-SEC 4/3/2015 Prabhu Mike
Transcript
Page 1: Data structures & algorithms

Prabhu Mike

DATA STRUCTURES & ALGORITHMS

R.PRABHU132912B-SEC

4/3/2015

Page 2: Data structures & algorithms

Prabhu Mike

Introduction

Definition:Given a set of cities and the distance between each possible pair, the Travelling Salesman Problem is to find the best possible way of ‘visiting all the cities exactly once and returning to the starting point’

4/3/2015

Page 3: Data structures & algorithms

Prabhu Mike

The Traveling Salesman

• Computer scientists call the problem of finding an optimal path between n points the traveling salesman problem (TSP)

• The TSP is a famous problem– first posed by Irish mathematician

W. R. Hamilton in the 19th century– intensely studied in

operations research and other areas since 1930

This tour of 13,500 US cities was generated by an advanced algorithm that used several “tricks” to limit the number of possible tours

http://www.tsp.gatech.edu/Required 5 “CPU-years”

4/3/2015

Page 4: Data structures & algorithms

Prabhu Mike

A genetic algorithm for a computationally demanding problem

The Traveling Salesman

• Maps and Tours• Exhaustive Search• Random Search• The Genetic Algorithm• Crossovers

4/3/2015

Page 5: Data structures & algorithms

Prabhu Mike

Find a tour with minimum distance, visiting every city only once

Madiera Island (west of Morocco in Atlantic ocean)

4/3/2015

Page 6: Data structures & algorithms

Prabhu Mike

Applications of TSP• Even in its purest form the TSP, has several applications such

as planning, logistics, and the manufacture of microchips.• Slightly modified, it appears as a sub-problem in many areas,

such as DNA sequencing.• In these applications, the concept city represents, for example,

customers, soldering points, or DNA fragments • The concept distance represents travelling times or cost, or a

similarity measure between DNA fragments.• As TSP is a NP hard problem it is often used as a benchmark

for optimization techniques.

4/3/2015

Page 7: Data structures & algorithms

Prabhu Mike

Applications of TSPMechanical arm• When a mechanical arm is used to fasten the nuts for assembling parts, it

moves through each nut in proper order and returns to the initial position. • The most economical travelling route will enable the mechanical arm to

finish its work within the shortest time.Integrated circuit • Inserting electrical elements in the manufacturing of integrated circuits

consumes certain energy when moving from one electrical element to the other during manufacturing.

• We need to arrange the manufacturing order to minimize the energy consumption.

In both these cases, TSP is required to be solved as a sub-problem.

4/3/2015

Page 8: Data structures & algorithms

Prabhu Mike

Genetic Algorithms for TSP

Genetic algorithm has many steps in itEvolution• finding out good members from the population

Cross Over• combining two parent members to form two new

different members(children) with similar characteristics as parents.• Some of newly formed members are altered randomly• Keeps them from becoming identical and converging to

a local minima

4/3/2015

Page 9: Data structures & algorithms

Prabhu Mike

• Completing the graph– Missing edges are inserted with a weight of

Infinity (INF)

4/3/2015

Page 10: Data structures & algorithms

Prabhu Mike4/3/2015

Doubly-Linked Lists It is a way of going both directions in

a linked list, forward and reverse. Many applications require a quick

access to the predecessor node of some node in list.

Page 11: Data structures & algorithms

Prabhu Mike4/3/2015

Advantages over Singly-linked Lists• Quick update operations:

such as: insertions, deletions at both ends (head and tail), and also at the middle of the list.

• A node in a doubly-linked list store two references: • A next link; that points to the next node in the list,

and• A prev link; that points to the previous node in the

list.

Page 12: Data structures & algorithms

Prabhu Mike4/3/2015

Doubly Linked List• A doubly linked list provides a natural

implementation of the List ADT• Nodes implement Position and store:

• element• link to the previous node• link to the next node

• Special trailer and header nodes

prev next

elem

trailerheader nodes/positions

elements

node

Page 13: Data structures & algorithms

Prabhu Mike

A linked list as an array of records

• What are the advantages of using linked lists?(1) Dynamic memory allocation(2) Efficient insertion-deletion (for sorted lists)

• Can we implement a linked list without dynamic memory allocation ?

4/3/2015

Page 14: Data structures & algorithms

Prabhu Mike

Singly Linked Lists

• A singly linked list is a concrete data structure consisting of a sequence of nodes

• Each node stores– element– link to the next node

next

elem node

A B C D

4/3/2015

Page 15: Data structures & algorithms

Prabhu Mike

Insertion• We visualize operation insertAfter(p, X), which returns position q

A B X C

A B C

p

A B C

p

X

q

p q

4/3/2015

Page 16: Data structures & algorithms

Prabhu Mike

Insertion AlgorithmAlgorithm insertAfter(p,e):

Create a new node vv.setElement(e)v.setPrev(p) {link v to its predecessor}v.setNext(p.getNext()) {link v to its successor}(p.getNext()).setPrev(v) {link p’s old successor to v}p.setNext(v) {link p to its new successor, v}return v {the position for the element e}

4/3/2015

Page 17: Data structures & algorithms

Prabhu Mike

Deletion• We visualize remove(p), where p == last()

A B C D

p

A B C

D

p

A B C

4/3/2015

Page 18: Data structures & algorithms

Prabhu Mike

Deletion Algorithm

Algorithm remove(p):t = p.element {a temporary variable to hold the

return value}(p.getPrev()).setNext(p.getNext()) {linking out p}(p.getNext()).setPrev(p.getPrev())p.setPrev(null){invalidating the position p}p.setNext(null)return t

4/3/2015

Page 19: Data structures & algorithms

Prabhu Mike

Thank

you..

4/3/2015


Recommended