Professional Documents
Culture Documents
What is Stack:
A stack is a linear data structure in python in which addition and deletion of elements can be done at one
end only that is called TOP. A stack is known as LIFO (Last – In, First – Out) data structure in python.
Insertion in stack is also known as a PUSH operation. Deletion from stack is also known as POP operation
in stack.
L = len(st)
for i in range(L-1, -1, -1) : #to display in reverse order
print(st[i])
Underflow: It refers to situation when one tries to pop/delete an item from an empty stack or queue.
Example:
List=[]
List.pop()
What is Queue:
Queue is a data structures that is based on First In First Out (FIFO) strategy. Elements are added at one end
called Rear and removed from other end called Front. In a queue, one end is always used to insert data
(enqueue) and the other is used to delete data (dequeue), because queue is open at both its ends.
Operations on Queue:
Enqueue: In this a new element is added at the end of list called Rear.
Dequeue: In this an element is to be deleted from one end called Front.
Is empty: It is used to check whether the queue has any element or not. It is used to avoid underflow
condition while performing Dequeue operation.
Is full: It is used to check whether any more elements can be added to the queue or not, to avoid the
overflow condition while performing Enqueue operation.
Peek: It is used to view element at the front and back of the queue, without removing it from the queue.
We can do this by: list[0] or list[-1]
Working with Queue using List / Implementation of Queue using List:
Basic operations that we should know are :
1. How to create an empty Queue?
2. How to add elements to a Queue?
3. How to delete / remove elements from the Queue?
4. How to traverse or displaying elements of Queue?
5. How to check for empty Queue?
Stack Queue
Stack is a data structures that is based on Last In Queue is a data structures that is based on First In
First Out (LIFO) strategy. First Out (FIFO) strategy.
Insertion and deletion of elements can be done at Elements are added at one end called Rear and
one end only that id called TOP. removed from other end called Front.
Insertion in stack is also known as a PUSH Insertion in Queue is also known as a Enqueue
operation. Deletion from stack is also known as POP operation. Deletion from Queue is also known as
operation in stack. Dequeue operation in stack.
Important Questions for Exams For Video Lecture Click Here:
Q1. Write a function push(),pop() and display() to add a new student name, remove a student name and
to display student names in stack format, according to Data Structure in Python.
st=[ ]
def push():
sn=input("Enter name of student:")
st.append(sn)
print(st)
def pop():
if st==[]:
print("Stack is empty")
else:
print("Deleted student name :",st.pop())
def display():
if st==[]:
print("Stack is empty")
else:
for i in st[::-1]:
print(i)
Q2. Write a function Push() which to add in a stack named "MyStack". After calling push() three times, a
message should be displayed "Stack is Full"
st=[ ]
StackSize=3
def push():
sn=input("Enter name of student:")
if len(st)<StackSize:
st.append(sn)
else:
print("Stack is full!")
print(st)
Q3: Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform the following operations:
Push the keys (name of the student) of the dictionary into a stack, where the corresponding
value (marks) is greater than 75.
Pop and display the content of the stack.
def pop():
while True:
if st!=[]:
print(st.pop(),end=" ")
else:
break
Q4: Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the following operations based on this list.
Traverse the content of the list and push the even numbers into a stack.
Pop and display the content of the stack.
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
st=[]
def push():
for i in N:
if i%2==0:
st.append(i)
def pop():
while True:
if st!=[]:
print(st.pop(),end=" ")
else:
break
Q 5: Write a function push(l) to perform push opration in stack. Where a list is given:
L=[10,12,15,16,17,18,20,21,25]
Push only those element who is divisible by 5.
def push(l):
L2.append(l)
L2=[]
L1=[10,12,15,16,17,18,20,21,25]
for i in L1:
if i%5==0:
push(i)
print("Original List:\n",L1)
print("List after using push:\n",L2)
Q 6: Write a function Addvowel(l) to perform push opration in stack. Where a list is given:
L=[‘Ansh’,’Vipin’,’Ishan’,’Devesh’,’Om’,’Upashna’]
Push only those element who is started from vowels
def Addvowel(l):
L2.append(l)
L2=[]
L1=['Ansh','Vipin','Ishan','Devesh','Om','Upashna']
for i in L1:
if i[0] in 'aeiouAEIOU':
Addvowel(i)
print("Original List:\n",L1)
print("List after using push:\n",L2)
Chapter 7: Computer Networks (Part 1) For Video Lecture Click Here:
What is Computer Networks:
A computer network is a collection of interconnected computers and other devices to share data and
other resources ( hardware and software resource ) is called computer network.
Cost of setup and maintenance: It is very costly to set up larger network, cabling and equipment cost can
be expensive and maintenance cost may be very high for large networks.
Threat to data security: Hacking, data corruption, computer viruses, worms, malware, phishing etc, are
some of the threats to network security.
ARPANET: It is the first network and came into existence in 1969, The US department of defense formed
an agency named ARPANET (Advanced Research Projects Agency NETwork) to connect computers at
various universities and defense agencies. The main objective of ARPANET was to develop a network that
could continue to function efficiently even in the event of a nuclear attack.
NSFNET: In mid 80’s another federal agency, NSFNET (National Science Federation Network) created a
new network which was more capable than ARPANET. Its main aim was to use network only for
academic research and not for any kind of private business activity.
Internet: Later, many privately owned businesses with their very own private systems joined with
ARPANET and NSFNET to make more capable and wide network, the Internet. ARPANET + NSFNET +
PRIVATE NETWORKS = INTERNET. The internet is a globally connected network system that utilizes
TCP/IP to transmit information.
Following services are instantly available through internet : Email, Web-enabled audio/video
conferencing services, Online movies and gaming , Data transfer/file-sharing, Instant messaging , Internet
forums , Social networking , Online shopping ,Financial services.
Interspace: It is a client/server software program that allows multiple users to communicate online with
real –time audio, video and text chat in dynamic 3D environments.
IPv4 IPv6
IPv4 is a 32 bit address IPv6 is a 128 bit address.
IPv4 is the older version which has an space IPv6 is the new version can provide up to trillions of IP
of over 4 billion IP addresses. addresses.
Example: Example: 2001:0db8:0000:0000:0000:ff00:0042:7879
12.244.233.165
Chapter 7: Computer Networks (Part 2) For Video Lecture Click Here:
A thick coaxial cable does not bend easily and thus is difficult to install.
It is expensive as compared to Twisted pair cable.
3. Optical Fibre: An optical fibre consists of thin glass fibres that can carry information in the form of
visible light.
Advantage:
Disadvantage:
Advantage:
Disadvantage:
Advantage:
Disadvantages of Microwave
Disadvantage:
Satellite communication is very costly. So, it is not suitable for personal or low budget communication.
There is atmospheric loss of transmitted signals.
Bluetooth: is a wireless technology, which is used for exchanging data over short distances from fixed and
mobile devices. Such types of networks are categorized under personal area network.
Wifi: (wireless fidelity)Wi-Fi is a wireless networking technology that allows devices such as computers
(laptops and desktops), mobile devices and other equipment (printers and video cameras) to interface
with the Internet.
Wimax: It is a wireless communication system that provides broadband internet accessibility up to 30
miles. Such types of networks are categorized under MAN.
Network Devices:
Some Network devices are Modem, Ethernet card (NIC), RJ45, Repeater, Hub,
Switch, Router, Gateway, WIFI card, Bridge.
Modem:
Internal Modem: The modems that are fixed within the computer.
External Modem: The external modems that are connected externally to a
computer as other peripherals are connected.
RJ-45: (Registered Jack – 45) It is an eight wired connector that is used to connect
computers on a local area network (LAN), especially Ethernet cable.
NIC
NIC stands for Network Interface Card. It is also known as Ethernet Card.
This device helps the computer to connect to a network and
communicate.
It contain RJ-45 slot to connect Ethernet cable with RJ-45 connector.
HUB:
Bridge:
Gateway:
Repeater: A repeater is a device that amplifies and restore signals for long distance transmission.
Router:
Wi-Fi Card:
This is a small and portable cards that allows your computer to connect to the
internet through a wireless network.
Data transmission is through the radio waves, these signals are picked up by Wi-Fi
receivers such as computers and cell phones equipped with Wi-Fi cards.
Network Topology: The way or style of connecting several computer/devices in a network with each
other is called topology.
If there is fault or break in the main cable, the entire network shuts down.
Terminators are required at both ends of the backbone cable.
Fault isolation is difficult to detect if the entire network shuts down.
When the network is required in more the than one building, bus network cannot be used.
The signal becomes weaker if number of nodes becomes large.
Collision of data can take place because several nodes can transmit data to each other at one time.
Star Topology: In star topology, the server is directly connected with each and every node in the network
via a hub.
Advantages:
Disadvantages:
If there is a fault in a single node, it can cause the entire network to fail.
If there is a fault or break in cable, the entire network shut down.
For proper communication between each node, each computer must be turned on.
Tree Topology: The tree topology is an extension and
variation in bus topology. In this all or some of the devices
are connected to central hub, and some of the device are
connected to the secondary hub. In case of long distance
networking we use active hub, it contain repeaters that
makes weak signals stronger.
Advantage:
Disadvantage:
Multiple segment are connected to a central HUB. Its failure affects the entire network.
There is a requirement of long cable length.
Maintenance is not easy and cost is very high.
Network Types: On the basis of coverage or geographical spread, a network can be divided into following
types:
Network Protocol: A network protocol is an established set of rules that determine how data is
transmitted between different devices in the same network.
a) GSM (Global system for Mobile b) GPRS (General Packet Radio c) WLL (Wireless in Local Loop)
Communication) Services)
IP: The IP part handles the address of the destination computer so that the data is send to a correct
address.
HTTP (Hypertext Transfer Protocol): HTTP is the communication protocol for transferring of information
on the internet and the world wide web. When we access any website on internet HTTP protocol is
working in background. (http://www.google.com)
HTTPS (Hyper Text Transfer Protocol Secure): It is a standard protocol to secure the communication
between the browser and the web server. In HTTPS transferring of data is done in an encrypted format to
get protect data from hackers. (https://www.google.com)
Telnet: It is also known as Remote login. This protocol allows you to access a remote computer connected
on the network. Example: teamviewer, anydesk
FTP (File Transfer Protocol): FTP allows users to transfer files from one machine to another, like Uploading
and Downloading. Types of files may include program files, multimedia files, text files, and documents, etc.
POP3 (Post office protocol): POP3 is designed for receiving incoming E-mails.
SMTP ( Simple Mail Transfer Protocol ): It is used to for sending email messages to other computer. It
handle only out going messages and not incoming messages.
VoIP (Voice over Internet Protocol ) : This Protocol that allows you to make voice calls using a broadband
Internet connection instead of a regular (or analog) phone line.
PPP (Point to point Protocol): It is most commonly used data link protocol. It is a protocol used to
establish a direct connection between two nodes. It is used to connect the Home PC to the server of ISP by
telephone line. This communication takes place through high speed modem.
GSM (Global System for mobile Communication): GSM is a wireless communication medium that
provides the user with roaming facility, good voice quality, SMS, etc, through digital signals. It is also
known as 2G mobile technology.
GPRS (General Packet Radio Services): GPRS provides high speed data transfer. A user is allowed to
download video streaming, audio files, email messages, etc. It is also known as 2.5G Mobile technology.
WLL : WLL stands for Wireless in Local Loop. It provides user wireless phone facility to communicate with
each other.
HTML is a language that enables users to create WebPages and format them using
predefined tags. Tags are called coded elements.
HTML document can be written using text editor such as NOTEPAD and save in
.HTM or .HTML.
Some HTML tags are: <HTML>, <HEAD>, <BOBY>
XML (Extensible Markup Language):
XML is a text based markup language that allows the user to create their own tags to store data in a
structured format.
XML is designed to carry data and not to display data.
Domain Name:
Domain name is the address of your website that people type in the browser’s URL bar to visit your
website.
URL:
URL stands for Uniform Resource Locator which is a unique address of a webpage.
Website:
Web Browser:
A web browser is application software for accessing the World Wide Web. When a user requests a web
page from a particular website, the web browser retrieves the necessary content from a web server and
then displays the page on the user's device.
Web Server:
Web Hosting:
Web hosting is the place where all the files of your website live. It is like the home of our website where it
actually lives.
Mobile Telecommunication Technologies:
Features of 1G technology:
2G Technology: 2G Technology is the first digital cellular system that was launched
in the early 1990’s that provides high data transmission rate in digital format. 2G
also introduced data services for mobiles, starting with SMS. For example, D-
AMPS, GSM/GPRS, CDMA one.
Features of 2G technology:
Features of 3G technology:
Features of 4G technology:
What is Database:
Elimination of data redundancy: It removes duplication of data because data are kept at one place
and all the application refers to the centrally maintained database.
Sharing of data: Same database can be used by various platforms.
Manages large amounts of data: A database stores and manages a large amount of data on a daily
basis. This would not be possible using any other tool such as a spreadsheet.
Data is logically accurate: Through validation rule in database ,data accuracy can be maintained.
Easy to update data: In a database, it is easy to update data using various Data Manipulation
languages (DML) available. One of these languages is SQL.
Security of data: There are user logins required before accessing a database. It allows only
authorized users to access the database.
What is DBMS:
A DBMS refers to a software that is responsible for storing, maintaining and utilizing database in an
efficient way.
A Database along with DBMS software is called Database System.
Example of DBMS software are Oracle, MS SQL Server, MS Access, Paradox, DB2 and MySQL etc.
Advantages of DBMS or Need of DBMS or Importance of DBMS:
DBMS Model: Data model is a model or presentation which shows How data is organized ? or stored in the
database. Data models are categorized into four categories:
Keys in a Database:
Key plays an important role in relational database; it is used for identifying unique rows from table &
establishes relationship among tables on need.
Types of keys in DBMS:
Primary Key: A primary is a column or set of columns in a table that uniquely identifies tuples (rows) in
that table.
Candidate Key: A candidate key is one that is capable of becoming the primary key.
Alternate Key: Out of all candidate keys, only one gets selected as primary key, remaining keys are known
as alternate or secondary keys.
Foreign Key: Foreign keys are the columns of a table that points to the primary key of another table. They
act as a cross-reference between tables .
Chapter 9: SQL (Structured Query Language) For Video Lecture Click Here:
What is SQL:
SQL is a language that is used to create, modify and access a database. SQL is being used by many
database management systems. The SQL language was originally developed at the IBM research laboratory
in 1970. Some of them are: MySQL, PostgreSQL, Oracle, SQLite, Microsoft SQL Server.
MySQL: MySQL is an open-source and freely available Relational Database Management System (RDBMS)
that uses Structured Query Language (SQL). It provides excellent features for creating, storing, maintaining
and accessing data, from database.
Interactive Language : This language can be used for communicating with the databases and used
to manage database.
Portability : SQL is compatible with other database programs like Dbase IV, FoxPro, MS Access,
DB2, MS SQL Server, Oracle, Sybase, MySQL.
No coding needed : It is very easy to manage the database systems without any need to write the
substantial amount of code by using the standard SQL.
Not case-sensitive language : SQL is not a case-sensitive language, both capital and small letters
are recognized.
Types of SQL:
Chapter 9: SQL (Structured Query Language) Part 2 For Video Lecture Click Here:
3. Use: After database creation we can open the database using USE command.
Mysql> Use school;
4. Drop database: To physically remove or delete a database along with all its table, DROP command is
used.
Mysql> Drop database school;
9. DROP TABLE Command: To remove or delete any table permanently, DROP TABLE command is
used.
mysql> drop table student;
Chapter 9: SQL (Structured Query Language) Part 3 For Video Lecture Click Here:
2. We can insert data by specifies both the column names and the values to be inserted:
mysql> insert into student (rollno, name, gender, marks,dob)
values(2,NULL,'m',93,'2000-11-17');
12. Modifying data in table: The UPDATE command in SQL is used to modify data in table using the
WHERE clause and the new data is written in place of old data using the SET keyword.
1. To Update single or multiple columns:
mysql> update students set city="Fatehpur" where rollno=1;
13. Removing data from a table: The DELETE command in SQL is used to delete rows from a table using
WHERE clause.
delete from students2 where rollno=3;
14. Removing all data from a table: The TRUNCATE command in SQL is used to delete all rows from a table
free the space containing table.
truncate table students2;
Chapter 9: SQL (Structured Query Language) Part 4 For Video Lecture Click Here:
Constraints in MySQL:
4. Default Constraint:
Default constraint is used to assign the default value to a column, when user does not provide
any value.
However, if a user provide any value, then it will be overwrite.
5. Check Constraint:
The CHECK constraint ensures that all the values in a column satisfies certain conditions.
Chapter 9: SQL (Structured Query Language) Part 5 For Video Lecture Click Here:
Operators in MySQL:
There are mainly three types of operators in MySQL.
Arithmetic Operators: Arithmetic operators used to perform simple arithmetic operations like addition (+),
Subtraction (-), multiplication (*), division(/), Modulus (%).
Relational Operators:
Logical Operators:
The SQL logical operators are the operators used to combine multiple conditions and filter data on the
basis of the condition specified in an SQL statement. Logical operators are also known as Boolean
operators.
There are three types of operators are:
AND operators: The AND operator displays a record and returns a true if all conditions (usually two
conditions) specified in the WHERE clause are true.
Example: mysql> select * from emp where salary > 20000 and age < 25;
OR operators: The OR operator displays a record and returns a true if either of the conditions (usually two
conditions) specified in the WHERE clause is true.
Example: mysql> select * from emp where salary > 20000 or age > 25;
NOT operators: NOT operators is also termed as a negation operator. This operator takes only one
condition and gives the reverse of it as the result.
Example: mysql> select * from emp where not age > 22;
Between
This operator defines the range of values that the column values must fall into make the condition True.
The range includes both the upper Values as well as Lower Values.
Example: select * from emp where salary between 15000 and 20000;
Not Between
The NOT BETWEEN operators works opposite to the BETWEEN operators. It retrieves the rows which do
not satisfy the BETWEEN condition.
The range not includes both the upper Values as well as Lower Values.
Example: select * from emp where salary not between 15000 and 20000;
IN
This operator selects values that match any values in the given list. The SQL IN condition is used to help
reduce the need for multiple OR conditions in a SELECT statement.
Example: select * from emp where salary in (15000,20000,25000);
NOT IN
The NOT IN operators works opposite to IN operator. It matches, finds and returns the rows that do not
match the list.
Example: select * from emp where salary not in (15000,20000);
IS NULL
THE IS NULL is used to search for null values in a column.
mysql> select * from emp where salary is null;
IS NOT NULL
THE IS NOT NULL is used to search for not null values in a column.
Chapter 9: SQL (Structured Query Language) Part 6 For Video Lecture Click Here:
Like
The LIKE operators is used to search for a specified pattern in a column. This operator is used with the
columns of types CHAR and VARCHAR.
SQL provides two Wild Card Characters that are used while comparing the strings with LIKE operators:
Chapter 9: SQL (Structured Query Language) Part 7 For Video Lecture Click Here:
MAX(): Max() function is used to find the highest value among the given set of values of any column or
expression based on the column.
AVG(): AVG() function is used to find the average value of any column or expression based on column.
mysql> select avg(age) from emp;
COUNT(): COUNT() function is used to count the number of values in a column. COUNT() returns the
number of non-null values in that column. If the argument is asterisk (*) then count() counts the number
of records/rows including Null values.
mysql> select count(age) from emp;
mysql> select count(*) salary from emp;
mysql> select count(distinct age) from emp;
Chapter 9: SQL (Structured Query Language) Part 8 For Video Lecture Click Here:
ALIASES
SQL aliases are used to give an alternate name or temporary name, to a
column in a table. Name changes temporarily and does not changes the
actual name in the database. They are created to make column name
more readable.
For Column:
select name as "Employee name" from emp;
ORDER BY
The SQL ORDER BY clause is used to sort the data in ascending order or descending order based on one or
more columns. This clause sorts the records in the ascending order (ASC) by default. And in order to sort
the records in descending order, DESC keyword is to be used.
select * from emp order by age;
select * from emp order by age desc;
GROUP BY
The GROUP BY clause combines all those records that have identical values in a particular field.
Grouping can be done with aggregate functions, such as SUM, AVG, MAX, MIN, and COUNT.
HAVING clause
The purpose of HAVING clause with GROUP BY is to aggregate functions to be used along with the
specified condition because the aggregate functions are not allowed to be used with WHERE clause.
mysql> select stream, count(*) from student group by stream having count(*)>3;
SQL Joins: For Video Lecture Click Here:
SQL JOIN clause is used to combine rows from two or more tables, based on a common field between
them.
The types of SQL joins are as follows:
Equi Join
An Equi join is a simple SQL join condition that uses the equal to sign(=) as a comparison operator for
defining a relationship between two tables on the basis of common filed, primary key and foreign key.
Here, column with the same name appears two times.
mysql> select * from emp,dep where emp.d_no=dep.d_no;
or
mysql> select * from emp join dep on emp.d_no=dep.d_no;
Natural Join
The SQL Natural Join is a type of Equi Join and is structured in such a way that columns with the same
name of associated tables will appear only once.
In NATURAL JOIN, the join condition is not required, it automatically joins based on the common column
value.
mysql.connector. connect(): The connect() statement creates a connection to the Mysql server and return
a Mysql Connection object.
This function required four parameters: host, database, user and password.
mydb.is_connected(): This function is used to verify that our python application is connected to Mysql.
Here, mydb is Mysql Connection object.
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="123456")
print(mydb)
mydb.cursor():This function returns a cursor object. Using a cursor object, we can execute SQL queries.
Cursor object interact with the MySQL server using a Mysql Connection object.
execute():The execute() method accepts arguments of SQL statements in string format, enclosed in double
quotes(“ ”).
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="123456")
mycursor=mydb.cursor()
mycursor.execute("create database demo")
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="123456")
mycursor=mydb.cursor()
mycursor.execute("Show databases")
for i in mycursor:
print(i)
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="123456")
mycursor=mydb.cursor()
mycursor.execute("drop database demo")
Creating table inside any database through Python:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",password="123456",database="school")
mycursor=mydb.cursor()
mycursor.execute("create table std_details3(rno int primary key,name varchar(20), age int, city
varchar(20))")
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="123456",database="school")
mycursor=mydb.cursor()
mycursor.execute("alter table student add(city varchar(20))")
Chapter 10 : Interface of python with an SQL database (Part -2) For Video Lecture Click Here:
mycon.commit(): While working on insert, update and delete operation commit() is used to
show changes in table data.
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="123456",database="school")
mycursor=mydb.cursor()
mycursor.execute("delete from student where rno=2")
mydb.commit()
Chapter 10 : Interface of python with an SQL database (Part -3) For Video Lecture Click Here:
fetchone(): It fetch one record from the resultset as a tuple. First time, it will fetch the first record, next
time it will fetch the second record.
fetchmany(n): It fetches the specified number of rows from the result set. The defult size is 1.
rowcount: This is a read-only attribute and returns the number of rows that were affected by an execute()
method.
Chapter 10 : Interface of python with an SQL database (Part -4) For Video Lecture Click Here: