Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes DSA

Rating
-
Sold
-
Pages
2
Uploaded on
24-02-2023
Written in
2022/2023

This lecture is made in continuation with Part -1 [ • Lecture 3: If-Els... ], Please watch that before watching this.

Institution
Course

Content preview

Lecture 4: Solving Pattern Questions (Part-2)
We are going to solve 18 pattern questions in this video. In the last lecture,
we studied about the if else and while loop. We also did 2 pattern
questions. We are not able to find any relation but we know that it is simply
printing the counting So we can make a variable count , print it and then
increment it Let 's try to try this approach. This is the pattern which we
have to print now - Triangle pattern. We know that row = n. Also we can
notice that number of stars in a particular row is equal to the row number
which is 'i' Now let 's take a variable count=1 and we will print this count
and then increment it outside this loop. Outside this loop , we will enter a
new line and increment ' i' We will declare a variable inside this row loop
but outside the col loop. Then after printing it inside col loop , we will keep
on incrementing it by 1 There is an another method for this question But
first let 's write the code for this one We ca n't simply print row and
increment it , because then our program will misbehave. We just need to
think about the upper limit of row number and column number.



We have done 9 pattern questions. Let 's do some more questions to
understand this topic completely. Next pattern looks like this 1st obs - row
= n 2nd obs- A is mapped to 1 , B is mapping to 2 and so on. This time we
will run both loops from 1 to n because it is a square pattern. We got our
counting correct but just had to map 1 to ' A ' so to do so , we added ' A -1
on both sides , so to. do so. We just have to print ' A'+i -1 , but it will be
typecasted to integer so to avoid that. I will put this value inside a character
and then print it Then incremented col , added a new line outside the col
while loop and then incremented row too Simple You have to implement it
by yourself. Bhaiya: We have to find a relation for printing our answer. If
you are not able to do this question by yourself, then revise these first. We
can see their dependence on row number and col number. We know that it
is written in the reverse order. Also 'A ' will be there for sure. We will get
1

Written for

Institution
Course

Document information

Uploaded on
February 24, 2023
Number of pages
2
Written in
2022/2023
Type
Class notes
Professor(s)
J
Contains
1 to 4

Subjects

$33.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sameerchauhan

Get to know the seller

Seller avatar
sameerchauhan galgotia
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
4
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions