Data Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Size: px
Start display at page:

Download "Data Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU"

Transcription

1 Data Structures Chapter 04 1

2 Linear Array A linear array is a list of finite number N of homogeneous data elements such that: The elements of the array are referenced respectively by an index set consisting of N consecutive numbers. The elements of the array are stored respectively in successive memory locations. The number N of elements is called the length or size of the array. 2

3 Linear Array Three numbers define an array: Lower Bound, Upper Bound, and Size. The lower bound is the smallest subscript you can use in the array (usually 0). The upper bound is the largest subscript you can use in the array. The size / length of the array refers to the number of elements in the array. It can be computed as Length= Upper bound - Lower bound + 1 Let the array name be A. Then the elements of A are: a 1, a 2,.., a n. Or by the bracket notation: A[1], A[2], A[3],., A[n] The number k in A[k] is called a subscript and A[k] is called a subscripted variable. 3

4 Linear Array Example: A linear array DATA consisting of six elements: DATA DATA [1] = 247 DATA [2] = 56 DATA [3] = 429 DATA [4] = 135 DATA [5] = 87 DATA [6] = 156 4

5 Linear Array Example: An automobile company uses an array AUTO to record the number of auto mobile sold each year from 1932 through LB = 1932, UB = 1984 AUTO[k] = Number of auto mobiles sold in the year k. Length = UB LB+1 = =55 5

6 Operations on Linear 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. 6

7 Representation of Linear Array in Memory Let LA be a linear array in the memory of the computer. The memory of the computer is a sequence of addressed locations. The computer does not need to keep track of the address of every element of LA, but needs to keep track only of the first element of LA, denoted by Base (LA) called the base address of LA. Using this address Base (LA), the computer calculates the address of any element of LA by the following formula: LOC(LA[k]) = Base(LA) + w(k lower bound) Where w is the number of words per memory cell for the array LA 7

8 Representation of Linear Array in Memory Example: An automobile company uses an array AUTO to record the number of auto mobiles sold each year from 1932 through Suppose AUTO appears in memory as pictured in Fig. That is, Base(AUTO) = 200, and w = 4 words per memory cell, LB=1932, UB=1984. Then, LOC(AUTO[1932]) = 200, LOC(AUTO[1933]) =204 LOC(AUTO[1934]) = 208 The address of the array element for the year K = 1965 can be obtained by using: LOC(AUTO[1965]) = Base(AUTO) + w(1965 LB) =200+4( ) = AUTO 8

9 Solved Problems 4.1: Consider the linear arrays AAA(5:50), BBB(-5:10) and CCC(18). (a) Find the number of elements in each array. (b) Suppose Base(AAA)=300 and w=4 words per memory cell for AAA. Find the address of AAA[15], AAA[35] and AAA[55]. Solution: (a) The number of elements is equal to the length; hence use the formula Length = UB LB+1 Accordingly, Length(AAA) = =46 Length(BBB) =10-(-5)+1=16 Length(CCC) = =18 9

10 Solved Problems 4.1: Consider the linear arrays AAA(5:50), BBB(-5:10) and CCC(18). (a) Find the number of elements in each array. (b) Suppose Base(AAA)=300 and w=4 words per memory cell for AAA. Find the address of AAA[15], AAA[35] and AAA[55]. Solution: (b) Use the formula, LOC(AAA[K]) = Base(AAA) + w(k LB) Hence, LOC (AAA[15])=300+4(15-5)=340 LOC(AAA[35])=300+4(35-5)=420 AAA[55] is not an element of AAA, since 55 exceeds UB=50 10

11 Algorithm 4.1: (Traversing a Linear Array) Here LA is a linear array with lower boundary LB and upper boundary UB. This algorithm traverses LA applying an operation Process to each element of LA. 1. [Initialize counter.] Set K=LB. 2. Repeat Steps 3 and 4 while K UB. 3. [Visit element.] Apply PROCESS to LA[K]. 4. [Increase counter.] Set k=k+1. [End of Step 2 loop.] 5. Exit. 11

12 Algorithm 4.1: (Traversing a Linear Array) Here LA is a linear array with lower boundary LB and upper boundary UB. This algorithm traverses LA applying an operation Process to each element of LA. 1. Repeat for K=LB to UB Apply PROCESS to LA[K]. [End of loop]. 2. Exit. 12

