Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Reading Material

In
Data Structure and
Algorithm
(Part 1)

Prepared by:
Rodolfo G. Puyat III
IT FACULTY
WHAT IS DATA STRUCTURE:

A data structure is a group of data elements that provides the easiest way to store and perform different
actions on the data of the computer. A data structure is a particular way of organizing data in a computer
so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. 

The choice of a good data structure makes it possible to perform a variety of critical operations effectively.
An efficient data structure also uses minimum memory space and execution time to process the structure.

WHAT IS ALGORITHM

An algorithm is a procedure used for solving a problem or performing a computation. Algorithms act as an
exact list of instructions that conduct specified actions step by step in either hardware- or software-
based routines.

Algorithms are widely used throughout all areas of IT. In mathematics and computer science, an algorithm
usually refers to a small procedure that solves a recurrent problem. Algorithms are also used as
specifications for performing data processing and play a major role in automated systems.

An algorithm could be used for sorting sets of numbers or for more complicated tasks, like recommending
user content on social media. Algorithms typically start with initial input and instructions that describe a
specific computation. When the computation is executed, the process produces an output.

ARRAYS

Array in Data Structure

Arrays are defined as the collection of similar types of data items stored at contiguous memory locations.
It is one of the simplest data structures where each data element can be randomly accessed by using its
index number.

In C programming, they are the derived data types that can store the primitive type of data such as int,
char, double, float, etc. For example, if we want to store the marks of a student in 6 subjects, then we
don't need to define a different variable for the marks in different subjects. Instead, we can define an array
that can store the marks in each subject at the contiguous memory locations.

Properties of array

There are some of the properties of an array that are listed as follows -

o Each element in an array is of the same data type and carries the same size that is 4 bytes.

o Elements in the array are stored at contiguous memory locations from which the first element is
stored at the smallest memory location.

o Elements of the array can be randomly accessed since we can calculate the address of each
element of the array with the given base address and the size of the data element.

Representation of an array
We can represent an array in various ways in different programming languages. As an illustration, let's
see the declaration of array in C language -

As per the above illustration, there are some of the following important points -

o Index starts with 0.

o The array's length is 10, which means we can store 10 elements.

o Each element in the array can be accessed via its index.

STACK AND QUEUES

Stacks
 A stack is a linear data structure in which elements can be inserted and deleted only from one side of
the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at
the last is the first element to come out. The insertion of an element into the stack is
called push operation, and the deletion of an element from the stack is called  pop operation. In stack,
we always keep track of the last element present in the list with a pointer called top.
The diagrammatic representation of the stack is given below: 
Queues
Queue is a linear data structure in which elements can be inserted only from one side of the list
called rear, and the elements can be deleted only from the other side called the front. The queue data
structure follows the FIFO (First In First Out) principle, i.e. the element inserted at first in the list, is the
first element to be removed from the list. The insertion of an element in a queue is called
an enqueue operation and the deletion of an element is called a dequeue operation. In queue, we
always maintain two pointers, one pointing to the element which was inserted at the first and still
present in the list with the front pointer and the second pointer pointing to the element inserted at the
last with the rear pointer.
The diagrammatic representation of the queue is given below:
Difference between Stack and Queue Data Structures are as follows: 

Stacks Queues

Stacks are based on the LIFO principle, Queues are based on the FIFO principle, i.e., the element
i.e., the element inserted at the last, is inserted at the first, is the first element to come out of the
the first element to come out of the list. list.

Insertion and deletion in queues takes place from the


Insertion and deletion in stacks takes opposite ends of the list. The insertion takes place at the
place only from one end of the list rear of the list and the deletion takes place from the front
called the top. of the list.

Insert operation is called push


operation. Insert operation is called enqueue operation.

Delete operation is called pop


operation. Delete operation is called dequeue operation.

In stacks we maintain only one pointer In queues we maintain two pointers to access the list. The
to access the list, called the top, which front pointer always points to the first element inserted in
always points to the last element the list and is still present, and the rear pointer always
present in the list. points to the last inserted element.

Stack is used in solving problems works Queue is used in solving problems having sequential
on recursion. processing.
Stacks Queues

Queue is of three types – 1. Circular Queue 2. Priority


Stack does not have any types. queue 3. double-ended queue.

Can be considered as a vertical


collection visual. Can be considered as a horizontal collection visual.

References:

Difference between stack and queue data structures. GeeksforGeeks. (2022, July 14). Retrieved
from https://www.geeksforgeeks.org/difference-between-stack-and-queue-data-structures/
#:~:text=Queues,come%20out%20of%20the%20list.

DS array - javatpoint. www.javatpoint.com. (n.d.). Retrieved from https://www.javatpoint.com/data-


structure-array

Gillis, A. S. (2022, May 19). What is an algorithm? - definition from whatis.com. WhatIs.com.
Retrieved from https://www.techtarget.com/whatis/definition/algorithm

Introduction to data structures. GeeksforGeeks. (2022, August 4). Retrieved from


https://www.geeksforgeeks.org/introduction-to-data-structures/

You might also like