1 ARRAYS AND STRUCTURES. 2 Arrays Array: a set of index and value data structure For each index, there is a value associated with that index. representation.

Slides:



Advertisements
Similar presentations
CSCE 3110 Data Structures & Algorithm Analysis
Advertisements

EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Data Structures: Doubly Linked List1 Doubly linked list l The linear linked list is accessed from the first node each time we want to insert or delete.
Introduction to Programming Lecture 39. Copy Constructor.
Elementary Data Structures: Part 2: Strings, 2D Arrays, Graphs
Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
CS-240 Data Structures in C Arrays Dick Steflik. Abstract Data Type A collection of pairs where index is an ordered set of integers and are values of.
Chapter 2. C++ Class A class name Data members Member functions Levels of program access –Public: section of a class can be accessed by anyone –Private:
Relation Discrete Mathematics and Its Applications Baojian Hua
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Lecture 2 Pointers Pointers with Arrays Dynamic Memory Allocation.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Dynamic Structures & Arrays.
CS Data Structures Chapter 4 Lists.
Matrix table of values
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
CS Data Structures Chapter 2 Arrays and Structures.
Arrays and Matrices 황승원 Fall 2010 CSE, POSTECH. 2 2 Any real-life matrix you know?
Introduction to Data Structures Systems Programming.
CSCE 3110 Data Structures & Algorithm Analysis Arrays and Lists.
CHAPTER 21 ARRAYS AND STRUCTURES. CHAPTER 22 Arrays Array: a set of index and value data structure For each index, there is a value associated with that.
Chapter 2 Arrays and Structures  The array as an abstract data type  Structures and Unions  The polynomial Abstract Data Type  The Sparse Matrix Abstract.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Arrays- Part 2 Spring 2013Programming and Data Structure1.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Data Strcutures.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Linked List (Part II). Introduction  Definition of equivalence relation: A relation ≡ over a set S, is said to be an equivalence relation over S iff.
 Program data code Data StructureAlgorithm  Data vs. Variables int i = 10; int i[5]={3,5,7,9,10};
Chapter 4 (cont.) Additional Lists Operations Circular Lists The link field of the last node points to the first node in the list... BATCATFATWAT.
Data Structure Sang Yong Han Chung-Ang University Spring
Data Structures & Algorithm Analysis Arrays. Array: a set of pairs (index and value) data structure For each index, there is a value associated with that.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Arrays and Pointers1 Arrays of Arrays: We can have arrays of any type, even arrays whose elements are themselves arrays. With two bracket pairs, we obtain.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
CS1010E Programming Methodology Tutorial 9 Pointers in Arrays & Structures C14,A15,D11,C08,C11,A02.
ECE Application Programming
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
REEM ALMOTIRI Information Technology Department Majmaah University.
CSCE 3110 Data Structures & Algorithm Analysis More on lists. Circular lists. Doubly linked lists.
Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
1. Traversing a linear array Here A is a linear array with lower bound LB and upper bound UB. This algorithm traverses A applying an operation PROCESS.
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.
◦ A one-dimensional array in C is declared implicitly by appending brackets to the name of a variable int list[5], *plist[5]; ◦ arrays start at index.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
Strings C supports strings using one-dimensional character arrays. A string is defined as a null-terminated character array. In C, a null is 0. You must.
Data Structure Sang Yong Han
Linked List :: Basic Concepts
CSCE 3110 Data Structures & Algorithm Analysis
CHAPTER 2 ARRAYS AND STRUCTURES
Abstract Data Types Sparse Matrices CSCI 240
Data Structures Unit-2 Engineered for Tomorrow CSE, MVJCE.
Reminder: Array Representation In C++
Basic notes on pointers in C
Chapter 16-2 Linked Structures
Instructor: Mr.Vahidipour
Reminder: Array Representation In C++
CSCE 3110 Data Structures & Algorithm Analysis
CS111 Computer Programming
C Programming Lecture-8 Pointers and Memory Management
Reminder: Array Representation In C++
Arrays and Pointers.
Presentation transcript:

1 ARRAYS AND STRUCTURES

2 Arrays Array: a set of index and value data structure For each index, there is a value associated with that index. representation (possible) implemented by using consecutive memory.

3 Arrays in C int list[5], list[5]: five integers list[0], list[1], list[2], list[3], list[4] implementation of 1-D array list[0]base address =  list[1]  + sizeof(int) list[2]  + 2*sizeof(int) list[3]  + 3*sizeof(int) list[4]  + 4*size(int)

4 Example: 1-dimension array addressing int one[] = {0, 1, 2, 3, 4}; Goal: print out address and value void print1(int *ptr, int rows) { /* print out a one-dimensional array using a pointer */ int i; printf(“Address Contents\n”); for (i=0; i < rows; i++) printf(“%8u%5d\n”, ptr+i, *(ptr+i)); printf(“\n”); }

5 One- dimensional array addressing call print1(&one[0], 5)

6 Structures struct { char name[10]; int age; float salary; } person; strcpy(person.name, “james”); person.age=10; person.salary=35000;

7 Create structure data type typedef struct human_being { char name[10]; int age; float salary; }; or typedef struct { char name[10]; int age; float salary } human_being; human_being person1, person2;

8 Self-Referential Structures One or more of its components is a pointer to itself. typedef struct list { char data; list *link; } list item1, item2, item3; item1.data=‘a’; item2.data=‘b’; item3.data=‘c’; item1.link=item2.link=item3.link=NULL; Construct a list with three nodes item1.link=&item2; item2.link=&item3; malloc: obtain a node abc

9 Ordered List Examples n (MONDAY, TUEDSAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAYY, SUNDAY) n (2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace) n (1941, 1942, 1943, 1944, 1945) n (a 1, a 2, a 3, …, a n-1, a n ) ordered (linear) list: (item1, item2, item3, …, itemn)

10 Operations on Ordered List n Find the length, n, of the list. n Read the items from left to right (or right to left). n Retrieve the i’th element. n Store a new value into the i’th position. n Insert a new element at the position i, causing elements numbered i, i+1, …, n to become numbered i+1, i+2, …, n+1 n Delete the element at position i, causing elements numbered i+1, …, n to become numbered i, i+1, …, n-1

11 col1 col2 col3 col4 col5 col6 row0 row1 row2 row3 row4 row5 (a) (b) Two matrices 8/36 6*65*3 15/15 Sparse Matrix sparse matrix data structure?

12 row col value row col value a[0] b[0] [1] [1] [2] [2] [3] [3] [4] [4] [5] [5] [6] [6] [7] [7] [8] [8] (a) (b) Sparse matrix and its transpose stored as triples (1)Represented by a two-dimensional array. Sparse matrix wastes space. (2)Each element is characterized by. row, column in ascending order # of rows (columns) # of nonzero terms transpose

13 Transpose a Matrix (1) for each row i take element and store it in element of the transpose. difficulty: where to put (0, 0, 15) ====> (0, 0, 15) (0, 3, 22) ====> (3, 0, 22) (0, 5, -15) ====> (5, 0, -15) (1, 1, 11) ====> (1, 1, 11) Move elements down very often. (2) For all elements in column j, place element in element