13 Insertion into Arrays Inserting an element somewhere in the middle of the array require that each subsequent element be moved downward to new locations to accommodate the new element and keep the order of the other elements. Algorithm 4.2: (Inserting into a linear array) Here LA is linear array with N elements and K is a positive integer such that K<=N. This algorithm inserts an element ITEM into the K-th position in LA. Step 1. Step 2. Step 3. Step 4. Step 5. Step 6. Step 7. Set J:=N Repeat Steps 3 and 4 while J>=K Set LA [J+1]: =LA [J] Set J:=J-1 [End of step 2 loop] Set LA [K]: =ITEM Set N:=N+1 Exit 13

14 Deletion of elements from linear arrays Deleting an element somewhere in the middle of the array requires that each subsequent element be moved one location upward in order to fill up the array. Algorithm 4.3: (Deleting from a linear array) Here LA is a linear array with N elements and K is a positive integer such that K N. This algorithm deletes the K-th element from LA. Step 1. Set ITEM: = LA [K] Step 2. Repeat for J=K to N-1 Step 3. Step 4. Set LA [J]: =LA [J+1] [End of loop] Set N:=N-1 Exit 14

15 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. Pass 1: (a) Compare A 1 and A 2. Since 32< 51, the list is not altered. A: 32, 51, 27, 85, 66, 23, 13, 57 (b) Compare A 2 and A 3. Since 51>27, interchange 51 and 27. A: 32, 27, 51, 85, 66, 23, 13, 57 (c) Compare A 3 and A 4. Since 51<85, the list is not altered. A: 32, 27, 51, 85, 66, 23, 13, 57 (d) Compare A 4 and A 5. Since 85>66, interchange 85 and 66. A: 32, 27, 51, 66, 85, 23, 13, 57 15

16 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. Pass 1: (e) Compare A 5 and A 6. Since 85>23, interchange 85 and 23. A: 32, 27, 51, 66, 23, 85, 13, 57 (f) Compare A 6 and A 7. Since 85>13, interchange 85and 13. A: 32, 27, 51, 66, 23, 13, 85, 57 (g) Compare A 7 and A 8. Since 85>57, interchange 85 and 57. A: 32, 27, 51, 66, 23, 13, 57, 85 16

17 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 Pass 2: 27, 32, 51, 66, 23, 13, 57, 85 27, 32, 51, 66, 23, 13, 57, 85 27, 32, 51, 66, 23, 13, 57, 85 27, 32, 51, 23, 66, 13, 57, 85 27, 32, 51, 23, 13, 66, 57, 85 27, 32, 51, 23, 13, 57, 66, 85 17

18 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 Pass 3: 27, 32, 51, 23, 13, 57, 66, 85 27, 32, 51, 23, 13, 57, 66, 85 27, 32, 23, 51, 13, 57, 66, 85 27, 32, 23, 13, 51, 57, 66, 85 27, 32, 23, 13, 51, 57, 66, 85 18

19 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 After Pass 3: A: 27, 32, 23, 13, 51, 57, 66, 85 Pass 4: 27, 32, 23, 13, 51, 57, 66, 85 27, 23, 32, 13, 51, 57, 66, 85 27, 23, 13, 32, 51, 57, 66, 85 27, 23, 13, 32, 51, 57, 66, 85 19

20 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 After Pass 3: A: 27, 32, 23, 13, 51, 57, 66, 85 After Pass 4: A: 27, 23, 13, 32, 51, 57, 66, 85 Pass 5: 23, 27, 13, 32, 51, 57, 66, 85 23, 13, 27, 32, 51, 57, 66, 85 23, 13, 27, 32, 51, 57, 66, 85 20

21 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 After Pass 3: A: 27, 32, 23, 13, 51, 57, 66, 85 After Pass 4: A: 27, 23, 13, 32, 51, 57, 66, 85 After Pass 5: A: 23, 13, 27, 32, 51, 57, 66, 85 Pass 6: 13, 23, 27, 32, 51, 57, 66, 85 13, 23, 27, 32, 51, 57, 66, 85 21

22 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 After Pass 3: A: 27, 32, 23, 13, 51, 57, 66, 85 After Pass 4: A: 27, 23, 13, 32, 51, 57, 66, 85 After Pass 5: A: 23, 13, 27, 32, 51, 57, 66, 85 After Pass 6: A: 13, 23, 27, 32, 51, 57, 66, 85 Pass 7: 13, 23, 27, 32, 51, 57, 66, 85 22

23 Bubble Sort Suppose the following numbers are stored in an array A: A: 32, 51, 27, 85, 66, 23, 13, 57 Apply the bubble sort to the array A. Show each pass separately. After Pass 1: A: 32, 27, 51, 66, 23, 13, 57, 85 After Pass 2: A: 27, 32, 51, 23, 13, 57, 66, 85 After Pass 3: A: 27, 32, 23, 13, 51, 57, 66, 85 After Pass 4: A: 27, 23, 13, 32, 51, 57, 66, 85 After Pass 5: A: 23, 13, 27, 32, 51, 57, 66, 85 After Pass 6: A: 13, 23, 27, 32, 51, 57, 66, 85 After Pass 7: A: 13, 23, 27, 32, 51, 57, 66, 85 Sorted List: A: 13, 23, 27, 32, 51, 57, 66, 85 23

24 Algorithm 4.4: (Bubble Sort) BUBBLE (DATA, N) Here DATA is an Array with N elements. This algorithm sorts the elements in DATA. 1. Repeat Steps 2 and 3 for K = 1 to N-1 2. Set PTR: =1 3. Repeat while PTR<=N-K 4. Exit (a) If DATA[PTR]>DATA[PTR+1], then: Interchange DATA[PTR] and DATA[PTR+1] [End of if structure] (b) Set PTR: =PTR+1 [End of inner loop] [End of Step 1 Outer loop] 24

25 Complexity of the bubble sort algorithm The time for a sorting algorithm is measured in terms of the number of comparisons. The number f(n) of comparisons in the bubble sort is easily computed. Specifically, there are n-1 comparisons during first pass, which places the largest element in the last position, there are n-2 comparisons in the second pass, which places the second largest element in the next to last position, and so on. Thus, f(n) = (n-1) + (n-2) = n(n-1)/2=n 2 /2+O(n) = O(n 2 ) In other words, the time required to execute bubble sort algorithm is proportional to n 2, where n is the number of input items. 25

26 Solved Problem 4.9: Using the bubble sort algorithm, find the number C of comparisons and the number D of interchanges which alphabetize the n=6 letters in PEOPLE. Pass 1: P E O P L E, E P O P L E, E O P P L E E O P P L E, E O P L P E, E O P L E P Pass 2: E O P L E P, E O P L E P, E O P L E P E O L P E P, E O L E P P Pass 3: E O L E P P, E O L E P P, E L O E P P E L E O P P Pass 4: E L E O P P, E L E O P P, E E L O P P Pass 5: E E L O P P, E E L O P P 26

27 Solved Problem 4.9: Using the bubble sort algorithm, find the number C of comparisons and the number D of interchanges which alphabetize the n=6 letters in PEOPLE. Since n=6, the number of comparisons, C = =15 and the number of interchanges, D = 9. 27

28 Binary Search Example 4.9: Suppose the following sorted 13 elements are stored in an array A: 11, 22, 30, 33, 40, 44, 55, 60, 66, 77, 80, 88, 99 Now apply the binary search to array A for i) ITEM = 40 and ii) ITEM= 85. Solution: i) For ITEM = BEG = 1 and END =13 MID = INT [(1+13)/2] = 7. So, A [MID] = 55 ITEM 2. Since 40<55, BEG=1 and END = MID-1 = 7-1 = 6 MID = INT [(1+6)/2] = 3. So, A[MID] = 30 ITEM 3. Since 40>30, BEG = MID+1 = 3+1= 4 and END = 6 MID= INT [(4+6)/2] = 5. So, A[MID] = 40 = ITEM We have found ITEM in location LOC = MID = 5 28

29 Binary Search Example 4.9: Suppose the following sorted 13 elements are stored in an array A: 11, 22, 30, 33, 40, 44, 55, 60, 66, 77, 80, 88, 99 Now apply the binary search to array A for i) ITEM = 40 and ii) ITEM= 85. Solution: ii) For ITEM = BEG = 1 and END =13 MID = INT [(1+13)/2] = 7. So, A [MID] = 55 ITEM 2. Since 85>55, BEG=MID+1=7+1=8 and END = 13 MID = INT [(8+13)/2] = 10. So, A[MID] = 77 ITEM 3. Since 85>77, BEG = MID+1 = 10+1= 11 and END = 13 MID= INT [(11+13)/2] = 12. So, A[MID] = 88 ITEM 29

30 Binary Search Example 4.9: Suppose the following sorted 13 elements are stored in an array A: 11, 22, 30, 33, 40, 44, 55, 60, 66, 77, 80, 88, 99 Now apply the binary search to array A for i) ITEM = 40 and ii) ITEM= 85. Solution: ii) For ITEM = Since 85<88, BEG = 11 and END = MID-1 =12-1=11 MID= INT [(11+11)/2] = 11. So, A[MID] = 80 ITEM 5. Since 85>80, BEG = MID + 1 = =12 and END = 11 Since BEG > END, ITEM does not belong to A. 30

