[go: up one dir, main page]

0% found this document useful (0 votes)
2 views7 pages

Notes Chapter 1 QA-1

Chapter 1 discusses problem solving and algorithm design, outlining the four essential steps: defining the problem, generating alternative solutions, evaluating and selecting an algorithm, and implementing the solution. It also covers the advantages of algorithms and flowcharts, the differences between various data structures (trees, graphs, stacks, queues, and arrays), and the concept of non-linear data structures. The chapter emphasizes the importance of structured approaches to problem-solving and the utility of different data structures in programming.

Uploaded by

AYESHA NAWAB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Notes Chapter 1 QA-1

Chapter 1 discusses problem solving and algorithm design, outlining the four essential steps: defining the problem, generating alternative solutions, evaluating and selecting an algorithm, and implementing the solution. It also covers the advantages of algorithms and flowcharts, the differences between various data structures (trees, graphs, stacks, queues, and arrays), and the concept of non-linear data structures. The chapter emphasizes the importance of structured approaches to problem-solving and the utility of different data structures in programming.

Uploaded by

AYESHA NAWAB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CHAPTER # 1

PROBLEM SOLVING
AND ALGORITHM
DESIGNING

DHACSS DCK CAMPUS


Chapter# 1: Problem Solving and Algorithm Designing

QUESTIONS AND ANSWERS


Q1: Define the steps involved in problem solving.
Ans. Steps involved in Problem Solving:
There are four basic steps involved in problem solving:
1- Define the problem.
2- Generate Alternative solution.
3-Evaluate and select an Algorithm.
4- Implement and Follow up on the solution.
1-Define the Problem:
It is most difficult and the most important of all the steps. It involves diagnosing the
situation so that the focus should be on the real problem and not on its symptoms. A
well-described problem will also help others to understand the problem.
2-Generate Alternative Solutions:
Considering multiple alternatives can significantly enhance the value of your ideal
solution. So, it is best to develop a list of all feasible solutions that can be assessed
and decide which one will be the best for the particular problem.
3- Evaluate and Select an Algorithm:
Many alternative solutions to the problem should be generated before final
evaluation. A Common mistake in problem solving is that alternatives are evaluated
as they are proposed; so, the first acceptable solution is chosen, even if it's not the
best solution. Therefore, alternatives should be evaluated, and then best solution
should be selected.
4-Implement and Follow up on the Solution:
When the best solution is implemented, it is important to track and measure the
results be able to answer questions such as: Did it work? Was this a good solution?
When choosing most appropriate solution, the solver should consider about the
possible impacts of the solution. ·
Q2: What are the advantages of developing algorithm?
Ans. Advantages of Algorithm:
1- It is a step-wise representation of a solution to a given problem, which makes it
easy say to understand.
2- An algorithm uses a definite procedure.
3- It is not dependent on any understand I language, so it is easy programming for
anyone even without programming knowledge.
4- Every step in an algorithm has its own logical sequence so it is easy to debag.
5- By using algorithm, the problem is broken down into smaller pieces or steps
hence, it is easier for programmer to convert it into an actual program.
6- It produces the best possible answer every time.

1
Chapter# 1: Problem Solving and Algorithm Designing

Q3 List the advantages of designing flowcharts.


Ans. Advantages of Designing Flowcharts:
1- The flowchart is an excellent way of communicating the logic of a program.
2- It is easy and efficient to analyze problem using flowchart.
3- During program development cycle, the flowchart plays the role of a guide a
guide or a Blueprint. Which makes program development process easier.
4- After successful development of a program, it needs continuous timely
maintenance during the course of its operation. The flowchart makes program or
system maintenance easier.
5- It helps the programmer to write the program, code.
6- It is easy to convert the flowchart into any programming language code as it does
not use any specific programming language concept
Q4- What is the difference between tree and graph data structure?
Ans.
Graph Tree
1 Graph is a non-linear data structure. Tree is a non-linear data structure.

2 It is a collection of vertices/nodes It is a collection of nodes and


and edges edges.

3 Each node can have any number of General trees consist of any the
edges modes having and number of child
nodes but in case of binary trees
every node can have
at the most two child nodes.
4 There is no unique node. called root There is a unique node called root
in graph in trees.

5 A cycle can be formed. There will be not any cycle

6 Applications: For finding shortest Applications: For game trees,


