Download presentation

Presentation is loading. Please wait.

Published byJack Wilkinson Modified over 4 years ago

1
Data Structures & Algorithms Kathleen Christie Teaching Fellow, Department of Computing Science, University of Aberdeen

2
CS5539 Introduction to Course What is an algorithm What is a data structure Different algorithms Reading Lecture 1 : Introduction

3
Algorithm: Solution to a Problem Recipe Flat pack furniture Music score Knitting pattern What are the common features of these?

4
Algorithm Systematic instructions on a task Step-wise form Makes use of sequence, selection, iteration, recursion Language and details agent specific

5
What is an Algorithm? Step-by-step procedure used to solve a problem These steps should be capable of being performed by a machine Must eventually stop and so produce an answer

6
Different Algorithms for Same Problem Devise an algorithm to find the solution to a number raised to a positive power eg 4 5 or 10 3 ie number power 1set answer to 1 2Loop 1 to power times 2.1answer becomes answer * number 3report answer Notice the layout and numbering

7
Find the result of number power 1Set answer to 1 2Loop for 1 to 5 times 2.1answer becomes answer * 2 3Report answer AnswerLoop12 4343 8484 165 32? 2 5 3 4 1Set answer to 1 2Loop for 1 to 4 times 2.1 answer becomes answer * 3 3Report answer AnswerLoop1 3232 9393 274 81?

8
Different Algorithms for Same Problem Devise an algorithm to find the solution to a number raised to a positive power eg 4 5 or 10 3 ie number power 4 5 = 4 2 * 4 2 * 4 1 = 16 * 16 * 4 = 1024

9
Find the result of number power 2 5 3 4 1 Set answer to 1, num to number, value to power 2 Loop while value is positive 2.1 if value is odd then multiply answer by num 2.2 divide value by 2 ignore remainder, multiply num by itself 3Report answer answernumvalue 125125 242242 2161 320 answernumvalue 134134 192192 1811 810

10
Data Structure A way of organizing a collection of Data (Ref BlueJ Book page 243 exercise 8.14) –Array –ArrayList –HashMap –HashSet Ch 10 BlueJ The same collection of data may be represented by several data structures so there is a choice

11
Different Representations Data:types typestypes t y p e s

12
Searching algorithms Linear search: unsorted array Linear search: sorted array Binary search: sorted array

13
Algorithm for Linear Search (Unsorted Array) Go through the array comparing the item required with the item in the array at each position If item is not found state this If item is found state position of item Number of comparisons: Average for successful search = number of elements/2 (n/2) Unsuccessful search = number of elements (n)

14
Code for Linear Search (Unsorted Array) public static int search(int array[], int item) { //local variable to store position of required item set initially to –1 int place = -1; int index = 0; //Go through array till whole array searched or item found while ( index < array.length && place == -1) { //check if item is found, and if so set place accordingly if ( array[index] == item) { place = index; } else { index++; } //Return the items place in the array return place; }

15
Reading Watt and Brown: Chapter 1

Similar presentations

OK

General Computer Science for Engineers CISC 106 Lecture 06 James Atlas Computer and Information Sciences 06/24/2009.

General Computer Science for Engineers CISC 106 Lecture 06 James Atlas Computer and Information Sciences 06/24/2009.

© 2018 SlidePlayer.com Inc.

All rights reserved.

By using this website, you agree with our use of **cookies** to functioning of the site. More info in our Privacy Policy and Google Privacy & Terms.

Ads by Google

Ppt on web design and development Ppt on complex numbers class 11th economics Ppt on ntfs file system Ppt on civil engineering structures Ppt online examination project in php Ppt on chapter 12 electricity prices Ppt on sustainable agriculture in india Ppt on carburetor parts Ppt on network theory business Ppt on art of war quotes