31 Binary Search Data Structures- Chapter 4 Algorithm 4.6: (Binary Search) BINARY (DATA, LB, UB, ITEM, LOC) Here DATA is a sorted array with lower bound LB and upper bound UB, and ITEM is a given item of information. The variables BEG, END and MID denote respectively the beginning, end and middle locations of a segment of elements of DATA. This algorithm finds the location LOC of ITEM in DATA or sets LOC=NULL. 31

32 Binary Search 1. Set BEG=LB, END=UB and MID=INT ((BEG+END)/2). 2. Repeat Steps 3 and 4 while BEG END and DATA[MID] ITEM 3. If ITEM < DATA[MID], then Else Set END= MID - 1 Set BEG= MID + 1 [End of If structure] 4. Set MID= INT((BEG+END)/2) [End of Step 2 loop] 5. If ITEM = DATA[MID], then Else Set LOC= MID Set LOC= NULL [End of If structure] 6. Exit. 32

33 Complexity of the Binary Search Algorithm The Complexity of the Binary Search algorithm is measured by the maximum (worst case) number of Comparisons it performs for searching operations. The searched array is divided by 2 for each comparison/iteration. Therefore, we require at most f(n) comparisons to locate ITEM: 2 f(n) > n or equivalently, f(n) = log 2 n + 1 Approximately, equal to log 2 n. Example: If a given sorted array contains 1024 elements, then the maximum number of comparisons required is: log 2 (1024) = 10 (only 10 comparisons are enough) 33

34 Limitations of the Binary Search Algorithm The algorithm requires two conditions: The list must be sorted. One must have direct access to the middle element in any sub list. 34

35 Solved Problem 4.11: Suppose multidimensional arrays A and B are declared using A(-2:2, 2:22) and B(1:8, -5:5, -10;5) (a) Find the length of each dimension and the number of elements in A and B. (b) Consider the element B[3, 3, 3] in B. Find the effective indices E 1, E 2, E 3 and the address of the element, assuming Base(B)=400 and there are w=4 words per memory location. Solution: (a) Length = UB LB +1 Hence, the lengths of the dimensions of A are: L 1 = 2-(-2)+1=5 and L 2 = =21 Accordingly, A has 5.21=105 elements. The lengths of the dimensions of B are: L 1 = 8-1+1=8, L 2 = 5-(-5)+1=11, and L 3 =5-(-10)+1=16 Therefore, B has =1408 elements. 35

36 Solved Problem 4.11: Suppose multidimensional arrays A and B are declared using A(-2:2, 2:22) and B(1:8, -5:5, -10;5) (b) Consider the element B[3, 3, 3] in B. Find the effective indices E 1, E 2, E 3 and the address of the element, assuming Base(B)=400 and there are w=4 words per memory location. Solution: (b) The effective index E i is obtained from E i =k i LB, where k i is the given index and LB is the lower bound. Hence, E 1 =3-1=2 E 2 =3-(-5)=8 E 3 =3-(-10)=13 The address depends on whether the programming language stores B in rowmajor order or column-major order. Assuming B is the stored in column major order, we get: E 3 L 2 =13.11=143 E 3 L 2 + E 2 =143+8=151 (E 3 L 2 + E 2 )L 1 =151.8=1208 (E 3 L 2 + E 2 )L 1 +E 1 =1208+2=1210 Therefore, LOC(B[3,3,3])=400+4(1210)= =

wwwashekalazizwordpresscom Data Structure Test Paper 3 1(a) Define Data Structure Mention the subject matters of data structure The logical and mathematical model of a particular organization of data is

More information

DATA STRUCTURES/UNIT 3

DATA STRUCTURES/UNIT 3 UNIT III SORTING AND SEARCHING 9 General Background Exchange sorts Selection and Tree Sorting Insertion Sorts Merge and Radix Sorts Basic Search Techniques Tree Searching General Search Trees- Hashing.

More information

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

Searching, Sorting. Arizona State University 1

Searching, Sorting. Arizona State University 1 Searching, Sorting CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 9 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State

More information

AE52/AC52/AT52 C & Data Structures JUNE 2014

AE52/AC52/AT52 C & Data Structures JUNE 2014 Q.2 a. Write a program to add two numbers using a temporary variable. #include #include int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1);

More information

Advanced Algorithms, Third Class, Computer Science Department, CSW,

Advanced Algorithms, Third Class, Computer Science Department, CSW, Done by Mokhtar M. Hasan, Lecturer at the Computer Science Department, College of Science for Women, to fulfill the course subject of Advanced Algorithm material. Advanced Algorithms, Third Class, Computer

More information

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU Data Structures Chapter 06 1 Stacks A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. This means that elements are removed from