path in networking, graph is used. decision trees. the tree is used

2
Chapter# 1: Problem Solving and Algorithm Designing

Q5- Write down the difference between algorithm and flowchart.


Ans.
ALGORITHM FLOWCHART
1 Algorithm is step by step solution of Flowchart is a diagram of different
problem shapes which shows flaws of data
through processing system.

2 In algorithm text is used. In flowchart, symbol or shapes are


used.
3 Algorithm easy to debug. Flowchart is difficult to debug

4 Algorithm is easy to white and Flowchart is easy to construct and


understand understand

5 Algorithm does not follow any rules. Flowchart follows. rules for its
construction.

6 Algorithm is the Pseudo bode of the Flowchart is just graphical or visual


program. presentation of Program Logic

Q6- What is the difference between queue and stack data structure?
Ans.
Stack Queue
Definition
Stack is a linear data structure which Queue is a linear data structure which
follows a particular order to perform follows a particular order to perform
different operations. different operations.
Order
The order that stack follows is LIFO The order that queue follows is FIFO
(Last In First Out) method. (First In First out) method.
Add/Del of Items
Items may be added or removed only at Deletions take place at one end called
the top of the stack. We cannot remove Front of head and instructions take
data from the bottom as middle. place only at the other end called rear
for tail.

3
Chapter# 1: Problem Solving and Algorithm Designing

Q7. What is the need of index in an array?


Ans. Index:
Each location of an element in an array has a numerical value called index, which is
used to identify the element. Set if indices in an array are consecutive numbers.
Q8. With the help of a sketch define push, pop, overflow, enqueue and dequeue.
Ans. Push:
The term push is used to insert a new element into the stack. Insertion can be done
at one end called top.
Pop:
The term pop is used to remove an element from the stack. Removal can be done at
one end called top.
Overflow:
Overflow is a state in which stack falls when it is completely full. In this state we
cannot add an item in the stack.
Underflow:
Underflow is a state in which stack falls when it is completely empty. In this state
we cannot remove an item from the stack.
Enqueue:
The process to add an element into queue is called enqueue.
Dequeue:
The process to delete an element from the queue is called dequeue.

Q9. What is meant by an array? Explain with the help of diagram.


Ans. Array:
It holds a list of finite data elements of same data type. Each element of array
is referenced by a set of index of consecutive numbers. The elements of array
are stored in successive memory locations.
Element:
Each item stored in an array is called an element.
Operations:
Operations like Traversal, Search, Insertion, Deletion and Sorting can be
performed on arrays.

4
Chapter# 1: Problem Solving and Algorithm Designing

Q10. Explain non-linear data structure.


Ans. Non-Linear Data Structure:
The elements of a non-linear data structure are not connected in a sequence.
Each element can have multiple paths to connect to other elements. They
support multi-level storage and often cannot be traversed in single run.
Use:
Such data structures are difficult to implement but are more efficient in
utilizing computer memory.
Example:
Examples of non-linear data structures are Tree, Graphs etc.

Q11. Explain non-linear data structure and its types with the help of diagram.
Ans.
1. Tree:
This non-linear data structure is used to represent data containing a hierarchical
relationship between elements.
Representation:
Tree represents its elements as the nodes connected to each other by edges.
Root Node:
In each tree collection, we have one root node, which is the very first node
in our tree.
Parent Node:
In each tree collection, we have one root node, which is the very first node
in our tree.
Child Node:
The sub-connected node to the parent node is called child node. Each node
element may or may not have child node.
Binary Search Tree:
There is also a binary tree or binary search tree. A binary tree is a special data
structure used to store data in which each node can have a maximum of two
children.

5
Chapter# 1: Problem Solving and Algorithm Designing

2. Graph:
A graph is a non-linear data structure consisting of data elements called
nodes/vertices and edges that are lines that connect any two nodes in a graph.
In graph each node can have any number of edges, there is no any node
called root or child.
Use:
Graphs are used to solve network problems.
Examples:
Examples of networks include telephone networks, social networks like
Facebook, etc.
Types of graphs:
There are two types of graphs.
1. Undirected Graph:
In an undirected graph, nodes are connected by edges that are all bidirectional.
2. Directed Graph:
In a directed graph, nodes are connected by directed edges - they only go in
one direction.

You might also like