Posts

Time Complexity Analysis

Image
How to analyze Time Complexity?                        Running time of an algorithm depends upon multiple factors: Single vs Multiple Processors(It is using a single processor, then we cannot run our program parallelly) Read and write speed of the program to the memory or the disk. 32-bit vs 64-bit architecture Configuration of the machine Input Consider a Model Machine with: Single Processor 32 bit Sequential Execution 1 unit of time for arithmetic and logical operations 1 unit of time for assignment and return statements Let's define a function which calculates the sum of two numbers: sum(n1, n2):     return (a+b) Now, we know that 1 unit of time is taken for arithmetic operations and 1 unit of time for return statement. Therefore, irrespective of the inputs, the above program is executed in two units of time. Let's define a function which calculated the sum of the list: sum(list, n):     total = 0  ...

Python Problem Solving - Lonely Integer

Given an array of integers, where all elements but one occur twice, find the unique element. Solution: n  =  int ( input ()) array  =  list ( map ( int ,   input () . rstrip () . split ())) for   element   in   array :      count  =  array . count ( element )      if   count  ==  1 :          print ( element )

Python-HackerRank-String Formatting

def   print_formatted ( number ):      results  =  []      for   i   in   range ( 1 ,   n + 1 ):          decimal  =  str ( i )          octal  =  str ( oct ( i )[ 2 :])          hex_  =  str ( hex ( i )[ 2 :]) . upper ()          binary  =  str ( bin ( i )[ 2 :])          results . append ([ decimal ,   octal ,   hex_ ,   binary ])      # print(results)      width  =  len ( results [ -1 ][ 3 ])        # print(width) # largest binary number      for   i   in   results :          print (...

HackerRank Python Problem - String Validators

HackerRank Python Problem: Question: You are given a string S. Your task is to find out if the string S contains: alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters .  Solution: if  __ name__  ==  '__main__' :      s  =  input ()      print ( any ( i . isalnum ()   for   i   in   s ))      print ( any ( i . isalpha ()   for   i   in   s ))      print ( any ( i . isdigit ()   for   i   in   s ))      print ( any ( i . islower ()   for   i   in   s ))      print ( any ( i . isupper ()   for   i   in   s ))

HackerRank Problem - Python

 HackerRank Python Problem: Question: In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. Solution: def   count_substring ( string ,   sub_string ):      count  =  0      for   i   in   range ( len ( string )):          if   string [ i :] . startswith ( sub_string ):                  count  +=  1      return   count if  __ name__  ==  '__main__' :      string  =  input () . strip ()      sub_string  =  input () . strip ()           count  =  count_subst...

Python Syntax, Comments, Variables, Indentation

Execute Python Syntax As we learned in the past page, Python grammar can be executed by composing straightforwardly in the Command Line: >>> print("Hello, World!") Hello, World!  Or on the other hand by making a python record on the server, utilizing the .py document augmentation, and running it in the Command Line: C:\Users\ Your Name >python myfile.py  Python Indentation Space alludes to the spaces toward the start of a code line. Where in other programming dialects the space in code is for lucidness just, the space in Python is vital. Python utilizes space to show a square of code. if 5 > 2 :   print ( "Five is greater than two!" )   Python Variables In Python, factors are made when you relegate a worth to it: x = 5 y = "Hello, World!"   Python has no order for proclaiming a variable. Comments Python has remarking capacity with the end goal of in-code documentation. Remarks start with a #, and Python will deliver the remainder ...

Introduction to Python Programming

  Python is a well known programming language. It was made by Guido van Rossum, and delivered in 1991. It is utilized for:     web advancement (server-side),     programming advancement,     arithmetic,     framework prearranging. What else is there to do?     Python can be utilized on a server to make web applications.     Python can be utilized close by programming to make work processes.     Python can associate with information base frameworks. It can likewise peruse and alter documents.     Python can be utilized to deal with large information and perform complex arithmetic.     Python can be utilized for fast prototyping, or for creation prepared programming advancement. Why Python?     Python chips away at various stages (Windows, Mac, Linux, Raspberry Pi, and so on)     Python has a basic grammar like the Englis...

Python Problem- Find the Runner Up Score!!!

Problem Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.   Source Code n =  int ( input ()) list1 =  list ( map ( int , input () .strip () .split ()))[: n ] list2 =  list ( set ( list1 )) list2.sort ( reverse =  True ) x = list2 [ 1 ] print ( x )

Python-HackerRank Problem List Comprehensions

Problem Print a list of all possible coordinates given by (i,j,k) on a 3D grid where the sum of i+j+k is not equal to  n. Here, 0<=i<=x;0<=j<=y;0<=k<=z. Please use list comprehensions rather than multiple loops, as a learning exercise.  Source Code   if  __name__ ==  '__main__' :     x =  int ( input ())     y =  int ( input ())     z =  int ( input ())     n =  int ( input ())      print   ([[ a , b , c ]   for  a  in   range ( 0 , x+1 )   for  b  in   range ( 0 , y+1 )   for  c  in   range ( 0 , z+1 )     if  a + b + c != n  ])                 

Flip-Flop

Image
SR FLIP-FLOP The SR Flip-Flop is bistable device having 2 inputs Set and Reset. The Set input (S) sets the device or produces the output 1, and the Reset input (R) resets the device or produces the output 0.  The Reset input is used to get back the flip flop to its original state from the current state with an output Q. This output depends on the set and reset conditions, which is either at the logic level 0 or 1.  The NAND Gate SR FLIP-FLOP We can implement the SR Flip-Flop by using two cross-coupled 2-input NAND gates together. In the SR Flip-Flop, from each output to one of the NAND gate inputs, feedback is connected. So, the device has two inputs, S and R and two outputs Q and Q'. The NAND Gate SR Flip-Flop is a basic Flip-Flop which provides feedback from both of its output back to its opposing inputs. This circuit is used to store single data bit in the memory circuit.So, the SR Flip-Flop. So, the SR Flip-Flop has three inputs, S , R and the output Q. The output Q is rel...