More information

CSE101-lec#19. Array searching and sorting techniques. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

CSE101-lec#19. Array searching and sorting techniques. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming CSE101-lec#19 Array searching and sorting techniques Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Introduction Linear search Binary search Bubble sort Introduction The process of finding

More information

Purpose of Database Systems View of Data Database Languages Relational Databases Database Design Object based and semistructured Data Storage and

Purpose of Database Systems View of Data Database Languages Relational Databases Database Design Object based and semistructured Data Storage and Introduction (DBMS) Purpose of Database Systems View of Data Database Languages Relational Databases Database Design Object based and semistructured Data Storage and Querying Transaction Management Database

More information

How to declare an array in C?

How to declare an array in C? Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS 301 DATA STRUCTURE USING C Unit-1 Part-3 Arrays Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction Array is a contiguous memory of homogeneous

More information

Searching Algorithms/Time Analysis

Searching Algorithms/Time Analysis Searching Algorithms/Time Analysis CSE21 Fall 2017, Day 8 Oct 16, 2017 https://sites.google.com/a/eng.ucsd.edu/cse21-fall-2017-miles-jones/ (MinSort) loop invariant induction Loop invariant: After the

More information

Sorting Pearson Education, Inc. All rights reserved.

Sorting Pearson Education, Inc. All rights reserved. 1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,

More information

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous

More information

Lecture 6 Sorting and Searching

Lecture 6 Sorting and Searching Lecture 6 Sorting and Searching Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 77 42 35 12 101 5 1 2 3 4 5 6 5 12 35 42 77 101 There are many algorithms for sorting a list

More information

Adapted By Manik Hosen

Adapted By Manik Hosen Adapted By Manik Hosen Question: What is Data Structure? Ans: The logical or mathematical model of particular organization of data is called Data Structure. Question: What are the difference between linear

More information

Binary Search and Worst-Case Analysis

Binary Search and Worst-Case Analysis Department of Computer Science and Engineering Chinese University of Hong Kong A significant part of computer science is devoted to understanding the power of the RAM model in solving specific problems.

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 7/e This chapter serves as an introduction to data structures. Arrays are data structures consisting of related data items of the same type. In Chapter 10, we discuss C s notion of

More information

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning. Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.

More information

Sorting. Introduction. Classification

Sorting. Introduction. Classification Sorting Introduction In many applications it is necessary to order give objects as per an attribute. For example, arranging a list of student information in increasing order of their roll numbers or arranging

More information

PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti

PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti memory. So for the better performance of an algorithm, time complexity and space complexity has been considered.

More information

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014

AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 2014 AC64/AT64 DESIGN & ANALYSIS OF ALGORITHMS DEC 214 Q.2 a. Design an algorithm for computing gcd (m,n) using Euclid s algorithm. Apply the algorithm to find gcd (31415, 14142). ALGORITHM Euclid(m, n) //Computes

More information

Comparison of x with an entry in the array

Comparison of x with an entry in the array 1. Basic operations in algorithm An algorithm to solve a particular task employs some set of basic operations. When we estimate the amount of work done by an algorithm we usually do not consider all the

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

CS S-02 Algorithm Analysis 1

CS S-02 Algorithm Analysis 1 CS245-2008S-02 Algorithm Analysis 1 02-0: Algorithm Analysis When is algorithm A better than algorithm B? 02-1: Algorithm Analysis When is algorithm A better than algorithm B? Algorithm A runs faster 02-2:

More information

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables 1 6 C Arrays 6.2 Arrays 2 Array Group of consecutive memory locations Same name and type To refer to an element, specify Array name + position number arrayname[ position number ] First element at position

More information

Analysis of Algorithms. CS 1037a Topic 13

Analysis of Algorithms. CS 1037a Topic 13 Analysis of Algorithms CS 1037a Topic 13 Overview Time complexity - exact count of operations T(n) as a function of input size n - complexity analysis using O(...) bounds - constant time, linear, logarithmic,

More information

Recursion: The Beginning

Recursion: The Beginning Department of Computer Science and Engineering Chinese University of Hong Kong This lecture will introduce a useful technique called recursion. If used judiciously, this technique often leads to elegant

More information

[ DATA STRUCTURES] to Data Structures

[ DATA STRUCTURES] to Data Structures [ DATA STRUCTURES] Chapter - 01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which

More information

8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms

8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms Chapter 8: Searching and Sorting Arrays 8.1 Introduction to Search Algorithms Introduction to Search Algorithms Search: locate an item in a list of information Two algorithms we will examine: Linear search

More information

Time Analysis of Sorting and Searching Algorithms

