Top Banner
Introduction
29

Data structure algorithms introduction

Jan 22, 2018

Download

Software

Sugandh Wafai
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data structure  algorithms introduction

Introduction

Page 2: Data structure  algorithms introduction

Values or sets of values

A “Data Item” refers to a single set of values

Group Items

Elementary Items

Page 3: Data structure  algorithms introduction

Collections of data are frequently organized into a hierarchy of fields, records, and files.

An entity is something that has certain attributes.

Entities with similar attributes form an entity set.

Each attribute of an entity set has a range of values.

Page 4: Data structure  algorithms introduction

Data with given attributes

Meaningful or processed data

Data Processing Information

Page 5: Data structure  algorithms introduction

The logical or mathematical model of a particular organization is called data structure.

OR A data structure is the arrangement of data in

a computer’s memory (or sometimes on a disk)

Page 6: Data structure  algorithms introduction

It should have two qualities:1. It should be able to create the model as close

to reality as possible.

2. It should be simple enough to process the data efficiently when needed.

Page 7: Data structure  algorithms introduction

There are two types of data:1. Primitive: integers, real, character, Boolean.

2. Non-primitive: Linked-lists, stacks, queues, trees & graphs

Page 8: Data structure  algorithms introduction
Page 9: Data structure  algorithms introduction

Linear: elements form a sequence or a linear list. Examples: Arrays, Linked Lists, Stacks, Queues.

Non-linear: Data is not arranged in sequence. The insertion and deletion of data is not possible in a linear fashion. Examples: Trees & Graphs

Page 10: Data structure  algorithms introduction

A list of a finite number “n” of similar data.

Page 11: Data structure  algorithms introduction

If elements of an array are referenced as “1,2,3, … ,n”

The array is called “A”.

Then the elements of “A” are denoted by subscript notation “a₁, a₂, a₃, … an

Page 12: Data structure  algorithms introduction

Or by the parenthesis notationA(1), A(2), A(3), … , A(N)

Or by the bracket notationA[1], A[2], A[3], … , A[N]

Page 13: Data structure  algorithms introduction

A linked list is a linear data structure where each element is a separate object

A linked list has two parts: one is info and the other is link part. Info part gives information and link part is address of next node.

Page 14: Data structure  algorithms introduction

Each element has two items : the data and a reference to next node

The last node has reference to null

The first node is called the head. It is not a separate node but reference to first node.

If the list is empty then the head is a null reference.

Page 15: Data structure  algorithms introduction

It is dynamic data structure.

The nodes can grow and shrink on demand.

Good for applications dealing with unknown number of objects.

Page 16: Data structure  algorithms introduction

Tree or branched data structure consists of sets of elements (nodes) which could be linked to other elements.

Trees represent hierarchies, while graphs represent more general relations such as maps of city.

Page 17: Data structure  algorithms introduction

Tree Graph

Page 18: Data structure  algorithms introduction

Every circle in a tree is called a node, and every line an edge.

Root is the node without parent

Leaf is a node without child.

Internal nodes are neither leaf or root.

Path is called a sequence of nodes connecting with edges.

Page 19: Data structure  algorithms introduction

Stacks also called a last in first out system.

Queue also called a first in first out system

Graphs contain a relationship between pairs of elements which is not necessarily hierarchical in nature.

Page 20: Data structure  algorithms introduction

1. Traversing: Assessing each record exactly once so that certain items in the record may be processed. Also called visiting the record.

2. Searching: Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.

Page 21: Data structure  algorithms introduction

3. Inserting: Adding a new record to the structure.

4. Deleting: Removing a record from the structure.

5. Sorting: Arranging the records in some logical order.

6. Merging: Combing the records in two different sorted files into a single sorted file.

Page 22: Data structure  algorithms introduction

Data type defined in terms of operations on it, and its implementation is hidden.

It is easier to replace the implementation and it will not interfere with anything in the program.

Page 23: Data structure  algorithms introduction

An ADT has 2 parts:1. A name or type specifying a set of data

(dictionary)

2. Descriptions of all the operations (or methods) that do things with that type (e.g., find, insert, remove). The descriptions indicate what the operations do, not how they do it.

Examples: Interfaces in Java(roughly) header files and typedef in C

Page 24: Data structure  algorithms introduction
Page 25: Data structure  algorithms introduction

An Algorithm is a well defined list of steps for solving a particular problem.

The time and space it uses are two major measures of the efficiency of an algorithm.

Page 26: Data structure  algorithms introduction

The complexity of an algorithm is the function which gives the running time and/or space in terms of the input size.

Page 27: Data structure  algorithms introduction

Refers to a choice between algorithmic solutions of a data processing problems that allows one to decrease the running time of an algorithmic solution by increasing the space to store that data and vice versa.

Page 28: Data structure  algorithms introduction

Linear search searches for a specified value in a list by checking every element in the list.

Binary search method halves the number of elements checked (in each iteration), reducing the time taken to locate the given item in the list.

Page 29: Data structure  algorithms introduction

Binary Search Linear Search

Works only on sorted items. such as1,2,3,4,5,6 etc.

Works on sorted as well as unsorted items.12,4,5,3,2,1 etc.

Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such asSuppose your list items are :12,3,4,5,1and you want to search 12 number then you get beginning in the list.

Works well with arrays and not on linked lists.

Works with arrays and linked lists.

Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.