Data Structure and Algorithms

Slides:



Advertisements
Similar presentations
Chapter 1: INTRODUCTION TO DATA STRUCTURE
Advertisements

Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Lecture - 1 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Data Type and Data Structure Data type Set of possible values for variables.
Data Structures Data Structures Topic #8. Today’s Agenda Continue Discussing Table Abstractions But, this time, let’s talk about them in terms of new.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
C++ for Engineers and Scientists Third Edition
Programming Logic and Design Fourth Edition, Comprehensive
INTRODUCTION TO DATA STRUCTURE. Topics To Be Discussed………………………. Meaning of Data Structure Classification of Data Structure Data Structure Operations.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Important Problem Types and Fundamental Data Structures
Data Structures Lecture-1:Introduction
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Lecture No.01 Data Structures Dr. Sohail Aslam
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
EENG212 Algorithms and Data Structures
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
CSC 211 Data Structures Lecture 7
Chapter 8: Data Abstractions Senem Kumova Metin. 8-2 Chapter 8: Data Abstractions 8.1 Basic Data Structures – Arrays – Lists, Stacks, Queues – Trees 8.2.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Information and Computer Sciences University of Hawaii, Manoa
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
1 Introduction to Data Structures. 2 Course Name : Data Structure (CSI 221) Course Teacher : Md. Zakir Hossain Lecturer, Dept. of Computer Science Stamford.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
COSC 2007 Data Structures II Chapter 15 External Methods.
Chapter 8 Data Abstractions. © 2005 Pearson Addison-Wesley. All rights reserved 8-2 Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
Data Structure Introduction.
Lecture -3 on Data structures Array. Prepared by, Jesmin Akhter, Lecturer, IIT, JU Array Data structures are classified as either linear or nonlinear.
Data Structure & Algorithm
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
REEM ALMOTIRI Information Technology Department Majmaah University.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
ARRAYS IN C/C++ (1-Dimensional & 2-Dimensional) Introduction 1-D 2-D Applications Operations Limitations Conclusion Bibliography.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
LINKED LISTS.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Introduction toData structures and Algorithms
Introduction to Data Structures
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Course Developer/Writer: A. J. Ikuomola
Top 50 Data Structures Interview Questions
Data Structures & File Processing
Data Structure Interview Question and Answers
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Data Structures Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective.
Data Structures Interview / VIVA Questions and Answers
Program based on pointers in C.
DATA STRUCTURES Introduction: Basic Concepts and Notations
Introduction to Data Structure
Introduction to Data Structures
Introduction to Data Structures
Important Problem Types and Fundamental Data Structures
Non-Linear data structures
Presentation transcript:

Data Structure and Algorithms Lecture 01 Data Structure and Algorithms

Outline Basic Terminology – Data and Data Structure Categories of Data Structure Data Structure Operations Algorithm Complexity

Questions ?? What is the Computer Science? Why we need to study data structures?

CSE and Data Structure Organization of data processing and methods of data processing are a subject of Computer Science. A Data Structure is a collection of data organized in some logical pre-defined way. Studying Computer Science you will study different methods of data processing.

Data Structure A data structure is an arrangement of data in a computer's memory or even disk storage. The logical and mathematical model of a particular organization of data is called a data structure. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. The choice of a particular data model depends on the two considerations first; It must be rich enough in structure to mirror the actual relationships of the data in the real world. On the other hand, the structure should be simple enough that one can effectively process the data whenever necessary.

Categories of Data Structure The data structure can be classified in to major types:  Linear Data Structure  Non-linear Data Structure

Categories of Data Structure Linear Data Structure: A data structure is said to be linear if its elements form any sequence. There are basically two ways of representing such linear structure in memory. a) One way is to have the linear relationships between the elements represented by means of sequential memory location. These linear structures are called arrays. b) The other way is to have the linear relationship between the elements represented by means of pointers or links. These linear structures are called linked lists. The common examples of linear data structure are  Arrays  Linked lists  Queues  Stacks

Categories of Data Structure Non-linear Data Structure: This structure is mainly used to represent data containing a hierarchical relationship between elements. The common examples of Non-linear data structure are  Graphs  Trees

Categories of Data Structure

Linear Data Structure Array One Dimensional Array Multidimensional Array Array Addressing (One Dimensional) Array Addressing (Two Dimensional)

Linear Data Structure Array Data Structure It can hold multiple values of a single type. Elements are referenced by the array name and an ordinal index. Each element is a value Indexing begins at zero. The array forms a contiguous list in memory. The name of the array holds the address of the first array element. We specify the array size at compile time, often with a named constant.

Linear Data Structure Array Data Structure It can hold multiple values of a single type. Elements are referenced by the array name and an ordinal index. Each element is a value Indexing begins at zero. The array forms a contiguous list in memory. The name of the array holds the address of the first array element. We specify the array size at compile time, often with a named constant.

Linear Data Structure (Linked lists) A linked list, or one way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. Dynamically allocate space for each element as needed. Next Data Node In linked list Each node of the list contains the data item & a pointer to the next node Collection structure has a pointer to the list Start Initially NULL Start

Linear Data Structure (Linked lists) Start Data Next node Linked list with 2 nodes