Time Analysis of Sorting and Searching Algorithms Time Analysis of Sorting and Searching Algorithms CSE21 Winter 2017, Day 5 (B00), Day 3 (A00) January 20, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Binary Search: WHEN procedure binary search (x:

More information

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Recursion: The Beginning

Recursion: The Beginning Yufei Tao ITEE University of Queensland This lecture is the inception of a powerful technique called recursion. If used judiciously, this technique can simplify the design of an algorithm significantly,

More information

Test 1 Review Questions with Solutions

Test 1 Review Questions with Solutions CS3510 Design & Analysis of Algorithms Section A Test 1 Review Questions with Solutions Instructor: Richard Peng Test 1 in class, Wednesday, Sep 13, 2017 Main Topics Asymptotic complexity: O, Ω, and Θ.

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

THE UNIVERSITY OF WESTERN AUSTRALIA

THE UNIVERSITY OF WESTERN AUSTRALIA THE UNIVERSITY OF WESTERN AUSTRALIA MID SEMESTER EXAMINATION April 2018 DEPARTMENT OF COMPUTER SCIENCE & SOFTWARE ENGINEERING DATA STRUCTURES AND ALGORITHMS CITS2200 This Paper Contains: 6 Pages 10 Questions

More information

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Chapter 9 Introduction to Arrays. Fundamentals of Java

Chapter 9 Introduction to Arrays. Fundamentals of Java Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced

More information

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE Looking for something COMP 10 EXPLORING COMPUTER SCIENCE Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE Searching algorithms Linear search Complexity Sorting algorithms

More information

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace CS 704 Introduction to Data Structures and Software Engineering Sorting Terms & Definitions Internal sorts holds all data in RAM External sorts use Files Ascending : Low to High Descending : High to Low

More information

Algorithm Analysis. Spring Semester 2007 Programming and Data Structure 1

Algorithm Analysis. Spring Semester 2007 Programming and Data Structure 1 Algorithm Analysis Spring Semester 2007 Programming and Data Structure 1 What is an algorithm? A clearly specifiable set of instructions to solve a problem Given a problem decide that the algorithm is

More information

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms Algorithm Efficiency & Sorting Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms Overview Writing programs to solve problem consists of a large number of decisions how to represent

More information

Algorithm Analysis. CENG 707 Data Structures and Algorithms

Algorithm Analysis. CENG 707 Data Structures and Algorithms Algorithm Analysis CENG 707 Data Structures and Algorithms 1 Algorithm An algorithm is a set of instructions to be followed to solve a problem. There can be more than one solution (more than one algorithm)

More information

LECTURE 17. Array Searching and Sorting

LECTURE 17. Array Searching and Sorting LECTURE 17 Array Searching and Sorting ARRAY SEARCHING AND SORTING Today we ll be covering some of the more common ways for searching through an array to find an item, as well as some common ways to sort

More information

Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course

Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course Irena Pevac Department of Computer Science Central Connecticut State University, New Britain, CT, USA Abstract: We propose

More information

C/C++ Programming Lecture 18 Name:

C/C++ Programming Lecture 18 Name: . The following is the textbook's code for a linear search on an unsorted array. //***************************************************************** // The searchlist function performs a linear search

More information

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1 CPS 100 Exam 2 Solutions Spring 199 Dr Rodger 1 (3 pts) A virtual function in C++ is bound dynamically or statically? dynamic 2 (3 pts) When does one use a class template in C++? Templates are used to

More information

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Page 1 UNIT I INTRODUCTION 2 marks 1. Why is the need of studying algorithms? From a practical standpoint, a standard set of algorithms from different

More information

Searching. 11. Searching

Searching. 11. Searching Searching In many applications it is necessary to search a list of data elements for one (or more) that matches some specific criterion. For example: - find the largest integer in a list of test scores

More information

Here we will only consider the problem of searching among the elements of an array. Intro Programming in C++

Here we will only consider the problem of searching among the elements of an array. Intro Programming in C++ S 10 Fall 00 May 1, 006 Searching In many applications it is necessary to search a list of data elements for one (or more) that matches some specific criterion. For example: - find the largest integer

More information

Assertions & Verification & Example Loop Invariants Example Exam Questions

Assertions & Verification & Example Loop Invariants Example Exam Questions 2014 November 27 1. Assertions & Verification & Example Loop Invariants Example Exam Questions 2. A B C Give a general template for refining an operation into a sequence and state what questions a designer

More information

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types Chapter 4 - Arrays 1 4.1 Introduction 4.2 Arrays 4.3 Declaring Arrays 4.4 Examples Using Arrays 4.5 Passing Arrays to Functions 4.6 Sorting Arrays 4.7 Case Study: Computing Mean, Median and Mode Using

More information

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program)

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) Chapter - Arrays 1.1 Introduction 2.1 Introduction.2 Arrays.3 Declaring Arrays. Examples Using Arrays.5 Passing Arrays to Functions.6 Sorting Arrays. Case Study: Computing Mean, Median and Mode Using Arrays.8

