Docsity

Data Structures: Intro, Arrays, Stacks, Queues, Linked Lists, Trees, Sorting, Hashing, Lecture notes of Data Structures and Algorithms

Toggle sidebar
bg1
Data Structures | Level 2 | Lab 1
1 | P a g e
Introduction to DS & Abstract Data Types
Data Structures Definition:
It is a particular way of storing and organizing data in a computer so that it can
be used efficiently.
Why to Learn Data Structures?
As applications are getting complex and data rich, there are three common
problems that applications face now-a-days.
Data Search − Consider an inventory of 1 million(106) items of a store.
If the application is to search an item, it has to search an item in 1
million(106) items every time slowing down the search. As data grows,
search will become slower.
Processor speed − Processor speed although being very high, falls
limited if the data grows to billion records.
Multiple requests − As thousands of users can search data
simultaneously on a web server, even the fast server fails while
searching the data.
IDE Used and Programming Language:
IDE Used: Visual Studio 2010
Programming Language: C++
Today Only Revision about C++ Programming Language (Stress on Arrays &
Struct) then Show them the Course Plan.
Check if they are understand well these points or not! (They already taught
them in Fundamentals of Structured Programming Course):
1- Data Types, Variables, Operations.
2- Selection Techniques (If Condition – Switch Case).
3- Looping (For Loop – While Loop – Do.. While Loop).
4- Functions.
5- Arrays.
pf3
pf4
pf5

Partial preview of the text

Download Data Structures: Intro, Arrays, Stacks, Queues, Linked Lists, Trees, Sorting, Hashing and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Introduction to DS & Abstract Data Types

Data Structures Definition:

It is a particular way of storing and organizing data in a computer so that it can

be used efficiently.

Why to Learn Data Structures?

As applications are getting complex and data rich, there are three common

problems that applications face now-a-days.

 Data Search − Consider an inventory of 1 million(10^6 ) items of a store.

If the application is to search an item, it has to search an item in 1

million(10^6 ) items every time slowing down the search. As data grows,

search will become slower.

 Processor speed − Processor speed although being very high, falls

limited if the data grows to billion records.

 Multiple requests − As thousands of users can search data

simultaneously on a web server, even the fast server fails while

searching the data.

IDE Used and Programming Language:

IDE Used: Visual Studio 2010

Programming Language: C++

Today Only Revision about C++ Programming Language (Stress on Arrays &

Struct) then Show them the Course Plan.

Check if they are understand well these points or not! (They already taught

them in Fundamentals of Structured Programming Course):

1- Data Types, Variables, Operations.

2- Selection Techniques (If Condition – Switch Case).

3- Looping (For Loop – While Loop – Do.. While Loop).

4- Functions.

5- Arrays.

Course Plan

1 - 1 - Course Specifications

Academic year / Level: 2 nd^ Specialization: Computer Science

Title: Data Structures Code: C 201

Lecture: 4 Tutorial: - Practical: 2 Total: 6 (Hour/week)

Week No. Lectures Practical

Chapter 1: Introduction 1.1 An introduction to data structure 1.2 A Philosophy of Data Structures 1.3 Abstract Data Types Revision (Functions - Arrays) 2 Chapter 2: Arrays 2.1 Declaring and Initializing Arrays 2.2 Accessing Array Elements 2.3 Multidimensional Arrays 2.4 Pointer to an Array 2.5 Passing Arrays to Functions 2.6 Return Array from functions Abstract Data Types 3 Chapter 3: Stacks 3.1 Operations performed on Stack 3.2 Stack Implementation 3.3 Stack using Arrays 3.4 Stack using Struct 3.5 Applications of Stacks 3.6 Summary Implementation of Struct 4 Chapter 4: Queues 4.1 Queue Implementation Implementation of Stack 5 4.2 Circular Queue 4.3 Circular Queue Implementation 4.4 Applications of Queues 4.5 Summary Implementation of Queue 6 Chapter 5: Linked List 5.1 Representation of Linked List 5.2 Operation on Linked List Implementation of Circular Queue 7 Chapter 5: Linked List 5.3 Singly Linked List 5.4 Linked Stacks Pointers and Dynamic Allocation

Definition of Struct:

is a group of data elements grouped together under one name. These data

elements, known as members, can have different types and different lengths.

  • A struct is a container with different data of different types.
  • It's a way of storing many data elements of different types under the same

name.

Example on simple struct

Differentiate between array & structure

Struct can contain array.

Ex: struct student { int id; char name[30]; int grades[6]; };

We can define array of struct

Ex:

student s[3];

Program #1: Struct

#include using namespace std; void main() { struct student { int id; char name[10]; }; student s; cout<<"Enter Student ID "; cin>>s.id; cout<<"Enter name"; cin>>s.name; cout<<"1 Student Found \n Student ID:"<<s.id<<"\n Student Name:"<<s.name<<endl; }

Program #2: Array of Struct

Write a program that represents the students’ data by name (char array),

id (int) and 6 grades. The user should input the data of 3 students (array

of struct), and then the program should output the sum of grades of each

student beside his name.

#include using namespace std; void main() { struct student { int id; char name[30]; int grades[6]; }; student s[3]; for(int i=0;i<3;i++) {