Linear Data Structure (Linked lists) INFO LINK 1 2 3 4 5 6 7 8 A M G N O 5 2 7 4 START START=3, INFO[3]=M LINK[3]=2, INFO[2]=A LINK[2]=5, INFO[5]=N LINK[5]=4, INFO[4]=G LINK[4]=7, INFO[7]=O LINK[7]=0, NULL value, So the list has ended 3

Linear Data Structure (Stack) Stacks are a special form of collection with LIFO semantics Two methods - add item to the top of the stack - remove an item from the top of the stack Like a plate stacker

Linear Data Structure (Queues) Like a stack, a queue is also a list. However, with a queue, insertion is done at one end, while deletion is performed at the other end The insertion end is called rear The deletion end is called front Insert Remove rear front

Non-Linear Data Structure 2 primary types: Trees Graphs All trees are graphs, but not all graphs are trees Recursion is useful and is the easiest way to process them.

Graphs Graphs can be directed or undirected and cyclic or acyclic Graphs can have multiple references in and multiple references out (whereas tree node only has one reference in) Graphs can be directed or undirected and cyclic or acyclic

Trees Single parent 0 or more children A node with no children is called a "leaf" The topmost node is called the "root"

Data structure operations The data appearing in our data structure is processed by means of certain operations. In fact, the particular data structure that one chooses for a given situation depends largely on the frequency with which specific operations are performed. The following four operations play a major role: Traversing Accessing each record exactly once so that certain items in the record may be processed. (This accessing or processing is sometimes called 'visiting" the records.) 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. Inserting Adding new records to the structure. Deleting Removing a record from the structure.

Data structure operations The following two operations, which are used in special situations, will also be considered: Sorting: Arranging the records in some logical order Merging: Combining the records in two different sorted files into a single sorted files

Algorithms An essential aspect to data structures is algorithms. Data structures are implemented using algorithms. An Algorithm is a finite step – by – step list of well defined instructions for solving a particular problem. It is used to manipulate the data contained in the data structures as in searching and sorting. It states explicitly how the data will be manipulated.

Complexity The complexity of an algorithm is a function describing the efficiency of the algorithm in terms of the amount of data the algorithm must process. There are two main complexity measures of the efficiency of an algorithm: Time complexity is a function describing the amount of time an algorithm takes in terms of the amount of input to the algorithm. Space complexity is a function describing the amount of memory (space) an algorithm takes in terms of the amount of input to the algorithm.

Data structure operations on Array Traversing: means to visit all the elements of the array in an operation is called traversing. Insertion: means to put values into an array Deletion / Remove: to delete a value from an array. Sorting: Re-arrangement of values in an array in a specific order (Ascending / Descending) is called sorting. Searching: The process of finding the location of a particular element in an array is called searching. There are two popular searching techniques/mechanisms : Linear search and binary search and will be discussed later.

Data structure operations on Array Traversing in Linear Array: It means processing or visiting each element in the array exactly once; Let ‘A’ is an array stored in the computer’s memory. If we want to display the contents of ‘A’, it has to be traversed i.e. by accessing and processing each element of ‘A’ exactly once.

Data structure operations on Array This program will traverse each element of the array to calculate the sum and then calculate & print the average of the following array of integers. ( 4, 3, 7, -1, 7, 2, 0, 4, 2, 13) # define size 10 // another way // int const size = 10 int main() { int x[10]={4,3,7,-1,7,2,0,4,2,13}, i, sum=0,LB=0, UB = size; float av; for(i=LB,i<UB;i++) sum = sum + x[i]; av = (float)sum/size; printf( “The average of the numbers= %.2f“,av); return 0; }

Data structure operations on Array Sorting in Linear Array: Sorting an array is the ordering the array elements in ascending (increasing from min to max) or descending (decreasing – from max to min) order. Example:  {2 1 5 7 4 3}  {1, 2, 3, 4, 5,7} ascending order  {2 1 5 7 4 3}  {7,5, 4, 3, 2, 1} descending order

Data structure operations on Array Bubble Sort: The technique we use is called “Bubble Sort” because the bigger value gradually bubbles their way up to the top of array like air bubble rising in water, while the small values sink to the bottom of array. This technique is to make several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is in decreasing order, their values are swapped in the array.

Data structure operations on Array Bubble Sort:

Data structure operations on Array Bubble Sort: The technique we use is called “Bubble Sort” because the bigger value gradually bubbles their way up to the top of array like air bubble rising in water, while the small values sink to the bottom of array. Below is the algorithm of Bubble Sort

Data structure operations on Array Bubble Sort: #include <stdio.h> int const SIZE = 6 void BubbleSort(int [ ], int); int main() { int a[SIZE]= {77,42,35,12,101,6}; int i; cout<< “The elements of the array before sorting\n”; for (i=0; i<= SIZE-1; i++) prinf(“%d ”,a[i]); BubbleSort(a, SIZE); cout<< “\n\nThe elements of the array after sorting\n”; return 0; }

Data structure operations on Array void BubbleSort(int A[ ], int N) { int i, pass, hold; for (pass=1; pass<= N-1; pass++) for (i=0; i<= SIZE-pass; i++) if(A[i] >A[i+1]) hold =A[i]; A[i]=A[i+1]; A[i+1]=hold; } //if condition } //Inner for loop } //Outer for loop }

Data structure operations on Array Home Work Write a program to determine the median of the array given below: (9, 4, 5, 1, 7, 78, 22, 15, 96, 45,25) Note that the median of an array is the middle element of a sorted array.