More information

Stack. S Array or Vector representing stack containing N elements

Stack. S Array or Vector representing stack containing N elements Stack Algorithm to Insert an element in a St ack: Procedure PUSH(S, TOP, X) X Value of element to be inserted in stack TOP A pointer ( or index) pointing to the top element of stack S Array or Vector representing

More information

CS126 Final Exam Review

CS126 Final Exam Review CS126 Final Exam Review Fall 2007 1 Asymptotic Analysis (Big-O) Definition. f(n) is O(g(n)) if there exists constants c, n 0 > 0 such that f(n) c g(n) n n 0 We have not formed any theorems dealing with

More information

Types of Data Structures

Types of Data Structures DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

MODULE 3: LINKED LIST

MODULE 3: LINKED LIST MODULE 3: LINKED LIST DEFINITION 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. That is, each node is divided

More information

Assertions & Verification Example Exam Questions

Assertions & Verification Example Exam Questions 2009 November 23 Assertions & Verification Example Exam Questions 1. 2. A B C Give a general template for refining an operation into a sequence and state what questions a designer must answer to verify

More information

Data Structures Lecture 3 Order Notation and Recursion

Data Structures Lecture 3 Order Notation and Recursion Data Structures Lecture 3 Order Notation and Recursion 1 Overview The median grade.cpp program from Lecture 2 and background on constructing and using vectors. Algorithm analysis; order notation Recursion

More information

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms Analysis of Algorithms Unit 4 - Analysis of well known Algorithms 1 Analysis of well known Algorithms Brute Force Algorithms Greedy Algorithms Divide and Conquer Algorithms Decrease and Conquer Algorithms

More information

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms Computer Science 4U Unit 1 Programming Concepts and Skills Algorithms Algorithm In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation,

More information

COMPUTER SCIENCE. Paper 1

COMPUTER SCIENCE. Paper 1 COMPUTER SCIENCE Paper 1 (THEORY) Three hours (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) ----------------------------------------------------------------------------------------------------------------------------------

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

SCJ2013 Data Structure & Algorithms. Bubble Sort. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi

SCJ2013 Data Structure & Algorithms. Bubble Sort. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi SCJ2013 Data Structure & Algorithms Bubble Sort Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi 1 Bubble Sort Sorting activities for Bubble: Go through multiple passes over the array. In every pass: Compare

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

Sorting Techniques in data Structure Alluvial Zone

Sorting Techniques in data Structure Alluvial Zone International Journal of Research in Advanced Engineering and Technology ISSN: 2455-0876; Impact Factor: RJIF 5.44 www.engineeringresearchjournal.com Volume 2; Issue 3; May 2016; Page No. 61-71 Sorting

More information

CSE 214 Computer Science II Searching

CSE 214 Computer Science II Searching CSE 214 Computer Science II Searching Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction Searching in a

More information

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015 Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 1 Wednesday, February 11, 2015 Marking Exemplar Duration of examination: 75

More information

Chapter 6 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

Chapter 6 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS Chapter 6 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS 1 Reference books: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie Programming in C (3rd Edition) by Stephen G. Kochan. Data

More information

UNIT 5. Sorting and Hashing

UNIT 5. Sorting and Hashing UNIT 5 Sorting and Hashing SORTING METHODS SYLLABUS: 5.1.Sorting Methods a. Bubble Sort, b. Selection Sort, c. Quick Sort, d. Insertion Sort, e. Merge Sort, f. Radix Sort 5.2.Hashing Concepts CONTINUE

More information

Algorithmic Analysis. Go go Big O(h)!

Algorithmic Analysis. Go go Big O(h)! Algorithmic Analysis Go go Big O(h)! 1 Corresponding Book Sections Pearson: Chapter 6, Sections 1-3 Data Structures: 4.1-4.2.5 2 What is an Algorithm? Informally, any well defined computational procedure

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

ENGI 4892: Data Structures Assignment 2 SOLUTIONS

ENGI 4892: Data Structures Assignment 2 SOLUTIONS ENGI 4892: Data Structures Assignment 2 SOLUTIONS Due May 30 in class at 1:00 Total marks: 50 Notes: You will lose marks for giving only the final answer for any question on this assignment. Some steps

