Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Algorithms & Data Structures, Study notes of Computer Science

General Problem Solving Concepts Types of Problems Problem solving with computers Difficulties with problem solving Problem solving Aspect

Typology: Study notes

2019/2020

Available from 03/23/2023

raj-paliwal-1
raj-paliwal-1 🇮🇳

5 documents

1 / 100

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UNIT- I
Introduction to Algorithms & Data
Structures
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Introduction to Algorithms & Data Structures and more Study notes Computer Science in PDF only on Docsity!

UNIT- I

Introduction to Algorithms & Data

Structures

Contents

Introduction

General Problem Solving Concepts

Types of Problems

Problem solving with computers

Difficulties with problem solving

Problem solving Aspect

Problem Solving Concepts for

Computer

Constants and variables

Data types

Functions

Operators

Expressions and equations

Programming Concepts

Communicating with computers

Organizing the problem

Using the tools

Testing the solution

Coding the program

Example: Problem what to do this evening

1. Indentify the Problem: How do the Individuals wish to spend the

evening?

2. Understand the problem: The knowledge base of the participants

must be considered. The only solutions that should be selected are

ones that everyone would know how to do. You probably would not

select as a possible solution playing a game of chess if the

participants do not know how to play chess.

3. Identify Alternatives :

Watch Television

▫ Invite friends over

▫ Play games

▫ Go to the movie

▫ Play miniature golf

▫ Go to a friends party

▫ Go to the amusement park

▫ List is complete only when you can think of no more alternatives

4. Select best way to solve the problem

▫ Cut out alternatives that are not acceptable

▫ Specify pros and Cons of each Remaining alternative

▫ Compare pros and cons to make final decision

General Problem-Solving Concepts

Problem solving with

computers

Results means the outcome or the completed

computer assisted answer

Program means the set of instructions that make up

the solution using programming language

Computers are built to deal with algorithmic solutions

Difficulty lies in Programming

Solutions must be transformed into an algorithmic

format

Difficulties with Problem

Solving

People have many problems with problem solving

Afraid to make decisions

People go through one or more steps incorrectly

Problem solving process is not easy

Problem solving on computer

Difficult task of writing instructions

Computer has specific system of communication

Problem Definition Phase

  • What must be done?
  • We must try to extract set of precisely defined tasks.
  • E.g. Finding Square root, Greatest Common Divisor

Getting Started on a Problem

  • Sometimes, even after problem definition people do

not know where to start?

  • What can we do?

The use of Specific Examples

  • Best approach when we are stuck is to make a start on a

problem is to pick a specific example

  • Geometrical and graphical representing certain aspect of

a problem can be useful

Similarities among problems

  • Bring as much as past experiences as possible
  • New problem cannot be completely different
  • Sometimes it blocks us from discovering a new thing
  • In the first instance try to independently solve the problem

Algorithm

“Algorithm is any well defined

computational procedure that takes

some values or set of values as input

and produces some value or a set of

values as output”

Characteristics of algorithm

  • Input : algorithm is supplied with zero or more external

quantities

  • Output : Algorithm must produce one or more results/output
  • Definiteness : Each step in an algorithm must be clear and

unambiguous

  • Finiteness: Must have finite number of steps
  • Effectiveness : Every instruction must be sufficiently basic
  • Feasibility − Should be feasible with the available resources.
  • Independent − An algorithm should have step-by-step

directions, which should be independent of any programming

code.

Algorithms tell the programmers how to code

the program. Alternatively, the algorithm can be

written as −

Step 1 − START ADD

Step 2 − get values of a & b

Step 3 − c ← a + b

Step 4 − display c

Step 5 − STOP

Pseudo code

Expression:

Use standard mathematical symbols to

describe numeric and boolean expression

Use  for assignment

Use = for equality relationship

Method Declaration

Algorithm name( param1,param2)

Return : return value

Pseudo code

Algorithm arrayMax(A,n)

//Input: An array A storing n integers

//Output: The maximum element in A

currentMax A[0]

for i1 to n-1 do

If currentMax<A[i] then currentMaxA[i]

return currentMax

Pseudo code

Algorithm arraySum(A,n)

//Input: An array A storing n integers

//Output: The Addition of elements in A

sum:=

for i:=0 to n-1do

sum= sum + a [i]

return (sum)