Docsity

How to write reports on algorithms, Lecture notes of Data Structures and Algorithms

Partial preview of the text

Download How to write reports on algorithms and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Lecture 1: Algorithm Introduction

Kamilla Klonowska

A flowchart:

A pseudo code:

4

Algorithm and Programming

  • Programming can be viewed as the process of designing and implementing algorithms that a computer can carry out
  • Programmer’s job is to:
    • create an algorithm for accomplishing a given objective, then
    • translate the individual steps of the algorithm into a programming language that the computer can understand

Expressing an algorithm

  • English
  • Pseudo-codes
    • a detailed yet readable description of what a program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language
    • It is easy to find errors
  • Computer languages
  • Flow charts
    • a formalized graphic representation of a program logic sequence

Problem 1b:

Given a following sequence of numbers: 1, 4, 7, 10, 13, …, 3n + 1, where n is a positive integer. Design the algorithm. Write a pseudo-code. Translate a pseudo-code into a code. Try if the program works for the following input: n = 5 and n = 10.

Problem 2

Guess the number game Instructions

  • Enter the range of numbers you want the random number to be between
  • Enter your guess
  • See if your guess is too high or too low
  • Change your guess
  • The computer will tell you how many guesses you had Design an algorithm to the game.

1. Work harder (increased processor speed)

  • Speedup
    • how much a parallel algorithm is faster than a corresponding sequential algorithm
  • Amdahl’s law: The speedup of a program using multiple processors in parallel computing is limited by the sequential fraction of the program
  1. Get help (parallel processing)
  • Multicore
  • Multiprocessing
  • Flynn's taxonomy
  • Flynn, Michael J. (September 1972). "Some Computer Organizations and Their Effectiveness". IEEE Transactions on Computers. C- 21 (9): 948–960)
  • Multi-Threading
  • Multi-Processing
  • Multi-Tasking
  • Multi-Programming Wikipedia: Supercomputer https://en.wikipedia.org/wiki/Supercomputer

Example 1

Given a list of N unsorted numbers, find the k-th largest

number

Example 1 – Algorithm 1

  1. Read N numbers into an array: A[0], A[1], A[N-1]
  2. Sort array A into decreasing order A[0] ≥ A[1] ≥ … ≥ A[N-1]
  3. Return A[k-1]