IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Arrays.
The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
Programming Logic and Design Fourth Edition, Comprehensive
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
1 Two-Dimensional Arrays. 2 Can be visualized as consisting m rows, each of n columns Syntax: datatype arrayname [row] [ column] ; Example: int val[3]
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
Arrays in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR
Chapter 8 Arrays and Strings
 Data is always stored in a logical way so that it can be accessed efficiently. Ex:A telephone directory  The way data is stored is called the structure.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 19 Thanks for Lecture Slides:
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
FP201 - PROGRAMMING FUNDAMENTALS Unit Understand the use of array PREPARED BY: MAZNAH AHMAD, JTMK PSIS.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
Arrays.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Chapter 8 Slides from GaddisText Arrays of more than 1 dimension.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
C++ Programming Lecture 16 Arrays – Part III The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Objectives You should be able to describe: One-Dimensional Arrays
Data Structures I (CPCS-204)
Computer Programming BCT 1113
Arrays … The Sequel Applications and Extensions
C++ Programming Lecture 16 Arrays – Part III
Review of Arrays and Pointers
Data Structures (CS212D) Week # 2: Arrays.
Arrays Week 2.
Presentation transcript:

IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL

Topic Arrays

What is Arrays ? An array is a group of consective memory locations with same name and data type OR Collection of contiguous location to store homogeneous data. Array is a way to manage that data into memory.. The memory locations in the array are known as elements of array. The total number of elements in the array is called length. The elements of array is accessed with reference to its position in array, that is call index or subscript.

Advantages / Uses of Arrays Th Huge amount of data can be stored under single variable name. Searching of data item is faster. Two dimension arrays are used to represent the matrices The values stored in an array can be sorted easily.

Types of Arrays: One-Dimensional Array Two-Dimensional Array Multi-Dimensional Array

One dimensional array A rray have only one subscript variable is called one dimensional array. SYNTAX: data-type arr_ name[index]; EXAMPLE: int num[7];

One-D array Intialization The process of assigning values to array elements at the time of array declaration is called array initialization OR population of array. Syntax: data_type identifier[length]={ List of values }; e.g: int marks[5]={45,59,78,54,23};

Accessing element of array Individual Element: Array_name[index]; Using Loop: int marks[5]; for(int i=0;i<=4;i++) marks[i]=i;

Searching In Array Searching is a process of finding the required data in the array. Searching becomes more important when the length of the array is very large. There are two techniques to searching elements in array as follows: Sequential search Binary search

Sequential Search Sequential search is also known as linear or serial search. It follows the following step to search a value in array. Visit the first element of array and compare its value with required value. If the value of array matches with the desired value, the search is complete. If the value of array does not match, move to next element an repeat same process.

Binary Search Binary search is a quicker method of searching for value in the array. Binary search is very quick but it can only search an sorted array. It cannot be applied on an unsorted array. o It locates the middle element of array and compare with desired number. o If they are equal, search is successful and the index of middle element is returned. o If they are not equal, it reduces the search to half of the array. o If the search number is less than the middle element, it searches the first half of array. Otherwise it searches the second half of the array. The process continues until the required number is found or loop completes without successful search.

Sorting Arrays Sorting is a process of arranging the value of array in a particular order. An array can be sorted in two order. oAoA scending Order oDoD escending Order

Techniques Of Sorting Array There are two techniques of sorting array: o Selection Sort o Bubble Sort

Selection Sort Selection sort is a technique that sort an array. It selects an element in the array and moves it to its proper position. Selection sort works as follows: 1. Find the minimum value in the list. 2. Swap it with value in the first position. 3. Sort the remainder of the list excluding the first value.

Bubble Sort Bubble Sort is also known as exchange sort. It repeatedly visits the array and compares two items at a time. It works as follows: o Compare adjacent element. If the first is greater than the second, swap them. o Repeat this for each pair of adjacent element, starting with the first two and ending with the last two. (at this point last element should be greatest). o Repeat the step for all elements except the last one. o Keep repeating for one fewer element each time until there are no pairs to compare.

Two-D Arrays Two-D array can be considered as table that consists of rows and columns. Each element in 2-D array is refered with the help of two indexes. One index indicates row and second indicates the column. Declaring 2-D Array: Data_type arr_name[row][column]; EXAMPLE: Int a[3][3];

Accessig individual elements of two D array: The array name and indexes of row and columns are used to accessing individual elements of two -D array. For exemple : Arr[3][2] = 460; The number 460 will store in third column of forth row.

Two-D array Intialization The two-D array can also be initialized at the time of declaration. Initialization is performed by assigning the initial values in braces seperated by commas. Some important points : o The elements of each row are enclosed within braces and seperated by comma. o All rows are enclosed within braces. o For number arrays, if all elements are not specified, the un specified elements are initialized by zero.