More information

Lecture 2: Algorithm Analysis

Lecture 2: Algorithm Analysis ECE4050/CSC5050 Algorithms and Data Structures Lecture 2: Algorithm Analysis 1 Mathematical Background Logarithms Summations Recursion Induction Proofs Recurrence Relations 2 2 Logarithm Definition: 3

More information

You should know the first sum above. The rest will be given if you ever need them. However, you should remember that,, and.

You should know the first sum above. The rest will be given if you ever need them. However, you should remember that,, and. Big-Oh Notation Formal Definitions A function is in (upper bound) iff there exist positive constants k and n 0 such that for all. A function is in (lower bound) iff there exist positive constants k and

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 20 Priority Queues Today we are going to look at the priority

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,... Chapter 9 Computer Arithmetic Reading: Section 9.1 on pp. 290-296 Computer Representation of Data Groups of two-state devices are used to represent data in a computer. In general, we say the states are

More information

One Dimension Arrays 1

One Dimension Arrays 1 One Dimension Arrays 1 Array n Many applications require multiple data items that have common characteristics In mathematics, we often express such groups of data items in indexed form: n x 1, x 2, x 3,,

More information

Introduction to Analysis of Algorithms

Introduction to Analysis of Algorithms Introduction to Analysis of Algorithms Analysis of Algorithms To determine how efficient an algorithm is we compute the amount of time that the algorithm needs to solve a problem. Given two algorithms

More information

ECE 122. Engineering Problem Solving Using Java

ECE 122. Engineering Problem Solving Using Java ECE 122 Engineering Problem Solving Using Java Lecture 27 Linear and Binary Search Overview Problem: How can I efficiently locate data within a data structure Searching for data is a fundamental function

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-02 Algorithm Analysis David Galles Department of Computer Science University of San Francisco 02-0: Algorithm Analysis When is algorithm A better than algorithm

More information

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani

Arrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani Arrays Dr. Madhumita Sengupta Assistant Professor IIIT Kalyani INTRODUCTION An array is a collection of similar data s / data types. The s of the array are stored in consecutive memory locations and are

More information

Arrays. Week 4. Assylbek Jumagaliyev

Arrays. Week 4. Assylbek Jumagaliyev Arrays Week 4 Assylbek Jumagaliyev a.jumagaliyev@iitu.kz Introduction Arrays Structures of related data items Static entity (same size throughout program) A few types Pointer-based arrays (C-like) Arrays

More information

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science

CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science CHENNAI MATHEMATICAL INSTITUTE M.Sc. / Ph.D. Programme in Computer Science Entrance Examination, 5 May 23 This question paper has 4 printed sides. Part A has questions of 3 marks each. Part B has 7 questions

More information

Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays

Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays Arrays Elementary Data Representation Different Data Structure Operation on Data Structure Arrays Elementary Data Representation Data can be in the form of raw data, data items and data structure. Raw

More information

LECTURE 08 SEARCHING AND SORTING ARRAYS

LECTURE 08 SEARCHING AND SORTING ARRAYS PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 08 SEARCHING AND

More information

Binary Search and Worst-Case Analysis

Binary Search and Worst-Case Analysis Yufei Tao ITEE University of Queensland A significant part of computer science is devoted to understanding the power of the RAM model in solving specific problems. Every time we discuss a problem in this

More information

LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes.

LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes. LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes. Input Algorithm Output An algorithm is a step-by-step procedure for

More information

(Refer Slide Time: 00:50)

(Refer Slide Time: 00:50) Programming, Data Structures and Algorithms Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology Madras Module - 03 Lecture 30 Searching Unordered linear

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Q (Quaternary) Search Algorithm

Q (Quaternary) Search Algorithm Q (Quaternary) Search Algorithm Taranjit Khokhar Abstract In computer science, there are many ways to search the position of the required input value in an array. There are algorithms such as binary search

More information

AN ENHANCED SELECTION SORT ALGORITHM

AN ENHANCED SELECTION SORT ALGORITHM AN ENHANCED SELECTION SORT ALGORITHM Ramesh M. Patelia 1, Shilpan D. Vyas 2, Parina S. Vyas 3, Nayan S. Patel 4 1 Department of M.Sc. (IT) & HOD of BCA, AMCOST, Anand, Gujarat, (India) 2 Department of

More information

Chapter 10 - Notes Applications of Arrays

Chapter 10 - Notes Applications of Arrays Chapter - Notes Applications of Arrays I. List Processing A. Definition: List - A set of values of the same data type. B. Lists and Arrays 1. A convenient way to store a list is in an array, probably a

More information